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 Oct 21, 2023
1 parent cc842ce commit 429960b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
14 changes: 7 additions & 7 deletions internal/authenticator/auto_authenticator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/snapp-incubator/soteria/internal/config"
"github.com/snapp-incubator/soteria/internal/topics"
"github.com/snapp-incubator/soteria/pkg/acl"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -219,14 +219,14 @@ func (suite *AutoAuthenticatorTestSuite) TestACL_Driver() {

suite.Run("testing driver subscribe on valid superapp event topic", func() {
ok, err := suite.Authenticator.ACL(acl.Sub, token, validDriverSuperappEventTopic)
suite.NoError(err)
suite.True(ok)
require.NoError(err)
require.True(ok)
})

suite.Run("testing driver subscribe on invalid superapp event topic", func() {
ok, err := suite.Authenticator.ACL(acl.Sub, token, invalidDriverSuperappEventTopic)
suite.Error(err)
suite.False(ok)
require.Error(err)
require.False(ok)
})

suite.Run("testing driver subscribe on valid shared location topic", func() {
Expand Down Expand Up @@ -291,7 +291,7 @@ func TestAutoAuthenticator_ValidateTopicBySender(t *testing.T) {
cfg.UseValidator = true

hid, err := topics.NewHashIDManager(cfg.HashIDMap)
assert.NoError(t, err)
require.NoError(t, err)

// nolint: exhaustruct
authenticator := authenticator.AutoAuthenticator{
Expand All @@ -304,7 +304,7 @@ func TestAutoAuthenticator_ValidateTopicBySender(t *testing.T) {
t.Parallel()

topicTemplate := authenticator.TopicManager.ParseTopic(validDriverCabEventTopic, topics.DriverIss, "DXKgaNQa7N5Y7bo")
assert.True(t, topicTemplate != nil)
require.NotNil(t, topicTemplate)
})
}

Expand Down
14 changes: 7 additions & 7 deletions internal/authenticator/manual_authenticator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/snapp-incubator/soteria/internal/config"
"github.com/snapp-incubator/soteria/internal/topics"
"github.com/snapp-incubator/soteria/pkg/acl"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -221,14 +221,14 @@ func (suite *ManualAuthenticatorTestSuite) TestACL_Driver() {

suite.Run("testing driver subscribe on valid superapp event topic", func() {
ok, err := suite.Authenticator.ACL(acl.Sub, token, validDriverSuperappEventTopic)
suite.NoError(err)
suite.True(ok)
require.NoError(err)
require.True(ok)
})

suite.Run("testing driver subscribe on invalid superapp event topic", func() {
ok, err := suite.Authenticator.ACL(acl.Sub, token, invalidDriverSuperappEventTopic)
suite.Error(err)
suite.False(ok)
require.Error(err)
require.False(ok)
})

suite.Run("testing driver subscribe on valid shared location topic", func() {
Expand Down Expand Up @@ -292,7 +292,7 @@ func TestManualAuthenticator_ValidateTopicBySender(t *testing.T) {
cfg := config.SnappVendor()

hid, err := topics.NewHashIDManager(cfg.HashIDMap)
assert.NoError(t, err)
require.NoError(t, err)

// nolint: exhaustruct
authenticator := authenticator.ManualAuthenticator{
Expand All @@ -304,7 +304,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")
assert.True(t, topicTemplate != nil)
require.NotNil(t, topicTemplate)
})
}

Expand Down
6 changes: 4 additions & 2 deletions internal/topics/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ package topics

import (
"crypto/md5" //nolint: gosec
"encoding/hex"
"fmt"
"regexp"
"strconv"
"strings"
"text/template"

Expand Down Expand Up @@ -127,7 +129,7 @@ func (t *Manager) ParseTopic(topic, iss, sub string) *Template {
func (t *Manager) EncodeMD5(iss string) string {
hid := md5.Sum([]byte(fmt.Sprintf("%s-%s", EmqCabHashPrefix, iss))) //nolint:gosec

return fmt.Sprintf("%x", hid)
return hex.EncodeToString(hid[:])
}

func (t *Manager) DecodeHashID(sub, iss string) string {
Expand All @@ -138,7 +140,7 @@ func (t *Manager) DecodeHashID(sub, iss string) string {
return ""
}

return fmt.Sprintf("%d", id[0])
return strconv.Itoa(id[0])
}

func (t *Manager) IssEntityMapper(iss string) string {
Expand Down

0 comments on commit 429960b

Please sign in to comment.