Ivan Mikhalka
03/05/2023, 10:57 PMverify
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?Ivan Mikhalka
03/06/2023, 2:06 AMcustom_middleware.rb
seems working:
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.