mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-11 03:26:58 +02:00
Merge main into proxy branch (formatting and docs)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
{
|
||||
"name": "@yaak/action-copy-curl",
|
||||
"displayName": "Copy as Curl",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"description": "Copy request as a curl command",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/mountain-loop/yaak.git",
|
||||
"directory": "plugins/action-copy-curl"
|
||||
},
|
||||
"private": true,
|
||||
"version": "0.1.0",
|
||||
"scripts": {
|
||||
"build": "yaakcli build",
|
||||
"dev": "yaakcli dev",
|
||||
"test": "vitest --run tests"
|
||||
"test": "vp test --run tests"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
import type { HttpRequest, PluginDefinition } from '@yaakapp/api';
|
||||
import type { HttpRequest, PluginDefinition } from "@yaakapp/api";
|
||||
|
||||
const NEWLINE = '\\\n ';
|
||||
const NEWLINE = "\\\n ";
|
||||
|
||||
export const plugin: PluginDefinition = {
|
||||
httpRequestActions: [
|
||||
{
|
||||
label: 'Copy as Curl',
|
||||
icon: 'copy',
|
||||
label: "Copy as Curl",
|
||||
icon: "copy",
|
||||
async onSelect(ctx, args) {
|
||||
const rendered_request = await ctx.httpRequest.render({
|
||||
httpRequest: args.httpRequest,
|
||||
purpose: 'send',
|
||||
purpose: "send",
|
||||
});
|
||||
const data = await convertToCurl(rendered_request);
|
||||
await ctx.clipboard.copyText(data);
|
||||
await ctx.toast.show({
|
||||
message: 'Command copied to clipboard',
|
||||
icon: 'copy',
|
||||
color: 'success',
|
||||
message: "Command copied to clipboard",
|
||||
icon: "copy",
|
||||
color: "success",
|
||||
});
|
||||
},
|
||||
},
|
||||
@@ -25,40 +25,40 @@ export const plugin: PluginDefinition = {
|
||||
};
|
||||
|
||||
export async function convertToCurl(request: Partial<HttpRequest>) {
|
||||
const xs = ['curl'];
|
||||
const xs = ["curl"];
|
||||
|
||||
// Add method and URL all on first line
|
||||
if (request.method) xs.push('-X', request.method);
|
||||
if (request.method) xs.push("-X", request.method);
|
||||
|
||||
// Build final URL with parameters (compatible with old curl)
|
||||
let finalUrl = request.url || '';
|
||||
let finalUrl = request.url || "";
|
||||
const urlParams = (request.urlParameters ?? []).filter(onlyEnabled);
|
||||
if (urlParams.length > 0) {
|
||||
// Build url
|
||||
const [base, hash] = finalUrl.split('#');
|
||||
const separator = base?.includes('?') ? '&' : '?';
|
||||
const [base, hash] = finalUrl.split("#");
|
||||
const separator = base?.includes("?") ? "&" : "?";
|
||||
const queryString = urlParams
|
||||
.map((p) => `${encodeURIComponent(p.name)}=${encodeURIComponent(p.value)}`)
|
||||
.join('&');
|
||||
finalUrl = base + separator + queryString + (hash ? `#${hash}` : '');
|
||||
.join("&");
|
||||
finalUrl = base + separator + queryString + (hash ? `#${hash}` : "");
|
||||
}
|
||||
|
||||
// Add API key authentication
|
||||
if (request.authenticationType === 'apikey') {
|
||||
if (request.authentication?.location === 'query') {
|
||||
const sep = finalUrl.includes('?') ? '&' : '?';
|
||||
if (request.authenticationType === "apikey") {
|
||||
if (request.authentication?.location === "query") {
|
||||
const sep = finalUrl.includes("?") ? "&" : "?";
|
||||
finalUrl = [
|
||||
finalUrl,
|
||||
sep,
|
||||
encodeURIComponent(request.authentication?.key ?? 'token'),
|
||||
'=',
|
||||
encodeURIComponent(request.authentication?.value ?? ''),
|
||||
].join('');
|
||||
encodeURIComponent(request.authentication?.key ?? "token"),
|
||||
"=",
|
||||
encodeURIComponent(request.authentication?.value ?? ""),
|
||||
].join("");
|
||||
} else {
|
||||
request.headers = request.headers ?? [];
|
||||
request.headers.push({
|
||||
name: request.authentication?.key ?? 'X-Api-Key',
|
||||
value: request.authentication?.value ?? '',
|
||||
name: request.authentication?.key ?? "X-Api-Key",
|
||||
value: request.authentication?.value ?? "",
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -68,80 +68,80 @@ export async function convertToCurl(request: Partial<HttpRequest>) {
|
||||
|
||||
// Add headers
|
||||
for (const h of (request.headers ?? []).filter(onlyEnabled)) {
|
||||
xs.push('--header', quote(`${h.name}: ${h.value}`));
|
||||
xs.push("--header", quote(`${h.name}: ${h.value}`));
|
||||
xs.push(NEWLINE);
|
||||
}
|
||||
|
||||
// Add form params
|
||||
const type = request.bodyType ?? 'none';
|
||||
const type = request.bodyType ?? "none";
|
||||
if (
|
||||
(type === 'multipart/form-data' || type === 'application/x-www-form-urlencoded') &&
|
||||
(type === "multipart/form-data" || type === "application/x-www-form-urlencoded") &&
|
||||
Array.isArray(request.body?.form)
|
||||
) {
|
||||
const flag = request.bodyType === 'multipart/form-data' ? '--form' : '--data';
|
||||
const flag = request.bodyType === "multipart/form-data" ? "--form" : "--data";
|
||||
for (const p of (request.body?.form ?? []).filter(onlyEnabled)) {
|
||||
if (p.file) {
|
||||
let v = `${p.name}=@${p.file}`;
|
||||
v += p.contentType ? `;type=${p.contentType}` : '';
|
||||
v += p.contentType ? `;type=${p.contentType}` : "";
|
||||
xs.push(flag, v);
|
||||
} else {
|
||||
xs.push(flag, quote(`${p.name}=${p.value}`));
|
||||
}
|
||||
xs.push(NEWLINE);
|
||||
}
|
||||
} else if (type === 'graphql' && typeof request.body?.query === 'string') {
|
||||
} else if (type === "graphql" && typeof request.body?.query === "string") {
|
||||
const body = {
|
||||
query: request.body.query || '',
|
||||
query: request.body.query || "",
|
||||
variables: maybeParseJSON(request.body.variables, undefined),
|
||||
};
|
||||
xs.push('--data', quote(JSON.stringify(body)));
|
||||
xs.push("--data", quote(JSON.stringify(body)));
|
||||
xs.push(NEWLINE);
|
||||
} else if (type !== 'none' && typeof request.body?.text === 'string') {
|
||||
xs.push('--data', quote(request.body.text));
|
||||
} else if (type !== "none" && typeof request.body?.text === "string") {
|
||||
xs.push("--data", quote(request.body.text));
|
||||
xs.push(NEWLINE);
|
||||
}
|
||||
|
||||
// Add basic/digest authentication
|
||||
if (request.authentication?.disabled !== true) {
|
||||
if (request.authenticationType === 'basic' || request.authenticationType === 'digest') {
|
||||
if (request.authenticationType === 'digest') xs.push('--digest');
|
||||
if (request.authenticationType === "basic" || request.authenticationType === "digest") {
|
||||
if (request.authenticationType === "digest") xs.push("--digest");
|
||||
xs.push(
|
||||
'--user',
|
||||
"--user",
|
||||
quote(
|
||||
`${request.authentication?.username ?? ''}:${request.authentication?.password ?? ''}`,
|
||||
`${request.authentication?.username ?? ""}:${request.authentication?.password ?? ""}`,
|
||||
),
|
||||
);
|
||||
xs.push(NEWLINE);
|
||||
}
|
||||
|
||||
// Add bearer authentication
|
||||
if (request.authenticationType === 'bearer') {
|
||||
if (request.authenticationType === "bearer") {
|
||||
const value =
|
||||
`${request.authentication?.prefix ?? 'Bearer'} ${request.authentication?.token ?? ''}`.trim();
|
||||
xs.push('--header', quote(`Authorization: ${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') {
|
||||
if (request.authenticationType === "auth-aws-sig-v4") {
|
||||
xs.push(
|
||||
'--aws-sigv4',
|
||||
"--aws-sigv4",
|
||||
[
|
||||
'aws',
|
||||
'amz',
|
||||
request.authentication?.region ?? '',
|
||||
request.authentication?.service ?? '',
|
||||
].join(':'),
|
||||
"aws",
|
||||
"amz",
|
||||
request.authentication?.region ?? "",
|
||||
request.authentication?.service ?? "",
|
||||
].join(":"),
|
||||
);
|
||||
xs.push(NEWLINE);
|
||||
xs.push(
|
||||
'--user',
|
||||
"--user",
|
||||
quote(
|
||||
`${request.authentication?.accessKeyId ?? ''}:${request.authentication?.secretAccessKey ?? ''}`,
|
||||
`${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("--header", quote(`X-Amz-Security-Token: ${request.authentication.sessionToken}`));
|
||||
}
|
||||
xs.push(NEWLINE);
|
||||
}
|
||||
@@ -152,7 +152,7 @@ export async function convertToCurl(request: Partial<HttpRequest>) {
|
||||
xs.splice(xs.length - 1, 1);
|
||||
}
|
||||
|
||||
return xs.join(' ');
|
||||
return xs.join(" ");
|
||||
}
|
||||
|
||||
function quote(arg: string): string {
|
||||
|
||||
@@ -1,60 +1,60 @@
|
||||
import { describe, expect, test } from 'vitest';
|
||||
import { convertToCurl } from '../src';
|
||||
import { describe, expect, test } from "vite-plus/test";
|
||||
import { convertToCurl } from "../src";
|
||||
|
||||
describe('exporter-curl', () => {
|
||||
test('Exports GET with params', async () => {
|
||||
describe("exporter-curl", () => {
|
||||
test("Exports GET with params", async () => {
|
||||
expect(
|
||||
await convertToCurl({
|
||||
url: 'https://yaak.app',
|
||||
url: "https://yaak.app",
|
||||
urlParameters: [
|
||||
{ name: 'a', value: 'aaa' },
|
||||
{ name: 'b', value: 'bbb', enabled: true },
|
||||
{ name: 'c', value: 'ccc', enabled: false },
|
||||
{ name: "a", value: "aaa" },
|
||||
{ name: "b", value: "bbb", enabled: true },
|
||||
{ name: "c", value: "ccc", enabled: false },
|
||||
],
|
||||
}),
|
||||
).toEqual([`curl 'https://yaak.app?a=aaa&b=bbb'`].join(' \\n '));
|
||||
).toEqual([`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 () => {
|
||||
expect(
|
||||
await convertToCurl({
|
||||
url: 'https://yaak.app/path#section',
|
||||
url: "https://yaak.app/path#section",
|
||||
urlParameters: [
|
||||
{ name: 'a', value: 'aaa' },
|
||||
{ name: 'b', value: 'bbb', enabled: true },
|
||||
{ name: 'c', value: 'ccc', enabled: false },
|
||||
{ name: "a", value: "aaa" },
|
||||
{ name: "b", value: "bbb", enabled: true },
|
||||
{ name: "c", value: "ccc", enabled: false },
|
||||
],
|
||||
}),
|
||||
).toEqual([`curl 'https://yaak.app/path?a=aaa&b=bbb#section'`].join(' \\n '));
|
||||
).toEqual([`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(
|
||||
await convertToCurl({
|
||||
url: 'https://yaak.app',
|
||||
method: 'POST',
|
||||
bodyType: 'application/x-www-form-urlencoded',
|
||||
url: "https://yaak.app",
|
||||
method: "POST",
|
||||
bodyType: "application/x-www-form-urlencoded",
|
||||
body: {
|
||||
form: [
|
||||
{ name: 'a', value: 'aaa' },
|
||||
{ name: 'b', value: 'bbb', enabled: true },
|
||||
{ name: 'c', value: 'ccc', enabled: false },
|
||||
{ name: "a", value: "aaa" },
|
||||
{ name: "b", value: "bbb", enabled: true },
|
||||
{ name: "c", value: "ccc", enabled: false },
|
||||
],
|
||||
},
|
||||
}),
|
||||
).toEqual(
|
||||
[`curl -X POST 'https://yaak.app'`, `--data 'a=aaa'`, `--data 'b=bbb'`].join(' \\\n '),
|
||||
[`curl -X POST 'https://yaak.app'`, `--data 'a=aaa'`, `--data 'b=bbb'`].join(" \\\n "),
|
||||
);
|
||||
});
|
||||
|
||||
test('Exports POST with GraphQL data', async () => {
|
||||
test("Exports POST with GraphQL data", async () => {
|
||||
expect(
|
||||
await convertToCurl({
|
||||
url: 'https://yaak.app',
|
||||
method: 'POST',
|
||||
bodyType: 'graphql',
|
||||
url: "https://yaak.app",
|
||||
method: "POST",
|
||||
bodyType: "graphql",
|
||||
body: {
|
||||
query: '{foo,bar}',
|
||||
query: "{foo,bar}",
|
||||
variables: '{"a": "aaa", "b": "bbb"}',
|
||||
},
|
||||
}),
|
||||
@@ -62,37 +62,37 @@ describe('exporter-curl', () => {
|
||||
[
|
||||
`curl -X POST 'https://yaak.app'`,
|
||||
`--data '{"query":"{foo,bar}","variables":{"a":"aaa","b":"bbb"}}'`,
|
||||
].join(' \\\n '),
|
||||
].join(" \\\n "),
|
||||
);
|
||||
});
|
||||
|
||||
test('Exports POST with GraphQL data no variables', async () => {
|
||||
test("Exports POST with GraphQL data no variables", async () => {
|
||||
expect(
|
||||
await convertToCurl({
|
||||
url: 'https://yaak.app',
|
||||
method: 'POST',
|
||||
bodyType: 'graphql',
|
||||
url: "https://yaak.app",
|
||||
method: "POST",
|
||||
bodyType: "graphql",
|
||||
body: {
|
||||
query: '{foo,bar}',
|
||||
query: "{foo,bar}",
|
||||
},
|
||||
}),
|
||||
).toEqual(
|
||||
[`curl -X POST 'https://yaak.app'`, `--data '{"query":"{foo,bar}"}'`].join(' \\\n '),
|
||||
[`curl -X POST 'https://yaak.app'`, `--data '{"query":"{foo,bar}"}'`].join(" \\\n "),
|
||||
);
|
||||
});
|
||||
|
||||
test('Exports PUT with multipart form', async () => {
|
||||
test("Exports PUT with multipart form", async () => {
|
||||
expect(
|
||||
await convertToCurl({
|
||||
url: 'https://yaak.app',
|
||||
method: 'PUT',
|
||||
bodyType: 'multipart/form-data',
|
||||
url: "https://yaak.app",
|
||||
method: "PUT",
|
||||
bodyType: "multipart/form-data",
|
||||
body: {
|
||||
form: [
|
||||
{ name: 'a', value: 'aaa' },
|
||||
{ name: 'b', value: 'bbb', enabled: true },
|
||||
{ name: 'c', value: 'ccc', enabled: false },
|
||||
{ name: 'f', file: '/foo/bar.png', contentType: 'image/png' },
|
||||
{ name: "a", value: "aaa" },
|
||||
{ name: "b", value: "bbb", enabled: true },
|
||||
{ name: "c", value: "ccc", enabled: false },
|
||||
{ name: "f", file: "/foo/bar.png", contentType: "image/png" },
|
||||
],
|
||||
},
|
||||
}),
|
||||
@@ -101,314 +101,314 @@ describe('exporter-curl', () => {
|
||||
`curl -X PUT 'https://yaak.app'`,
|
||||
`--form 'a=aaa'`,
|
||||
`--form 'b=bbb'`,
|
||||
'--form f=@/foo/bar.png;type=image/png',
|
||||
].join(' \\\n '),
|
||||
"--form f=@/foo/bar.png;type=image/png",
|
||||
].join(" \\\n "),
|
||||
);
|
||||
});
|
||||
|
||||
test('Exports JSON body', async () => {
|
||||
test("Exports JSON body", async () => {
|
||||
expect(
|
||||
await convertToCurl({
|
||||
url: 'https://yaak.app',
|
||||
method: 'POST',
|
||||
bodyType: 'application/json',
|
||||
url: "https://yaak.app",
|
||||
method: "POST",
|
||||
bodyType: "application/json",
|
||||
body: {
|
||||
text: `{"foo":"bar's"}`,
|
||||
},
|
||||
headers: [{ name: 'Content-Type', value: 'application/json' }],
|
||||
headers: [{ name: "Content-Type", value: "application/json" }],
|
||||
}),
|
||||
).toEqual(
|
||||
[
|
||||
`curl -X POST 'https://yaak.app'`,
|
||||
`--header 'Content-Type: application/json'`,
|
||||
`--data '{"foo":"bar\\'s"}'`,
|
||||
].join(' \\\n '),
|
||||
].join(" \\\n "),
|
||||
);
|
||||
});
|
||||
|
||||
test('Exports multi-line JSON body', async () => {
|
||||
test("Exports multi-line JSON body", async () => {
|
||||
expect(
|
||||
await convertToCurl({
|
||||
url: 'https://yaak.app',
|
||||
method: 'POST',
|
||||
bodyType: 'application/json',
|
||||
url: "https://yaak.app",
|
||||
method: "POST",
|
||||
bodyType: "application/json",
|
||||
body: {
|
||||
text: `{"foo":"bar",\n"baz":"qux"}`,
|
||||
},
|
||||
headers: [{ name: 'Content-Type', value: 'application/json' }],
|
||||
headers: [{ name: "Content-Type", value: "application/json" }],
|
||||
}),
|
||||
).toEqual(
|
||||
[
|
||||
`curl -X POST 'https://yaak.app'`,
|
||||
`--header 'Content-Type: application/json'`,
|
||||
`--data '{"foo":"bar",\n"baz":"qux"}'`,
|
||||
].join(' \\\n '),
|
||||
].join(" \\\n "),
|
||||
);
|
||||
});
|
||||
|
||||
test('Exports headers', async () => {
|
||||
test("Exports headers", async () => {
|
||||
expect(
|
||||
await convertToCurl({
|
||||
headers: [
|
||||
{ name: 'a', value: 'aaa' },
|
||||
{ name: 'b', value: 'bbb', enabled: true },
|
||||
{ name: 'c', value: 'ccc', enabled: false },
|
||||
{ name: "a", value: "aaa" },
|
||||
{ name: "b", value: "bbb", enabled: true },
|
||||
{ name: "c", value: "ccc", enabled: false },
|
||||
],
|
||||
}),
|
||||
).toEqual([`curl ''`, `--header 'a: aaa'`, `--header 'b: bbb'`].join(' \\\n '));
|
||||
).toEqual([`curl ''`, `--header 'a: aaa'`, `--header 'b: bbb'`].join(" \\\n "));
|
||||
});
|
||||
|
||||
test('Basic auth', async () => {
|
||||
test("Basic auth", async () => {
|
||||
expect(
|
||||
await convertToCurl({
|
||||
url: 'https://yaak.app',
|
||||
authenticationType: 'basic',
|
||||
url: "https://yaak.app",
|
||||
authenticationType: "basic",
|
||||
authentication: {
|
||||
username: 'user',
|
||||
password: 'pass',
|
||||
username: "user",
|
||||
password: "pass",
|
||||
},
|
||||
}),
|
||||
).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 () => {
|
||||
test("Basic auth disabled", async () => {
|
||||
expect(
|
||||
await convertToCurl({
|
||||
url: 'https://yaak.app',
|
||||
authenticationType: 'basic',
|
||||
url: "https://yaak.app",
|
||||
authenticationType: "basic",
|
||||
authentication: {
|
||||
disabled: true,
|
||||
username: 'user',
|
||||
password: 'pass',
|
||||
username: "user",
|
||||
password: "pass",
|
||||
},
|
||||
}),
|
||||
).toEqual([`curl 'https://yaak.app'`].join(' \\\n '));
|
||||
).toEqual([`curl 'https://yaak.app'`].join(" \\\n "));
|
||||
});
|
||||
|
||||
test('Broken basic auth', async () => {
|
||||
test("Broken basic auth", async () => {
|
||||
expect(
|
||||
await convertToCurl({
|
||||
url: 'https://yaak.app',
|
||||
authenticationType: 'basic',
|
||||
url: "https://yaak.app",
|
||||
authenticationType: "basic",
|
||||
authentication: {},
|
||||
}),
|
||||
).toEqual([`curl 'https://yaak.app'`, `--user ':'`].join(' \\\n '));
|
||||
).toEqual([`curl 'https://yaak.app'`, `--user ':'`].join(" \\\n "));
|
||||
});
|
||||
|
||||
test('Digest auth', async () => {
|
||||
test("Digest auth", async () => {
|
||||
expect(
|
||||
await convertToCurl({
|
||||
url: 'https://yaak.app',
|
||||
authenticationType: 'digest',
|
||||
url: "https://yaak.app",
|
||||
authenticationType: "digest",
|
||||
authentication: {
|
||||
username: 'user',
|
||||
password: 'pass',
|
||||
username: "user",
|
||||
password: "pass",
|
||||
},
|
||||
}),
|
||||
).toEqual([`curl 'https://yaak.app'`, `--digest --user 'user:pass'`].join(' \\\n '));
|
||||
).toEqual([`curl 'https://yaak.app'`, `--digest --user 'user:pass'`].join(" \\\n "));
|
||||
});
|
||||
|
||||
test('Bearer auth', async () => {
|
||||
test("Bearer auth", async () => {
|
||||
expect(
|
||||
await convertToCurl({
|
||||
url: 'https://yaak.app',
|
||||
authenticationType: 'bearer',
|
||||
url: "https://yaak.app",
|
||||
authenticationType: "bearer",
|
||||
authentication: {
|
||||
token: 'tok',
|
||||
token: "tok",
|
||||
},
|
||||
}),
|
||||
).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 () => {
|
||||
test("Bearer auth with custom prefix", async () => {
|
||||
expect(
|
||||
await convertToCurl({
|
||||
url: 'https://yaak.app',
|
||||
authenticationType: 'bearer',
|
||||
url: "https://yaak.app",
|
||||
authenticationType: "bearer",
|
||||
authentication: {
|
||||
token: 'abc123',
|
||||
prefix: 'Token',
|
||||
token: "abc123",
|
||||
prefix: "Token",
|
||||
},
|
||||
}),
|
||||
).toEqual(
|
||||
[`curl 'https://yaak.app'`, `--header 'Authorization: Token abc123'`].join(' \\\n '),
|
||||
[`curl 'https://yaak.app'`, `--header 'Authorization: Token abc123'`].join(" \\\n "),
|
||||
);
|
||||
});
|
||||
|
||||
test('Bearer auth with empty prefix', async () => {
|
||||
test("Bearer auth with empty prefix", async () => {
|
||||
expect(
|
||||
await convertToCurl({
|
||||
url: 'https://yaak.app',
|
||||
authenticationType: 'bearer',
|
||||
url: "https://yaak.app",
|
||||
authenticationType: "bearer",
|
||||
authentication: {
|
||||
token: 'xyz789',
|
||||
prefix: '',
|
||||
token: "xyz789",
|
||||
prefix: "",
|
||||
},
|
||||
}),
|
||||
).toEqual([`curl 'https://yaak.app'`, `--header 'Authorization: xyz789'`].join(' \\\n '));
|
||||
).toEqual([`curl 'https://yaak.app'`, `--header 'Authorization: xyz789'`].join(" \\\n "));
|
||||
});
|
||||
|
||||
test('Broken bearer auth', async () => {
|
||||
test("Broken bearer auth", async () => {
|
||||
expect(
|
||||
await convertToCurl({
|
||||
url: 'https://yaak.app',
|
||||
authenticationType: 'bearer',
|
||||
url: "https://yaak.app",
|
||||
authenticationType: "bearer",
|
||||
authentication: {
|
||||
username: 'user',
|
||||
password: 'pass',
|
||||
username: "user",
|
||||
password: "pass",
|
||||
},
|
||||
}),
|
||||
).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 () => {
|
||||
test("AWS v4 auth", async () => {
|
||||
expect(
|
||||
await convertToCurl({
|
||||
url: 'https://yaak.app',
|
||||
authenticationType: 'auth-aws-sig-v4',
|
||||
url: "https://yaak.app",
|
||||
authenticationType: "auth-aws-sig-v4",
|
||||
authentication: {
|
||||
accessKeyId: 'ak',
|
||||
secretAccessKey: 'sk',
|
||||
sessionToken: '',
|
||||
region: 'us-east-1',
|
||||
service: 's3',
|
||||
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 ',
|
||||
[`curl 'https://yaak.app'`, "--aws-sigv4 aws:amz:us-east-1:s3", `--user 'ak:sk'`].join(
|
||||
" \\\n ",
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('AWS v4 auth with session', async () => {
|
||||
test("AWS v4 auth with session", async () => {
|
||||
expect(
|
||||
await convertToCurl({
|
||||
url: 'https://yaak.app',
|
||||
authenticationType: 'auth-aws-sig-v4',
|
||||
url: "https://yaak.app",
|
||||
authenticationType: "auth-aws-sig-v4",
|
||||
authentication: {
|
||||
accessKeyId: 'ak',
|
||||
secretAccessKey: 'sk',
|
||||
sessionToken: 'st',
|
||||
region: 'us-east-1',
|
||||
service: 's3',
|
||||
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',
|
||||
"--aws-sigv4 aws:amz:us-east-1:s3",
|
||||
`--user 'ak:sk'`,
|
||||
`--header 'X-Amz-Security-Token: st'`,
|
||||
].join(' \\\n '),
|
||||
].join(" \\\n "),
|
||||
);
|
||||
});
|
||||
|
||||
test('API key auth header', async () => {
|
||||
test("API key auth header", async () => {
|
||||
expect(
|
||||
await convertToCurl({
|
||||
url: 'https://yaak.app',
|
||||
authenticationType: 'apikey',
|
||||
url: "https://yaak.app",
|
||||
authenticationType: "apikey",
|
||||
authentication: {
|
||||
location: 'header',
|
||||
key: 'X-Header',
|
||||
value: 'my-token',
|
||||
location: "header",
|
||||
key: "X-Header",
|
||||
value: "my-token",
|
||||
},
|
||||
}),
|
||||
).toEqual([`curl 'https://yaak.app'`, `--header 'X-Header: my-token'`].join(' \\\n '));
|
||||
).toEqual([`curl 'https://yaak.app'`, `--header 'X-Header: my-token'`].join(" \\\n "));
|
||||
});
|
||||
|
||||
test('API key auth header query', async () => {
|
||||
test("API key auth header query", async () => {
|
||||
expect(
|
||||
await convertToCurl({
|
||||
url: 'https://yaak.app?hi=there',
|
||||
urlParameters: [{ name: 'param', value: 'hi' }],
|
||||
authenticationType: 'apikey',
|
||||
url: "https://yaak.app?hi=there",
|
||||
urlParameters: [{ name: "param", value: "hi" }],
|
||||
authenticationType: "apikey",
|
||||
authentication: {
|
||||
location: 'query',
|
||||
key: 'foo',
|
||||
value: 'bar',
|
||||
location: "query",
|
||||
key: "foo",
|
||||
value: "bar",
|
||||
},
|
||||
}),
|
||||
).toEqual([`curl 'https://yaak.app?hi=there¶m=hi&foo=bar'`].join(' \\\n '));
|
||||
).toEqual([`curl 'https://yaak.app?hi=there¶m=hi&foo=bar'`].join(" \\\n "));
|
||||
});
|
||||
|
||||
test('API key auth header query with params', async () => {
|
||||
test("API key auth header query with params", async () => {
|
||||
expect(
|
||||
await convertToCurl({
|
||||
url: 'https://yaak.app',
|
||||
urlParameters: [{ name: 'param', value: 'hi' }],
|
||||
authenticationType: 'apikey',
|
||||
url: "https://yaak.app",
|
||||
urlParameters: [{ name: "param", value: "hi" }],
|
||||
authenticationType: "apikey",
|
||||
authentication: {
|
||||
location: 'query',
|
||||
key: 'foo',
|
||||
value: 'bar',
|
||||
location: "query",
|
||||
key: "foo",
|
||||
value: "bar",
|
||||
},
|
||||
}),
|
||||
).toEqual([`curl 'https://yaak.app?param=hi&foo=bar'`].join(' \\\n '));
|
||||
).toEqual([`curl 'https://yaak.app?param=hi&foo=bar'`].join(" \\\n "));
|
||||
});
|
||||
|
||||
test('API key auth header default', async () => {
|
||||
test("API key auth header default", async () => {
|
||||
expect(
|
||||
await convertToCurl({
|
||||
url: 'https://yaak.app',
|
||||
authenticationType: 'apikey',
|
||||
url: "https://yaak.app",
|
||||
authenticationType: "apikey",
|
||||
authentication: {
|
||||
location: 'header',
|
||||
location: "header",
|
||||
},
|
||||
}),
|
||||
).toEqual([`curl 'https://yaak.app'`, `--header 'X-Api-Key: '`].join(' \\\n '));
|
||||
).toEqual([`curl 'https://yaak.app'`, `--header 'X-Api-Key: '`].join(" \\\n "));
|
||||
});
|
||||
|
||||
test('API key auth query', async () => {
|
||||
test("API key auth query", async () => {
|
||||
expect(
|
||||
await convertToCurl({
|
||||
url: 'https://yaak.app',
|
||||
authenticationType: 'apikey',
|
||||
url: "https://yaak.app",
|
||||
authenticationType: "apikey",
|
||||
authentication: {
|
||||
location: 'query',
|
||||
key: 'foo',
|
||||
value: 'bar-baz',
|
||||
location: "query",
|
||||
key: "foo",
|
||||
value: "bar-baz",
|
||||
},
|
||||
}),
|
||||
).toEqual([`curl 'https://yaak.app?foo=bar-baz'`].join(' \\\n '));
|
||||
).toEqual([`curl 'https://yaak.app?foo=bar-baz'`].join(" \\\n "));
|
||||
});
|
||||
|
||||
test('API key auth query with existing', async () => {
|
||||
test("API key auth query with existing", async () => {
|
||||
expect(
|
||||
await convertToCurl({
|
||||
url: 'https://yaak.app?foo=bar&baz=qux',
|
||||
authenticationType: 'apikey',
|
||||
url: "https://yaak.app?foo=bar&baz=qux",
|
||||
authenticationType: "apikey",
|
||||
authentication: {
|
||||
location: 'query',
|
||||
key: 'hi',
|
||||
value: 'there',
|
||||
location: "query",
|
||||
key: "hi",
|
||||
value: "there",
|
||||
},
|
||||
}),
|
||||
).toEqual([`curl 'https://yaak.app?foo=bar&baz=qux&hi=there'`].join(' \\\n '));
|
||||
).toEqual([`curl 'https://yaak.app?foo=bar&baz=qux&hi=there'`].join(" \\\n "));
|
||||
});
|
||||
|
||||
test('API key auth query default', async () => {
|
||||
test("API key auth query default", async () => {
|
||||
expect(
|
||||
await convertToCurl({
|
||||
url: 'https://yaak.app?foo=bar&baz=qux',
|
||||
authenticationType: 'apikey',
|
||||
url: "https://yaak.app?foo=bar&baz=qux",
|
||||
authenticationType: "apikey",
|
||||
authentication: {
|
||||
location: 'query',
|
||||
location: "query",
|
||||
},
|
||||
}),
|
||||
).toEqual([`curl 'https://yaak.app?foo=bar&baz=qux&token='`].join(' \\\n '));
|
||||
).toEqual([`curl 'https://yaak.app?foo=bar&baz=qux&token='`].join(" \\\n "));
|
||||
});
|
||||
|
||||
test('Stale body data', async () => {
|
||||
test("Stale body data", async () => {
|
||||
expect(
|
||||
await convertToCurl({
|
||||
url: 'https://yaak.app',
|
||||
bodyType: 'none',
|
||||
url: "https://yaak.app",
|
||||
bodyType: "none",
|
||||
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