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

[DDO-3305] Expose GHA OIDC claims throughout Sherlock #361

Merged
merged 6 commits into from
Nov 14, 2023

Conversation

jack-r-warren
Copy link
Contributor

@jack-r-warren jack-r-warren commented Nov 13, 2023

Closes #360 (this PR is cherry-picked with the same contents against main, so it can be merged ahead of #356)

A bunch of refactoring work to make the following test happen:

func (s *handlerSuite) TestCiRunsV3Upsert_GithubActionsClaimDefaults() {
	// Note that the request body is empty!
	// Normally this would result in an error due to missing fields, but suppose a GHA OIDC JWT was passed...
	request := s.NewRequest(http.MethodPut, "/api/ci-runs/v3", CiRunV3Upsert{})
	request.Header.Set(gha_oidc.Header, "some GHA OIDC token")

	var got CiRunV3
	var code int
	gha_oidc.UseMockedVerifier(s.T(), func(v *gha_oidc_mocks.MockMockableVerifier) {
		v.EXPECT().VerifyAndParseClaims(mock.AnythingOfType("*gin.Context"), "some GHA OIDC token").
			Return(gha_oidc_claims.Claims{
				RepositoryOwner: "broadinstitute",
				Repository:      "broadinstitute/terra-github-workflows",
				WorkflowRef:     "broadinstitute/terra-github-workflows/.github/workflows/bee-create.yaml@refs/heads/main",
				RunID:           "123456",
				RunAttempt:      "1",
			}, nil)
	}, func() {
		code = s.HandleRequest(request, &got)
	})

	s.Equal(http.StatusCreated, code)
	s.NotZero(got.ID)
	s.Equal(got.Platform, "github-actions")
	s.Equal(got.GithubActionsOwner, "broadinstitute")
	s.Equal(got.GithubActionsRepo, "terra-github-workflows")
	s.Equal(got.GithubActionsRunID, uint(123456))
	s.Equal(got.GithubActionsAttemptNumber, uint(1))
	s.Equal(got.GithubActionsWorkflowPath, ".github/workflows/bee-create.yaml")
}

This will make calling this endpoint from Thelma way, way easier.

Testing

Fully mocked, most of why this wasn't trivial

Risk

Very low

@jack-r-warren jack-r-warren requested a review from a team as a code owner November 13, 2023 21:11
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 11 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

Copy link

No API changes detected

Copy link

Published image from 10d9112 (merge 46d3aea):

us-central1-docker.pkg.dev/dsp-artifact-registry/sherlock/sherlock:v0.2.40-46d3aea

Copy link

codecov bot commented Nov 13, 2023

Codecov Report

Merging #361 (10d9112) into main (71ba041) will increase coverage by 1.59%.
Report is 5 commits behind head on main.
The diff coverage is 76.09%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #361      +/-   ##
==========================================
+ Coverage   66.91%   68.50%   +1.59%     
==========================================
  Files         151      157       +6     
  Lines        9155    10253    +1098     
==========================================
+ Hits         6126     7024     +898     
- Misses       2617     2742     +125     
- Partials      412      487      +75     
Files Coverage Δ
...herlock/internal/api/sherlock/ci_runs_v3_upsert.go 59.58% <100.00%> (+2.39%) ⬆️
.../authentication/gha_oidc/gha_oidc_claims/claims.go 100.00% <100.00%> (ø)
...k/internal/authentication/gha_oidc/parse_header.go 100.00% <100.00%> (ø)
...rlock/internal/authentication/gha_oidc/verifier.go 100.00% <100.00%> (ø)
...internal/authentication/test_users/parse_header.go 100.00% <100.00%> (ø)
...nal/authentication/test_users/test_suite_helper.go 100.00% <100.00%> (ø)
sherlock/internal/models/test_data.go 99.52% <100.00%> (+0.61%) ⬆️
sherlock/internal/github/client.go 73.52% <0.00%> (-2.23%) ⬇️
...lock/internal/models/deploy_hook_trigger_config.go 70.00% <33.33%> (-2.73%) ⬇️
sherlock/internal/slack/client.go 66.66% <0.00%> (-33.34%) ⬇️
... and 7 more

... and 1 file with indirect coverage changes

@jack-r-warren jack-r-warren merged commit 49d1ed8 into main Nov 14, 2023
15 checks passed
@jack-r-warren jack-r-warren deleted the DDO-3305-gha-claims-cherry-picked branch November 14, 2023 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants