Vaidas Sieber
04/20/2023, 2:10 PM$config = new VerifierConfig();
$config
->header('headers' => ['Authorization' => 'Bearer <value>'])
->setRequestFilter(
function (RequestInterface $r) {
return $r->withHeader('Authorization', 'Bearer <value>');
}
);
Matt (pactflow.io / pact-js / pact-go)
Vaidas Sieber
04/21/2023, 5:36 AMpublic function testPactVerifyConsumer() {
$config = new VerifierConfig();
$config
->setProviderName('Provider')
->setProviderVersion('1.0.0')
->setProviderBaseUrl(new Uri('<http://localhost:8081>'))
->setBrokerUri(new Uri('<http://localhost:9292>'))
// not working ->header('headers' => ['Authorization' => 'Bearer <value>'])
/* not working ->setRequestFilter(
function (RequestInterface $r) {
return $r->withHeader('Authorization', 'Bearer <value>');
}
);*/
;
$verifier = new Verifier($config);
// not working $verifier->setAdditionalRequestHeaders(['Authorization' => 'Bearer <value>'])
$verifier->verifyFiles([__DIR__ . '/../../../pacts/*.json']);
$this->assertTrue(true, 'Pact Verification has failed.');
}
Vaidas Sieber
04/21/2023, 6:01 AMuse GuzzleHttp\Psr7\Uri;
use PhpPact\Standalone\ProviderVerifier\Model\VerifierConfig;
use PhpPact\Standalone\ProviderVerifier\Verifier;
use PhpPact\Standalone\Runner\ProcessRunner;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\RequestInterface;
public function testPactVerifyConsumer() {
$config = new VerifierConfig();
$config
->setProviderName('Provider')
->setProviderVersion('1.0.0')
->setProviderBaseUrl(new Uri('<http://localhost:8081>'))
->setBrokerUri(new Uri('<http://localhost:9292>'))
->setRequestFilter(
function (RequestInterface $r) {
$authHeader = ['Authorization' => 'Bearer <value>'];
return $r->withHeader($authHeader);
}
);
;
$verifier = new Verifier($config);
$verifier->verifyFiles([__DIR__ . '/../../../pacts/*.json']);
$this->assertTrue(true, 'Pact Verification has failed.');
}
Vaidas Sieber
04/21/2023, 6:57 AMMatt (pactflow.io / pact-js / pact-go)
Vaidas Sieber
04/21/2023, 9:17 AMI, [2023-04-21T09:14:13.465219 #48] INFO -- : Running example 'Verifying a pact between Consumer and Provider A request for a clients list with GET /api/clients returns a response which has status code 200'
I, [2023-04-21T09:14:13.468601 #48] INFO -- : Sending GET request to path: "/api/clients" with headers: {}, see debug logs for body
D, [2023-04-21T09:14:13.469643 #48] DEBUG -- : body :
I, [2023-04-21T09:14:15.490512 #48] INFO -- : Received response with status: 401, headers: {"Content-Type"=>"application/json", "Connection"=>"keep-alive", "Www-Authenticate"=>"Bearer", "Cache-Control"=>"no-cache, private", "Date"=>"Fri, 21 Apr 2023 09:14:14 GMT", "Link"=>"<<http://localhost:8081/api/docs.jsonld>>; rel=\"<http://www.w3.org/ns/hydra/core#apiDocumentation>\"", "X-Debug-Token"=>"3afd26", "X-Debug-Token-Link"=>"<http://localhost:8081/api/_profiler/3afd26>", "X-Robots-Tag"=>"noindex", "Content-Length"=>"44"}, see debug logs for body
D, [2023-04-21T09:14:15.491504 #48] DEBUG -- : body: {"code":401,"message":"JWT Token not found"}
->setVerbose(true)
same output
Vaidas Sieber
04/21/2023, 10:06 AM->addCustomProviderHeader('Authorization', 'Bearer <value>')
Which I found here in line 41: https://github.com/pact-foundation/pact-php/blob/master/tests/PhpPact/Standalone/ProviderVerifier/VerifierTest.php.Matt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)