Skip to content

Commit d989e0c

Browse files
fix: resolve golangci-lint issues
- Use assert.Len/require.Len for length checks (testifylint) - Use require.Error for critical error assertions (testifylint) - Remove unused removeHost/patchHost methods (from removed dynamic host management) All tests pass. 0 linting issues.
1 parent b3f736c commit d989e0c

File tree

2 files changed

+7
-25
lines changed

2 files changed

+7
-25
lines changed

internal/remediation/captcha/cookie_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func TestSignAndVerifyCaptchaToken(t *testing.T) {
3131

3232
// JWT format check: header.payload.signature
3333
parts := strings.Split(signed, ".")
34-
assert.Equal(t, 3, len(parts), "JWT should have 3 parts")
34+
assert.Len(t, parts, 3, "JWT should have 3 parts")
3535

3636
// Verify the token
3737
verified, err := ParseAndVerifyCaptchaToken(signed, []byte(testSecret))
@@ -54,7 +54,7 @@ func TestSignCaptchaTokenEmptySecret(t *testing.T) {
5454
// Signing with empty secret should still work (HMAC accepts any key length)
5555
// but it's cryptographically weak - validation should catch this in config
5656
signed, err := SignCaptchaToken(tok, []byte(""))
57-
assert.NoError(t, err, "signing with empty secret succeeds (validation happens at config level)")
57+
require.NoError(t, err, "signing with empty secret succeeds (validation happens at config level)")
5858
assert.NotEmpty(t, signed)
5959
}
6060

@@ -73,7 +73,7 @@ func TestParseAndVerifyExpiredToken(t *testing.T) {
7373

7474
// Verification should fail due to expiration
7575
_, err = ParseAndVerifyCaptchaToken(signed, []byte(testSecret))
76-
assert.Error(t, err, "expired token should be rejected")
76+
require.Error(t, err, "expired token should be rejected")
7777
assert.Contains(t, strings.ToLower(err.Error()), "token is expired", "error should mention expiration")
7878
}
7979

@@ -113,7 +113,7 @@ func TestParseAndVerifyTamperedPayload(t *testing.T) {
113113

114114
// Tamper with the payload (change middle part)
115115
parts := strings.Split(signed, ".")
116-
require.Equal(t, 3, len(parts))
116+
require.Len(t, parts, 3)
117117
parts[1] = parts[1][:len(parts[1])-5] + "XXXXX" // Tamper with payload
118118
tampered := strings.Join(parts, ".")
119119

@@ -145,7 +145,7 @@ func TestParseAndVerifyWrongSecret(t *testing.T) {
145145
// TestParseAndVerifyEmptyToken tests parsing an empty token
146146
func TestParseAndVerifyEmptyToken(t *testing.T) {
147147
_, err := ParseAndVerifyCaptchaToken("", []byte(testSecret))
148-
assert.Error(t, err, "empty token should be rejected")
148+
require.Error(t, err, "empty token should be rejected")
149149
assert.Contains(t, err.Error(), "empty token")
150150
}
151151

@@ -285,7 +285,7 @@ func TestGenerateCaptchaCookie(t *testing.T) {
285285

286286
// Value should be a valid JWT
287287
parts := strings.Split(cookie.Value, ".")
288-
assert.Equal(t, 3, len(parts), "cookie value should be a JWT")
288+
assert.Len(t, parts, 3, "cookie value should be a JWT")
289289
}
290290

291291
// TestGenerateCaptchaCookieInsecure tests cookie generation without secure flag
@@ -361,7 +361,7 @@ func TestCookieLengthLimit(t *testing.T) {
361361
}
362362

363363
_, err := GenerateCaptchaCookie(tok, testSecret, "test_cookie", true, true)
364-
assert.Error(t, err, "cookie exceeding 4096 bytes should be rejected")
364+
require.Error(t, err, "cookie exceeding 4096 bytes should be rejected")
365365
assert.Contains(t, err.Error(), "cookie value too long")
366366
}
367367

pkg/host/root.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -133,24 +133,6 @@ func (h *Manager) sort() {
133133
})
134134
}
135135

136-
func (h *Manager) removeHost(host *Host) {
137-
for i, th := range h.Hosts {
138-
if th == host {
139-
// No cleanup needed
140-
if i == len(h.Hosts)-1 {
141-
h.Hosts = h.Hosts[:i]
142-
} else {
143-
h.Hosts = append(h.Hosts[:i], h.Hosts[i+1:]...)
144-
}
145-
return
146-
}
147-
}
148-
}
149-
150-
func (h *Manager) patchHost(host *Host) {
151-
//TODO
152-
}
153-
154136
// createHostLogger creates a logger for a host that inherits from the base logger
155137
// while allowing host-specific overrides like log level
156138
func (h *Manager) createHostLogger(host *Host) *log.Entry {

0 commit comments

Comments
 (0)