From c1e4aded9db2971bd2f5cfc39e2afb4ba30f5357 Mon Sep 17 00:00:00 2001 From: DeniskaRediska Date: Fri, 7 Oct 2022 16:12:01 +0300 Subject: [PATCH] MSP-1070 add logout test --- tests/auth_test.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tests/auth_test.go b/tests/auth_test.go index 537c6fc..2485093 100644 --- a/tests/auth_test.go +++ b/tests/auth_test.go @@ -5,6 +5,7 @@ import ( "net/http" "net/http/httptest" "testing" + "time" "github.com/integration-system/isp-kit/dbx" "github.com/integration-system/isp-kit/grpc/client" @@ -170,3 +171,44 @@ func (s *AuthTestSuite) initMockSudir() (*httptest.Server, string) { srv := httptest.NewServer(mux) return srv, srv.URL } + +func (s *AuthTestSuite) Test_Logout_HappyPath() { + InsertTokenEntity(s.db, entity.Token{ + Token: "token-841297641213", + UserId: 841297641213, + Status: entity.TokenStatusAllowed, + CreatedAt: time.Time{}, + ExpiredAt: time.Time{}, + }) + err := s.grpcCli.Invoke("admin/auth/logout"). + AppendMetadata(domain.AdminAuthIdHeader, "841297641213"). + Do(context.Background()) + s.Require().NoError(err) + + tokenInfo := SelectTokenEntityByToken(s.db, "token-841297641213") + s.Require().Equal(entity.TokenStatusRevoked, tokenInfo.Status) +} + +func (s *AuthTestSuite) Test_Logout_NotFound() { + err := s.grpcCli.Invoke("admin/auth/logout"). + AppendMetadata(domain.AdminAuthIdHeader, "0143218411981"). + Do(context.Background()) + s.Require().NoError(err) +} + +func (s *AuthTestSuite) Test_Logout_AlreadyRevoke() { + InsertTokenEntity(s.db, entity.Token{ + Token: "token-148623719462", + UserId: 148623719462, + Status: entity.TokenStatusRevoked, + CreatedAt: time.Time{}, + ExpiredAt: time.Time{}, + }) + err := s.grpcCli.Invoke("admin/auth/logout"). + AppendMetadata(domain.AdminAuthIdHeader, "148623719462"). + Do(context.Background()) + s.Require().NoError(err) + + tokenInfo := SelectTokenEntityByToken(s.db, "token-148623719462") + s.Require().Equal(entity.TokenStatusRevoked, tokenInfo.Status) +}