mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-01 23:13:16 +02:00
Copy as curl AWS auth, and handle disabled auth
This commit is contained in:
@@ -82,21 +82,49 @@ export async function convertToCurl(request: Partial<HttpRequest>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add basic/digest authentication
|
// Add basic/digest authentication
|
||||||
if (request.authenticationType === 'basic' || request.authenticationType === 'digest') {
|
if (request.authentication?.disabled !== true) {
|
||||||
if (request.authenticationType === 'digest') xs.push('--digest');
|
if (request.authenticationType === 'basic' || request.authenticationType === 'digest') {
|
||||||
xs.push(
|
if (request.authenticationType === 'digest') xs.push('--digest');
|
||||||
'--user',
|
xs.push(
|
||||||
quote(`${request.authentication?.username ?? ''}:${request.authentication?.password ?? ''}`),
|
'--user',
|
||||||
);
|
quote(
|
||||||
xs.push(NEWLINE);
|
`${request.authentication?.username ?? ''}:${request.authentication?.password ?? ''}`,
|
||||||
}
|
),
|
||||||
|
);
|
||||||
|
xs.push(NEWLINE);
|
||||||
|
}
|
||||||
|
|
||||||
// Add bearer authentication
|
// Add bearer authentication
|
||||||
if (request.authenticationType === 'bearer') {
|
if (request.authenticationType === 'bearer') {
|
||||||
const value =
|
const value =
|
||||||
`${request.authentication?.prefix ?? 'Bearer'} ${request.authentication?.token ?? ''}`.trim();
|
`${request.authentication?.prefix ?? 'Bearer'} ${request.authentication?.token ?? ''}`.trim();
|
||||||
xs.push('--header', quote(`Authorization: ${value}`));
|
xs.push('--header', quote(`Authorization: ${value}`));
|
||||||
xs.push(NEWLINE);
|
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
|
// Remove trailing newline
|
||||||
|
|||||||
@@ -170,6 +170,20 @@ describe('exporter-curl', () => {
|
|||||||
).toEqual([`curl 'https://yaak.app'`, `--user 'user:pass'`].join(` \\\n `));
|
).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 () => {
|
test('Broken basic auth', async () => {
|
||||||
expect(
|
expect(
|
||||||
await convertToCurl({
|
await convertToCurl({
|
||||||
@@ -246,6 +260,51 @@ describe('exporter-curl', () => {
|
|||||||
).toEqual([`curl 'https://yaak.app'`, `--header 'Authorization: Bearer'`].join(` \\\n `));
|
).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 () => {
|
test('Stale body data', async () => {
|
||||||
expect(
|
expect(
|
||||||
await convertToCurl({
|
await convertToCurl({
|
||||||
|
|||||||
Reference in New Issue
Block a user