-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get IDP endpoints from well-known config (#470)
* Get IDP endpoints from well-known config * Refactor parsing of the well known config * Fix lint * Add unit test * Fix resource-manager custom endpoint
- Loading branch information
1 parent
394f4dd
commit 2526406
Showing
11 changed files
with
236 additions
and
64 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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,110 @@ | ||
package auth | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/zalando/go-keyring" | ||
) | ||
|
||
type apiClientMocked struct { | ||
getFails bool | ||
getResponse string | ||
} | ||
|
||
func (a *apiClientMocked) Do(_ *http.Request) (*http.Response, error) { | ||
if a.getFails { | ||
return &http.Response{ | ||
StatusCode: http.StatusNotFound, | ||
}, fmt.Errorf("not found") | ||
} | ||
return &http.Response{ | ||
Status: "200 OK", | ||
StatusCode: http.StatusAccepted, | ||
Body: io.NopCloser(strings.NewReader(a.getResponse)), | ||
}, nil | ||
} | ||
|
||
func TestParseWellKnownConfig(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
getFails bool | ||
getResponse string | ||
isValid bool | ||
expected *wellKnownConfig | ||
}{ | ||
{ | ||
name: "success", | ||
getFails: false, | ||
getResponse: `{"issuer":"issuer","authorization_endpoint":"auth","token_endpoint":"token"}`, | ||
isValid: true, | ||
expected: &wellKnownConfig{ | ||
Issuer: "issuer", | ||
AuthorizationEndpoint: "auth", | ||
TokenEndpoint: "token", | ||
}, | ||
}, | ||
{ | ||
name: "get_fails", | ||
getFails: true, | ||
getResponse: "", | ||
isValid: false, | ||
expected: nil, | ||
}, | ||
{ | ||
name: "empty_response", | ||
getFails: true, | ||
getResponse: "", | ||
isValid: false, | ||
expected: nil, | ||
}, | ||
{ | ||
name: "missing_issuer", | ||
getFails: true, | ||
getResponse: `{"authorization_endpoint":"auth","token_endpoint":"token"}`, | ||
isValid: false, | ||
expected: nil, | ||
}, | ||
{ | ||
name: "missing_authorization", | ||
getFails: true, | ||
getResponse: `{"issuer":"issuer","token_endpoint":"token"}`, | ||
isValid: false, | ||
expected: nil, | ||
}, | ||
{ | ||
name: "missing_token", | ||
getFails: true, | ||
getResponse: `{"issuer":"issuer","authorization_endpoint":"auth"}`, | ||
isValid: false, | ||
expected: nil, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
keyring.MockInit() | ||
|
||
testClient := apiClientMocked{ | ||
tt.getFails, | ||
tt.getResponse, | ||
} | ||
|
||
got, err := parseWellKnownConfiguration(&testClient, "") | ||
|
||
if tt.isValid && err != nil { | ||
t.Fatalf("expected no error, got %v", err) | ||
} | ||
if !tt.isValid && err == nil { | ||
t.Fatalf("expected error, got none") | ||
} | ||
|
||
if tt.isValid && !cmp.Equal(*got, *tt.expected) { | ||
t.Fatalf("expected %v, got %v", tt.expected, got) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.