From d7b8506ea2483f9c03cca074f22d271d7882f57a Mon Sep 17 00:00:00 2001 From: Lukasz Leszczuk Date: Tue, 20 Aug 2019 21:06:29 +0200 Subject: [PATCH] Fix existing tests --- oauthproxy_test.go | 13 +++++++++++-- providers/azure_test.go | 13 ++++++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/oauthproxy_test.go b/oauthproxy_test.go index 8dd3adf..d51d242 100644 --- a/oauthproxy_test.go +++ b/oauthproxy_test.go @@ -266,6 +266,16 @@ func (tp *TestProvider) GetEmailAddress(session *sessions.SessionState) (string, return tp.EmailAddress, nil } +func (tp *TestProvider) GetUserDetails(s *sessions.SessionState) (map[string]string, error) { + userDetails := map[string]string{} + email, err := tp.GetEmailAddress(s) + if err != nil { + return nil, err + } + userDetails["email"] = email + return userDetails, nil +} + func (tp *TestProvider) ValidateSessionState(session *sessions.SessionState) bool { return tp.ValidToken } @@ -412,8 +422,7 @@ func (patTest *PassAccessTokenTest) Close() { patTest.providerServer.Close() } -func (patTest *PassAccessTokenTest) getCallbackEndpoint() (httpCode int, - cookie string) { +func (patTest *PassAccessTokenTest) getCallbackEndpoint() (httpCode int, cookie string) { rw := httptest.NewRecorder() req, err := http.NewRequest("GET", "/oauth2/callback?code=callback_code&state=nonce:", strings.NewReader("")) diff --git a/providers/azure_test.go b/providers/azure_test.go index 8d34bdc..12b65a6 100644 --- a/providers/azure_test.go +++ b/providers/azure_test.go @@ -40,9 +40,9 @@ func TestAzureProviderDefaults(t *testing.T) { p.Data().LoginURL.String()) assert.Equal(t, "https://login.microsoftonline.com/common/oauth2/token", p.Data().RedeemURL.String()) - assert.Equal(t, "https://graph.windows.net/me?api-version=1.6", + assert.Equal(t, "https://graph.microsoft.com/v1.0/me", p.Data().ProfileURL.String()) - assert.Equal(t, "https://graph.windows.net", + assert.Equal(t, "https://graph.microsoft.com", p.Data().ProtectedResource.String()) assert.Equal(t, "", p.Data().ValidateURL.String()) @@ -96,9 +96,9 @@ func TestAzureSetTenant(t *testing.T) { p.Data().LoginURL.String()) assert.Equal(t, "https://login.microsoftonline.com/example/oauth2/token", p.Data().RedeemURL.String()) - assert.Equal(t, "https://graph.windows.net/me?api-version=1.6", + assert.Equal(t, "https://graph.microsoft.com/v1.0/me", p.Data().ProfileURL.String()) - assert.Equal(t, "https://graph.windows.net", + assert.Equal(t, "https://graph.microsoft.com", p.Data().ProtectedResource.String()) assert.Equal(t, "", p.Data().ValidateURL.String()) @@ -106,12 +106,11 @@ func TestAzureSetTenant(t *testing.T) { } func testAzureBackend(payload string) *httptest.Server { - path := "/me" - query := "api-version=1.6" + path := "/v1.0/me" return httptest.NewServer(http.HandlerFunc( func(w http.ResponseWriter, r *http.Request) { - if r.URL.Path != path || r.URL.RawQuery != query { + if r.URL.Path != path { w.WriteHeader(404) } else if r.Header.Get("Authorization") != "Bearer imaginary_access_token" { w.WriteHeader(403)