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

[Key Vault Admin] Tests #11010

Merged
merged 18 commits into from
Sep 11, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
53 changes: 44 additions & 9 deletions sdk/keyvault/keyvault-admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"url": "https://github.com/Azure/azure-sdk-for-js/issues"
},
"main": "./dist/index.js",
"module": "dist-esm/src/index.js",
"module": "dist-esm/keyvault-admin/src/index.js",
"types": "./types/keyvault-admin.d.ts",
"engine": {
"node": ">=8.0.0"
Expand All @@ -29,10 +29,11 @@
"node": ">=8.0.0"
},
"files": [
"types/",
"types/keyvault-admin.d.ts",
"dist/",
"dist-browser/",
"dist-esm/src",
"dist-esm/keyvault-admin/src",
"dist-esm/keyvault-common/src",
"README.md",
"LICENSE"
],
Expand All @@ -45,20 +46,21 @@
"build:samples": "echo skipped",
"build:es6": "tsc -p tsconfig.json",
"build:nodebrowser": "rollup -c 2>&1",
"build:test": "echo skipped",
"build:test": "npm run build:es6 && rollup -c rollup.test.config.js 2>&1",
"build": "npm run extract-api && npm run build:es6 && npm run build:nodebrowser",
"check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
"clean": "rimraf dist dist-esm dist-test types *.tgz *.log dist-browser statistics.html coverage && rimraf src/**/*.js && rimraf test/**/*.js",
"execute:js-samples": "echo skipped",
"execute:ts-samples": "echo skipped",
"execute:samples": "npm run build:samples && npm run execute:js-samples && npm run execute:ts-samples",
"extract-api": "echo skipped",
"extract-api": "tsc -p . && api-extractor run --local",
"format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
"integration-test:browser": "echo skipped",
"integration-test:node": "echo skipped",
"integration-test:node": "nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 180000 --full-trace dist-esm/**/*.spec.js",
"integration-test:node:no-timeout": "nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --no-timeouts --full-trace dist-esm/**/*.spec.js",
Copy link
Member

Choose a reason for hiding this comment

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

is this needed?

Copy link
Contributor Author

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!

"integration-test": "npm run integration-test:node && npm run integration-test:browser",
"lint:fix": "eslint package.json src --ext .ts --fix --fix-type [problem,suggestion]",
"lint": "eslint package.json src --ext .ts -f html -o keyvault-admin-lintReport.html",
"lint": "eslint package.json api-extractor.json src --ext .ts",
"lint:terminal": "eslint package.json src test --ext .ts",
"pack": "npm pack 2>&1",
"prebuild": "npm run clean",
Expand All @@ -72,29 +74,61 @@
},
"sideEffects": false,
"dependencies": {
"@azure/abort-controller": "^1.0.0",
"@azure/core-http": "^1.1.6",
"@azure/core-lro": "^1.0.2",
"@azure/core-paging": "^1.1.1",
"@azure/core-tracing": "1.0.0-preview.9",
"@azure/logger": "^1.0.0",
"@opentelemetry/api": "^0.10.2",
"tslib": "^2.0.0"
"tslib": "^2.0.0",
"@azure/keyvault-keys": "~4.1.1"
},
"devDependencies": {
"@azure/abort-controller": "^1.0.0",
"@azure/dev-tool": "^1.0.0",
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
"@azure/identity": "^1.1.0",
"@azure/test-utils-recorder": "^1.0.0",
"@microsoft/api-extractor": "7.7.11",
"@rollup/plugin-commonjs": "11.0.2",
"@rollup/plugin-json": "^4.0.0",
"@rollup/plugin-multi-entry": "^3.0.0",
"@rollup/plugin-node-resolve": "^8.0.0",
"@rollup/plugin-replace": "^2.2.0",
"@types/chai": "^4.1.6",
"@types/fs-extra": "^8.0.0",
"@types/mocha": "^7.0.2",
"@types/node": "^8.0.0",
"@types/uuid": "^8.0.0",
"@typescript-eslint/eslint-plugin": "^2.0.0",
"@typescript-eslint/parser": "^2.0.0",
"assert": "^1.4.1",
"chai": "^4.2.0",
"cross-env": "^7.0.2",
"dotenv": "^8.2.0",
"eslint": "^6.1.0",
"eslint-config-prettier": "^6.0.0",
"eslint-plugin-no-null": "^1.0.2",
"eslint-plugin-no-only-tests": "^2.3.0",
"eslint-plugin-promise": "^4.1.1",
"esm": "^3.2.18",
"karma": "^5.1.0",
"karma-chrome-launcher": "^3.0.0",
"karma-coverage": "^2.0.0",
"karma-edge-launcher": "^0.4.2",
"karma-env-preprocessor": "^0.1.1",
"karma-firefox-launcher": "^1.1.0",
"karma-ie-launcher": "^1.0.0",
"karma-json-preprocessor": "^0.3.3",
"karma-json-to-file-reporter": "^1.0.1",
"karma-junit-reporter": "^2.0.1",
"karma-mocha": "^2.0.1",
"karma-mocha-reporter": "^2.2.5",
"karma-remap-istanbul": "^0.6.0",
"mocha": "^7.1.1",
"mocha-junit-reporter": "^1.18.0",
"nyc": "^14.0.0",
"prettier": "^1.16.4",
"rimraf": "^3.0.0",
"rollup": "^1.16.3",
Expand All @@ -103,6 +137,7 @@
"rollup-plugin-terser": "^5.1.1",
"rollup-plugin-visualizer": "^4.0.4",
"source-map-support": "^0.5.9",
"typescript": "~3.9.3"
"typescript": "~3.9.3",
"uuid": "^8.1.0"
}
}
6 changes: 6 additions & 0 deletions sdk/keyvault/keyvault-admin/rollup.test.config.js
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)];
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
});
});
});
});
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 sdk/keyvault/keyvault-admin/test/public/backupClient.abort.spec.ts
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
});
});
});
});
Loading