From df80cdfe335ea9d1cc29cc4352faeed51044976f Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Sat, 25 Oct 2025 08:33:27 -0700 Subject: [PATCH] Copy as curl AWS auth, and handle disabled auth --- plugins/action-copy-curl/src/index.ts | 56 ++++++++++++++----- plugins/action-copy-curl/tests/index.test.ts | 59 ++++++++++++++++++++ 2 files changed, 101 insertions(+), 14 deletions(-) diff --git a/plugins/action-copy-curl/src/index.ts b/plugins/action-copy-curl/src/index.ts index 1ad92a68..fe3fc38a 100644 --- a/plugins/action-copy-curl/src/index.ts +++ b/plugins/action-copy-curl/src/index.ts @@ -82,21 +82,49 @@ export async function convertToCurl(request: Partial) { } // Add basic/digest authentication - if (request.authenticationType === 'basic' || request.authenticationType === 'digest') { - if (request.authenticationType === 'digest') xs.push('--digest'); - xs.push( - '--user', - quote(`${request.authentication?.username ?? ''}:${request.authentication?.password ?? ''}`), - ); - xs.push(NEWLINE); - } + if (request.authentication?.disabled !== true) { + if (request.authenticationType === 'basic' || request.authenticationType === 'digest') { + if (request.authenticationType === 'digest') xs.push('--digest'); + xs.push( + '--user', + quote( + `${request.authentication?.username ?? ''}:${request.authentication?.password ?? ''}`, + ), + ); + xs.push(NEWLINE); + } - // Add bearer authentication - if (request.authenticationType === 'bearer') { - const value = - `${request.authentication?.prefix ?? 'Bearer'} ${request.authentication?.token ?? ''}`.trim(); - xs.push('--header', quote(`Authorization: ${value}`)); - xs.push(NEWLINE); + // Add bearer authentication + if (request.authenticationType === 'bearer') { + const value = + `${request.authentication?.prefix ?? 'Bearer'} ${request.authentication?.token ?? ''}`.trim(); + xs.push('--header', quote(`Authorization: ${value}`)); + xs.push(NEWLINE); + } + + if (request.authenticationType === 'auth-aws-sig-v4') { + xs.push( + '--aws-sigv4', + [ + 'aws', + 'amz', + request.authentication?.region ?? '', + request.authentication?.service ?? '', + ].join(':'), + ); + xs.push(NEWLINE); + xs.push( + '--user', + quote( + `${request.authentication?.accessKeyId ?? ''}:${request.authentication?.secretAccessKey ?? ''}`, + ), + ); + if (request.authentication?.sessionToken) { + xs.push(NEWLINE); + xs.push('--header', quote(`X-Amz-Security-Token: ${request.authentication.sessionToken}`)); + } + xs.push(NEWLINE); + } } // Remove trailing newline diff --git a/plugins/action-copy-curl/tests/index.test.ts b/plugins/action-copy-curl/tests/index.test.ts index 8220655d..958de016 100644 --- a/plugins/action-copy-curl/tests/index.test.ts +++ b/plugins/action-copy-curl/tests/index.test.ts @@ -170,6 +170,20 @@ describe('exporter-curl', () => { ).toEqual([`curl 'https://yaak.app'`, `--user 'user:pass'`].join(` \\\n `)); }); + test('Basic auth disabled', async () => { + expect( + await convertToCurl({ + url: 'https://yaak.app', + authenticationType: 'basic', + authentication: { + disabled: true, + username: 'user', + password: 'pass', + }, + }), + ).toEqual([`curl 'https://yaak.app'`].join(` \\\n `)); + }); + test('Broken basic auth', async () => { expect( await convertToCurl({ @@ -246,6 +260,51 @@ describe('exporter-curl', () => { ).toEqual([`curl 'https://yaak.app'`, `--header 'Authorization: Bearer'`].join(` \\\n `)); }); + test('AWS v4 auth', async () => { + expect( + await convertToCurl({ + url: 'https://yaak.app', + authenticationType: 'auth-aws-sig-v4', + authentication: { + accessKeyId: 'ak', + secretAccessKey: 'sk', + sessionToken: '', + region: 'us-east-1', + service: 's3', + }, + }), + ).toEqual( + [ + `curl 'https://yaak.app'`, + `--aws-sigv4 aws:amz:us-east-1:s3`, + `--user 'ak:sk'`, + ].join(` \\\n `), + ); + }); + + test('AWS v4 auth with session', async () => { + expect( + await convertToCurl({ + url: 'https://yaak.app', + authenticationType: 'auth-aws-sig-v4', + authentication: { + accessKeyId: 'ak', + secretAccessKey: 'sk', + sessionToken: 'st', + region: 'us-east-1', + service: 's3', + }, + }), + ).toEqual( + [ + `curl 'https://yaak.app'`, + `--aws-sigv4 aws:amz:us-east-1:s3`, + `--user 'ak:sk'`, + `--header 'X-Amz-Security-Token: st'`, + ].join(` \\\n `), + ); + }); + test('Stale body data', async () => { expect( await convertToCurl({