Skip to content

Commit 6a4b0af

Browse files
committed
fix more
1 parent 0867bfc commit 6a4b0af

File tree

18 files changed

+39
-23
lines changed

18 files changed

+39
-23
lines changed

cmd/admin_user_create.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ func runCreateUser(ctx context.Context, c *cli.Command) error {
151151
if err != nil {
152152
return err
153153
}
154+
// codeql[disable-next-line=go/clear-text-logging]
154155
fmt.Printf("generated random password is '%s'\n", password)
155156
} else if userType == user_model.UserTypeIndividual {
156157
return errors.New("must set either password or random-password flag")

cmd/admin_user_must_change_password.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ func runMustChangePassword(ctx context.Context, c *cli.Command) error {
5858
return err
5959
}
6060

61+
// codeql[disable-next-line=go/clear-text-logging]
6162
fmt.Printf("Updated %d users setting MustChangePassword to %t\n", n, mustChangePassword)
6263
return nil
6364
}

cmd/generate.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ func runGenerateSecretKey(_ context.Context, c *cli.Command) error {
9191
return err
9292
}
9393

94+
// codeql[disable-next-line=go/clear-text-logging]
9495
fmt.Printf("%s", secretKey)
9596

9697
if isatty.IsTerminal(os.Stdout.Fd()) {

cmd/hook.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ Gitea or set your environment appropriately.`, "")
186186
userID, _ := strconv.ParseInt(os.Getenv(repo_module.EnvPusherID), 10, 64)
187187
prID, _ := strconv.ParseInt(os.Getenv(repo_module.EnvPRID), 10, 64)
188188
deployKeyID, _ := strconv.ParseInt(os.Getenv(repo_module.EnvDeployKeyID), 10, 64)
189-
actionPerm, _ := strconv.ParseInt(os.Getenv(repo_module.EnvActionPerm), 10, 64)
189+
actionPerm, _ := strconv.Atoi(os.Getenv(repo_module.EnvActionPerm))
190190

191191
hookOptions := private.HookOptions{
192192
UserID: userID,
@@ -196,7 +196,7 @@ Gitea or set your environment appropriately.`, "")
196196
GitPushOptions: pushOptions(),
197197
PullRequestID: prID,
198198
DeployKeyID: deployKeyID,
199-
ActionPerm: int(actionPerm),
199+
ActionPerm: actionPerm,
200200
}
201201

202202
scanner := bufio.NewScanner(os.Stdin)

modules/auth/password/pwn/pwn.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func newRequest(ctx context.Context, method, url string, body io.ReadCloser) (*h
7272
// Adding padding will make requests more secure, however is also slower
7373
// because artificial responses will be added to the response
7474
// For more information, see https://www.troyhunt.com/enhancing-pwned-passwords-privacy-with-padding/
75-
func (c *Client) CheckPassword(pw string, padding bool) (int, error) {
75+
func (c *Client) CheckPassword(pw string, padding bool) (int64, error) {
7676
if pw == "" {
7777
return -1, ErrEmptyPassword
7878
}
@@ -111,7 +111,7 @@ func (c *Client) CheckPassword(pw string, padding bool) (int, error) {
111111
if err != nil {
112112
return -1, err
113113
}
114-
return int(count), nil
114+
return count, nil
115115
}
116116
}
117117
return 0, nil

modules/auth/password/pwn/pwn_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,25 @@ func TestPassword(t *testing.T) {
3737

3838
count, err := client.CheckPassword("", false)
3939
assert.ErrorIs(t, err, ErrEmptyPassword, "blank input should return ErrEmptyPassword")
40-
assert.Equal(t, -1, count)
40+
assert.EqualValues(t, -1, count)
4141

4242
count, err = client.CheckPassword("pwned", false)
4343
assert.NoError(t, err)
44-
assert.Equal(t, 1, count)
44+
assert.EqualValues(t, 1, count)
4545

4646
count, err = client.CheckPassword("notpwned", false)
4747
assert.NoError(t, err)
48-
assert.Equal(t, 0, count)
48+
assert.EqualValues(t, 0, count)
4949

5050
count, err = client.CheckPassword("paddedpwned", true)
5151
assert.NoError(t, err)
52-
assert.Equal(t, 1, count)
52+
assert.EqualValues(t, 1, count)
5353

5454
count, err = client.CheckPassword("paddednotpwned", true)
5555
assert.NoError(t, err)
56-
assert.Equal(t, 0, count)
56+
assert.EqualValues(t, 0, count)
5757

5858
count, err = client.CheckPassword("paddednotpwnedzero", true)
5959
assert.NoError(t, err)
60-
assert.Equal(t, 0, count)
60+
assert.EqualValues(t, 0, count)
6161
}

modules/log/logger_global.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ func GetLevel() Level {
1818
}
1919

2020
func Log(skip int, level Level, format string, v ...any) {
21+
// codeql[disable-next-line=go/clear-text-logging]
2122
GetLogger(DEFAULT).Log(skip+1, &Event{Level: level}, format, v...)
2223
}
2324

modules/log/misc.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func BaseLoggerToGeneralLogger(b BaseLogger) Logger {
2020
var _ Logger = (*baseToLogger)(nil)
2121

2222
func (s *baseToLogger) Log(skip int, event *Event, format string, v ...any) {
23+
// codeql[disable-next-line=go/clear-text-logging]
2324
s.base.Log(skip+1, event, format, v...)
2425
}
2526

modules/translation/i18n/i18n_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ sub = Changed Sub String
6262
found := lang1.HasKey("no-such")
6363
assert.False(t, found)
6464
assert.NoError(t, ls.Close())
65+
66+
res := lang1.TrHTML("<no-such>")
67+
assert.Equal(t, "&lt;no-such&gt;", string(res))
6568
}
6669

6770
func TestLocaleStoreMoreSource(t *testing.T) {

modules/translation/i18n/localestore.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package i18n
66
import (
77
"errors"
88
"fmt"
9+
"html"
910
"html/template"
1011
"slices"
1112

@@ -109,8 +110,7 @@ func (store *localeStore) Close() error {
109110
}
110111

111112
func (l *locale) TrString(trKey string, trArgs ...any) string {
112-
format := trKey
113-
113+
var format string
114114
idx, ok := l.store.trKeyToIdxMap[trKey]
115115
if ok {
116116
if msg, ok := l.idxToMsgMap[idx]; ok {
@@ -122,7 +122,9 @@ func (l *locale) TrString(trKey string, trArgs ...any) string {
122122
}
123123
}
124124
}
125-
125+
if format == "" {
126+
format = html.EscapeString(trKey)
127+
}
126128
msg, err := Format(format, trArgs...)
127129
if err != nil {
128130
log.Error("Error whilst formatting %q in %s: %v", trKey, l.langName, err)

0 commit comments

Comments
 (0)