Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove authentiacation cache #584

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion internal/primitive/authentication/authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,12 @@ func (a *authentication) checkTokenExpired() {
}

func (a *authentication) Authenticate(ctx context.Context, token string) (string, error) {
/* remove cache
v, exist := a.tokens.Load(token)
if exist {
return v.(string), nil
}
*/
// todo breakdown cache
user, err := a.client.GetUser(ctx, token)
if err != nil {
Expand All @@ -94,6 +96,6 @@ func (a *authentication) Authenticate(ctx context.Context, token string) (string
if user == "" {
return "", errors.ErrResourceNotFound.WithMessage("token is invalid")
}
a.tokens.Store(token, user)
// a.tokens.Store(token, user)
return user, nil
}
12 changes: 6 additions & 6 deletions internal/primitive/authentication/authentication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ func TestAuthentication_Authenticate(t *testing.T) {
ctx := context.Background()
m := NewAuthentication(tokenClient).(*authentication)
token := "test"
Convey("cache exist", func() {
m.tokens.Store(token, "user")
user, err := m.Authenticate(ctx, token)
So(err, ShouldBeNil)
So(user, ShouldEqual, "user")
})
// Convey("cache exist", func() {
// m.tokens.Store(token, "user")
// user, err := m.Authenticate(ctx, token)
// So(err, ShouldBeNil)
// So(user, ShouldEqual, "user")
// })
Convey("cache no exist", func() {
Convey("user exist", func() {
tokenClient.EXPECT().GetUser(gomock.Any(), gomock.Eq(token)).Return("user", nil)
Expand Down