diff --git a/packages/hoppscotch-cli/src/__tests__/e2e/commands/test.spec.ts b/packages/hoppscotch-cli/src/__tests__/e2e/commands/test.spec.ts index e350e077..3de3367f 100644 --- a/packages/hoppscotch-cli/src/__tests__/e2e/commands/test.spec.ts +++ b/packages/hoppscotch-cli/src/__tests__/e2e/commands/test.spec.ts @@ -95,6 +95,7 @@ describe("hopp test [options] ", { timeout: 100000 }, () => { const testFixtures = [ { fileName: "env-v0.json", version: 0 }, { fileName: "env-v1.json", version: 1 }, + { fileName: "env-v2.json", version: 2 }, ]; testFixtures.forEach(({ fileName, version }) => { diff --git a/packages/hoppscotch-cli/src/__tests__/e2e/fixtures/environments/aws-signature-auth-envs.json b/packages/hoppscotch-cli/src/__tests__/e2e/fixtures/environments/aws-signature-auth-envs.json index 534bf711..486e69c6 100644 --- a/packages/hoppscotch-cli/src/__tests__/e2e/fixtures/environments/aws-signature-auth-envs.json +++ b/packages/hoppscotch-cli/src/__tests__/e2e/fixtures/environments/aws-signature-auth-envs.json @@ -1,34 +1,42 @@ { - "v": 1, + "v": 2, "id": "cm0dsn3v70004p4qk3l9b7sjm", "name": "AWS Signature - environments", "variables": [ { "key": "awsRegion", - "value": "us-east-1", + "currentValue": "us-east-1", + "initialValue": "us-east-1", "secret": false }, { "key": "serviceName", - "value": "s3", + "currentValue": "s3", + "initialValue": "s3", "secret": false }, { "key": "accessKey", - "value": "test-access-key", + "currentValue": "test-access-key", + "initialValue": "test-access-key", "secret": true }, { "key": "secretKey", + "currentValue": "", + "initialValue": "", "secret": true }, { "key": "url", - "value": "https://echo.hoppscotch.io", + "currentValue": "https://echo.hoppscotch.io", + "initialValue": "https://echo.hoppscotch.io", "secret": false }, { "key": "serviceToken", + "currentValue": "", + "initialValue": "", "secret": true } ] diff --git a/packages/hoppscotch-cli/src/__tests__/e2e/fixtures/environments/digest-auth-envs.json b/packages/hoppscotch-cli/src/__tests__/e2e/fixtures/environments/digest-auth-envs.json index eacbcbc0..eb1c2aea 100644 --- a/packages/hoppscotch-cli/src/__tests__/e2e/fixtures/environments/digest-auth-envs.json +++ b/packages/hoppscotch-cli/src/__tests__/e2e/fixtures/environments/digest-auth-envs.json @@ -1,21 +1,24 @@ { - "v": 1, + "v": 2, "id": "cm0dsn3v70004p4qk3l9b7sjm", "name": "Digest Auth - environments", "variables": [ { "key": "username", - "value": "admin", + "currentValue": "", + "initialValue": "admin", "secret": true }, { "key": "password", - "value": "admin", + "currentValue": "", + "initialValue": "admin", "secret": true }, { "key": "url", - "value": "https://test.insightres.org/digest/" + "currentValue": "", + "initialValue": "https://test.insightres.org/digest/" } ] } diff --git a/packages/hoppscotch-cli/src/__tests__/e2e/fixtures/environments/env-v1.json b/packages/hoppscotch-cli/src/__tests__/e2e/fixtures/environments/env-v1.json index 4ab5aa65..c6f7c919 100644 --- a/packages/hoppscotch-cli/src/__tests__/e2e/fixtures/environments/env-v1.json +++ b/packages/hoppscotch-cli/src/__tests__/e2e/fixtures/environments/env-v1.json @@ -1,10 +1,10 @@ { - "name": "env-v0", - "variables": [ - { - "key": "baseURL", - "value": "https://echo.hoppscotch.io", - "secret": false - } - ] - } \ No newline at end of file + "name": "env-v1", + "variables": [ + { + "key": "baseURL", + "value": "https://echo.hoppscotch.io", + "secret": false + } + ] +} diff --git a/packages/hoppscotch-cli/src/__tests__/e2e/fixtures/environments/env-v2.json b/packages/hoppscotch-cli/src/__tests__/e2e/fixtures/environments/env-v2.json new file mode 100644 index 00000000..1c170dbd --- /dev/null +++ b/packages/hoppscotch-cli/src/__tests__/e2e/fixtures/environments/env-v2.json @@ -0,0 +1,13 @@ +{ + "id": "env-v2", + "v": 2, + "name": "env-v2", + "variables": [ + { + "key": "baseURL", + "initialValue": "https://echo.hoppscotch.io", + "currentValue": "https://echo.hoppscotch.io", + "secret": false + } + ] +} diff --git a/packages/hoppscotch-cli/src/__tests__/e2e/fixtures/environments/request-vars-envs.json b/packages/hoppscotch-cli/src/__tests__/e2e/fixtures/environments/request-vars-envs.json index 844af010..ff96dced 100644 --- a/packages/hoppscotch-cli/src/__tests__/e2e/fixtures/environments/request-vars-envs.json +++ b/packages/hoppscotch-cli/src/__tests__/e2e/fixtures/environments/request-vars-envs.json @@ -1,33 +1,42 @@ { - "v": 1, + "v": 2, "id": "cm00r7kpb0006mbd2nq1560w6", "name": "Request variables alongside environment variables", "variables": [ { "key": "url", - "value": "https://echo.hoppscotch.io", + "initialValue": "https://echo.hoppscotch.io", + "currentValue": "https://echo.hoppscotch.io", "secret": false }, { "key": "secretBasicAuthPasswordEnvVar", + "initialValue": "", + "currentValue": "", "secret": true }, { "key": "secretBasicAuthUsernameEnvVar", - "value": "username", + "initialValue": "username", + "currentValue": "", "secret": true }, { "key": "username", + "initialValue": "", + "currentValue": "", "secret": true }, { "key": "password", + "initialValue": "", + "currentValue": "", "secret": true }, { "key": "testHeaderValue", - "value": "test-header-value", + "initialValue": "test-header-value", + "currentValue": "", "secret": false } ] diff --git a/packages/hoppscotch-cli/src/__tests__/e2e/fixtures/environments/secret-envs-persistence-scripting-envs.json b/packages/hoppscotch-cli/src/__tests__/e2e/fixtures/environments/secret-envs-persistence-scripting-envs.json index b03e0508..e1411452 100644 --- a/packages/hoppscotch-cli/src/__tests__/e2e/fixtures/environments/secret-envs-persistence-scripting-envs.json +++ b/packages/hoppscotch-cli/src/__tests__/e2e/fixtures/environments/secret-envs-persistence-scripting-envs.json @@ -1,26 +1,36 @@ { - "v": 1, + "v": 2, "id": "2", "name": "secret-envs-persistence-scripting-envs", "variables": [ { "key": "preReqVarOne", + "initialValue": "", + "currentValue": "", "secret": true }, { "key": "preReqVarTwo", + "initialValue": "", + "currentValue": "", "secret": true }, { "key": "postReqVarOne", + "initialValue": "", + "currentValue": "", "secret": true }, { "key": "preReqVarTwo", + "initialValue": "", + "currentValue": "", "secret": true }, { "key": "customHeaderValueFromSecretVar", + "initialValue": "", + "currentValue": "", "secret": true } ] diff --git a/packages/hoppscotch-cli/src/__tests__/e2e/fixtures/environments/secret-envs.json b/packages/hoppscotch-cli/src/__tests__/e2e/fixtures/environments/secret-envs.json index 266f821c..1c4ae820 100644 --- a/packages/hoppscotch-cli/src/__tests__/e2e/fixtures/environments/secret-envs.json +++ b/packages/hoppscotch-cli/src/__tests__/e2e/fixtures/environments/secret-envs.json @@ -1,44 +1,60 @@ { "id": "2", - "v": 1, + "v": 2, "name": "secret-envs", "variables": [ { "key": "secretBearerToken", + "initialValue": "", + "currentValue": "", "secret": true }, { "key": "secretBasicAuthUsername", + "initialValue": "", + "currentValue": "", "secret": true }, { "key": "secretBasicAuthPassword", + "initialValue": "", + "currentValue": "", "secret": true }, { "key": "secretQueryParamValue", + "initialValue": "", + "currentValue": "", "secret": true }, { "key": "secretBodyValue", + "initialValue": "", + "currentValue": "", "secret": true }, { "key": "secretHeaderValue", + "initialValue": "", + "currentValue": "", "secret": true }, { "key": "nonExistentValueInSystemEnv", + "initialValue": "", + "currentValue": "", "secret": true }, { "key": "echoHoppBaseURL", - "value": "https://echo.hoppscotch.io", + "initialValue": "https://echo.hoppscotch.io", + "currentValue": "", "secret": false }, { "key": "httpbinBaseURL", - "value": "https://httpbin.org", + "initialValue": "https://httpbin.org", + "currentValue": "", "secret": false } ] diff --git a/packages/hoppscotch-cli/src/__tests__/e2e/fixtures/environments/secret-supplied-values-envs.json b/packages/hoppscotch-cli/src/__tests__/e2e/fixtures/environments/secret-supplied-values-envs.json index 88155f84..9c331bd9 100644 --- a/packages/hoppscotch-cli/src/__tests__/e2e/fixtures/environments/secret-supplied-values-envs.json +++ b/packages/hoppscotch-cli/src/__tests__/e2e/fixtures/environments/secret-supplied-values-envs.json @@ -1,50 +1,60 @@ { - "v": 1, + "v": 2, "id": "2", "name": "secret-values-envs", "variables": [ { "key": "secretBearerToken", - "value": "test-token", + "initialValue": "test-token", + "currentValue": "test-token", "secret": true }, { "key": "secretBasicAuthUsername", - "value": "test-user", + "initialValue": "test-user", + "currentValue": "test-user", "secret": true }, { "key": "secretBasicAuthPassword", - "value": "test-pass", + "initialValue": "test-pass", + "currentValue": "test-pass", "secret": true }, { "key": "secretQueryParamValue", - "value": "secret-query-param-value", + "initialValue": "secret-query-param-value", + "currentValue": "secret-query-param-value", "secret": true }, { "key": "secretBodyValue", - "value": "secret-body-value", + "initialValue": "secret-body-value", + "currentValue": "secret-body-value", "secret": true }, { "key": "secretHeaderValue", - "value": "secret-header-value", + "initialValue": "secret-header-value", + "currentValue": "secret-header-value", "secret": true }, { "key": "nonExistentValueInSystemEnv", + "initialValue": "", + "currentValue": "", "secret": true }, { "key": "echoHoppBaseURL", - "value": "https://echo.hoppscotch.io", + "initialValue": "https://echo.hoppscotch.io", + "currentValue": "https://echo.hoppscotch.io", "secret": false }, { "key": "httpbinBaseURL", - "value": "https://httpbin.org", + "initialValue": "https://httpbin.org", + "currentValue": "https://httpbin.org", "secret": false } ] diff --git a/packages/hoppscotch-cli/src/__tests__/unit/getters.spec.ts b/packages/hoppscotch-cli/src/__tests__/unit/getters.spec.ts index 3950a9fe..627683eb 100644 --- a/packages/hoppscotch-cli/src/__tests__/unit/getters.spec.ts +++ b/packages/hoppscotch-cli/src/__tests__/unit/getters.spec.ts @@ -44,7 +44,12 @@ describe("getters", () => { describe("getEffectiveFinalMetaData", () => { const environmentVariables = [ - { key: "PARAM", value: "parsed_param", secret: false }, + { + key: "PARAM", + initialValue: "parsed_param", + currentValue: "parsed_param", + secret: false, + }, ]; test("Empty list of meta-data", () => { @@ -421,27 +426,32 @@ describe("getters", () => { const environmentVariables = [ { key: "SHARED_KEY_I", - value: "environment-variable-shared-value-I", + initialValue: "environment-variable-shared-value-I", + currentValue: "environment-variable-shared-value-I", secret: false, }, { key: "SHARED_KEY_II", - value: "environment-variable-shared-value-II", + initialValue: "environment-variable-shared-value-II", + currentValue: "environment-variable-shared-value-II", secret: false, }, { key: "ENV_VAR_III", - value: "environment-variable-value-III", + initialValue: "environment-variable-value-III", + currentValue: "environment-variable-value-III", secret: false, }, { key: "ENV_VAR_IV", - value: "environment-variable-value-IV", + initialValue: "environment-variable-value-IV", + currentValue: "environment-variable-value-IV", secret: false, }, { key: "ENV_VAR_V", - value: "environment-variable-value-V", + initialValue: "environment-variable-value-V", + currentValue: "environment-variable-value-V", secret: false, }, ]; @@ -450,32 +460,38 @@ describe("getters", () => { const expected = [ { key: "SHARED_KEY_I", - value: "request-variable-shared-value-I", + currentValue: "request-variable-shared-value-I", + initialValue: "request-variable-shared-value-I", secret: false, }, { key: "REQUEST_VAR_III", - value: "request-variable-value-III", + currentValue: "request-variable-value-III", + initialValue: "request-variable-value-III", secret: false, }, { key: "SHARED_KEY_II", - value: "environment-variable-shared-value-II", + currentValue: "environment-variable-shared-value-II", + initialValue: "environment-variable-shared-value-II", secret: false, }, { key: "ENV_VAR_III", - value: "environment-variable-value-III", + currentValue: "environment-variable-value-III", + initialValue: "environment-variable-value-III", secret: false, }, { key: "ENV_VAR_IV", - value: "environment-variable-value-IV", + currentValue: "environment-variable-value-IV", + initialValue: "environment-variable-value-IV", secret: false, }, { key: "ENV_VAR_V", - value: "environment-variable-value-V", + currentValue: "environment-variable-value-V", + initialValue: "environment-variable-value-V", secret: false, }, ]; diff --git a/packages/hoppscotch-cli/src/commands/test.ts b/packages/hoppscotch-cli/src/commands/test.ts index 0291fa31..3e40978c 100644 --- a/packages/hoppscotch-cli/src/commands/test.ts +++ b/packages/hoppscotch-cli/src/commands/test.ts @@ -75,7 +75,8 @@ export const test = (pathOrId: string, options: TestCmdOptions) => async () => { (key) => { key: key, - value: iterationDataItem[key], + initialValue: iterationDataItem[key], + currentValue: iterationDataItem[key], secret: false, } ) diff --git a/packages/hoppscotch-cli/src/options/test/env.ts b/packages/hoppscotch-cli/src/options/test/env.ts index cc674652..8bd3fa70 100644 --- a/packages/hoppscotch-cli/src/options/test/env.ts +++ b/packages/hoppscotch-cli/src/options/test/env.ts @@ -60,11 +60,16 @@ export async function parseEnvsData(options: TestCmdEnvironmentOptions) { if (HoppEnvKeyPairResult.success) { for (const [key, value] of Object.entries(HoppEnvKeyPairResult.data)) { - envPairs.push({ key, value, secret: false }); + envPairs.push({ + key, + initialValue: value, + currentValue: value, + secret: false, + }); } } else if (HoppEnvExportObjectResult.type === "ok") { // Original environment variables from the supplied export file - const originalEnvVariables = (contents as NonSecretEnvironment).variables; + const originalEnvVariables = (contents as Environment).variables; // Above environment variables conforming to the latest schema // `value` fields if specified will be omitted for secret environment variables @@ -73,10 +78,10 @@ export async function parseEnvsData(options: TestCmdEnvironmentOptions) { // The values supplied for secret environment variables have to be considered in the CLI // For each secret environment variable, include the value in case supplied const resolvedEnvVariables = migratedEnvVariables.map((variable, idx) => { - if (variable.secret && originalEnvVariables[idx].value) { + if (variable.secret && originalEnvVariables[idx].initialValue) { return { ...variable, - value: originalEnvVariables[idx].value, + initialValue: originalEnvVariables[idx].initialValue, }; } diff --git a/packages/hoppscotch-cli/src/utils/getters.ts b/packages/hoppscotch-cli/src/utils/getters.ts index 07fe43fc..c76ff0ea 100644 --- a/packages/hoppscotch-cli/src/utils/getters.ts +++ b/packages/hoppscotch-cli/src/utils/getters.ts @@ -275,9 +275,15 @@ export const getResolvedVariables = ( requestVariables: HoppRESTRequestVariables, environmentVariables: EnvironmentVariable[] ): EnvironmentVariable[] => { + // Transforming request variables to the shape of environment variables const activeRequestVariables = requestVariables .filter(({ active, value }) => active && value) - .map(({ key, value }) => ({ key, value, secret: false })); + .map(({ key, value }) => ({ + key, + initialValue: value, + currentValue: value, + secret: false, + })); const requestVariableKeys = activeRequestVariables.map(({ key }) => key); @@ -286,5 +292,17 @@ export const getResolvedVariables = ( ({ key }) => !requestVariableKeys.includes(key) ); - return [...activeRequestVariables, ...filteredEnvironmentVariables]; + // Setting currentValue to initialValue for environment variables + // because the exported file might not have the currentValue field + const processedEnvironmentVariables = filteredEnvironmentVariables.map( + ({ key, initialValue, currentValue, secret }) => ({ + key, + initialValue, + currentValue: + currentValue && currentValue !== "" ? currentValue : initialValue, + secret, + }) + ); + + return [...activeRequestVariables, ...processedEnvironmentVariables]; }; diff --git a/packages/hoppscotch-cli/src/utils/request.ts b/packages/hoppscotch-cli/src/utils/request.ts index a80b8244..d769c5ac 100644 --- a/packages/hoppscotch-cli/src/utils/request.ts +++ b/packages/hoppscotch-cli/src/utils/request.ts @@ -42,8 +42,10 @@ const processVariables = (variable: Environment["variables"][number]) => { if (variable.secret) { return { ...variable, - value: - "value" in variable ? variable.value : process.env[variable.key] || "", + currentValue: + "currentValue" in variable && variable.currentValue !== "" + ? variable.currentValue + : process.env[variable.key] || "", }; } return variable; diff --git a/packages/hoppscotch-common/locales/en.json b/packages/hoppscotch-common/locales/en.json index 4b8cf526..677ba431 100644 --- a/packages/hoppscotch-common/locales/en.json +++ b/packages/hoppscotch-common/locales/en.json @@ -340,11 +340,13 @@ } }, "count": { + "currentValue": "Current value {count}", + "description": "Description {count}", "header": "Header {count}", + "initialValue": "Initial value {count}", + "key": "Key {count}", "message": "Message {count}", "parameter": "Parameter {count}", - "key": "Key {count}", - "description": "Description {count}", "protocol": "Protocol {count}", "value": "Value {count}", "variable": "Variable {count}" diff --git a/packages/hoppscotch-common/src/components/environments/Add.vue b/packages/hoppscotch-common/src/components/environments/Add.vue index 5eed9be6..71dedb1d 100644 --- a/packages/hoppscotch-common/src/components/environments/Add.vue +++ b/packages/hoppscotch-common/src/components/environments/Add.vue @@ -70,7 +70,6 @@