-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
インターフェース名をtokenAuthenticatorからjwtAuthenticatorに変更
- Loading branch information
YutaKakiki
authored and
YutaKakiki
committed
Jan 24, 2025
1 parent
80a995c
commit c153465
Showing
18 changed files
with
215 additions
and
215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package repository | ||
|
||
import ( | ||
"context" | ||
|
||
"time" | ||
) | ||
|
||
type jwtAuthenticatorRepository struct { | ||
kvsCommander KvsCommander | ||
} | ||
|
||
func NewJwtAuthenticatorRepository(kvsCommander KvsCommander) *jwtAuthenticatorRepository { | ||
return &jwtAuthenticatorRepository{ | ||
kvsCommander: kvsCommander, | ||
} | ||
} | ||
|
||
func (tar *jwtAuthenticatorRepository) Save(ctx context.Context, duration time.Duration, userID, jwtID string) error { | ||
return tar.kvsCommander.Save(ctx, duration, userID, jwtID) | ||
} | ||
|
||
// 存在しないKEYを指定した場合は空文字を返す | ||
func (tar *jwtAuthenticatorRepository) Load(ctx context.Context, userID string) (string, error) { | ||
return tar.kvsCommander.Load(ctx, userID) | ||
} | ||
|
||
func (tar *jwtAuthenticatorRepository) Delete(ctx context.Context, userID string) error { | ||
return tar.kvsCommander.Delete(ctx, userID) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,14 +15,14 @@ func TestAuth_LoginUsecase_Run(t *testing.T) { | |
user1, _ := user.NewUser("[email protected]", "user1", "password") | ||
tests := []struct { | ||
name string | ||
mockFn func(mur *user.MockUserRepository, ma *MockTokenAuthenticator, mar *MockTokenAuthenticatorRepository) | ||
mockFn func(mur *user.MockUserRepository, ma *MockJwtAuthenticator, mar *MockJwtAuthenticatorRepository) | ||
input LoginUsecaseInputDTO | ||
want *LoginUsecaseOutputDTO | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "正常系:ユーザーにJWTトークンが返る", | ||
mockFn: func(mur *user.MockUserRepository, ma *MockTokenAuthenticator, mar *MockTokenAuthenticatorRepository) { | ||
mockFn: func(mur *user.MockUserRepository, ma *MockJwtAuthenticator, mar *MockJwtAuthenticatorRepository) { | ||
mur.EXPECT().FindByEmail(gomock.Any(), gomock.Any()).Return(user1, nil) | ||
ma.EXPECT().GenerateToken(gomock.Any(), gomock.Any()).Return(&jwt.Token{}) | ||
ma.EXPECT().SignToken(gomock.Any()).Return("jwt", nil) | ||
|
@@ -39,7 +39,7 @@ func TestAuth_LoginUsecase_Run(t *testing.T) { | |
}, | ||
{ | ||
name: "準正常系:パスワードが異なる", | ||
mockFn: func(mur *user.MockUserRepository, ma *MockTokenAuthenticator, mar *MockTokenAuthenticatorRepository) { | ||
mockFn: func(mur *user.MockUserRepository, ma *MockJwtAuthenticator, mar *MockJwtAuthenticatorRepository) { | ||
mur.EXPECT().FindByEmail(gomock.Any(), gomock.Any()).Return(user1, nil) | ||
}, | ||
input: LoginUsecaseInputDTO{ | ||
|
@@ -55,8 +55,8 @@ func TestAuth_LoginUsecase_Run(t *testing.T) { | |
t.Parallel() | ||
ctrl := gomock.NewController(t) | ||
mockUserRepository := user.NewMockUserRepository(ctrl) | ||
mockAuthenticator := NewMockTokenAuthenticator(ctrl) | ||
mockAuthenticatorRepository := NewMockTokenAuthenticatorRepository(ctrl) | ||
mockAuthenticator := NewMockJwtAuthenticator(ctrl) | ||
mockAuthenticatorRepository := NewMockJwtAuthenticatorRepository(ctrl) | ||
tt.mockFn(mockUserRepository, mockAuthenticator, mockAuthenticatorRepository) | ||
sut := NewLoginUsecase(mockUserRepository, mockAuthenticatorRepository, mockAuthenticator) | ||
ctx := context.Background() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.