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
10 changes: 8 additions & 2 deletions lib/auth/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"io"
"net/http"
"net/url"
"strings"
"time"

"github.com/coreos/go-oidc/oauth2"
Expand Down Expand Up @@ -950,8 +951,8 @@ func (c *githubAPIClient) getTeams() ([]teamResponse, error) {
}

// get makes a GET request to the provided URL using the client's token for auth
func (c *githubAPIClient) get(url string) ([]byte, string, error) {
request, err := http.NewRequest("GET", fmt.Sprintf("https://api.%s/%s", c.endpointHostname, url), nil)
func (c *githubAPIClient) get(page string) ([]byte, string, error) {
request, err := http.NewRequest("GET", formatGithubURL(c.endpointHostname, page), nil)
if err != nil {
return nil, "", trace.Wrap(err)
}
Expand All @@ -977,6 +978,11 @@ func (c *githubAPIClient) get(url string) ([]byte, string, error) {
return bytes, wls.NextPage, nil
}

// formatGithubURL is a helper for formatting github api request URLs.
func formatGithubURL(host string, path string) string {
return fmt.Sprintf("https://%s/%s", host, strings.TrimPrefix(path, "/"))
}

const (
// GithubAuthPath is the GitHub authorization endpoint
GithubAuthPath = "login/oauth/authorize"
Expand Down
28 changes: 28 additions & 0 deletions lib/auth/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,3 +532,31 @@ func TestCheckGithubOrgSSOSupport(t *testing.T) {
})
}
}

func TestGithubURLFormat(t *testing.T) {
tts := []struct {
host string
path string
expect string
}{
{
host: "example.com",
path: "foo/bar",
expect: "https://example.com/foo/bar",
},
{
host: "example.com",
path: "/foo/bar?spam=eggs",
expect: "https://example.com/foo/bar?spam=eggs",
},
{
host: "example.com",
path: "/foo/bar",
expect: "https://example.com/foo/bar",
},
}

for _, tt := range tts {
require.Equal(t, tt.expect, formatGithubURL(tt.host, tt.path))
}
}