From ed33332dce70fbc800007e2c0e70298149c3ae91 Mon Sep 17 00:00:00 2001 From: Livio Amstutz Date: Thu, 15 Oct 2020 13:41:31 +0200 Subject: [PATCH] merging and missing mocks --- example/internal/mock/storage.go | 15 +++++++++++++-- pkg/op/mock/storage.mock.go | 8 ++++---- pkg/op/mock/storage.mock.impl.go | 6 ++++++ pkg/op/token.go | 2 +- pkg/op/userinfo.go | 6 +++--- 5 files changed, 27 insertions(+), 10 deletions(-) diff --git a/example/internal/mock/storage.go b/example/internal/mock/storage.go index a9d5c9b..9671ec7 100644 --- a/example/internal/mock/storage.go +++ b/example/internal/mock/storage.go @@ -210,10 +210,10 @@ func (s *AuthStorage) AuthorizeClientIDSecret(_ context.Context, id string, _ st return nil } -func (s *AuthStorage) GetUserinfoFromToken(ctx context.Context, _, _, _ string) (oidc.UserInfoSetter, error) { +func (s *AuthStorage) GetUserinfoFromToken(ctx context.Context, _, _, _ string) (oidc.UserInfo, error) { return s.GetUserinfoFromScopes(ctx, "", "", []string{}) } -func (s *AuthStorage) GetUserinfoFromScopes(_ context.Context, _, _ string, _ []string) (oidc.UserInfoSetter, error) { +func (s *AuthStorage) GetUserinfoFromScopes(_ context.Context, _, _ string, _ []string) (oidc.UserInfo, error) { userinfo := oidc.NewUserInfo() userinfo.SetSubject(a.GetSubject()) userinfo.SetAddress(oidc.NewUserInfoAddress("Test 789\nPostfach 2", "", "", "", "", "")) @@ -223,6 +223,9 @@ func (s *AuthStorage) GetUserinfoFromScopes(_ context.Context, _, _ string, _ [] userinfo.AppendClaims("private_claim", "test") return userinfo, nil } +func (s *AuthStorage) GetPrivateClaimsFromScopes(_ context.Context, _, _ string, _ []string) (map[string]interface{}, error) { + return map[string]interface{}{"private_claim": "test"}, nil +} type ConfClient struct { applicationType op.ApplicationType @@ -280,3 +283,11 @@ func (c *ConfClient) DevMode() bool { func (c *ConfClient) AllowedScopes() []string { return nil } + +func (c *ConfClient) AssertAdditionalIdTokenScopes() bool { + return false +} + +func (c *ConfClient) AssertAdditionalAccessTokenScopes() bool { + return false +} diff --git a/pkg/op/mock/storage.mock.go b/pkg/op/mock/storage.mock.go index a184597..9e4963a 100644 --- a/pkg/op/mock/storage.mock.go +++ b/pkg/op/mock/storage.mock.go @@ -214,18 +214,18 @@ func (mr *MockStorageMockRecorder) GetUserinfoFromScopes(arg0, arg1, arg2, arg3 } // GetUserinfoFromToken mocks base method -func (m *MockStorage) GetUserinfoFromToken(arg0 context.Context, arg1, arg2 string) (oidc.UserInfo, error) { +func (m *MockStorage) GetUserinfoFromToken(arg0 context.Context, arg1, arg2, arg3 string) (oidc.UserInfo, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetUserinfoFromToken", arg0, arg1, arg2) + ret := m.ctrl.Call(m, "GetUserinfoFromToken", arg0, arg1, arg2, arg3) ret0, _ := ret[0].(oidc.UserInfo) ret1, _ := ret[1].(error) return ret0, ret1 } // GetUserinfoFromToken indicates an expected call of GetUserinfoFromToken -func (mr *MockStorageMockRecorder) GetUserinfoFromToken(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockStorageMockRecorder) GetUserinfoFromToken(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetUserinfoFromToken", reflect.TypeOf((*MockStorage)(nil).GetUserinfoFromToken), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetUserinfoFromToken", reflect.TypeOf((*MockStorage)(nil).GetUserinfoFromToken), arg0, arg1, arg2, arg3) } // Health mocks base method diff --git a/pkg/op/mock/storage.mock.impl.go b/pkg/op/mock/storage.mock.impl.go index 54cd059..de9dee9 100644 --- a/pkg/op/mock/storage.mock.impl.go +++ b/pkg/op/mock/storage.mock.impl.go @@ -171,3 +171,9 @@ func (c *ConfClient) DevMode() bool { func (c *ConfClient) AllowedScopes() []string { return nil } +func (c *ConfClient) AssertAdditionalIdTokenScopes() bool { + return false +} +func (c *ConfClient) AssertAdditionalAccessTokenScopes() bool { + return false +} diff --git a/pkg/op/token.go b/pkg/op/token.go index 67bcaae..2d66ef5 100644 --- a/pkg/op/token.go +++ b/pkg/op/token.go @@ -74,7 +74,7 @@ func CreateAccessToken(ctx context.Context, tokenRequest TokenRequest, accessTok token, err = CreateJWT(ctx, creator.Issuer(), tokenRequest, exp, id, creator.Signer(), client, creator.Storage()) return } - token, err = CreateBearerToken(id, authReq.GetSubject(), creator.Crypto()) + token, err = CreateBearerToken(id, tokenRequest.GetSubject(), creator.Crypto()) return } diff --git a/pkg/op/userinfo.go b/pkg/op/userinfo.go index d5ca68e..1163598 100644 --- a/pkg/op/userinfo.go +++ b/pkg/op/userinfo.go @@ -67,11 +67,11 @@ func getAccessToken(r *http.Request, decoder utils.Decoder) (string, error) { func getTokenIDAndSubject(ctx context.Context, userinfoProvider UserinfoProvider, accessToken string) (string, string, bool) { tokenIDSubject, err := userinfoProvider.Crypto().Decrypt(accessToken) if err == nil { - splittedToken := strings.Split(tokenIDSubject, ":") - if len(splittedToken) != 2 { + splitToken := strings.Split(tokenIDSubject, ":") + if len(splitToken) != 2 { return "", "", false } - return splittedToken[0], splittedToken[1], true + return splitToken[0], splitToken[1], true } accessTokenClaims, err := VerifyAccessToken(ctx, accessToken, userinfoProvider.AccessTokenVerifier()) if err != nil {