-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[Key Vault Admin] Tests #11010
Merged
Merged
[Key Vault Admin] Tests #11010
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
e76302b
[Key Vault Admin] Tests
sadasant 1e47c1e
Addressing https://github.com/Azure/azure-sdk-for-js/pull/11010#discu…
sadasant 822d51b
Merge remote-tracking branch 'Azure/master' into keyvault-admin/tests
sadasant 1bae90c
recent feedback and changes after recent API changes
sadasant 8406f27
environment variable changes and SAS token recorder cleanup
sadasant 6f849c1
test-resources has KEYVAULT_URI
sadasant f3b9e8a
new tests that wont pass, but that I want to have
sadasant b0c6a86
Merge remote-tracking branch 'Azure/master' into keyvault-admin/tests
sadasant 944615e
wip
sadasant eb246d2
updates after the full source was merged
sadasant 4baa40e
chai on the rollup.base
sadasant a87bb75
[Key Vault Admin] Docs and Samples (#11075)
sadasant 646ee0b
Replacing the BLOB_STORAGE_URI
sadasant 94bf14f
No unnecesary new credentials
sadasant ee2e28c
all of the recent feedback
sadasant 94f4fb0
addressing https://github.com/Azure/azure-sdk-for-js/pull/11010#discu…
sadasant c57f3d6
Merge remote-tracking branch 'Azure/master' into keyvault-admin/tests
sadasant 0ea78a7
formatting
sadasant File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
import * as base from "./rollup.base.config"; | ||
|
||
export default [base.nodeConfig(true), base.browserConfig(true)]; |
82 changes: 82 additions & 0 deletions
82
sdk/keyvault/keyvault-admin/test/public/accessControlClient.aborts.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import { env, Recorder } from "@azure/test-utils-recorder"; | ||
import { AbortController } from "@azure/abort-controller"; | ||
|
||
import { KeyVaultAccessControlClient } from "../../src"; | ||
import { assertThrowsAbortError } from "../utils/common"; | ||
import { authenticate } from "../utils/authentication"; | ||
|
||
describe("Aborting KeyVaultAccessControlClient's requests", () => { | ||
let client: KeyVaultAccessControlClient; | ||
let recorder: Recorder; | ||
let generateFakeUUID: () => string; | ||
const globalScope = "/"; | ||
|
||
beforeEach(async function() { | ||
const authentication = await authenticate(this); | ||
client = authentication.accessControlClient; | ||
recorder = authentication.recorder; | ||
generateFakeUUID = authentication.generateFakeUUID; | ||
}); | ||
|
||
afterEach(async function() { | ||
await recorder.stop(); | ||
}); | ||
|
||
// The tests follow | ||
|
||
it("can abort listRoleDefinitions", async function() { | ||
const controller = new AbortController(); | ||
controller.abort(); | ||
|
||
await assertThrowsAbortError(async () => { | ||
await client | ||
.listRoleDefinitions("/", { | ||
abortSignal: controller.signal | ||
}) | ||
.next(); | ||
}); | ||
}); | ||
|
||
it("can abort createRoleAssignment", async function() { | ||
const roleDefinitionId = generateFakeUUID(); | ||
const name = generateFakeUUID(); | ||
|
||
const controller = new AbortController(); | ||
controller.abort(); | ||
|
||
await assertThrowsAbortError(async () => { | ||
await client.createRoleAssignment(globalScope, name, roleDefinitionId, env.AZURE_TENANT_ID, { | ||
abortSignal: controller.signal | ||
}); | ||
}); | ||
}); | ||
|
||
it("can abort getRoleAssignment", async function() { | ||
const name = generateFakeUUID(); | ||
|
||
const controller = new AbortController(); | ||
controller.abort(); | ||
|
||
await assertThrowsAbortError(async () => { | ||
await client.getRoleAssignment(globalScope, name, { | ||
abortSignal: controller.signal | ||
}); | ||
}); | ||
}); | ||
|
||
it("can abort deleteRoleAssignment", async function() { | ||
const name = generateFakeUUID(); | ||
|
||
const controller = new AbortController(); | ||
controller.abort(); | ||
|
||
await assertThrowsAbortError(async () => { | ||
await client.deleteRoleAssignment(globalScope, name, { | ||
abortSignal: controller.signal | ||
}); | ||
}); | ||
}); | ||
}); |
84 changes: 84 additions & 0 deletions
84
sdk/keyvault/keyvault-admin/test/public/accessControlClient.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import { assert } from "chai"; | ||
import { env, Recorder } from "@azure/test-utils-recorder"; | ||
|
||
import { KeyVaultAccessControlClient } from "../../src"; | ||
import { authenticate } from "../utils/authentication"; | ||
|
||
describe("KeyVaultAccessControlClient", () => { | ||
let client: KeyVaultAccessControlClient; | ||
let recorder: Recorder; | ||
let generateFakeUUID: () => string; | ||
const globalScope = "/"; | ||
|
||
beforeEach(async function() { | ||
const authentication = await authenticate(this); | ||
client = authentication.accessControlClient; | ||
recorder = authentication.recorder; | ||
generateFakeUUID = authentication.generateFakeUUID; | ||
}); | ||
|
||
afterEach(async function() { | ||
await recorder.stop(); | ||
}); | ||
|
||
// The tests follow | ||
|
||
it("listRoleDefinitions", async function() { | ||
const expectedType = "Microsoft.Authorization/roleDefinitions"; | ||
let receivedRoles: string[] = []; | ||
|
||
for await (const roleDefinition of client.listRoleDefinitions("/")) { | ||
sadasant marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Each role definition will have the shape of: | ||
// | ||
// { | ||
// id: 'Microsoft.KeyVault/providers/Microsoft.Authorization/roleDefinitions/<ID>', | ||
// name: '<ID>', | ||
// type: '<role-type>', | ||
// roleName: '<role-name>', | ||
// // ... | ||
// } | ||
// | ||
assert.equal(roleDefinition.type, expectedType); | ||
receivedRoles.push(roleDefinition.roleName!); | ||
} | ||
|
||
assert.deepEqual(receivedRoles, [ | ||
sadasant marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"Managed HSM Administrator", | ||
"Managed HSM Crypto Officer", | ||
"Managed HSM Crypto User", | ||
"Managed HSM Policy Administrator", | ||
"Managed HSM Crypto Auditor", | ||
"Managed HSM Crypto Service Encryption", | ||
"Managed HSM Backup" | ||
]); | ||
}); | ||
|
||
it("createRoleAssignment and deleteRoleAssignment", async function() { | ||
const roleDefinition = (await client.listRoleDefinitions(globalScope).next()).value; | ||
const name = generateFakeUUID(); | ||
const assignment = await client.createRoleAssignment( | ||
globalScope, | ||
name, | ||
roleDefinition.id!, | ||
env.AZURE_TENANT_ID | ||
sadasant marked this conversation as resolved.
Show resolved
Hide resolved
|
||
); | ||
assert.equal(assignment.name, name); | ||
assert.equal(assignment.properties?.roleDefinitionId, roleDefinition.id); | ||
assert.equal(assignment.properties?.principalId, env.AZURE_TENANT_ID); | ||
await client.deleteRoleAssignment(globalScope, name); | ||
sadasant marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
|
||
it("createRoleAssignment, getRoleAssignment and deleteRoleAssignment", async function() { | ||
const roleDefinition = (await client.listRoleDefinitions(globalScope).next()).value; | ||
const name = generateFakeUUID(); | ||
await client.createRoleAssignment(globalScope, name, roleDefinition.id!, env.AZURE_TENANT_ID); | ||
const assignment = await client.getRoleAssignment(globalScope, name); | ||
assert.equal(assignment.name, name); | ||
sadasant marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert.equal(assignment.properties?.roleDefinitionId, roleDefinition.id); | ||
assert.equal(assignment.properties?.principalId, env.AZURE_TENANT_ID); | ||
await client.deleteRoleAssignment(globalScope, name); | ||
}); | ||
}); |
74 changes: 74 additions & 0 deletions
74
sdk/keyvault/keyvault-admin/test/public/backupClient.abort.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import { env, Recorder } from "@azure/test-utils-recorder"; | ||
import { AbortController } from "@azure/abort-controller"; | ||
|
||
import { KeyVaultBackupClient } from "../../src"; | ||
import { authenticate } from "../utils/authentication"; | ||
import { testPollerProperties } from "../utils/recorder"; | ||
import { assertThrowsAbortError, getFolderName } from "../utils/common"; | ||
|
||
describe("Aborting KeyVaultBackupClient's requests", () => { | ||
let client: KeyVaultBackupClient; | ||
let recorder: Recorder; | ||
|
||
beforeEach(async function() { | ||
const authentication = await authenticate(this); | ||
client = authentication.backupClient; | ||
recorder = authentication.recorder; | ||
}); | ||
|
||
afterEach(async function() { | ||
await recorder.stop(); | ||
}); | ||
|
||
// The tests follow | ||
|
||
it("can abort beginBackup", async function() { | ||
const blobStorageUri = env.BLOB_STORAGE_URI; | ||
const sasToken = env.BLOB_STORAGE_SAS_TOKEN; | ||
|
||
const controller = new AbortController(); | ||
controller.abort(); | ||
|
||
await assertThrowsAbortError(async () => { | ||
await client.beginBackup(blobStorageUri, sasToken, { | ||
...testPollerProperties, | ||
abortSignal: controller.signal | ||
}); | ||
}); | ||
}); | ||
|
||
it("can abort beginRestore", async function() { | ||
const blobStorageUri = env.BLOB_STORAGE_URI; | ||
const sasToken = env.BLOB_STORAGE_SAS_TOKEN; | ||
const folderName = getFolderName(blobStorageUri); | ||
sadasant marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const controller = new AbortController(); | ||
controller.abort(); | ||
|
||
await assertThrowsAbortError(async () => { | ||
await client.beginRestore(blobStorageUri, sasToken, folderName, { | ||
...testPollerProperties, | ||
abortSignal: controller.signal | ||
}); | ||
}); | ||
}); | ||
|
||
it("can abort beginSelectiveRestore", async function() { | ||
const blobStorageUri = env.BLOB_STORAGE_URI; | ||
const sasToken = env.BLOB_STORAGE_SAS_TOKEN; | ||
const folderName = getFolderName(blobStorageUri); | ||
sadasant marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const controller = new AbortController(); | ||
controller.abort(); | ||
|
||
await assertThrowsAbortError(async () => { | ||
await client.beginSelectiveRestore("Key Name", blobStorageUri, sasToken, folderName, { | ||
...testPollerProperties, | ||
abortSignal: controller.signal | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like to use this!