Hi, everyone. I am using Pact docker CLI `verify`...
# pact-ruby
i
Hi, everyone. I am using Pact docker CLI
verify
for verifying my provider, Pactflow is a broker. Issue is that I need to pass valid ID to graphql request variable on the fly. This situation described here: https://docs.pact.io/provider/handling_auth#4-modify-the-request-to-use-real-credentials. So I have such request body:
{ "query": "....", "variables": { "ID": "placeholder" } }
, so I need to replace placeholder with real ID. I know that
--custom-middleware
option stands for this, but I am complete newb in Ruby, could you, please, provide some examples, or appropriate reading for my level, to understand the topic and be able to implement it?
After some reading, such
custom_middleware.rb
seems working:
Copy code
class AddCustomAuth < Pact::ProviderVerifier::CustomMiddleware
    def initialize app
      @app = app
    end
  
    def call env
      body_string = env['rack.input'].read
      new_body_string = body_string.sub("placeholder", "realID")
      new_body_io = StringIO.new(new_body_string)
      env['rack.input'] = new_body_io
      @app.call(env)
    end
  end
realID is going to comes from file.