mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-24 01:28:35 +02:00
[Plugins] [CopyAsCURL] [Auth] [JWT] Include custom bearer prefix to copy CURL (#253)
Co-authored-by: Gregory Schier <gschier1990@gmail.com>
This commit is contained in:
@@ -93,7 +93,9 @@ export async function convertToCurl(request: Partial<HttpRequest>) {
|
|||||||
|
|
||||||
// Add bearer authentication
|
// Add bearer authentication
|
||||||
if (request.authenticationType === 'bearer') {
|
if (request.authenticationType === 'bearer') {
|
||||||
xs.push('--header', quote(`Authorization: Bearer ${request.authentication?.token ?? ''}`));
|
const value =
|
||||||
|
`${request.authentication?.prefix ?? 'Bearer'} ${request.authentication?.token ?? ''}`.trim();
|
||||||
|
xs.push('--header', quote(`Authorization: ${value}`));
|
||||||
xs.push(NEWLINE);
|
xs.push(NEWLINE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,9 +12,7 @@ describe('exporter-curl', () => {
|
|||||||
{ name: 'c', value: 'ccc', enabled: false },
|
{ name: 'c', value: 'ccc', enabled: false },
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
).toEqual(
|
).toEqual([`curl 'https://yaak.app?a=aaa&b=bbb'`].join(` \\n `));
|
||||||
[`curl 'https://yaak.app?a=aaa&b=bbb'`].join(` \\n `),
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Exports GET with params and hash', async () => {
|
test('Exports GET with params and hash', async () => {
|
||||||
@@ -27,9 +25,7 @@ describe('exporter-curl', () => {
|
|||||||
{ name: 'c', value: 'ccc', enabled: false },
|
{ name: 'c', value: 'ccc', enabled: false },
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
).toEqual(
|
).toEqual([`curl 'https://yaak.app/path?a=aaa&b=bbb#section'`].join(` \\n `));
|
||||||
[`curl 'https://yaak.app/path?a=aaa&b=bbb#section'`].join(` \\n `),
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
test('Exports POST with url form data', async () => {
|
test('Exports POST with url form data', async () => {
|
||||||
expect(
|
expect(
|
||||||
@@ -62,7 +58,10 @@ describe('exporter-curl', () => {
|
|||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
).toEqual(
|
).toEqual(
|
||||||
[`curl -X POST 'https://yaak.app'`, `--data '{"query":"{foo,bar}","variables":{"a":"aaa","b":"bbb"}}'`].join(` \\\n `),
|
[
|
||||||
|
`curl -X POST 'https://yaak.app'`,
|
||||||
|
`--data '{"query":"{foo,bar}","variables":{"a":"aaa","b":"bbb"}}'`,
|
||||||
|
].join(` \\\n `),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -206,6 +205,34 @@ describe('exporter-curl', () => {
|
|||||||
).toEqual([`curl 'https://yaak.app'`, `--header 'Authorization: Bearer tok'`].join(` \\\n `));
|
).toEqual([`curl 'https://yaak.app'`, `--header 'Authorization: Bearer tok'`].join(` \\\n `));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Bearer auth with custom prefix', async () => {
|
||||||
|
expect(
|
||||||
|
await convertToCurl({
|
||||||
|
url: 'https://yaak.app',
|
||||||
|
authenticationType: 'bearer',
|
||||||
|
authentication: {
|
||||||
|
token: 'abc123',
|
||||||
|
prefix: 'Token',
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
).toEqual(
|
||||||
|
[`curl 'https://yaak.app'`, `--header 'Authorization: Token abc123'`].join(` \\\n `),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Bearer auth with empty prefix', async () => {
|
||||||
|
expect(
|
||||||
|
await convertToCurl({
|
||||||
|
url: 'https://yaak.app',
|
||||||
|
authenticationType: 'bearer',
|
||||||
|
authentication: {
|
||||||
|
token: 'xyz789',
|
||||||
|
prefix: '',
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
).toEqual([`curl 'https://yaak.app'`, `--header 'Authorization: xyz789'`].join(` \\\n `));
|
||||||
|
});
|
||||||
|
|
||||||
test('Broken bearer auth', async () => {
|
test('Broken bearer auth', async () => {
|
||||||
expect(
|
expect(
|
||||||
await convertToCurl({
|
await convertToCurl({
|
||||||
@@ -216,7 +243,7 @@ describe('exporter-curl', () => {
|
|||||||
password: 'pass',
|
password: 'pass',
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
).toEqual([`curl 'https://yaak.app'`, `--header 'Authorization: Bearer '`].join(` \\\n `));
|
).toEqual([`curl 'https://yaak.app'`, `--header 'Authorization: Bearer'`].join(` \\\n `));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Stale body data', async () => {
|
test('Stale body data', async () => {
|
||||||
@@ -226,7 +253,7 @@ describe('exporter-curl', () => {
|
|||||||
bodyType: 'none',
|
bodyType: 'none',
|
||||||
body: {
|
body: {
|
||||||
text: 'ignore me',
|
text: 'ignore me',
|
||||||
}
|
},
|
||||||
}),
|
}),
|
||||||
).toEqual([`curl 'https://yaak.app'`].join(` \\\n `));
|
).toEqual([`curl 'https://yaak.app'`].join(` \\\n `));
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user