diff --git a/internal/authenticator/auto_authenticator_test.go b/internal/authenticator/auto_authenticator_test.go index 2576980..b3269f7 100644 --- a/internal/authenticator/auto_authenticator_test.go +++ b/internal/authenticator/auto_authenticator_test.go @@ -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" ) @@ -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() { @@ -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{ @@ -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) }) } diff --git a/internal/authenticator/manual_authenticator_test.go b/internal/authenticator/manual_authenticator_test.go index 1ebc731..69ec1e5 100644 --- a/internal/authenticator/manual_authenticator_test.go +++ b/internal/authenticator/manual_authenticator_test.go @@ -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" ) @@ -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() { @@ -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{ @@ -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) }) } diff --git a/internal/topics/manager.go b/internal/topics/manager.go index 446e063..03d841c 100644 --- a/internal/topics/manager.go +++ b/internal/topics/manager.go @@ -5,8 +5,10 @@ package topics import ( "crypto/md5" //nolint: gosec + "encoding/hex" "fmt" "regexp" + "strconv" "strings" "text/template" @@ -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 { @@ -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 {