-
Notifications
You must be signed in to change notification settings - Fork 3.9k
chore: gh-host as oauth auth server #2046
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
Merged
+213
−47
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
0ef5a75
chore: gh-host as oauth auth server
atharva1051 ee63c51
Initial plan
Copilot 3faac62
fix: only set AuthorizationServer when gh-host is explicitly configured
Copilot c7931aa
Merge pull request #7 from mercedes-benz/copilot/fix-authorization-se…
atharva1051 f5b8ecc
fix: joining url using net/url
atharva1051 f202f14
Merge branch 'github:main' into main
atharva1051 841dc1b
Merge branch 'main' into main
atharva1051 43e207d
Merge branch 'main' into main
atharva1051 412c6c9
fix: extended api host to have a oauth url
atharva1051 fbc5ba1
chore: oauth accepts APIHostResolver as argument
atharva1051 82eaaaa
Merge branch 'main' into main
atharva1051 60717a7
chore: made it similar to #2070
atharva1051 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,140 @@ | ||
| package utils //nolint:revive //TODO: figure out a better name for this package | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestOAuthURL(t *testing.T) { | ||
| ctx := context.Background() | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| host string | ||
| expectedOAuth string | ||
| expectError bool | ||
| errorSubstring string | ||
| }{ | ||
| { | ||
| name: "dotcom (empty host)", | ||
| host: "", | ||
| expectedOAuth: "https://github.com/login/oauth", | ||
| }, | ||
| { | ||
| name: "dotcom (explicit github.com)", | ||
| host: "https://github.com", | ||
| expectedOAuth: "https://github.com/login/oauth", | ||
| }, | ||
| { | ||
| name: "GHEC with HTTPS", | ||
| host: "https://acme.ghe.com", | ||
| expectedOAuth: "https://acme.ghe.com/login/oauth", | ||
| }, | ||
| { | ||
| name: "GHEC with HTTP (should error)", | ||
| host: "http://acme.ghe.com", | ||
| expectError: true, | ||
| errorSubstring: "GHEC URL must be HTTPS", | ||
| }, | ||
| { | ||
| name: "GHES with HTTPS", | ||
| host: "https://ghes.example.com", | ||
| expectedOAuth: "https://ghes.example.com/login/oauth", | ||
| }, | ||
| { | ||
| name: "GHES with HTTP", | ||
| host: "http://ghes.example.com", | ||
| expectedOAuth: "http://ghes.example.com/login/oauth", | ||
| }, | ||
| { | ||
| name: "GHES with HTTP and custom port (port stripped - not supported yet)", | ||
| host: "http://ghes.local:8080", | ||
| expectedOAuth: "http://ghes.local/login/oauth", // Port is stripped ref: ln222 api.go comment | ||
| }, | ||
| { | ||
| name: "GHES with HTTPS and custom port (port stripped - not supported yet)", | ||
| host: "https://ghes.local:8443", | ||
| expectedOAuth: "https://ghes.local/login/oauth", // Port is stripped ref: ln222 api.go comment | ||
atharva1051 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
atharva1051 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
atharva1051 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }, | ||
| { | ||
| name: "host without scheme (should error)", | ||
| host: "ghes.example.com", | ||
| expectError: true, | ||
| errorSubstring: "host must have a scheme", | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| apiHost, err := NewAPIHost(tt.host) | ||
|
|
||
| if tt.expectError { | ||
| require.Error(t, err) | ||
| if tt.errorSubstring != "" { | ||
| assert.Contains(t, err.Error(), tt.errorSubstring) | ||
| } | ||
| return | ||
| } | ||
|
|
||
| require.NoError(t, err) | ||
| require.NotNil(t, apiHost) | ||
|
|
||
| oauthURL, err := apiHost.OAuthURL(ctx) | ||
| require.NoError(t, err) | ||
| require.NotNil(t, oauthURL) | ||
|
|
||
| assert.Equal(t, tt.expectedOAuth, oauthURL.String()) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestAPIHost_AllURLsHaveConsistentScheme(t *testing.T) { | ||
| ctx := context.Background() | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| host string | ||
| expectedScheme string | ||
| }{ | ||
| { | ||
| name: "GHES with HTTPS", | ||
| host: "https://ghes.example.com", | ||
| expectedScheme: "https", | ||
| }, | ||
| { | ||
| name: "GHES with HTTP", | ||
| host: "http://ghes.example.com", | ||
| expectedScheme: "http", | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| apiHost, err := NewAPIHost(tt.host) | ||
| require.NoError(t, err) | ||
|
|
||
| restURL, err := apiHost.BaseRESTURL(ctx) | ||
| require.NoError(t, err) | ||
| assert.Equal(t, tt.expectedScheme, restURL.Scheme, "REST URL scheme should match") | ||
|
|
||
| gqlURL, err := apiHost.GraphqlURL(ctx) | ||
| require.NoError(t, err) | ||
| assert.Equal(t, tt.expectedScheme, gqlURL.Scheme, "GraphQL URL scheme should match") | ||
|
|
||
| uploadURL, err := apiHost.UploadURL(ctx) | ||
| require.NoError(t, err) | ||
| assert.Equal(t, tt.expectedScheme, uploadURL.Scheme, "Upload URL scheme should match") | ||
|
|
||
| rawURL, err := apiHost.RawURL(ctx) | ||
| require.NoError(t, err) | ||
| assert.Equal(t, tt.expectedScheme, rawURL.Scheme, "Raw URL scheme should match") | ||
|
|
||
| oauthURL, err := apiHost.OAuthURL(ctx) | ||
| require.NoError(t, err) | ||
| assert.Equal(t, tt.expectedScheme, oauthURL.Scheme, "OAuth URL scheme should match") | ||
| }) | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.