How do I verify pacts against an API that requires an auth token?

前端 未结 2 1623
不思量自难忘°
不思量自难忘° 2021-01-21 16:24

I\'m using the Pact gem (and loving it!) for my contract test suite. The API service I\'m testing requires an authorization token for all requests.

I know how to genera

2条回答
  •  醉梦人生
    2021-01-21 17:00

    The Ruby implementation of Pact doesn't support this directly as per the JVM implementation.

    If you're using the Pact Provider Proxy gem, you could take a look at some of the options discussed at https://github.com/realestate-com-au/pact/issues/49#issuecomment-65346357 and https://groups.google.com/forum/#!topic/pact-support/tSyKZMxsECk.

    An example might look something like:

    class ProxyApp
    
      def initialize real_app
        @real_app = real_app
      end
    
      def call env
        @real_app.call(env.merge('HTTP_AUTHORIZATION' => '12345'))
      end
    end
    
    Pact.service_provider "Some Provider" do
      app do
        ProxyApp.new(RealApp)
      end
    
      honours_pact_with "Some Consumer" do
        #...
      end
    end
    

提交回复
热议问题