From bd920d34fb3743e182e9db3f8606e6f2ee7bc442 Mon Sep 17 00:00:00 2001 From: rsmnarts <40693945+rsmnarts@users.noreply.github.com> Date: Sat, 6 Nov 2021 16:57:34 +0700 Subject: [PATCH] fix token don't send on feedback (#642) Co-authored-by: Romanenko Aleksei Co-authored-by: rsmnarts --- logx/log.go | 2 +- logx/log_test.go | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/logx/log.go b/logx/log.go index 056ac5b..b7b78b6 100644 --- a/logx/log.go +++ b/logx/log.go @@ -162,7 +162,6 @@ 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) @@ -170,6 +169,7 @@ func GetLogPushEntry(input *InputLog) LogPushEntry { errMsg = input.Error.Error() } + token := input.Token if input.HideToken { token = hideToken(input.Token, 10) } diff --git a/logx/log_test.go b/logx/log_test.go index ee1ed33..de6d275 100644 --- a/logx/log_test.go +++ b/logx/log_test.go @@ -1,6 +1,7 @@ package logx import ( + "errors" "testing" "github.com/appleboy/gorush/config" @@ -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) { @@ -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)) } @@ -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) +}