Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[KeyVault] - Include missing properties when reading SecretBundle #13614

Merged
merged 3 commits into from
Feb 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions sdk/keyvault/keyvault-secrets/rollup.base.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export function nodeConfig(test = false) {
// different output file
baseConfig.output.file = "dist-test/index.node.js";

baseConfig.external.push("assert", "fs", "path");
baseConfig.external.push("assert", "fs", "path", "chai");

baseConfig.context = "null";

Expand Down Expand Up @@ -117,7 +117,8 @@ export function browserConfig(test = false) {
json(),
cjs({
namedExports: {
assert: ["ok", "equal", "strictEqual", "deepEqual"],
chai: ["assert"],
assert: ["ok", "equal", "strictEqual", "deepEqual", "exists"],
"@opentelemetry/api": ["CanonicalCode", "SpanKind", "TraceFlags"]
}
})
Expand Down
10 changes: 7 additions & 3 deletions sdk/keyvault/keyvault-secrets/src/transformations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ export function getSecretFromSecretBundle(
value: secretBundle.value,
name: parsedId.name,
properties: {
expiresOn: (attributes as any).expires,
createdOn: (attributes as any).created,
updatedOn: (attributes as any).updated,
expiresOn: attributes?.expires,
createdOn: attributes?.created,
updatedOn: attributes?.updated,
enabled: attributes?.enabled,
notBefore: attributes?.notBefore,
recoverableDays: attributes?.recoverableDays,
recoveryLevel: attributes?.recoveryLevel,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woah! Thank you so much!

Before we had these transformers we used to use the spread operator a lot, and in my attempt to gain better control over it, I ended up missing these properties I think.

Should we see if we're having a similar issue in the other Key Vault clients?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! Maybe we can merge this in and then I can separately check the other packages?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good! I'll approve!


id: secretBundle.id,
contentType: secretBundle.contentType,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { assert } from "chai";
import { DeletedSecret, KeyVaultSecret } from "../../src";
import { DeletedSecretBundle, SecretBundle } from "../../src/generated";
import { getSecretFromSecretBundle } from "../../src/transformations";

describe("Transformations", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love this test 🌞

it("correctly assigns all properties for a secret", () => {
const date = new Date();
const bundle: SecretBundle = {
attributes: {
created: date,
enabled: true,
expires: date,
notBefore: date,
recoverableDays: 7,
recoveryLevel: "Purgable",
updated: date
},
contentType: "content_type",
id: "https://azure_keyvault.vault.azure.net/keys/abc123/1",
kid: "test_kid",
managed: true,
tags: {
tag1: "value1",
tag2: "value2"
},
value: "my secret value"
};

const expectedResult: KeyVaultSecret = {
value: bundle.value,
name: "abc123",
properties: {
expiresOn: date,
createdOn: date,
updatedOn: date,
enabled: true,
notBefore: date,
recoverableDays: 7,
recoveryLevel: "Purgable",
id: "https://azure_keyvault.vault.azure.net/keys/abc123/1",
contentType: "content_type",
tags: {
tag1: "value1",
tag2: "value2"
},
managed: true,
vaultUrl: "https://azure_keyvault.vault.azure.net",
version: "1",
name: "abc123"
}
};

const secret: KeyVaultSecret = getSecretFromSecretBundle(bundle);
assert.deepEqual(secret, expectedResult);
});

it("correctly assigns all properties for a deleted secret", () => {
const date = new Date();
const bundle: DeletedSecretBundle = {
id: "https://azure_keyvault.vault.azure.net/keys/abc123/1",
recoveryId: "recovery_id",
scheduledPurgeDate: date,
deletedDate: date
};

const secret: DeletedSecret = getSecretFromSecretBundle(bundle);
assert.equal(secret.properties.recoveryId, "recovery_id");
assert.equal(secret.properties.deletedOn, date);
assert.equal(secret.properties.scheduledPurgeDate, date);
});
});