All checks were successful
Deploy Smart Search Backend Test / deploy (push) Successful in 1m25s
159 lines
3.5 KiB
Go
159 lines
3.5 KiB
Go
package tests
|
|
|
|
import (
|
|
"context"
|
|
|
|
authpb "git.techease.ru/Smart-search/smart-search-back/pkg/pb/auth"
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
)
|
|
|
|
func (s *IntegrationSuite) TestAuthHandler_LoginWithNonExistentUser() {
|
|
req := &authpb.LoginRequest{
|
|
Email: "nonexistent@example.com",
|
|
Password: "password123",
|
|
Ip: "127.0.0.1",
|
|
UserAgent: "test-agent",
|
|
}
|
|
|
|
resp, err := s.authClient.Login(context.Background(), req)
|
|
|
|
s.Error(err)
|
|
s.Nil(resp)
|
|
|
|
st, ok := status.FromError(err)
|
|
s.True(ok)
|
|
s.Equal(codes.NotFound, st.Code())
|
|
}
|
|
|
|
func (s *IntegrationSuite) TestAuthHandler_ValidateWithInvalidToken() {
|
|
req := &authpb.ValidateRequest{
|
|
AccessToken: "invalid-token",
|
|
}
|
|
|
|
resp, err := s.authClient.Validate(context.Background(), req)
|
|
|
|
s.NoError(err)
|
|
s.NotNil(resp)
|
|
s.False(resp.Valid)
|
|
s.Equal(int64(0), resp.UserId)
|
|
}
|
|
|
|
func (s *IntegrationSuite) TestAuthHandler_ValidateWithEmptyToken() {
|
|
req := &authpb.ValidateRequest{
|
|
AccessToken: "",
|
|
}
|
|
|
|
resp, err := s.authClient.Validate(context.Background(), req)
|
|
|
|
s.NoError(err)
|
|
s.NotNil(resp)
|
|
s.False(resp.Valid)
|
|
s.Equal(int64(0), resp.UserId)
|
|
}
|
|
|
|
func (s *IntegrationSuite) TestAuthHandler_RefreshWithInvalidToken() {
|
|
req := &authpb.RefreshRequest{
|
|
RefreshToken: "invalid-refresh-token",
|
|
}
|
|
|
|
resp, err := s.authClient.Refresh(context.Background(), req)
|
|
|
|
s.Error(err)
|
|
s.Nil(resp)
|
|
|
|
st, ok := status.FromError(err)
|
|
s.True(ok)
|
|
s.Equal(codes.Unauthenticated, st.Code())
|
|
}
|
|
|
|
func (s *IntegrationSuite) TestAuthHandler_LogoutWithInvalidToken() {
|
|
req := &authpb.LogoutRequest{
|
|
AccessToken: "invalid-token",
|
|
}
|
|
|
|
resp, err := s.authClient.Logout(context.Background(), req)
|
|
|
|
s.NoError(err)
|
|
s.NotNil(resp)
|
|
s.True(resp.Success)
|
|
}
|
|
|
|
func (s *IntegrationSuite) TestAuthHandler_RefreshTokenFlow() {
|
|
ctx := context.Background()
|
|
|
|
loginReq := &authpb.LoginRequest{
|
|
Email: "test@example.com",
|
|
Password: "testpassword",
|
|
Ip: "127.0.0.1",
|
|
UserAgent: "integration-test",
|
|
}
|
|
|
|
loginResp, err := s.authClient.Login(ctx, loginReq)
|
|
s.NoError(err)
|
|
s.NotNil(loginResp)
|
|
s.NotEmpty(loginResp.AccessToken)
|
|
s.NotEmpty(loginResp.RefreshToken)
|
|
|
|
validateReq := &authpb.ValidateRequest{
|
|
AccessToken: loginResp.AccessToken,
|
|
}
|
|
|
|
validateResp, err := s.authClient.Validate(ctx, validateReq)
|
|
s.NoError(err)
|
|
s.NotNil(validateResp)
|
|
s.True(validateResp.Valid)
|
|
|
|
refreshReq := &authpb.RefreshRequest{
|
|
RefreshToken: loginResp.RefreshToken,
|
|
Ip: "127.0.0.1",
|
|
UserAgent: "integration-test",
|
|
}
|
|
|
|
refreshResp, err := s.authClient.Refresh(ctx, refreshReq)
|
|
s.NoError(err)
|
|
s.NotNil(refreshResp)
|
|
s.NotEmpty(refreshResp.AccessToken)
|
|
|
|
logoutReq := &authpb.LogoutRequest{
|
|
AccessToken: refreshResp.AccessToken,
|
|
}
|
|
|
|
logoutResp, err := s.authClient.Logout(ctx, logoutReq)
|
|
s.NoError(err)
|
|
s.NotNil(logoutResp)
|
|
s.True(logoutResp.Success)
|
|
}
|
|
|
|
func (s *IntegrationSuite) TestAuthHandler_LogoutInvalidatesSession() {
|
|
ctx := context.Background()
|
|
|
|
loginReq := &authpb.LoginRequest{
|
|
Email: "test@example.com",
|
|
Password: "testpassword",
|
|
Ip: "127.0.0.1",
|
|
UserAgent: "integration-test",
|
|
}
|
|
|
|
loginResp, err := s.authClient.Login(ctx, loginReq)
|
|
s.NoError(err)
|
|
s.NotEmpty(loginResp.AccessToken)
|
|
|
|
logoutReq := &authpb.LogoutRequest{
|
|
AccessToken: loginResp.AccessToken,
|
|
}
|
|
|
|
logoutResp, err := s.authClient.Logout(ctx, logoutReq)
|
|
s.NoError(err)
|
|
s.True(logoutResp.Success)
|
|
|
|
validateReq := &authpb.ValidateRequest{
|
|
AccessToken: loginResp.AccessToken,
|
|
}
|
|
|
|
validateResp, err := s.authClient.Validate(ctx, validateReq)
|
|
s.NoError(err)
|
|
s.NotNil(validateResp)
|
|
s.False(validateResp.Valid)
|
|
}
|