Skip to content

Commit

Permalink
fix token don't send on feedback (#642)
Browse files Browse the repository at this point in the history
Co-authored-by: Romanenko Aleksei <[email protected]>
Co-authored-by: rsmnarts <[email protected]>
  • Loading branch information
3 people authored Nov 6, 2021
1 parent eac2553 commit bd920d3
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion logx/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,14 @@ func hideToken(token string, markLen int) string {
// GetLogPushEntry get push data into log structure
func GetLogPushEntry(input *InputLog) LogPushEntry {
var errMsg string
var token string

plat := typeForPlatForm(input.Platform)

if input.Error != nil {
errMsg = input.Error.Error()
}

token := input.Token
if input.HideToken {
token = hideToken(input.Token, 10)
}
Expand Down
43 changes: 43 additions & 0 deletions logx/log_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package logx

import (
"errors"
"testing"

"github.com/appleboy/gorush/config"
Expand Down Expand Up @@ -56,6 +57,15 @@ func TestInitDefaultLog(t *testing.T) {
cfg.Log.ErrorLevel,
cfg.Log.ErrorLog,
))

isTerm = true

assert.NotNil(t, InitLog(
cfg.Log.AccessLevel,
cfg.Log.AccessLog,
cfg.Log.ErrorLevel,
cfg.Log.ErrorLog,
))
}

func TestAccessLevel(t *testing.T) {
Expand Down Expand Up @@ -113,12 +123,14 @@ func TestErrorLogPath(t *testing.T) {
func TestPlatFormType(t *testing.T) {
assert.Equal(t, "ios", typeForPlatForm(core.PlatFormIos))
assert.Equal(t, "android", typeForPlatForm(core.PlatFormAndroid))
assert.Equal(t, "huawei", typeForPlatForm(core.PlatFormHuawei))
assert.Equal(t, "", typeForPlatForm(10000))
}

func TestPlatFormColor(t *testing.T) {
assert.Equal(t, blue, colorForPlatForm(core.PlatFormIos))
assert.Equal(t, yellow, colorForPlatForm(core.PlatFormAndroid))
assert.Equal(t, green, colorForPlatForm(core.PlatFormHuawei))
assert.Equal(t, reset, colorForPlatForm(1000000))
}

Expand All @@ -127,3 +139,34 @@ func TestHideToken(t *testing.T) {
assert.Equal(t, "**345678**", hideToken("1234567890", 2))
assert.Equal(t, "*****", hideToken("12345", 10))
}

func TestLogPushEntry(t *testing.T) {
in := InputLog{}

in.Platform = 1
assert.Equal(t, "ios", GetLogPushEntry(&in).Platform)

in.Error = errors.New("error")
assert.Equal(t, "error", GetLogPushEntry(&in).Error)

in.Token = "1234567890"
in.HideToken = true
assert.Equal(t, "**********", GetLogPushEntry(&in).Token)
}

func TestLogPush(t *testing.T) {
in := InputLog{}
isTerm = true

in.Format = "json"
in.Status = "succeeded-push"
assert.Equal(t, "succeeded-push", LogPush(&in).Type)

in.Format = ""
in.Message = "success"
assert.Equal(t, "success", LogPush(&in).Message)

in.Status = "failed-push"
in.Message = "failed"
assert.Equal(t, "failed", LogPush(&in).Message)
}

0 comments on commit bd920d3

Please sign in to comment.