All checks were successful
Deploy Smart Search Backend Test / deploy (push) Successful in 1m25s
286 lines
6.4 KiB
Go
286 lines
6.4 KiB
Go
package tests
|
|
|
|
import (
|
|
"context"
|
|
|
|
authpb "git.techease.ru/Smart-search/smart-search-back/pkg/pb/auth"
|
|
invitepb "git.techease.ru/Smart-search/smart-search-back/pkg/pb/invite"
|
|
requestpb "git.techease.ru/Smart-search/smart-search-back/pkg/pb/request"
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
)
|
|
|
|
func (s *IntegrationSuite) TestEdgeCase_CreateTZWithEmptyRequestText() {
|
|
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)
|
|
|
|
validateReq := &authpb.ValidateRequest{
|
|
AccessToken: loginResp.AccessToken,
|
|
}
|
|
|
|
validateResp, err := s.authClient.Validate(ctx, validateReq)
|
|
s.NoError(err)
|
|
|
|
req := &requestpb.CreateTZRequest{
|
|
UserId: validateResp.UserId,
|
|
RequestTxt: "",
|
|
}
|
|
|
|
resp, err := s.requestClient.CreateTZ(ctx, req)
|
|
|
|
if err != nil {
|
|
st, ok := status.FromError(err)
|
|
s.True(ok)
|
|
s.Contains([]codes.Code{codes.InvalidArgument, codes.Internal}, st.Code())
|
|
return
|
|
}
|
|
|
|
s.NotNil(resp)
|
|
}
|
|
|
|
func (s *IntegrationSuite) TestEdgeCase_GenerateInviteWithZeroMaxUses() {
|
|
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)
|
|
|
|
validateReq := &authpb.ValidateRequest{
|
|
AccessToken: loginResp.AccessToken,
|
|
}
|
|
|
|
validateResp, err := s.authClient.Validate(ctx, validateReq)
|
|
s.NoError(err)
|
|
|
|
req := &invitepb.GenerateRequest{
|
|
UserId: validateResp.UserId,
|
|
TtlDays: 30,
|
|
MaxUses: 0,
|
|
}
|
|
|
|
resp, err := s.inviteClient.Generate(ctx, req)
|
|
|
|
if err != nil {
|
|
st, ok := status.FromError(err)
|
|
s.True(ok)
|
|
s.Contains([]codes.Code{codes.InvalidArgument, codes.Internal}, st.Code())
|
|
return
|
|
}
|
|
|
|
s.NotNil(resp)
|
|
}
|
|
|
|
func (s *IntegrationSuite) TestEdgeCase_GenerateInviteWithZeroTTL() {
|
|
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)
|
|
|
|
validateReq := &authpb.ValidateRequest{
|
|
AccessToken: loginResp.AccessToken,
|
|
}
|
|
|
|
validateResp, err := s.authClient.Validate(ctx, validateReq)
|
|
s.NoError(err)
|
|
|
|
req := &invitepb.GenerateRequest{
|
|
UserId: validateResp.UserId,
|
|
TtlDays: 0,
|
|
MaxUses: 10,
|
|
}
|
|
|
|
resp, err := s.inviteClient.Generate(ctx, req)
|
|
|
|
if err != nil {
|
|
st, ok := status.FromError(err)
|
|
s.True(ok)
|
|
s.Contains([]codes.Code{codes.InvalidArgument, codes.Internal}, st.Code())
|
|
return
|
|
}
|
|
|
|
s.NotNil(resp)
|
|
}
|
|
|
|
func (s *IntegrationSuite) TestEdgeCase_ApproveTZWithEmptyFinalTZ() {
|
|
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)
|
|
|
|
validateReq := &authpb.ValidateRequest{
|
|
AccessToken: loginResp.AccessToken,
|
|
}
|
|
|
|
validateResp, err := s.authClient.Validate(ctx, validateReq)
|
|
s.NoError(err)
|
|
|
|
createReq := &requestpb.CreateTZRequest{
|
|
UserId: validateResp.UserId,
|
|
RequestTxt: "Test request",
|
|
}
|
|
|
|
createResp, err := s.requestClient.CreateTZ(ctx, createReq)
|
|
if err != nil {
|
|
s.T().Skip("Cannot test ApproveTZ without CreateTZ")
|
|
return
|
|
}
|
|
|
|
approveReq := &requestpb.ApproveTZRequest{
|
|
RequestId: createResp.RequestId,
|
|
FinalTz: "",
|
|
UserId: validateResp.UserId,
|
|
}
|
|
|
|
approveResp, err := s.requestClient.ApproveTZ(ctx, approveReq)
|
|
|
|
if err != nil {
|
|
st, ok := status.FromError(err)
|
|
s.True(ok)
|
|
s.Contains([]codes.Code{codes.InvalidArgument, codes.Internal}, st.Code())
|
|
return
|
|
}
|
|
|
|
s.NotNil(approveResp)
|
|
}
|
|
|
|
func (s *IntegrationSuite) TestEdgeCase_DoubleLogout() {
|
|
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)
|
|
|
|
logoutReq := &authpb.LogoutRequest{
|
|
AccessToken: loginResp.AccessToken,
|
|
}
|
|
|
|
logoutResp1, err := s.authClient.Logout(ctx, logoutReq)
|
|
s.NoError(err)
|
|
s.True(logoutResp1.Success)
|
|
|
|
logoutResp2, err := s.authClient.Logout(ctx, logoutReq)
|
|
s.NoError(err)
|
|
s.True(logoutResp2.Success)
|
|
}
|
|
|
|
func (s *IntegrationSuite) TestEdgeCase_ValidateAfterLogout() {
|
|
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)
|
|
|
|
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.False(validateResp.Valid)
|
|
s.Equal(int64(0), validateResp.UserId)
|
|
}
|
|
|
|
func (s *IntegrationSuite) TestEdgeCase_RefreshAfterLogout() {
|
|
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)
|
|
|
|
logoutReq := &authpb.LogoutRequest{
|
|
AccessToken: loginResp.AccessToken,
|
|
}
|
|
|
|
logoutResp, err := s.authClient.Logout(ctx, logoutReq)
|
|
s.NoError(err)
|
|
s.True(logoutResp.Success)
|
|
|
|
refreshReq := &authpb.RefreshRequest{
|
|
RefreshToken: loginResp.RefreshToken,
|
|
Ip: "127.0.0.1",
|
|
UserAgent: "integration-test",
|
|
}
|
|
|
|
refreshResp, err := s.authClient.Refresh(ctx, refreshReq)
|
|
s.Error(err)
|
|
s.Nil(refreshResp)
|
|
|
|
st, ok := status.FromError(err)
|
|
s.True(ok)
|
|
s.Equal(codes.Unauthenticated, st.Code())
|
|
}
|
|
|
|
func (s *IntegrationSuite) TestEdgeCase_LoginWithWrongPassword() {
|
|
ctx := context.Background()
|
|
|
|
loginReq := &authpb.LoginRequest{
|
|
Email: "test@example.com",
|
|
Password: "wrongpassword",
|
|
Ip: "127.0.0.1",
|
|
UserAgent: "integration-test",
|
|
}
|
|
|
|
loginResp, err := s.authClient.Login(ctx, loginReq)
|
|
s.Error(err)
|
|
s.Nil(loginResp)
|
|
|
|
st, ok := status.FromError(err)
|
|
s.True(ok)
|
|
s.Equal(codes.Unauthenticated, st.Code())
|
|
}
|