Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publishing Results Using URI Sources Fails (Link/Resource was not found) #417

Closed
RobertGilmour opened this issue Sep 2, 2022 · 10 comments
Closed
Labels
bug Indicates an unexpected problem or unintended behavior

Comments

@RobertGilmour
Copy link
Contributor

Following on from Issue #392 (Support Publishing Results Using URI Sources). I'm still not getting publishing working on PactUrl set by the Pact Broker webhook.

When the contract verification fails I see the following log

Publishing of verification results failed with an error: Link/Resource was not found - Request to pact broker path '/pacticipants/MYPROVIDER' failed: 404 Not Found. URL: <url to contract in pact broker>

When the contract verification passes I don't see the logs the same way.

Trying that I get:

{
  "consumer": {
    "name": "MYCONSUMER"
  },
  "provider": {
    "name": "MYPROVIDER"
  },
  "interactions": [
    <omitted for brevity>
  ],
  "metadata": {
    "pactSpecification": {
      "version": "2.0.0"
    }
  },
  "createdAt": "2022-07-15T13:28:47+00:00",
  "_links": {
    "self": {
      "title": "Pact",
      "name": "Pact between MYCONSUMER (1.1.3) and MYPROVIDER",
      "href": "<base path obscured>/pacts/provider/MYPROVIDER/consumer/MYCONSUMER/version/1.1.3"
    },
    "pb:consumer": {
      "title": "Consumer",
      "name": "MYCONSUMER",
      "href": "<base path obscured>/pacticipants/MYCONSUMER"
    },
    "pb:consumer-version": {
      "title": "Consumer version",
      "name": "1.1.3",
      "href": "<base path obscured>/pacticipants/MYCONSUMER/versions/1.1.3"
    },
    "pb:consumer-versions": [
      {
        "title": "Consumer version",
        "name": "1.1.3",
        "href": "<base path obscured>/pacticipants/MYCONSUMER/versions/1.1.3"
      }
    ],
    "pb:provider": {
      "title": "Provider",
      "name": "MYPROVIDER",
      "href": "<base path obscured>/pacticipants/MYCONSUMER"
    },
    "pb:pact-version": {
      "title": "Pact content version permalink",
      "name": "0656cbf895ccf67d21811d64d586dfe812572362",
      "href": "<base path obscured>/pacts/provider/MYPROVIDER/consumer/MYCONSUMER/pact-version/0656cbf895ccf67d21811d64d586dfe812572362"
    },
    "pb:latest-pact-version": {
      "title": "Latest version of this pact",
      "href": "<base path obscured>/pacts/provider/MYPROVIDER/consumer/MYCONSUMER/latest"
    },
    "pb:all-pact-versions": {
      "title": "All versions of this pact",
      "href": "<base path obscured>/pacts/provider/MYPROVIDER/consumer/MYCONSUMER/versions"
    },
    "pb:latest-untagged-pact-version": {
      "title": "Latest untagged version of this pact",
      "href": "<base path obscured>/pacts/provider/MYPROVIDER/consumer/MYCONSUMER/latest-untagged"
    },
    "pb:latest-tagged-pact-version": {
      "title": "Latest tagged version of this pact",
      "href": "<base path obscured>/pacts/provider/MYPROVIDER/consumer/MYCONSUMER/latest/{tag}",
      "templated": true
    },
    "pb:previous-distinct": {
      "title": "Previous distinct version of this pact",
      "href": "<base path obscured>/pacts/provider/MYPROVIDER/consumer/MYCONSUMER/version/1.1.3/previous-distinct"
    },
    "pb:diff-previous-distinct": {
      "title": "Diff with previous distinct version of this pact",
      "href": "<base path obscured>/pacts/provider/MYPROVIDER/consumer/MYCONSUMER/version/1.1.3/diff/previous-distinct"
    },
    "pb:diff": {
      "title": "Diff with another specified version of this pact",
      "href": "<base path obscured>/pacts/provider/MYPROVIDER/consumer/MYCONSUMER/pact-version/0656cbf895ccf67d21811d64d586dfe812572362/diff/pact-version/{pactVersion}",
      "templated": true
    },
    "pb:pact-webhooks": {
      "title": "Webhooks for the pact between MYCONSUMER and MYPROVIDER",
      "href": "<base path obscured>/webhooks/provider/MYPROVIDER/consumer/MYCONSUMER"
    },
    "pb:consumer-webhooks": {
      "title": "Webhooks for all pacts with provider MYPROVIDER",
      "href": "<base path obscured>/webhooks/consumer/MYPROVIDER"
    },
    "pb:tag-prod-version": {
      "title": "PUT to this resource to tag this consumer version as 'production'",
      "href": "<base path obscured>/pacticipants/MYCONSUMER/versions/1.1.3/tags/prod"
    },
    "pb:tag-version": {
      "title": "PUT to this resource to tag this consumer version",
      "href": "<base path obscured>/pacticipants/MYCONSUMER/versions/1.1.3/tags/{tag}"
    },
    "pb:publish-verification-results": {
      "title": "Publish verification results",
      "href": "<base path obscured>/pacts/provider/MYPROVIDER/consumer/MYCONSUMER/pact-version/0656cbf895ccf67d21811d64d586dfe812572362/metadata/Y3ZuPTEuMS4zJnc9dHJ1ZQ/verification-results"
    },
    "pb:latest-verification-results": {
      "href": "<base path obscured>/pacts/provider/MYPROVIDER/consumer/MYCONSUMER/pact-version/0656cbf895ccf67d21811d64d586dfe812572362/verification-results/latest"
    },
    "pb:triggered-webhooks": {
      "title": "Webhooks triggered by the publication of this pact",
      "href": "<base path obscured>/pacts/provider/MYPROVIDER/consumer/MYCONSUMER/version/1.1.3/triggered-webhooks"
    },
    "pb:matrix-for-consumer-version": {
      "title": "View matrix rows for the consumer version to which this pact belongs",
      "href": "<base path obscured>/matrix?q[][pacticipant]=MYCONSUMER&q[][version]=1.1.3&latestby=cvpv"
    },
    "curies": [
      {
        "name": "pb",
        "href": "<base path obscured>/doc/{rel}?context=pact",
        "templated": true
      }
    ]
  }
}

My code:

var pactVerifier = new PactVerifier(config)
    .ServiceProvider(_pactOptions.ProviderName, ServerAddress);

IPactVerifierSource pactVerifierWithSource;

// when verification triggered by consumer contract changed webhook
if (_pactOptions.IsVerifyingSpecificPact) 
{
    pactVerifierWithSource = pactVerifier.WithUriSource(new Uri(_pactOptions.PactUrl!), options =>
    {
        options.BasicAuthentication(_pactOptions.BrokerUsername, _pactOptions.BrokerPassword);
        options.PublishResults(_pactOptions.ShouldPublishResults, _pactOptions.ProviderVersion,
            publishOptions => { publishOptions.ProviderBranch(_pactOptions.ProviderBranch); });
    });
}
// when triggered by testing provider
else 
{
    pactVerifierWithSource = pactVerifier.WithPactBrokerSource(new Uri(_pactOptions.BrokerBaseUrl!),
        options =>
        {
            options.BasicAuthentication(_pactOptions.BrokerUsername, _pactOptions.BrokerPassword);
            options.EnablePending();
            options.ConsumerVersionSelectors(
                new ConsumerVersionSelector { Environment = "test" },
                new ConsumerVersionSelector { Branch = "dev" });  
            options.PublishResults(_pactOptions.ShouldPublishResults, _pactOptions.ProviderVersion,
                publishOptions => { publishOptions.ProviderBranch(_pactOptions.ProviderBranch); });
        });
}

// Act / Assert
pactVerifierWithSource
    .WithSslVerificationDisabled()
    .WithProviderStateUrl(new Uri(ServerAddress, "/providerStates"))
    .Verify();
@adamrodger
Copy link
Contributor

Yeah the code looks fine to me, so this is most likely a bug in the FFI library. Tagging in @uglyog and @mefellows

@adamrodger adamrodger added bug Indicates an unexpected problem or unintended behavior upstream labels Sep 3, 2022
@rholshausen
Copy link

Ok, I'll have a look and see if I can spot what is going on

@rholshausen
Copy link

That is getting a Request to pact broker path '/pacticipants/MYPROVIDER' failed: 404 Not Found, so it looks like the request to fetch the Pact from the provided URL is not found. Can you confirm that the URL used is correct?

If you set logging to DEBUG (or TRACE which will be very verbose), you should see the requests being made to the broker.

@RobertGilmour
Copy link
Contributor Author

RobertGilmour commented Sep 5, 2022

Hello,

Hopefully this is enough detail

2022-09-05T07:46:24.584654Z  INFO ThreadId(01) pactffi_verifier_execute{handle=0x7f75fc00a180}: pact_verifier: Publishing verification results back to the Pact Broker
2022-09-05T07:46:24.584659Z DEBUG ThreadId(01) pactffi_verifier_execute{handle=0x7f75fc00a180}: pact_verifier: Publishing a failure result to PactBroker(https://<obscurred for github>/pacts/provider/MYPROVIDER/consumer/MYCONSUMER/pact-version/e70404d86b915fb60c2f2892fb044eaf5266ec96/metadata/Y3ZuPWU5MTE2NGQzZWRiNyZ3PXRydWU, provider_name='MYPROVIDER')
2022-09-05T07:46:24.585456Z TRACE ThreadId(01) pactffi_verifier_execute{handle=0x7f75fc00a180}: pact_verifier::pact_broker: navigate(link='pb:provider', template_values={})
2022-09-05T07:46:24.585471Z TRACE ThreadId(01) pactffi_verifier_execute{handle=0x7f75fc00a180}: pact_verifier::pact_broker: fetch_link(link='pb:provider', template_values={})
2022-09-05T07:46:24.585476Z TRACE ThreadId(01) pactffi_verifier_execute{handle=0x7f75fc00a180}: pact_verifier::pact_broker: fetch_url(link=Link { name: "pb:provider", href: Some("https://<obscurred for github>/pacticipants/MYPROVIDER"), templated: false, title: Some("Provider") }, template_values={})
2022-09-05T07:46:24.585521Z  INFO ThreadId(01) pactffi_verifier_execute{handle=0x7f75fc00a180}: pact_verifier::pact_broker: Fetching path '/pacticipants/MYPROVIDER' from pact broker
reqwest::async_impl::client: response '404 Not Found' for https://<obscurred for github>/pacts/provider/MYPROVIDER/consumer/MYCONSUMER/pact-version/e70404d86b915fb60c2f2892fb044eaf5266ec96/metadata/Y3ZuPWU5MTE2NGQzZWRiNyZ3PXRydWU/pacticipants/MYPROVIDER    
2022-09-05T07:46:24.965806Z TRACE ThreadId(01) pactffi_verifier_execute{handle=0x7f75fc00a180}: pact_verifier::utils: with_retries: attempt 2/3 is Ok(Response { url: Url { scheme: "https", cannot_be_a_base: false, username: "", password: None, host: Some(Domain("<obscurred for github>")), port: None, path: "/pacts/provider/MYPROVIDER/consumer/MYCONSUMER/pact-version/e70404d86b915fb60c2f2892fb044eaf5266ec96/metadata/Y3ZuPWU5MTE2NGQzZWRiNyZ3PXRydWU/pacticipants/MYPROVIDER", query: None, fragment: None }, status: 404, headers: {"vary": "Accept", "content-type": "application/hal+json;charset=utf-8", "x-pact-broker-version": "2.102.2", "x-content-type-options": "nosniff", "date": "Mon, 05 Sep 2022 07:46:24 GMT"} })
2022-09-05T07:46:24.965999Z ERROR ThreadId(01) pactffi_verifier_execute{handle=0x7f75fc00a180}: pact_verifier: Publishing of verification results failed with an error: Link/Resource was not found - Request to pact broker path '/pacticipants/MYPROVIDER' failed: 404 Not Found. URL: 'https://<obscurred for github>/pacts/provider/MYPROVIDER/consumer/MYCONSUMER/pact-version/e70404d86b915fb60c2f2892fb044eaf5266ec96/metadata/Y3ZuPWU5MTE2NGQzZWRiNyZ3PXRydWU'

The URLs all look fine to me, except it perhaps adding /pacticipants/MYPROVIDER onto the end of the pact URL that was sent by the webhook. Calling GET to this returns 404 for me. I think I would have expected it to end with /verification-results i.e. https://<obscurred for github>/pacts/provider/MYPROVIDER/consumer/MYCONSUMER/pact-version/e70404d86b915fb60c2f2892fb044eaf5266ec96/metadata/Y3ZuPWU5MTE2NGQzZWRiNyZ3PXRydWU/verification-results then POST the results there.

https://<obscurred for github>/pacts/provider/MYPROVIDER/consumer/MYCONSUMER/pact-version/e70404d86b915fb60c2f2892fb044eaf5266ec96/metadata/Y3ZuPWU5MTE2NGQzZWRiNyZ3PXRydWU is correct (i.e. returns 200 and the pact being verified)

@rholshausen
Copy link

Thanks for the logs, let me try replicate it. It should be using the links to make the request, so maybe there is a bug with how it handles that.

@rholshausen
Copy link

Confirmed. It is a bug when trying to publish the provider branch before the actual verification results.

@mefellows
Copy link
Member

mefellows commented Sep 6, 2022

Thanks Ron! We seem to have a similar report for Pact JS: https://pact-foundation.slack.com/archives/C9VBGLUM9/p1662460775969709. I'll let them know.

@rholshausen
Copy link

I've released Pact FFI Library 0.3.11 with a fix for this

@mefellows
Copy link
Member

Thanks Ron - releasing a new version of the core now for Pact JS.

@adamrodger
Copy link
Contributor

Fixed in #418

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

4 participants