Repository: oauth2-proxy/oauth2-proxy
Pull request #1650 (2022-05-13 17:46:17)

Corrects request endpoint
<!--- Provide a general summary of your changes in the Title above -->

## Description

The endpoint is repos, not repo, [documentation](https://docs.github.com/en/rest/repos/repos#get-a-repository)

<!--- Describe your changes in detail -->

## Motivation and Context

Don't see an open issue for this, but it is indeed broken, if checking if a user has a repo, the proxy just returns 500

<!--- Why is this change required? What problem does it solve? -->
<!--- If it fixes an open issue, please link to the issue here. -->

## How Has This Been Tested?

I double checked the endpoint is correct by making requests to it, if you really want me to test further I can, but I don't see the need

<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran to -->
<!--- see how your change affects other areas of the code, etc. -->

## Checklist:

<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->

- [x] My change requires a change to the documentation or CHANGELOG.
- [x] I have updated the documentation/CHANGELOG accordingly.
- [x] I have created a feature (non-master) branch for my PR.


adamsong: Should pass tests now

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c639091e..2e91dff1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -41,6 +41,7 @@ If you are using an architecture specific tag (ex: v7.2.1-arm64) you should move
 - [#1594](https://github.com/oauth2-proxy/oauth2-proxy/pull/1594) Release ARMv8 docker images (@braunsonm)
 - [#1649](https://github.com/oauth2-proxy/oauth2-proxy/pull/1649) Return a 400 instead of a 500 when a request contains an invalid redirect target (@niksko)
 - [#1638](https://github.com/oauth2-proxy/oauth2-proxy/pull/1638) Implement configurable upstream timeout (@jacksgt)
+- [#1650](https://github.com/oauth2-proxy/oauth2-proxy/pull/1650) Fixed 500 when checking if user has repo (@adamsong)
 - [#1635](https://github.com/oauth2-proxy/oauth2-proxy/pull/1635) Added description and unit tests for ipv6 address (@t-katsumura)
 
 # V7.2.1
diff --git a/providers/github.go b/providers/github.go
index a3572854..ae4b2e83 100644
--- a/providers/github.go
+++ b/providers/github.go
@@ -312,7 +312,7 @@ func (p *GitHubProvider) hasRepo(ctx context.Context, accessToken string) (bool,
 	endpoint := &url.URL{
 		Scheme: p.ValidateURL.Scheme,
 		Host:   p.ValidateURL.Host,
-		Path:   path.Join(p.ValidateURL.Path, "/repo/", p.Repo),
+		Path:   path.Join(p.ValidateURL.Path, "/repos/", p.Repo),
 	}
 
 	var repo repository


Test patch:
diff --git a/providers/github_test.go b/providers/github_test.go
index 6ef31979..28ab2baf 100644
--- a/providers/github_test.go
+++ b/providers/github_test.go
@@ -34,7 +34,7 @@ func testGitHubProvider(hostname string, opts options.GitHubOptions) *GitHubProv
 
 func testGitHubBackend(payloads map[string][]string) *httptest.Server {
 	pathToQueryMap := map[string][]string{
-		"/repo/oauth2-proxy/oauth2-proxy":                       {""},
+		"/repos/oauth2-proxy/oauth2-proxy":                      {""},
 		"/repos/oauth2-proxy/oauth2-proxy/collaborators/mbland": {""},
 		"/user":        {""},
 		"/user/emails": {""},
@@ -229,7 +229,7 @@ func TestGitHubProvider_getEmailWithWriteAccessToPrivateRepo(t *testing.T) {
 
 func TestGitHubProvider_getEmailWithNoAccessToPrivateRepo(t *testing.T) {
 	b := testGitHubBackend(map[string][]string{
-		"/repo/oauth2-proxy/oauth2-proxy": {`{}`},
+		"/repos/oauth2-proxy/oauth2-proxy": {`{}`},
 	})
 	defer b.Close()