Skip to content

Commit

Permalink
fix relevant tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hperl committed Oct 29, 2024
1 parent 04c14cd commit e776a3f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
6 changes: 3 additions & 3 deletions handler/oauth2/flow_resource_owner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,21 @@ func TestResourceOwnerFlow_HandleTokenEndpointRequest(t *testing.T) {
areq.Form.Set("password", "pan")
areq.Client = &fosite.DefaultClient{GrantTypes: fosite.Arguments{"password"}, Scopes: []string{"foo-scope"}, Audience: []string{"https://www.ory.sh/api"}}

store.EXPECT().Authenticate(gomock.Any(), "peter", "pan").Return(fosite.ErrNotFound)
store.EXPECT().Authenticate(gomock.Any(), "peter", "pan").Return("", fosite.ErrNotFound)
},
expectErr: fosite.ErrInvalidGrant,
},
{
description: "should fail because error on lookup",
setup: func(config *fosite.Config) {
store.EXPECT().Authenticate(gomock.Any(), "peter", "pan").Return(errors.New(""))
store.EXPECT().Authenticate(gomock.Any(), "peter", "pan").Return("", errors.New(""))
},
expectErr: fosite.ErrServerError,
},
{
description: "should pass",
setup: func(config *fosite.Config) {
store.EXPECT().Authenticate(gomock.Any(), "peter", "pan").Return(nil)
store.EXPECT().Authenticate(gomock.Any(), "peter", "pan").Return("", nil)
},
check: func(areq *fosite.AccessRequest) {
//assert.NotEmpty(t, areq.GetSession().GetExpiresAt(fosite.AccessToken))
Expand Down
9 changes: 5 additions & 4 deletions storage/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"time"

"github.com/go-jose/go-jose/v3"
"github.com/google/uuid"

"github.com/ory/fosite"
"github.com/ory/fosite/internal"
Expand Down Expand Up @@ -355,18 +356,18 @@ func (s *MemoryStore) DeleteRefreshTokenSession(_ context.Context, signature str
return nil
}

func (s *MemoryStore) Authenticate(_ context.Context, name string, secret string) error {
func (s *MemoryStore) Authenticate(_ context.Context, name string, secret string) (subject string, err error) {
s.usersMutex.RLock()
defer s.usersMutex.RUnlock()

rel, ok := s.Users[name]
if !ok {
return fosite.ErrNotFound
return "", fosite.ErrNotFound
}
if rel.Password != secret {
return fosite.ErrNotFound.WithDebug("Invalid credentials")
return "", fosite.ErrNotFound.WithDebug("Invalid credentials")
}
return nil
return uuid.New().String(), nil
}

func (s *MemoryStore) RevokeRefreshToken(ctx context.Context, requestID string) error {
Expand Down
2 changes: 1 addition & 1 deletion storage/memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestMemoryStore_Authenticate(t *testing.T) {
Users: tt.fields.Users,
usersMutex: tt.fields.usersMutex,
}
if err := s.Authenticate(tt.args.in0, tt.args.name, tt.args.secret); err == nil || !errors.Is(err, tt.wantErr) {
if _, err := s.Authenticate(tt.args.in0, tt.args.name, tt.args.secret); err == nil || !errors.Is(err, tt.wantErr) {
t.Errorf("Authenticate() error = %v, wantErr %v", err, tt.wantErr)
}
})
Expand Down

0 comments on commit e776a3f

Please sign in to comment.