@@ -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
146146func 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
0 commit comments