feat: ability to refresh tokens for oauth flows (#4302)

Co-authored-by: jamesgeorge007 <25279263+jamesgeorge007@users.noreply.github.com>
This commit is contained in:
Akash K
2024-08-29 13:27:31 +05:30
committed by GitHub
parent 2ed7221182
commit 181ad098e0
20 changed files with 488 additions and 68 deletions

View File

@@ -159,6 +159,30 @@ describe("hopp test [options] <file_path_or_id>", () => {
expect(error).toBeNull();
});
describe("OAuth 2 Authorization type with Authorization Code Grant Type", () => {
test("Successfully translates the authorization information to headers/query params and sends it along with the request", async () => {
const args = `test ${getTestJsonFilePath(
"oauth2-auth-code-coll.json",
"collection"
)}`;
const { error } = await runCLI(args);
expect(error).toBeNull();
});
});
describe("multipart/form-data content type", () => {
test("Successfully derives the relevant headers based and sends the form data in the request body", async () => {
const args = `test ${getTestJsonFilePath(
"oauth2-auth-code-coll.json",
"collection"
)}`;
const { error } = await runCLI(args);
expect(error).toBeNull();
});
});
});
describe("Test `hopp test <file_path_or_id> --env <file_path_or_id>` command:", () => {

View File

@@ -0,0 +1,55 @@
{
"v": 3,
"name": "Multpart form data content type - Collection",
"folders": [],
"requests": [
{
"v": "7",
"endpoint": "https://echo.hoppscotch.io",
"name": "multipart-form-data-sample-req",
"params": [],
"headers": [],
"method": "POST",
"auth": {
"authType": "none",
"authActive": true,
"addTo": "HEADERS",
"grantTypeInfo": {
"authEndpoint": "test-authorization-endpoint",
"tokenEndpoint": "test-token-endpont",
"clientID": "test-client-id",
"clientSecret": "test-client-secret",
"isPKCE": true,
"codeVerifierMethod": "S256",
"grantType": "AUTHORIZATION_CODE",
"token": "test-token"
}
},
"preRequestScript": "",
"testScript": "pw.test(\"Status code is 200\", ()=> {\n pw.expect(pw.response.status).toBe(200);\n});\n\npw.test(\"Successfully derives the relevant headers based on the content type\", () => {\n pw.expect(pw.response.body.headers['content-type']).toInclude(\"multipart/form-data\");\n});\n\npw.test(\"Successfully sends the form data in the request body\", () => {\n // Dynamic value\n pw.expect(pw.response.body.data).toBeType(\"string\");\n});",
"body": {
"contentType": "multipart/form-data",
"body": [
{
"key": "key1",
"value": "value1",
"active": true,
"isFile": false
},
{
"key": "key2",
"value": [{}],
"active": true,
"isFile": true
}
]
},
"requestVariables": []
}
],
"auth": {
"authType": "none",
"authActive": true
},
"headers": []
}

View File

@@ -0,0 +1,72 @@
{
"v": 3,
"name": "OAuth2 Authorization Code Grant Type - Collection",
"folders": [],
"requests": [
{
"v": "7",
"endpoint": "https://echo.hoppscotch.io",
"name": "oauth2-auth-code-sample-req-pass-by-headers",
"params": [],
"headers": [],
"method": "GET",
"auth": {
"authType": "oauth-2",
"authActive": true,
"addTo": "HEADERS",
"grantTypeInfo": {
"authEndpoint": "test-authorization-endpoint",
"tokenEndpoint": "test-token-endpont",
"clientID": "test-client-id",
"clientSecret": "test-client-secret",
"isPKCE": true,
"codeVerifierMethod": "S256",
"grantType": "AUTHORIZATION_CODE",
"token": "test-token"
}
},
"preRequestScript": "",
"testScript": "pw.test(\"Status code is 200\", ()=> {\n pw.expect(pw.response.status).toBe(200);\n});\n\npw.test(\"Successfully derives Authorization header from the supplied fields\", ()=> {\n pw.expect(pw.response.body.headers[\"authorization\"]).toBeType(\"string\");\n});",
"body": {
"contentType": null,
"body": null
},
"requestVariables": []
},
{
"v": "7",
"endpoint": "https://echo.hoppscotch.io",
"name": "oauth2-auth-code-sample-req-pass-by-query-params",
"params": [],
"headers": [],
"method": "GET",
"auth": {
"authType": "oauth-2",
"authActive": true,
"addTo": "HEADERS",
"grantTypeInfo": {
"authEndpoint": "test-authorization-endpoint",
"tokenEndpoint": "test-token-endpont",
"clientID": "test-client-id",
"clientSecret": "test-client-secret",
"isPKCE": true,
"codeVerifierMethod": "S256",
"grantType": "AUTHORIZATION_CODE",
"token": "test-token"
}
},
"preRequestScript": "",
"testScript": "pw.test(\"Status code is 200\", ()=> {\n pw.expect(pw.response.status).toBe(200);\n});\n\npw.test(\"Successfully derives Authorization header from the supplied fields\", ()=> {\n pw.expect(pw.response.body.headers[\"authorization\"]).toBeType(\"string\");\n});",
"body": {
"contentType": null,
"body": null
},
"requestVariables": []
}
],
"auth": {
"authType": "none",
"authActive": true
},
"headers": []
}