Hello everyone, everything good? I have the follow...
# pact-broker
c
Hello everyone, everything good? I have the following problem, when I enable the user and password configuration in broke when I go to pact-broker with user and password I get error 400 and when I disable the user and password in the dokerfile and everything goes correctly, has anyone experienced this ?
Copy code
environment:
      SSL_CERT_FILE: /Users/charlan.bettiol/Documents/certificados/_.livelo.intranet.cer
      PACT_BROKER_PORT: '9292'
      PACT_BROKER_DATABASE_URL: "<postgres://postgres:password@postgres/postgres>"
      PACT_BROKER_LOG_LEVEL: DEBUG
      PACT_BROKER_LOG_FORMAT: color
      PACT_BROKER_SQL_LOG_LEVEL: DEBUG
      PACT_BROKER_HTTP_DEBUG_LOGGING_ENABLED: true
      PACT_BROKER_DISABLE_SSL_VERIFICATION: true
      PACT_BROKER_BASIC_AUTH_ENABLED: true
      PACT_BROKER_BASIC_AUTH_USERNAME: teste
      PACT_BROKER_BASIC_AUTH_PASSWORD: 1234
command:
pact-broker list_environments -b <http://localhost:9292> --broker-username=teste --broker-password=1234
j
Just to double check, are you able to access the Pact Broker by pointing your browser to
<http://localhost:9292>
? It should prompt you for a username and password if you have basic auth enabled. You can also test this with
curl <http://user:pass@localhost:9292>
c
yes I can do it in the browser it asks for username and password
j
How very strange. Is it just the
pact-broker list-environments
endpoint that isn't working?
c
its works, i try this
pact-broker publish ${PWD}/target/pacts --consumer-app-version ${VERSION} --branch ${BRANCH} --broker-base-url <http://localhost:9292> -u teste -p 1234
and i have a same problem
pact-broker publish ${PWD}/target/pacts --consumer-app-version ${VERSION} --branch ${BRANCH} --broker-base-url <http://localhost:9292> -u teste -p 1234 -v
output:
Copy code
opening connection to localhost:9292...
opened
<- "GET /? HTTP/1.1\r\nAccept: application/hal+json\r\nUser-Agent: Ruby\r\nAuthorization: [redacted]\r\n"
-> "HTTP/1.1 200 OK\r\n"
-> "Vary: Accept\r\n"
-> "Content-Type: application/hal+json;charset=utf-8\r\n"
-> "Date: Wed, 10 Apr 2024 21:07:02 GMT\r\n"
-> "Server: Webmachine-Ruby/2.0.0 Rack/1.3\r\n"
-> "X-Pact-Broker-Version: 2.107.1\r\n"
-> "X-Content-Type-Options: nosniff\r\n"
-> "Content-Length: 4300\r\n"
-> "\r\n"
reading 4300 bytes...
-> "{\"_links\":{\"self\":{\"href\":\"<http://localhost:9292>\",\"title\":\"Index\",\"templated\":false},\"pb:publish-pact\":{\"href\":\"<http://localhost:9292/pacts/provider/{provider}/consumer/{consumer}/version/{consumerApplicationVersion}>\",\"title\":\"Publish a pact\",\"templated\":true},\"pb:publish-contracts\":{\"href\":\"<http://localhost:9292/contracts/publish>\",\"title\":\"Publish contracts\",\"templated\":false},\"pb:latest-pact-versions\":{\"href\":\"<http://localhost:9292/pacts/latest>\",\"title\":\"Latest pact versions\",\"templated\":false},\"pb:tagged-pact-versions\":{\"href\":\"<http://localhost:9292/pacts/provider/{provider}/consumer/{consumer}/tag/{tag}>\",\"title\":\"All versions of a pact for a given consumer, provider and consumer version tag\",\"templated\":false},\"pb:pacticipants\":{\"href\":\"<http://localhost:9292/pacticipants>\",\"title\":\"Pacticipants\",\"templated\":false},\"pb:pacticipant\":{\"href\":\"<http://localhost:9292/pacticipants/{pacticipant}>\",\"title\":\"Fetch pacticipant by name\",\"templated\":true},\"pb:latest-provider-pacts\":{\"href\":\"<http://localhost:9292/pacts/provider/{provider}/latest>\",\"title\":\"Latest pacts by provider\",\"templated\":true},\"pb:latest-provider-pacts-with-tag\":{\"href\":\"<http://localhost:9292/pacts/provider/{provider}/latest/{tag}>\",\"title\":\"Latest pacts for provider with the specified tag\",\"templated\":true},\"pb:provider-pacts-with-tag\":{\"href\":\"<http://localhost:9292/pacts/provider/{provider}/tag/{tag}>\",\"title\":\"All pact versions for the provider with the specified consumer version tag\",\"templated\":true},\"pb:provider-pacts\":{\"href\":\"<http://localhost:9292/pacts/provider/{provider}>\",\"title\":\"All pact versions for the specified provider\",\"templated\":true},\"pb:latest-version\":{\"href\":\"<http://localhost:9292/pacticipants/{pacticipant}/latest-version>\",\"title\":\"Latest pacticipant version\",\"templated\":true},\"pb:latest-tagged-version\":{\"href\":\"<http://localhost:9292/pacticipants/{pacticipant}/latest-version/{tag}>\",\"title\":\"Latest pacticipant version with the specified tag\",\"templated\":true},\"pb:webhooks\":{\"href\":\"<http://localhost:9292/webhooks>\",\"title\":\"Webhooks\",\"templated\":false},\"pb:webhook\":{\"href\":\"<http://localhost:9292/webhooks/{uuid}>\",\"title\":\"Webhook\",\"templated\":true},\"pb:integrations\":{\"href\":\"<http://localhost:9292/integrations>\",\"title\":\"Integrations\",\"templated\":false},\"pb:pacticipant-version-tag\":{\"href\":\"<http://localhost:9292/pacticipants/{pacticipant}/versions/{version}/tags/{tag}>\",\"title\":\"Get, create or delete a tag for a pacticipant version\",\"templated\":true},\"pb:pacticipant-branch-version\":{\"href\":\"<http://localhost:9292/pacticipants/{pacticipant}/branches/{branch}/versions/{version}>\",\"title\":\"Get or add/create a pacticipant version for a branch\",\"templated\":true},\"pb:pacticipant-version\":{\"href\":\"<http://localhost:9292/pacticipants/{pacticipant}/versions/{version}>\",\"title\":\"Get, create or delete a pacticipant version\",\"templated\":true},\"pb:metrics\":{\"href\":\"<http://localhost:9292/metrics>\",\"title\":\"Get Pact Broker metrics\"},\"pb:can-i-deploy-pacticipant-version-to-tag\":{\"href\":\"<http://localhost:9292/can-i-deploy?pacticipant={pacticipant}&version={version}&to={tag}>\",\"title\":\"Determine if an application version can be safely deployed to an environment identified by the given tag\",\"templated\":true},\"pb:can-i-deploy-pacticipant-version-to-environment\":{\"href\":\"<http://localhost:9292/can-i-deploy?pacticipant={pacticipant}&version={version}&environment={environment}>\",\"title\":\"Determine if an application version can be safely deployed to an environment\",\"templated\":true},\"pb:provider-pacts-for-verification\":{\"href\":\"<http://localhost:9292/pacts/provider/{provider}/for-verification>\",\"title\":\"Pact versions to be verified for the specified provider\",\"templated\":true},\"beta:provider-pacts-for-verification\":{\"name\":\"beta\",\"href\":\"<http://localhost:9292/pacts/provider/{provider}/for-verification>\",\"title\":\"DEPRECATED - please use pb:provider-pacts-for-verification\",\"templated\":true},\"curies\":[{\"name\":\"pb\",\"href\":\"<http://localhost:9292/doc/{rel}?context=index>\",\"templated\":true},{\"name\":\"beta\",\"href\":\"<http://localhost:9292/doc/{rel}?context=index>\",\"templated\":true}],\"pb:environments\":{\"title\":\"Environments\",\"href\":\"<http://localhost:9292/environments>\",\"templated\":false},\"pb:environment\":{\"title\":\"Environment\",\"href\":\"<http://localhost:9292/environments/{uuid}>\",\"templated\":true}}}"
read 4300 bytes
Conn keep-alive
opening connection to localhost:9292...
opened
<- "POST /contracts/publish HTTP/1.1\r\nAccept: application/hal+json\r\nUser-Agent: Ruby\r\nContent-Type: application/json\r\nAuthorization: [redacted]\r\n"
<- "{\"pacticipantName\":\"dummy-consumer-java17\",\"pacticipantVersionNumber\":\"0.1\",\"tags\":[],\"branch\":\"DQ-338-ConsumerJava17ok\",\"contracts\":[{\"consumerName\":\"dummy-consumer-java17\",\"providerName\":\"dummy-provider-java17\",\"specification\":\"pact\",\"contentType\":\"application/json\",\"content\":\"eyJjb25zdW1lciI6eyJuYW1lIjoiZHVtbXktY29uc3VtZXItamF2YTE3In0sImludGVyYWN0aW9ucyI6W3siZGVzY3JpcHRpb24iOiJhIHBhY3QiLCJwcm92aWRlclN0YXRlcyI6W3sibmFtZSI6InJldHJpZXZpbmcgYSBwYWN0In1dLCJyZXF1ZXN0Ijp7ImhlYWRlcnMiOnsiQ29udGVudC1UeXBlIjoiYXBwbGljYXRpb24vanNvbiJ9LCJtZXRob2QiOiJHRVQiLCJwYXRoIjoiL3YxL2NhdGVnb3JpZXMifSwicmVzcG9uc2UiOnsiYm9keSI6eyJldmVudFR5cGUiOiJDUkVBVEVEIn0sImhlYWRlcnMiOnsiQ29udGVudC1UeXBlIjoiYXBwbGljYXRpb24vanNvbjsgY2hhcnNldD1VVEYtOCJ9LCJtYXRjaGluZ1J1bGVzIjp7ImhlYWRlciI6eyJDb250ZW50LVR5cGUiOnsiY29tYmluZSI6IkFORCIsIm1hdGNoZXJzIjpbeyJtYXRjaCI6InJlZ2V4IiwicmVnZXgiOiJhcHBsaWNhdGlvbi9qc29uKDtcXHM/Y2hhcnNldD1bXFx3XFwtXSspPyJ9XX19fSwic3RhdHVzIjoyMDB9fV0sIm1ldGFkYXRhIjp7InBhY3QtanZtIjp7InZlcnNpb24iOiI0LjYuMyJ9LCJwYWN0U3BlY2lmaWNhdGlvbiI6eyJ2ZXJzaW9uIjoiMy4wLjAifX0sInByb3ZpZGVyIjp7Im5hbWUiOiJkdW1teS1wcm92aWRlci1qYXZhMTcifX0=\"}]}"
-> "HTTP/1.1 400 Bad Request\r\n"
-> "Content-Type: text/plain\r\n"
-> "Content-Length: 0\r\n"
-> "\r\n"
reading 0 bytes...
-> ""
read 0 bytes
Conn keep-alive
Copy code
curl --location 'localhost:9292/contracts/publish' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic dGVzdGU6MTIzNA==' \
--data '{
    "pacticipantName":"dummy-consumer-java17",
    "pacticipantVersionNumber":"0.1",
    "tags":[],
    "branch":"DQ-338-ConsumerJava17ok",
    "contracts":[
        {"consumerName":"dummy-consumer-java17",
        "providerName":"dummy-provider-java17",
        "specification":"pact",
        "contentType":"application/json",
        "content":"eyJwYWN0aWNpcGFudE5hbWUiOiJkdW1teS1jb25zdW1lci1qYXZhMTciLCJwYWN0aWNpcGFudFZlcnNpb25OdW1iZXIiOiIwLjEiLCJ0YWdzIjpbXSwiYnJhbmNoIjoiRFEtMzM4LUNvbnN1bWVySmF2YTE3b2siLCJjb250cmFjdHMiOlt7ImNvbnN1bWVyTmFtZSI6ImR1bW15LWNvbnN1bWVyLWphdmExNyIsInByb3ZpZGVyTmFtZSI6ImR1bW15LXByb3ZpZGVyLWphdmExNyIsInNwZWNpZmljYXRpb24iOiJwYWN0IiwiY29udGVudFR5cGUiOiJhcHBsaWNhdGlvbi9qc29uIiwiY29udGVudCI6ImV5SmpiMjV6ZFcxbGNpSTZleUp1WVcxbElqb2laSFZ0YlhrdFkyOXVj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jaWZYMD0ifV19"
        }
        ]
        }'
I made the same call via curl, simply copy it from the console and transform it to curl and it works, but it doesn't work with pact-bkoker cli
j
I wonder whether Matt knows about this (it's just a bit early right now in Australia). I'll ping him when it's a more reasonable hour 🙂
c
ok, thank you for help
m
What does the pact broker logs say (if anything) for the
400
?
c
@Matt (pactflow.io / pact-js / pact-go)
Copy code
pact-broker-1  | 2024-04-10 21:51:43.330570 D [8:puma srv tp 001] PactBroker::Api::Middleware::HttpDebugLogs -- env -- { "SCRIPT_NAME" => "", "QUERY_STRING" => "", "SERVER_PROTOCOL" => "HTTP/1.1", "SERVER_SOFTWARE" => "puma 5.6.5 Birdie's Version", "GATEWAY_INTERFACE" => "CGI/1.2", "REQUEST_METHOD" => "GET", "REQUEST_PATH" => "/", "REQUEST_URI" => "/?", "HTTP_VERSION" => "HTTP/1.1", "HTTP_ACCEPT" => "application/hal+json", "HTTP_USER_AGENT" => "Ruby", "HTTP_AUTHORIZATION" => "Bearer SpLx14YI_8ynt5rlb8NsbQ", "HTTP_HOST" => "localhost:9292", "SERVER_NAME" => "localhost", "SERVER_PORT" => "9292", "PATH_INFO" => "/", "REMOTE_ADDR" => "192.168.65.1", "rack.input" => "" }
pact-broker-1  | 2024-04-10 21:51:43.331570 D [8:puma srv tp 001] PactBroker::Api::Middleware::HttpDebugLogs -- response -- { "status" => 400, "headers" => { "Content-Type" => "text/plain", "Content-Length" => "0" }, "body" => [] }
m
“HTTP_AUTHORIZATION” => “Bearer SpLx14YI_8ynt5rlb8NsbQ”
So this looks suspicious. It shouldn’t be using a bearer token because you’ve supplied it basic auth credentials.
this implies perhaps there is an environment variable present when calling the CLI (
PACT_BROKER_TOKEN
), which is taking precedence
That might be what’s responsible for the 400, because it would be expecting basic auth?
c
I actually tested this with the variable set in the environment, even though I wasn't using it in the command, it was passing it, thank you very much!
🙌 1