Skip to content

Commit

Permalink
fix: correct lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
1995parham committed Feb 12, 2024
1 parent 1d1a8aa commit b418ce4
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 7 deletions.
8 changes: 3 additions & 5 deletions internal/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,11 @@ func TestExtractVendorToken(t *testing.T) {

t.Run(tt.name, func(t *testing.T) {
t.Parallel()

vendor, token := api.ExtractVendorToken(tt.fields.Token, tt.fields.Username, tt.fields.Password)
if vendor != tt.vendor {
if vendor != tt.vendor || token != tt.token {
t.Errorf("ExtractVendorToken() vendor = %v, vendor %v", vendor, tt.vendor)
}
if token != tt.token {
t.Errorf("ExtractVendorToken() token = %v, vendor %v", token, tt.token)
}
})
}
}
Expand Down Expand Up @@ -176,7 +174,7 @@ func (suite *APITestSuite) ValidToken() {

body, err := json.Marshal(api.AuthRequest{
Token: "",
Username: fmt.Sprintf("snapp-admin:%s", token),
Username: "snapp-admin:" + token,
Password: "",
})
require.NoError(err)
Expand Down
1 change: 1 addition & 0 deletions internal/authenticator/admin_authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func (a AdminAuthenticator) Auth(tokenString string) error {
if !ok {
return nil, ErrInvalidClaims
}

if claims[a.JwtConfig.IssName] == nil {
return nil, ErrIssNotFound
}
Expand Down
2 changes: 1 addition & 1 deletion internal/authenticator/auto_authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (a AutoAuthenticator) Auth(tokenString string) error {
"X-APP-Version": []string{""},
"X-APP-Name": []string{"soteria"},
"locale": []string{"en-US"},
}, fmt.Sprintf("bearer %s", tokenString)); err != nil {
}, "bearer "+tokenString); err != nil {
return fmt.Errorf("token is invalid: %w", err)
}

Expand Down
3 changes: 2 additions & 1 deletion internal/authenticator/auto_authenticator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (suite *AutoAuthenticatorTestSuite) SetupSuite() {
tokenString := strings.TrimPrefix(authHeader, "bearer ")

_, err := jwt.Parse(tokenString, func(
token *jwt.Token,
_ *jwt.Token,
) (interface{}, error) {
return pkey0, nil
})
Expand Down Expand Up @@ -128,6 +128,7 @@ func TestAutoAuthenticator_ValidateTopicBySender(t *testing.T) {

t.Run("testing valid driver cab event", func(t *testing.T) {
t.Parallel()

topicTemplate := authenticator.TopicManager.ParseTopic(validDriverCabEventTopic, topics.DriverIss, "DXKgaNQa7N5Y7bo")
require.NotNil(t, topicTemplate)
})
Expand Down
5 changes: 5 additions & 0 deletions internal/authenticator/manual_authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ func (a ManualAuthenticator) Auth(tokenString string) error {
if !ok {
return nil, ErrInvalidClaims
}

if claims[a.JWTConfig.IssName] == nil {
return nil, ErrIssNotFound
}

issuer := fmt.Sprintf("%v", claims[a.JWTConfig.IssName])

key := a.Keys[issuer]
if key == nil {
return nil, KeyNotFoundError{Issuer: issuer}
Expand Down Expand Up @@ -64,14 +66,17 @@ func (a ManualAuthenticator) ACL(
if !ok {
return nil, ErrInvalidClaims
}

if claims[a.JWTConfig.IssName] == nil {
return nil, ErrIssNotFound
}

if claims[a.JWTConfig.SubName] == nil {
return nil, ErrSubNotFound
}

issuer := fmt.Sprintf("%v", claims[a.JWTConfig.IssName])

key := a.Keys[issuer]
if key == nil {
return nil, KeyNotFoundError{Issuer: issuer}
Expand Down
1 change: 1 addition & 0 deletions internal/authenticator/manual_authenticator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ func TestManualAuthenticator_ValidateTopicBySender(t *testing.T) {

t.Run("testing valid driver cab event", func(t *testing.T) {
t.Parallel()

topicTemplate := authenticator.TopicManager.ParseTopic(validDriverCabEventTopic, topics.DriverIss, "DXKgaNQa7N5Y7bo")
require.NotNil(t, topicTemplate)
})
Expand Down
1 change: 1 addition & 0 deletions internal/topics/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ func TestTopicManager(t *testing.T) {
t.Parallel()

topic := tc.arg

topicTemplate := topicManager.ParseTopic(topic, tc.issuer, sub)
if topicTemplate != nil {
if len(tc.want) == 0 {
Expand Down

0 comments on commit b418ce4

Please sign in to comment.