@@ -257,86 +257,29 @@ describe("oauth", function()
257257 assert .is .same (" new_access_token" , get_auth_header ())
258258 end )
259259
260- it (" basic auth with credentials containing + character (standard Base64 required )" , function ()
260+ it (" encodes correctly Basic auth credentials - with Base64 (not url-safe )" , function ()
261261 cmd .queue .resume :revert ()
262262
263- -- Safe test credentials that produce '+' in Base64 (would fail with URL-safe encoding)
264- update_env {
265- [" Grant Type" ] = " Client Credentials" ,
266- [" Client Credentials" ] = " basic" ,
267- [" Client ID" ] = " test" ,
268- }
269-
270- update_env ({
271- [" Client Secret" ] = " >" ,
272- }, true )
273-
274- kulala .run ()
275- wait_for_requests (1 )
276-
277- -- Should use standard Base64 encoding (containing '+' character)
278- local expected_standard_b64 = " dGVzdDo+"
279- local expected_header = " Authorization: Basic " .. expected_standard_b64
280-
281- assert .has_properties (get_request (), {
282- audience = " kulala_api" ,
283- grant_type = " client_credentials" ,
284- headers = expected_header ,
285- url = " https://token.url" ,
286- })
287-
288- -- Verify the header contains '+' character (standard Base64) not '-' (URL-safe)
289- assert .is_true (
290- get_request ().headers :find (" +" , 1 , true ) ~= nil ,
291- " Authorization header should contain '+' character from standard Base64 encoding"
292- )
293- assert .is_false (
294- get_request ().headers :find (" dGVzdDo-" , 1 , true ) ~= nil ,
295- " Authorization header should NOT use URL-safe Base64 encoding (with '-' instead of '+')"
296- )
297-
298- assert .has_properties (get_env (), {
299- access_token = " new_access_token" ,
300- })
301- assert .near (os.time (), get_env ().acquired_at , 1 )
302-
303- assert .is .same (" new_access_token" , get_auth_header ())
304- end )
305-
306- it (" basic auth with credentials containing / character (standard Base64 required)" , function ()
307- cmd .queue .resume :revert ()
308-
309- -- Safe test credentials that produce '/' in Base64 (would fail with URL-safe encoding)
310263 update_env {
311264 [" Grant Type" ] = " Client Credentials" ,
312265 [" Client Credentials" ] = " basic" ,
313266 [" Client ID" ] = " user123" ,
314267 }
315268
316269 update_env ({
317- [" Client Secret" ] = " ?pass" ,
270+ [" Client Secret" ] = " ?pass>> " ,
318271 }, true )
319272
320273 kulala .run ()
321274 wait_for_requests (1 )
322275
323- -- Should use standard Base64 encoding (containing '/' character)
324- local expected_standard_b64 = " dXNlcjEyMzo/cGFzcw=="
325- local expected_header = " Authorization: Basic " .. expected_standard_b64
326-
327276 assert .has_properties (get_request (), {
328277 audience = " kulala_api" ,
329278 grant_type = " client_credentials" ,
330- headers = expected_header ,
279+ headers = " Authorization: Basic dXNlcjEyMzo/cGFzcz4+ " ,
331280 url = " https://token.url" ,
332281 })
333282
334- -- Verify the header contains '/' character (standard Base64) not '_' (URL-safe)
335- assert .is_true (
336- get_request ().headers :find (" /" , 1 , true ) ~= nil ,
337- " Authorization header should contain '/' character from standard Base64 encoding"
338- )
339-
340283 assert .has_properties (get_env (), {
341284 access_token = " new_access_token" ,
342285 })
@@ -677,38 +620,20 @@ describe("oauth", function()
677620 assert .is_true (# get_request ().code_verifier > 0 )
678621 end )
679622
680- it (" uses URL-safe Base64 encoding for PKCE (regression test)" , function ()
681- -- This test ensures our OAuth2 Basic auth fix didn't break PKCE URL-safe encoding
682- local crypto = require (" kulala.cmd.crypto" )
683-
684- -- Test data that produces different results with standard vs URL-safe encoding
685- local test_data = " test:>"
686-
687- local standard_b64 = crypto .base64_encode_standard (test_data )
688- local url_safe_b64 = crypto .base64_encode (test_data )
689-
690- -- They should be different (URL-safe should not have +, /, or = chars)
691- assert .is_not .same (standard_b64 , url_safe_b64 , " PKCE should use URL-safe Base64, not standard Base64" )
692-
693- -- Standard should have '+' character
694- assert .is_true (standard_b64 :find (" +" , 1 , true ) ~= nil , " Standard Base64 should contain '+' character" )
695-
696- -- URL-safe should not contain +, /, or = characters
697- assert .is_false (
698- url_safe_b64 :find (" +" , 1 , true ) ~= nil ,
699- " PKCE Base64 should not contain '+' character (should use URL-safe encoding)"
700- )
701- assert .is_false (
702- url_safe_b64 :find (" /" , 1 , true ) ~= nil ,
703- " PKCE Base64 should not contain '/' character (should use URL-safe encoding)"
704- )
705- assert .is_false (
706- url_safe_b64 :find (" =" , 1 , true ) ~= nil ,
707- " PKCE Base64 should not contain padding '=' character (should use URL-safe encoding)"
708- )
709-
710- -- URL-safe should have '-' instead of '+'
711- assert .is_true (url_safe_b64 :find (" -" , 1 , true ) ~= nil , " URL-safe Base64 should contain '-' instead of '+'" )
623+ it (" uses URL-safe Base64 encoding for PKCE" , function ()
624+ update_env {
625+ [" Grant Type" ] = " Authorization Code" ,
626+ PKCE = {
627+ [" Code Verifier" ] = " *YYLzIBzrXpVaH5KRx86itubKLXHNGnJBPAogEwkhveM" ,
628+ [" Code Challenge Method" ] = " S256" ,
629+ },
630+ }
631+
632+ kulala .run ()
633+ wait_for_requests (1 )
634+
635+ local code_challenge = result .url_params .code_challenge
636+ assert .is_falsy (code_challenge :find (" +" ) or code_challenge :find (" /" ) or code_challenge :find (" =" ))
712637 end )
713638 end )
714639
0 commit comments