Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
zulkhair committed May 16, 2024
1 parent eb09b9b commit e2b31dc
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 17 deletions.
3 changes: 1 addition & 2 deletions cmd/world/root/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ func getLoginCmd() *cobra.Command {
Short: "Authenticate using an access token",
RunE: func(cmd *cobra.Command, _ []string) error {
logger.SetDebugMode(cmd)

Check warning on line 41 in cmd/world/root/login.go

View check run for this annotation

Codecov / codecov/patch

cmd/world/root/login.go#L41

Added line #L41 was not covered by tests
var err error

// TODO : it's not necessary to check existing login token
// Check existing login
Expand All @@ -64,7 +63,7 @@ func getLoginCmd() *cobra.Command {
// logger.ErrorE(eris.Wrap(err, "failed to get access token"))
// }

err = loginOnBrowser(cmd.Context())
err := loginOnBrowser(cmd.Context())
if err != nil {
return eris.Wrap(err, "failed to login")

Check warning on line 68 in cmd/world/root/login.go

View check run for this annotation

Codecov / codecov/patch

cmd/world/root/login.go#L66-L68

Added lines #L66 - L68 were not covered by tests
}
Expand Down
11 changes: 6 additions & 5 deletions cmd/world/root/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

"github.com/spf13/cobra"
tassert "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gotest.tools/v3/assert"

"pkg.world.dev/world-cli/cmd/world/cardinal"
Expand Down Expand Up @@ -279,7 +280,7 @@ func TestGenerateTokenName(t *testing.T) {
name, err := generateTokenName()

// Ensure no error was returned
tassert.NoError(t, err)
require.NoError(t, err)

// Ensure the name follows the expected pattern
tassert.Contains(t, name, "cli_")
Expand Down Expand Up @@ -367,12 +368,12 @@ func TestPollForAccessToken(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
handler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
if test.retryAfterHeader != "" {
w.Header().Set("Retry-After", test.retryAfterHeader)
}
w.WriteHeader(test.statusCode)
w.Write([]byte(test.responseBody))
w.Write([]byte(test.responseBody)) //nolint:errcheck // Ignore error for test
})

server := httptest.NewServer(handler)
Expand All @@ -384,9 +385,9 @@ func TestPollForAccessToken(t *testing.T) {
response, err := pollForAccessToken(ctx, server.URL)

if test.expectError {
tassert.Error(t, err)
require.Error(t, err)
} else {
tassert.NoError(t, err)
require.NoError(t, err)
tassert.Equal(t, test.expectedResponse, response)
}
})
Expand Down
3 changes: 2 additions & 1 deletion common/globalconfig/globalconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import (
"path/filepath"

"github.com/rotisserie/eris"

"pkg.world.dev/world-cli/common/logger"
)

const (
configDir = ".worldcli"
credentialFileName = "credential.json"
credentialFileName = "credential.json" //nolint:gosec // This is not a credential
)

type Credential struct {
Expand Down
2 changes: 1 addition & 1 deletion common/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func Error(args ...interface{}) {

// Error function
func ErrorE(err error) {
log.Error().Timestamp().Err(err)
log.Error().Timestamp().Err(err).Msg(err.Error())
}

// Errorln function
Expand Down
15 changes: 8 additions & 7 deletions common/login/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,35 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestDecryptAccessToken(t *testing.T) {
// Initialize encryption
enc, err := NewEncryption()
assert.NoError(t, err)
require.NoError(t, err)

// Generate a remote key pair
remoteCurve := ecdh.P256()
remotePrivateKey, err := remoteCurve.GenerateKey(rand.Reader)
assert.NoError(t, err)
require.NoError(t, err)
remotePublicKey := remotePrivateKey.PublicKey()

// Sample access token and nonce
accessToken := "sample_access_token"
nonce := make([]byte, 12)
_, err = rand.Read(nonce)
assert.NoError(t, err)
require.NoError(t, err)

// Encrypt the access token
secret, err := remotePrivateKey.ECDH(enc.publicKey)
assert.NoError(t, err)
require.NoError(t, err)

block, err := aes.NewCipher(secret)
assert.NoError(t, err)
require.NoError(t, err)

aesgcm, err := cipher.NewGCM(block)
assert.NoError(t, err)
require.NoError(t, err)

ciphertext := aesgcm.Seal(nil, nonce, []byte(accessToken), nil)

Expand All @@ -49,6 +50,6 @@ func TestDecryptAccessToken(t *testing.T) {
decryptedAccessToken, err := enc.DecryptAccessToken(hexAccessToken, hexPublicKey, hexNonce)

// Assertions
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, accessToken, decryptedAccessToken)
}
3 changes: 2 additions & 1 deletion telemetry/sentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ func (h SentryHook) Run(_ *zerolog.Event, level zerolog.Level, msg string) {

// Levels returns the log levels that this hook should be triggered for
func (h SentryHook) Levels() []zerolog.Level {
return []zerolog.Level{zerolog.ErrorLevel, zerolog.FatalLevel, zerolog.DebugLevel, zerolog.PanicLevel, zerolog.WarnLevel}
return []zerolog.Level{zerolog.ErrorLevel, zerolog.FatalLevel, zerolog.DebugLevel,
zerolog.PanicLevel, zerolog.WarnLevel}

Check warning on line 39 in telemetry/sentry.go

View check run for this annotation

Codecov / codecov/patch

telemetry/sentry.go#L38-L39

Added lines #L38 - L39 were not covered by tests
}

// SentryInit initialize sentry
Expand Down

0 comments on commit e2b31dc

Please sign in to comment.