-
Couldn't load subscription status.
- Fork 1
bugfix: OAuth Discovery Robustness, Logging, and Test Coverage #1
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
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| **What I did** | ||
|
|
||
| **Related issue** | ||
| <!-- If this is a bug fix, make sure your description includes "fixes #xxxx", or "closes #xxxx" --> | ||
|
|
||
| **(not mandatory) A picture of a cute animal, if possible in relation to what you did** |
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,35 @@ | ||
| name: CI | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| on: | ||
| pull_request: | ||
| push: | ||
| branches: | ||
| - main | ||
|
|
||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 | ||
|
|
||
| - name: Set up Docker Buildx | ||
| uses: docker/setup-buildx-action@v3 | ||
|
|
||
| - name: Run tests | ||
| run: make test | ||
|
|
||
| lint: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 | ||
|
|
||
| - name: Set up Docker Buildx | ||
| uses: docker/setup-buildx-action@v3 | ||
|
|
||
| - name: Run linter for Linux | ||
| run: make lint-linux |
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,95 @@ | ||
| package oauth | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "io" | ||
| "net/http" | ||
| "net/http/httptest" | ||
| "testing" | ||
| ) | ||
|
|
||
| // TestPerformDCR_PublicClient verifies Dynamic Client Registration | ||
| // for public clients (no client secret) | ||
| func TestPerformDCR_PublicClient(t *testing.T) { | ||
| var capturedRequest *DCRRequest | ||
|
|
||
| // Mock registration endpoint | ||
| regServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| // Capture and verify the request | ||
| body, _ := io.ReadAll(r.Body) | ||
| _ = json.Unmarshal(body, &capturedRequest) | ||
|
|
||
| // Return successful registration response | ||
| _ = json.NewEncoder(w).Encode(DCRResponse{ | ||
| ClientID: "test-client-id-123", | ||
| TokenEndpointAuthMethod: "none", | ||
| GrantTypes: []string{"authorization_code", "refresh_token"}, | ||
| RedirectURIs: []string{"https://mcp.docker.com/oauth/callback"}, | ||
| }) | ||
| })) | ||
| defer regServer.Close() | ||
|
|
||
| // Create discovery with registration endpoint | ||
| discovery := &Discovery{ | ||
| RegistrationEndpoint: regServer.URL, | ||
| AuthorizationEndpoint: "https://auth.example.com/authorize", | ||
| TokenEndpoint: "https://auth.example.com/token", | ||
| ResourceURL: "https://api.example.com", | ||
| Scopes: []string{"read", "write"}, | ||
| } | ||
|
|
||
| // Perform DCR | ||
| creds, err := PerformDCR(context.Background(), discovery, "test-server") | ||
| // Verify no error | ||
| if err != nil { | ||
| t.Fatalf("DCR failed: %v", err) | ||
| } | ||
|
|
||
| // Verify credentials | ||
| if creds.ClientID != "test-client-id-123" { | ||
| t.Errorf("Expected ClientID=test-client-id-123, got %s", creds.ClientID) | ||
| } | ||
| if !creds.IsPublic { | ||
| t.Error("Expected IsPublic=true for public client") | ||
| } | ||
| if creds.ServerURL != "https://api.example.com" { | ||
| t.Errorf("Expected ServerURL=https://api.example.com, got %s", creds.ServerURL) | ||
| } | ||
|
|
||
| // Verify DCR request was correct | ||
| if capturedRequest == nil { | ||
| t.Fatal("DCR request not captured") | ||
| } | ||
| if capturedRequest.TokenEndpointAuthMethod != "none" { | ||
| t.Errorf("Expected token_endpoint_auth_method=none for public client, got %s", capturedRequest.TokenEndpointAuthMethod) | ||
| } | ||
| if len(capturedRequest.RedirectURIs) == 0 { | ||
| t.Error("Expected redirect_uris to be set") | ||
| } | ||
| if len(capturedRequest.GrantTypes) == 0 { | ||
| t.Error("Expected grant_types to be set") | ||
| } | ||
| } | ||
|
|
||
| // TestPerformDCR_NoRegistrationEndpoint verifies error handling | ||
| // when registration endpoint is not available | ||
| func TestPerformDCR_NoRegistrationEndpoint(t *testing.T) { | ||
| // Create discovery WITHOUT registration endpoint | ||
| discovery := &Discovery{ | ||
| AuthorizationEndpoint: "https://auth.example.com/authorize", | ||
| TokenEndpoint: "https://auth.example.com/token", | ||
| RegistrationEndpoint: "", // Empty - DCR not supported | ||
| } | ||
|
|
||
| // Attempt DCR | ||
| creds, err := PerformDCR(context.Background(), discovery, "test-server") | ||
|
|
||
| // Verify error occurred | ||
| if err == nil { | ||
| t.Fatal("Expected error when registration endpoint missing") | ||
| } | ||
| if creds != nil { | ||
| t.Error("Expected nil credentials on error") | ||
| } | ||
| } |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note moved to
.github/to matchmcp-gatewaylocation:https://github.com/docker/mcp-gateway/blob/main/.github/SECURITY.md