Skip to content

Commit

Permalink
Encode when decode is on. Release M188 (#14953)
Browse files Browse the repository at this point in the history
  • Loading branch information
tauhid621 authored Jun 9, 2021
1 parent 30577e1 commit 65e88e2
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Tasks/AzureKeyVaultV2/Tests/L0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('Azure Key Vault', function () {
assert(tr.stdout.indexOf("##vso[task.setvariable variable=secret2;issecret=true;]secret2-value") > 0, "##vso[task.setvariable variable=secret2;issecret=true;]secret2-value");
assert(tr.stdout.indexOf("##vso[task.setvariable variable=secret3;issecret=true;]secret3/versionIdentifierGuid-value") > 0, "##vso[task.setvariable variable=secret3;issecret=true;]secret3/versionIdentifierGuid-value");
assert(tr.stdout.indexOf("##vso[task.setvariable variable=secret3/versionIdentifierGuid;issecret=true;]secret3/versionIdentifierGuid-value") > 0, "##vso[task.setvariable variable=secret3/versionIdentifierGuid;issecret=true;]secret3/versionIdentifierGuid-value");
assert(tr.stdout.indexOf("##vso[task.setvariable variable=secret5_%AZP253B;issecret=true;]secret5_%AZP253B-value") > 0, "##vso[task.setvariable variable=secret5_%AZP253B;issecret=true;]secret5_%AZP253B-value");
assert(tr.stdout.indexOf("##vso[task.setvariable variable=secret5_%3B;issecret=true;]secret5_%3B-value") > 0, "##vso[task.setvariable variable=secret5_%3B;issecret=true;]secret5_%3B-value");

assert(tr.stdout.indexOf("##vso[task.setvariable variable=secret4;issecret=true;]secret4-value") < 0, "secret4 value should not be set");

Expand Down
1 change: 1 addition & 0 deletions Tasks/AzureKeyVaultV2/Tests/downloadSelectedSecrets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ process.env["ENDPOINT_DATA_AzureRMSpn_AzureKeyVaultServiceEndpointResourceId"] =
process.env["ENDPOINT_URL_AzureRMSpn"] = "https://management.azure.com/";
process.env["SYSTEM_DEFAULTWORKINGDIRECTORY"] = "C:\\a\\w\\";
process.env["AGENT_TEMPDIRECTORY"] = process.cwd();
process.env["DECODE_PERCENTS"] = "false";

tr.registerMock('azure-pipelines-task-lib/toolrunner', require('azure-pipelines-task-lib/mock-toolrunner'));
tr.registerMock('./azure-arm-keyvault', require('./mock_node_modules/azure-arm-keyvault'));
Expand Down
9 changes: 7 additions & 2 deletions Tasks/AzureKeyVaultV2/operations/KeyVault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import tl = require("azure-pipelines-task-lib/task");
import * as path from 'path';
import * as fs from 'fs';

const DECODE_PERCENTS = "DECODE_PERCENTS";

export class SecretsToErrorsMapping {
public errorsMap: { [key: string]: string; };

Expand Down Expand Up @@ -193,8 +195,11 @@ export class KeyVault {
}

// Encode percent explicitely as the task lib does not encode % to %AZP25 as of now.
secretName = secretName.replace(/%/g, '%AZP25');
secretValue = secretValue.replace(/%/g, '%AZP25');
let decodePercents = tl.getVariable(DECODE_PERCENTS);
if (decodePercents && decodePercents.toUpperCase() === "TRUE") {
secretName = secretName.replace(/%/g, '%AZP25');
secretValue = secretValue.replace(/%/g, '%AZP25');
}

// Support multiple stages using different key vaults with the same secret name but with different version identifiers
let secretNameWithoutVersion = secretName.split("/")[0];
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureKeyVaultV2/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 2,
"Minor": 186,
"Minor": 188,
"Patch": 0
},
"demands": [],
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureKeyVaultV2/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 2,
"Minor": 186,
"Minor": 188,
"Patch": 0
},
"demands": [],
Expand Down

0 comments on commit 65e88e2

Please sign in to comment.