-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a pipeline that runs on PRs, branches and on repository dispatch. Requires a JWT to be generated beforehand and included in headers for authentication. Fixes VEGA-2196 #minor
- Loading branch information
Showing
4 changed files
with
168 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
name: Pact Provider Verification | ||
|
||
on: | ||
repository_dispatch: | ||
types: [provider-verification] | ||
pull_request: | ||
branches: | ||
- main | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
test: | ||
name: Provider verification | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- run: make build up | ||
- run: go build -o ./api-test/tester ./api-test && chmod +x ./api-test/tester | ||
- run: echo "JWT=$(./api-test/tester -jwtSecret=secret JWT)" >> "$GITHUB_ENV" | ||
- name: Verify specified Pact | ||
if: ${{ github.event_name == 'repository_dispatch' }} | ||
run: | | ||
docker-compose run --rm pact-verifier \ | ||
--header="X-Jwt-Authorization: Bearer $JWT" \ | ||
--provider-version=$(git rev-parse HEAD) \ | ||
--provider-branch=main \ | ||
--publish \ | ||
--user=admin \ | ||
--password=${{ secrets.PACT_BROKER_PASSWORD }} \ | ||
--url=${{ github.event.client_payload.pact_url }} | ||
- name: Verify pacts, including pending | ||
if: ${{ github.event_name == 'push' }} | ||
run: | | ||
docker-compose run --rm pact-verifier \ | ||
--header="X-Jwt-Authorization: Bearer $JWT" \ | ||
--provider-version=$(git rev-parse HEAD) \ | ||
--provider-branch=main \ | ||
--publish \ | ||
--user=admin \ | ||
--password=${{ secrets.PACT_BROKER_PASSWORD }} \ | ||
--consumer-version-selectors='{"mainBranch": true}' \ | ||
--enable-pending | ||
- name: Verify pacts are still upheld | ||
if: ${{ github.event_name == 'pull_request' }} | ||
run: | | ||
docker-compose run --rm pact-verifier \ | ||
--header="X-Jwt-Authorization=Bearer $JWT" \ | ||
--provider-version=$(git rev-parse HEAD) \ | ||
--provider-branch=${{ github.head_ref }} \ | ||
--consumer-version-selectors='{"branch": "VEGA2174_lpastore_service"}' | ||
# --consumer-version-selectors='{"mainBranch": true}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,8 +17,9 @@ import ( | |
) | ||
|
||
// ./api-test/tester UID -> generate a UID | ||
// ./api-test/tester JWT -> generate a JWT | ||
// ./api-test/tester -jwtSecret=secret -expectedStatus=200 REQUEST <METHOD> <URL> <REQUEST BODY> | ||
// -> make a test request with a JWT generated using secret "secret" and expected status 200 | ||
// -> make a test request with a JWT generated using secret "secret" and expected status 200 | ||
// note that the jwtSecret sends a boilerplate JWT for now with valid iat, exp, iss and sub fields | ||
func main() { | ||
expectedStatusCode := flag.Int("expectedStatus", 200, "Expected response status code") | ||
|
@@ -33,6 +34,11 @@ func main() { | |
os.Exit(0) | ||
} | ||
|
||
if args[0] == "JWT" { | ||
fmt.Print(makeJwt([]byte(*jwtSecret))) | ||
os.Exit(0) | ||
} | ||
|
||
if args[0] != "REQUEST" { | ||
panic("Unrecognised command") | ||
} | ||
|
@@ -49,19 +55,9 @@ func main() { | |
req.Header.Add("Content-type", "application/json") | ||
|
||
if *jwtSecret != "" { | ||
secretKey := []byte(*jwtSecret) | ||
|
||
claims := jwt.MapClaims{ | ||
"exp": time.Now().Add(time.Hour * 24).Unix(), | ||
"iat": time.Now().Add(time.Hour * -24).Unix(), | ||
"iss": "opg.poas.sirius", | ||
"sub": "[email protected]", | ||
} | ||
tokenString := makeJwt([]byte(*jwtSecret)) | ||
|
||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims) | ||
tokenString, _ := token.SignedString(secretKey) | ||
|
||
req.Header.Add("X-Jwt-Authorization", fmt.Sprintf("Bearer: %s", tokenString)) | ||
req.Header.Add("X-Jwt-Authorization", fmt.Sprintf("Bearer %s", tokenString)) | ||
} | ||
|
||
sess := session.Must(session.NewSession()) | ||
|
@@ -88,6 +84,25 @@ func main() { | |
log.Printf("invalid status code %d; expected: %d", resp.StatusCode, *expectedStatusCode) | ||
log.Printf("error response: %s", buf.String()) | ||
} else { | ||
log.Print(resp.Header) | ||
log.Printf("Test passed - %s to %s - %d: %s", method, url, resp.StatusCode, buf.String()) | ||
} | ||
} | ||
|
||
func makeJwt(secretKey []byte) string { | ||
claims := jwt.MapClaims{ | ||
"exp": time.Now().Add(time.Hour * 24).Unix(), | ||
"iat": time.Now().Add(time.Hour * -24).Unix(), | ||
"iss": "opg.poas.sirius", | ||
"sub": "[email protected]", | ||
} | ||
|
||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims) | ||
tokenString, err := token.SignedString(secretKey) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
return tokenString | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters