Skip to content

Commit

Permalink
feat: oauth revamp + support for multiple grant types in oauth (#3885)
Browse files Browse the repository at this point in the history
Co-authored-by: jamesgeorge007 <jamesgeorge998001@gmail.com>
  • Loading branch information
amk-dev and jamesgeorge007 committed Mar 19, 2024
1 parent 457857a commit 6b58915
Show file tree
Hide file tree
Showing 44 changed files with 2,728 additions and 363 deletions.
Expand Up @@ -17,7 +17,7 @@
"folders": [],
"requests": [
{
"v": "2",
"v": "3",
"endpoint": "https://echo.hoppscotch.io",
"name": "RequestD",
"params": [],
Expand Down Expand Up @@ -53,7 +53,7 @@
],
"requests": [
{
"v": "2",
"v": "3",
"endpoint": "https://echo.hoppscotch.io",
"name": "RequestC",
"params": [],
Expand Down Expand Up @@ -90,7 +90,7 @@
],
"requests": [
{
"v": "2",
"v": "3",
"endpoint": "https://echo.hoppscotch.io",
"name": "RequestB",
"params": [],
Expand Down Expand Up @@ -119,7 +119,7 @@
],
"requests": [
{
"v": "2",
"v": "3",
"endpoint": "https://echo.hoppscotch.io",
"name": "RequestA",
"params": [],
Expand Down Expand Up @@ -162,7 +162,7 @@
"folders": [],
"requests": [
{
"v": "2",
"v": "3",
"endpoint": "https://echo.hoppscotch.io",
"name": "RequestB",
"params": [],
Expand Down Expand Up @@ -191,7 +191,7 @@
],
"requests": [
{
"v": "2",
"v": "3",
"endpoint": "https://echo.hoppscotch.io",
"name": "RequestA",
"params": [],
Expand Down
Expand Up @@ -4,7 +4,7 @@
"folders": [],
"requests": [
{
"v": "2",
"v": "3",
"endpoint": "<<URL>>",
"name": "test1",
"params": [],
Expand Down
Expand Up @@ -5,40 +5,34 @@
"folders": [],
"requests": [
{
"v": "2",
"v": "3",
"endpoint": "https://echo.hoppscotch.io/<<HEADERS_TYPE1>>",
"name": "",
"params": [],
"headers": [],
"method": "GET",
"auth": {
"authType": "none",
"authActive": true,
"addTo": "Headers",
"key": "",
"value": ""
"authActive": true
},
"preRequestScript": "pw.env.set(\"HEADERS_TYPE1\", \"devblin_local1\");",
"testScript": "// Check status code is 200\npwd.test(\"Status code is 200\", ()=> {\n pw.expect(pw.response.status).toBe(200);\n});\n\n// Check JSON response property\npw.test(\"Check JSON response property\", ()=> {\n pw.expect(pw.response.body.method).toBe(\"GET\");\n pw.expect(pw.response.body.headers).toBeType(\"string\");\n});",
"body": {
"contentType": "application/json",
"body": "{\n\"test\": \"<<HEADERS_TYPE1>>\"\n}"
},
"requestVariables": [],
"requestVariables": []
},
{
"v": "2",
"v": "3",
"endpoint": "https://echo.hoppscotch.dio/<<HEADERS_TYPE2>>",
"name": "success",
"params": [],
"headers": [],
"method": "GET",
"auth": {
"authType": "none",
"authActive": true,
"addTo": "Headers",
"key": "",
"value": ""
"authActive": true
},
"preRequestScript": "pw.env.setd(\"HEADERS_TYPE2\", \"devblin_local2\");",
"testScript": "// Check status code is 200\npw.test(\"Status code is 200\", ()=> {\n pw.expect(pw.response.status).toBe(300);\n});\n\n// Check JSON response property\npw.test(\"Check JSON response property\", ()=> {\n pw.expect(pw.response.body.method).toBe(\"GET\");\n pw.expect(pw.response.body.headers).toBeType(\"object\");\n});",
Expand Down
Expand Up @@ -4,18 +4,15 @@
"folders": [],
"requests":
{
"v": "2",
"v": "3",
"endpoint": "https://echo.hoppscotch.io/<<HEADERS_TYPE1>>",
"name": "fail",
"params": [],
"headers": [],
"method": "GET",
"auth": {
"authType": "none",
"authActive": true,
"addTo": "Headers",
"key": "",
"value": ""
"authActive": true
},
"preRequestScript": "pw.env.set(\"HEADERS_TYPE1\", \"devblin_local1\");",
"testScript": "// Check status code is 200\npw.test(\"Status code is 200\", ()=> {\n pw.expect(pw.response.status).toBe(200);\n});\n\n// Check JSON response property\npw.test(\"Check JSON response property\", ()=> {\n pw.expect(pw.response.body.method).toBe(\"GET\");\n pw.expect(pw.response.body.headers).toBeType(\"string\");\n});",
Expand All @@ -26,18 +23,15 @@
"requestVariables": [],
},
{
"v": "2",
"v": "3",
"endpoint": "https://echo.hoppscotch.io/<<HEADERS_TYPE2>>",
"name": "success",
"params": [],
"headers": [],
"method": "GET",
"auth": {
"authType": "none",
"authActive": true,
"addTo": "Headers",
"key": "",
"value": ""
"authActive": true
},
"preRequestScript": "pw.env.set(\"HEADERS_TYPE2\", \"devblin_local2\");",
"testScript": "// Check status code is 200\npw.test(\"Status code is 200\", ()=> {\n pw.expect(pw.response.status).toBe(300);\n});\n\n// Check JSON response property\npw.test(\"Check JSON response property\", ()=> {\n pw.expect(pw.response.body.method).toBe(\"GET\");\n pw.expect(pw.response.body.headers).toBeType(\"object\");\n});",
Expand Down
Expand Up @@ -5,18 +5,15 @@
"folders": [],
"requests": [
{
"v": "2",
"v": "3",
"endpoint": "https://echo.hoppscotch.io/<<HEADERS_TYPE1>>",
"name": "",
"params": [],
"headers": [],
"method": "GET",
"auth": {
"authType": "none",
"authActive": true,
"addTo": "Headers",
"key": "",
"value": ""
"authActive": true
},
"preRequestScript": "pw.env.set(\"HEADERS_TYPE1\", \"devblin_local1\");",
"testScript": "// Check status code is 200\npw.test(\"Status code is 200\", ()=> {\n pw.expect(pw.response.status).toBe(200);\n});\n\n// Check JSON response property\npw.test(\"Check JSON response property\", ()=> {\n pw.expect(pw.response.body.method).toBe(\"GET\");\n pw.expect(pw.response.body.headers).toBeType(\"object\");\n});",
Expand All @@ -27,18 +24,15 @@
"requestVariables": []
},
{
"v": "2",
"v": "3",
"endpoint": "https://echo.hoppscotch.io/<<HEADERS_TYPE2>>",
"name": "success",
"params": [],
"headers": [],
"method": "GET",
"auth": {
"authType": "none",
"authActive": true,
"addTo": "Headers",
"key": "",
"value": ""
"authActive": true
},
"preRequestScript": "pw.env.set(\"HEADERS_TYPE2\", \"devblin_local2\");",
"testScript": "// Check status code is 200\npw.test(\"Status code is 200\", ()=> {\n pw.expect(pw.response.status).toBe(200);\n});\n\n// Check JSON response property\npw.test(\"Check JSON response property\", ()=> {\n pw.expect(pw.response.body.method).toBe(\"GET\");\n pw.expect(pw.response.body.headers).toBeType(\"object\");\n});",
Expand Down
Expand Up @@ -4,7 +4,7 @@
"folders": [],
"requests": [
{
"v": "2",
"v": "3",
"auth": { "authType": "none", "authActive": true },
"body": { "body": null, "contentType": null },
"name": "sample-req",
Expand Down
Expand Up @@ -4,7 +4,7 @@
"folders": [],
"requests": [
{
"v": "2",
"v": "3",
"name": "test-request",
"endpoint": "https://echo.hoppscotch.io",
"method": "POST",
Expand Down
Expand Up @@ -4,7 +4,7 @@
"folders": [],
"requests": [
{
"v": "2",
"v": "3",
"auth": { "authType": "none", "authActive": true },
"body": { "body": null, "contentType": null },
"name": "test-secret-headers",
Expand All @@ -23,7 +23,7 @@
"preRequestScript": "const secretHeaderValueFromPreReqScript = pw.env.get(\"secretHeaderValue\")\npw.env.set(\"secretHeaderValueFromPreReqScript\", secretHeaderValueFromPreReqScript)"
},
{
"v": "2",
"v": "3",
"auth": { "authType": "none", "authActive": true },
"body": {
"body": "{\n \"secretBodyKey\": \"<<secretBodyValue>>\"\n}",
Expand All @@ -39,7 +39,7 @@
"preRequestScript": "const secretBodyValueFromPreReqScript = pw.env.get(\"secretBodyValue\")\npw.env.set(\"secretBodyValueFromPreReqScript\", secretBodyValueFromPreReqScript)"
},
{
"v": "2",
"v": "3",
"auth": { "authType": "none", "authActive": true },
"body": { "body": null, "contentType": null },
"name": "test-secret-query-params",
Expand All @@ -58,7 +58,7 @@
"preRequestScript": "const secretQueryParamValueFromPreReqScript = pw.env.get(\"secretQueryParamValue\")\npw.env.set(\"secretQueryParamValueFromPreReqScript\", secretQueryParamValueFromPreReqScript)"
},
{
"v": "2",
"v": "3",
"auth": {
"authType": "basic",
"password": "<<secretBasicAuthPassword>>",
Expand All @@ -76,7 +76,7 @@
"preRequestScript": ""
},
{
"v": "2",
"v": "3",
"auth": {
"token": "<<secretBearerToken>>",
"authType": "bearer",
Expand All @@ -95,7 +95,7 @@
"preRequestScript": "const secretBearerToken = pw.env.get(\"secretBearerToken\")\npw.env.set(\"preReqSecretBearerToken\", secretBearerToken)"
},
{
"v": "2",
"v": "3",
"auth": { "authType": "none", "authActive": true },
"body": { "body": null, "contentType": null },
"name": "test-secret-fallback",
Expand Down
Expand Up @@ -4,7 +4,7 @@
"folders": [],
"requests": [
{
"v": "2",
"v": "3",
"auth": {
"authType": "none",
"authActive": true
Expand All @@ -29,7 +29,7 @@
"preRequestScript": "pw.env.set(\"secretHeaderValue\", \"secret-header-value\")\n\nconst secretHeaderValueFromPreReqScript = pw.env.getResolve(\"secretHeaderValue\")\npw.env.set(\"secretHeaderValueFromPreReqScript\", secretHeaderValueFromPreReqScript)"
},
{
"v": "2",
"v": "3",
"auth": {
"authType": "none",
"authActive": true
Expand All @@ -54,7 +54,7 @@
"preRequestScript": "pw.env.set(\"secretHeaderValue\", \"secret-header-value-overriden\")\n\nconst secretHeaderValueFromPreReqScript = pw.env.getResolve(\"secretHeaderValue\")\npw.env.set(\"secretHeaderValueFromPreReqScript\", secretHeaderValueFromPreReqScript)"
},
{
"v": "2",
"v": "3",
"auth": {
"authType": "none",
"authActive": true
Expand All @@ -73,7 +73,7 @@
"preRequestScript": "const secretBodyValue = pw.env.get(\"secretBodyValue\")\n\nif (!secretBodyValue) { \n pw.env.set(\"secretBodyValue\", \"secret-body-value\")\n}\n\nconst secretBodyValueFromPreReqScript = pw.env.get(\"secretBodyValue\")\npw.env.set(\"secretBodyValueFromPreReqScript\", secretBodyValueFromPreReqScript)"
},
{
"v": "2",
"v": "3",
"auth": {
"authType": "none",
"authActive": true
Expand All @@ -98,7 +98,7 @@
"preRequestScript": "const secretQueryParamValue = pw.env.get(\"secretQueryParamValue\")\n\nif (!secretQueryParamValue) {\n pw.env.set(\"secretQueryParamValue\", \"secret-query-param-value\")\n}\n\nconst secretQueryParamValueFromPreReqScript = pw.env.get(\"secretQueryParamValue\")\npw.env.set(\"secretQueryParamValueFromPreReqScript\", secretQueryParamValueFromPreReqScript)"
},
{
"v": "2",
"v": "3",
"auth": {
"authType": "basic",
"password": "<<secretBasicAuthPassword>>",
Expand All @@ -119,7 +119,7 @@
"preRequestScript": "let secretBasicAuthUsername = pw.env.get(\"secretBasicAuthUsername\")\n\nlet secretBasicAuthPassword = pw.env.get(\"secretBasicAuthPassword\")\n\nif (!secretBasicAuthUsername) {\n pw.env.set(\"secretBasicAuthUsername\", \"test-user\")\n}\n\nif (!secretBasicAuthPassword) {\n pw.env.set(\"secretBasicAuthPassword\", \"test-pass\")\n}"
},
{
"v": "2",
"v": "3",
"auth": {
"token": "<<secretBearerToken>>",
"authType": "bearer",
Expand Down
Expand Up @@ -4,7 +4,7 @@
"folders": [],
"requests": [
{
"v": "2",
"v": "3",
"endpoint": "https://httpbin.org/post",
"name": "req",
"params": [],
Expand Down
13 changes: 9 additions & 4 deletions packages/hoppscotch-cli/src/options/test/env.ts
Expand Up @@ -6,7 +6,7 @@ import { error } from "../../types/errors";
import {
HoppEnvKeyPairObject,
HoppEnvPair,
HoppEnvs
HoppEnvs,
} from "../../types/request";
import { readJsonFile } from "../../utils/mutators";

Expand All @@ -17,7 +17,7 @@ import { readJsonFile } from "../../utils/mutators";
*/
export async function parseEnvsData(path: string) {
const contents = await readJsonFile(path);
const envPairs: Array<Environment["variables"][number] | HoppEnvPair> = [];
const envPairs: Array<HoppEnvPair | Record<string, string>> = [];

// The legacy key-value pair format that is still supported
const HoppEnvKeyPairResult = HoppEnvKeyPairObject.safeParse(contents);
Expand All @@ -26,7 +26,9 @@ export async function parseEnvsData(path: string) {
const HoppEnvExportObjectResult = Environment.safeParse(contents);

// Shape of the bulk environment export object that is exported from the app
const HoppBulkEnvExportObjectResult = z.array(entityReference(Environment)).safeParse(contents)
const HoppBulkEnvExportObjectResult = z
.array(entityReference(Environment))
.safeParse(contents);

// CLI doesnt support bulk environments export
// Hence we check for this case and throw an error if it matches the format
Expand All @@ -36,7 +38,10 @@ export async function parseEnvsData(path: string) {

// Checks if the environment file is of the correct format
// If it doesnt match either of them, we throw an error
if (!HoppEnvKeyPairResult.success && HoppEnvExportObjectResult.type === "err") {
if (
!HoppEnvKeyPairResult.success &&
HoppEnvExportObjectResult.type === "err"
) {
throw error({ code: "MALFORMED_ENV_FILE", path, data: error });
}

Expand Down

0 comments on commit 6b58915

Please sign in to comment.