@@ -105,6 +105,20 @@ def thing(id:)
105105 def crash
106106 raise "Crash the query"
107107 end
108+
109+ class SecretInput < GraphQL ::Schema ::InputObject
110+ argument :password , String
111+ end
112+
113+ field :secret_field , String do
114+ argument :cipher , String , required : false
115+ argument :password , String , required : false
116+ argument :input , [ [ SecretInput ] ] , required : false
117+ end
118+
119+ def secret_field ( cipher : nil , password : nil , input : nil )
120+ cipher || password || input [ 0 ] [ 0 ] [ :password ]
121+ end
108122 end
109123
110124 query ( Query )
@@ -159,6 +173,43 @@ def self.detailed_trace?(q)
159173 check_snapshot ( data , "example-rails-#{ Rails ::VERSION ::MAJOR } -#{ Rails ::VERSION ::MINOR } .json" )
160174 end
161175
176+ it "filters params with ActiveSupport" do
177+ query_str = 'query getStuff { secretField(cipher: "abcdef") }'
178+ res = PerfettoSchema . execute ( query_str , validate : false )
179+ json = res . context . query . current_trace . write ( file : nil , debug_json : true )
180+ assert_includes json , "abcdef"
181+ refute_includes json , "FILTERED"
182+
183+ prev_fp = ActiveSupport . filter_parameters
184+ ActiveSupport . filter_parameters = [ "cipher" ]
185+ res = PerfettoSchema . execute ( query_str )
186+ json = res . context . query . current_trace . write ( file : nil , debug_json : true )
187+ refute_includes json , "abcdef"
188+ assert_includes json , "[FILTERED]"
189+
190+ ActiveSupport . filter_parameters = [ "password" ]
191+ res = PerfettoSchema . execute ( 'query getStuff { secretField(input: [[{ password: "jklmn" }]]) }' )
192+ json = res . context . query . current_trace . write ( file : nil , debug_json : true )
193+ refute json . include? ( "jklmn" ) , "Value is removed"
194+ assert_includes json , "[FILTERED]"
195+ ensure
196+ ActiveSupport . filter_parameters = prev_fp
197+ end
198+
199+ it "filters params without ActiveSupport" do
200+ query_str = 'query getStuff { secretField(password: "qrstuv") }'
201+ res = PerfettoSchema . execute ( query_str , context : { detailed_trace_filter : GraphQL ::Tracing ::PerfettoTrace ::ArgumentsFilter . new } )
202+ json = res . context . query . current_trace . write ( file : nil , debug_json : true )
203+ assert_includes json , "[FILTERED]"
204+ refute_includes json , "qrstuv"
205+
206+ query_str = 'query getStuff { secretField(input: [[{ password: "lmnop" }]]) }'
207+ res = PerfettoSchema . execute ( query_str , context : { detailed_trace_filter : GraphQL ::Tracing ::PerfettoTrace ::ArgumentsFilter . new } )
208+ json = res . context . query . current_trace . write ( file : nil , debug_json : true )
209+ refute json . include? ( "lmnop" ) , "The password is obscured"
210+ assert json . include? ( "[FILTERED]" ) , "The replacement string is present"
211+ end
212+
162213 it "provides an error when google-protobuf isn't available" do
163214 stderr_and_stdout , _status = Open3 . capture2e ( %|ruby -e 'require "bundler/inline"; gemfile(true) { source("https://rubygems.org"); gem("graphql", path: "./") }; class MySchema < GraphQL::Schema; trace_with(GraphQL::Tracing::PerfettoTrace); end;'| )
164215 assert_includes stderr_and_stdout , "GraphQL::Tracing::PerfettoTrace can't be used because the `google-protobuf` gem wasn't available. Add it to your project, then try again."
0 commit comments