Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,9 @@ func (c *GitHubAppProcessorConfig) ResponseProcessor(_ map[string]string, sctx *
}

return func(resp *http.Response) error {
if resp.StatusCode != http.StatusOK {
// GitHub's installation token endpoint returns 201 Created on success.
// https://docs.github.com/en/rest/apps/apps#create-an-installation-access-token-for-an-app
if resp.StatusCode != http.StatusCreated {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should check if it's between 200 and 299, given the failure mode is exposing the token. Maybe add a 200 test as well.

return nil
}

Expand Down
6 changes: 3 additions & 3 deletions processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1387,7 +1387,7 @@ func TestGitHubAppProcessorConfig_ResponseProcessor_SealsInstallationToken(t *te
expiresAt := time.Now().Add(time.Hour).UTC().Format(time.RFC3339)
githubResp := fmt.Sprintf(`{"token":"ghs_installationtokenXYZ","expires_at":%q,"permissions":{"contents":"read"}}`, expiresAt)
resp := &http.Response{
StatusCode: 200,
StatusCode: 201,
Body: io.NopCloser(strings.NewReader(githubResp)),
Header: make(http.Header),
}
Expand Down Expand Up @@ -1446,7 +1446,7 @@ func TestGitHubAppProcessorConfig_ResponseProcessor_PinsToAPIHostWithoutOuterVal
expiresAt := time.Now().Add(time.Hour).UTC().Format(time.RFC3339)
githubResp := fmt.Sprintf(`{"token":"ghs_abc","expires_at":%q}`, expiresAt)
resp := &http.Response{
StatusCode: 200,
StatusCode: 201,
Body: io.NopCloser(strings.NewReader(githubResp)),
Header: make(http.Header),
}
Expand Down Expand Up @@ -1487,7 +1487,7 @@ func TestGitHubAppProcessorConfig_ResponseProcessor_MissingToken(t *testing.T) {
assert.NoError(t, err)

resp := &http.Response{
StatusCode: 200,
StatusCode: 201,
Body: io.NopCloser(strings.NewReader(`{"not_token":"nope"}`)),
Header: make(http.Header),
}
Expand Down
Loading