@@ -338,6 +338,129 @@ describe('importer-curl', () => {
338338 } ) ;
339339 } ) ;
340340
341+ test ( 'Imports Bearer token from Authorization header' , ( ) => {
342+ expect (
343+ convertCurl ( 'curl -H "Authorization: Bearer token123" https://yaak.app' ) ,
344+ ) . toEqual ( {
345+ resources : {
346+ workspaces : [ baseWorkspace ( ) ] ,
347+ httpRequests : [
348+ baseRequest ( {
349+ url : 'https://yaak.app' ,
350+ authenticationType : 'bearer' ,
351+ authentication : {
352+ token : 'token123' ,
353+ prefix : 'Bearer' ,
354+ } ,
355+ headers : [ ] ,
356+ } ) ,
357+ ] ,
358+ } ,
359+ } ) ;
360+ } ) ;
361+
362+ test ( 'Imports Basic auth from Authorization header (base64 decoded)' , ( ) => {
363+ expect (
364+ convertCurl ( 'curl -H "Authorization: Basic dXNlcjpwYXNzd29yZA==" https://yaak.app' ) ,
365+ ) . toEqual ( {
366+ resources : {
367+ workspaces : [ baseWorkspace ( ) ] ,
368+ httpRequests : [
369+ baseRequest ( {
370+ url : 'https://yaak.app' ,
371+ authenticationType : 'basic' ,
372+ authentication : {
373+ username : 'user' ,
374+ password : 'password' ,
375+ } ,
376+ headers : [ ] ,
377+ } ) ,
378+ ] ,
379+ } ,
380+ } ) ;
381+ } ) ;
382+
383+ test ( 'Authorization header takes precedence over -u flag' , ( ) => {
384+ expect (
385+ convertCurl ( 'curl -u admin:secret -H "Authorization: Bearer token123" https://yaak.app' ) ,
386+ ) . toEqual ( {
387+ resources : {
388+ workspaces : [ baseWorkspace ( ) ] ,
389+ httpRequests : [
390+ baseRequest ( {
391+ url : 'https://yaak.app' ,
392+ authenticationType : 'bearer' ,
393+ authentication : {
394+ token : 'token123' ,
395+ prefix : 'Bearer' ,
396+ } ,
397+ headers : [ ] ,
398+ } ) ,
399+ ] ,
400+ } ,
401+ } ) ;
402+ } ) ;
403+
404+ test ( 'Authorization header extraction is case-insensitive' , ( ) => {
405+ expect (
406+ convertCurl ( 'curl -H "authorization: bearer lowercaseToken" https://yaak.app' ) ,
407+ ) . toEqual ( {
408+ resources : {
409+ workspaces : [ baseWorkspace ( ) ] ,
410+ httpRequests : [
411+ baseRequest ( {
412+ url : 'https://yaak.app' ,
413+ authenticationType : 'bearer' ,
414+ authentication : {
415+ token : 'lowercaseToken' ,
416+ prefix : 'Bearer' ,
417+ } ,
418+ headers : [ ] ,
419+ } ) ,
420+ ] ,
421+ } ,
422+ } ) ;
423+ } ) ;
424+
425+ test ( 'Preserves other headers when extracting Authorization' , ( ) => {
426+ expect (
427+ convertCurl ( 'curl -H "Authorization: Bearer token123" -H "X-Custom: value" https://yaak.app' ) ,
428+ ) . toEqual ( {
429+ resources : {
430+ workspaces : [ baseWorkspace ( ) ] ,
431+ httpRequests : [
432+ baseRequest ( {
433+ url : 'https://yaak.app' ,
434+ authenticationType : 'bearer' ,
435+ authentication : {
436+ token : 'token123' ,
437+ prefix : 'Bearer' ,
438+ } ,
439+ headers : [ { name : 'X-Custom' , value : 'value' , enabled : true } ] ,
440+ } ) ,
441+ ] ,
442+ } ,
443+ } ) ;
444+ } ) ;
445+
446+ test ( 'Invalid base64 in Basic auth keeps header in headers' , ( ) => {
447+ expect (
448+ convertCurl ( 'curl -H "Authorization: Basic not-valid-base64!!!" https://yaak.app' ) ,
449+ ) . toEqual ( {
450+ resources : {
451+ workspaces : [ baseWorkspace ( ) ] ,
452+ httpRequests : [
453+ baseRequest ( {
454+ url : 'https://yaak.app' ,
455+ headers : [
456+ { name : 'Authorization' , value : 'Basic not-valid-base64!!!' , enabled : true } ,
457+ ] ,
458+ } ) ,
459+ ] ,
460+ } ,
461+ } ) ;
462+ } ) ;
463+
341464 test ( 'Imports cookie as header' , ( ) => {
342465 expect ( convertCurl ( 'curl --cookie "foo=bar" https://yaak.app' ) ) . toEqual ( {
343466 resources : {
0 commit comments