Fix existing tests

This commit is contained in:
Lukasz Leszczuk 2019-08-20 21:06:29 +02:00
parent 6f1c16f033
commit d7b8506ea2
2 changed files with 17 additions and 9 deletions

View File

@ -266,6 +266,16 @@ func (tp *TestProvider) GetEmailAddress(session *sessions.SessionState) (string,
return tp.EmailAddress, nil 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 { func (tp *TestProvider) ValidateSessionState(session *sessions.SessionState) bool {
return tp.ValidToken return tp.ValidToken
} }
@ -412,8 +422,7 @@ func (patTest *PassAccessTokenTest) Close() {
patTest.providerServer.Close() patTest.providerServer.Close()
} }
func (patTest *PassAccessTokenTest) getCallbackEndpoint() (httpCode int, func (patTest *PassAccessTokenTest) getCallbackEndpoint() (httpCode int, cookie string) {
cookie string) {
rw := httptest.NewRecorder() rw := httptest.NewRecorder()
req, err := http.NewRequest("GET", "/oauth2/callback?code=callback_code&state=nonce:", req, err := http.NewRequest("GET", "/oauth2/callback?code=callback_code&state=nonce:",
strings.NewReader("")) strings.NewReader(""))

View File

@ -40,9 +40,9 @@ func TestAzureProviderDefaults(t *testing.T) {
p.Data().LoginURL.String()) p.Data().LoginURL.String())
assert.Equal(t, "https://login.microsoftonline.com/common/oauth2/token", assert.Equal(t, "https://login.microsoftonline.com/common/oauth2/token",
p.Data().RedeemURL.String()) 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()) p.Data().ProfileURL.String())
assert.Equal(t, "https://graph.windows.net", assert.Equal(t, "https://graph.microsoft.com",
p.Data().ProtectedResource.String()) p.Data().ProtectedResource.String())
assert.Equal(t, "", assert.Equal(t, "",
p.Data().ValidateURL.String()) p.Data().ValidateURL.String())
@ -96,9 +96,9 @@ func TestAzureSetTenant(t *testing.T) {
p.Data().LoginURL.String()) p.Data().LoginURL.String())
assert.Equal(t, "https://login.microsoftonline.com/example/oauth2/token", assert.Equal(t, "https://login.microsoftonline.com/example/oauth2/token",
p.Data().RedeemURL.String()) 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()) p.Data().ProfileURL.String())
assert.Equal(t, "https://graph.windows.net", assert.Equal(t, "https://graph.microsoft.com",
p.Data().ProtectedResource.String()) p.Data().ProtectedResource.String())
assert.Equal(t, "", assert.Equal(t, "",
p.Data().ValidateURL.String()) p.Data().ValidateURL.String())
@ -106,12 +106,11 @@ func TestAzureSetTenant(t *testing.T) {
} }
func testAzureBackend(payload string) *httptest.Server { func testAzureBackend(payload string) *httptest.Server {
path := "/me" path := "/v1.0/me"
query := "api-version=1.6"
return httptest.NewServer(http.HandlerFunc( return httptest.NewServer(http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) { func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != path || r.URL.RawQuery != query { if r.URL.Path != path {
w.WriteHeader(404) w.WriteHeader(404)
} else if r.Header.Get("Authorization") != "Bearer imaginary_access_token" { } else if r.Header.Get("Authorization") != "Bearer imaginary_access_token" {
w.WriteHeader(403) w.WriteHeader(403)