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

[Unified Recorder] New test-utils package for test credential #19423

Merged
merged 29 commits into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b7a15ca
Fix retry handling for Session Not Found errors
southpolesteve Aug 23, 2021
ca193b8
Update sdk/cosmosdb/cosmos/test/internal/session.spec.ts
southpolesteve Aug 23, 2021
4b1a28d
Update CODEOWNERS for Application Insights (#17055)
omziv Aug 25, 2021
b063605
Add link to documentation (#18291)
diberry Oct 20, 2021
d4428c6
Update AzureIdentityExamples.md (#18958)
philip-gai Dec 7, 2021
d9393ed
new package for test credential
HarshaNalluru Dec 17, 2021
100a848
Merge branch 'master' of https://github.com/Azure/azure-sdk-for-js in…
HarshaNalluru Dec 17, 2021
7d79b8a
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-js into…
HarshaNalluru Dec 17, 2021
46dbee2
revert unrelated changes
HarshaNalluru Dec 17, 2021
d96372e
unrelated changes
HarshaNalluru Dec 17, 2021
10b997e
lock file
HarshaNalluru Dec 17, 2021
6d43a89
Update sdk/test-utils/identity-extensions/CHANGELOG.md
HarshaNalluru Dec 17, 2021
bca52d0
Update sdk/test-utils/identity-extensions/CHANGELOG.md
HarshaNalluru Dec 17, 2021
3d054ab
Update sdk/test-utils/identity-extensions/package.json
HarshaNalluru Dec 17, 2021
5c09e27
Update sdk/test-utils/identity-extensions/package.json
HarshaNalluru Dec 17, 2021
9ed57f3
Move NoOpCredential to identity extensions package
HarshaNalluru Dec 17, 2021
88b5342
Merge branch 'harshan/issue/recorder/19387' of https://github.com/Har…
HarshaNalluru Dec 17, 2021
d10b3cf
Update sdk/test-utils/identity-extensions/README.md
HarshaNalluru Dec 17, 2021
31e8d53
Update sdk/test-utils/identity-extensions/README.md
HarshaNalluru Dec 17, 2021
f6887b2
Update sdk/test-utils/identity-extensions/README.md
HarshaNalluru Dec 17, 2021
508e92a
Update sdk/test-utils/identity-extensions/README.md
HarshaNalluru Dec 17, 2021
2aadb31
Update sdk/test-utils/identity-extensions/src/index.ts
HarshaNalluru Dec 17, 2021
87592b2
renames
HarshaNalluru Dec 17, 2021
4688488
Merge branch 'harshan/issue/recorder/19387' of https://github.com/Har…
HarshaNalluru Dec 17, 2021
65b52b0
changelog
HarshaNalluru Dec 17, 2021
3a7cd33
more updates
HarshaNalluru Dec 17, 2021
a1dcfa5
ysage in readme
HarshaNalluru Dec 17, 2021
b49e850
unused in package.json
HarshaNalluru Dec 17, 2021
ec1b501
TokenCredentialOptions optional
HarshaNalluru Dec 17, 2021
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
59 changes: 55 additions & 4 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions rush.json
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,11 @@
"projectFolder": "sdk/test-utils/recorder-new",
"versionPolicyName": "utility"
},
{
"packageName": "@azure-tools/identity-extensions",
"projectFolder": "sdk/test-utils/identity-extensions",
"versionPolicyName": "utility"
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Moving fast 🔥

{
"packageName": "@azure/test-utils-perf",
"projectFolder": "sdk/test-utils/perf",
Expand Down
4 changes: 4 additions & 0 deletions sdk/test-utils/identity-extensions/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"plugins": ["@azure/azure-sdk"],
"extends": ["plugin:@azure/azure-sdk/azure-sdk-base"]
}
8 changes: 8 additions & 0 deletions sdk/test-utils/identity-extensions/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Release History

## 1.2.0 (#Unreleased)
HarshaNalluru marked this conversation as resolved.
Show resolved Hide resolved

### Features Added

Provides the credential to be used in the tests. `NoOpCredential` in playback and `ClientSecretCredential` in record/live modes.
[#19423](https://github.com/Azure/azure-sdk-for-js/pull/19423)
21 changes: 21 additions & 0 deletions sdk/test-utils/identity-extensions/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2021 Microsoft

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
40 changes: 40 additions & 0 deletions sdk/test-utils/identity-extensions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Azure @azure-tools/identity-extensions client library for JavaScript
HarshaNalluru marked this conversation as resolved.
Show resolved Hide resolved

This library provides the credential for testing.
HarshaNalluru marked this conversation as resolved.
Show resolved Hide resolved

## Getting started

### Installation

Add this library as a dev dependency in your project.

> rush add -p @azure-tools/identity-extensions --dev

## Key concepts

This library provides the credential to be used in the tests

In playback mode

- returns the `NoOpCredential` (helps bypass the AAD traffic)
- `NoOpCredential` is defined in `@azure-tools/test-recorder-new`
HarshaNalluru marked this conversation as resolved.
Show resolved Hide resolved

In record/live modes

- returns the `ClientSecretCredential` (expects AZURE_TENANT_ID, AZURE_CLIENT_ID, AZURE_CLIENT_SECRET in your environment or in the .env file)
- AAD traffic won't be recorded if this credential is used.
- `ClientSecretCredential` is coming from `@azure/identity`
HarshaNalluru marked this conversation as resolved.
Show resolved Hide resolved

## Next steps

Try out this package in your application and provide feedback!

## Troubleshooting

Log an issue at https://github.com/Azure/azure-sdk-for-js/issues

## Contributing

If you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) to learn more about how to build and test the code.

![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Ftest-utils%2Ftest-utils-identity%2FREADME.png)
76 changes: 76 additions & 0 deletions sdk/test-utils/identity-extensions/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"name": "@azure-tools/identity-extensions",
witemple-msft marked this conversation as resolved.
Show resolved Hide resolved
"version": "1.0.0",
"sdk-type": "utility",
"description": "Test utilities library for the Azure SDK for JavaScript and TypeScript",
HarshaNalluru marked this conversation as resolved.
Show resolved Hide resolved
"main": "dist/index.js",
"module": "dist-esm/src/index.js",
"browser": {
"./dist-esm/src/global.js": "./dist-esm/src/global.browser.js"
},
"types": "./types/latest/src/index.d.ts",
"engines": {
"node": ">=12.0.0"
},
"scripts": {
"audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit",
"build": "npm run clean && tsc -p . && rollup -c 2>&1",
"build:samples": "echo Skipped.",
"build:test": "echo not needed",
"check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
"clean": "rimraf dist dist-* types *.tgz *.log",
"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": "npm run integration-test:node && npm run integration-test:browser",
"lint:fix": "eslint --no-eslintrc -c ../../.eslintrc.internal.json package.json src test --ext .ts --fix --fix-type [problem,suggestion]",
"lint": "eslint --no-eslintrc -c ../../.eslintrc.internal.json package.json src test --ext .ts",
"pack": "npm pack 2>&1",
"unit-test:browser": "echo skipped",
"unit-test:node": "echo skipped",
"unit-test": "npm run unit-test:node && npm run unit-test:browser",
"test:browser": "npm run clean && npm run build npm run unit-test:browser",
"test:node": "npm run clean && npm run build && npm run unit-test:node",
"test": "npm run clean && npm run build && npm run unit-test"
},
"files": [
"dist/",
"dist-esm/src/",
"types/src/index.d.ts",
"README.md",
"LICENSE"
],
"repository": "github:Azure/azure-sdk-for-js",
"keywords": [
"Azure",
"cloud",
"test",
"framework"
],
"author": "Microsoft Corporation",
"license": "MIT",
"bugs": {
"url": "https://github.com/Azure/azure-sdk-for-js/issues"
},
"homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/test-utils/test-utils-identity/README.md",
HarshaNalluru marked this conversation as resolved.
Show resolved Hide resolved
"sideEffects": false,
"private": true,
"dependencies": {
"@azure-tools/test-recorder": "^1.0.0",
"@azure-tools/test-recorder-new": "1.0.0",
"@azure/identity": "^2.0.1"
Copy link
Contributor

Choose a reason for hiding this comment

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

Identity currently uses the recorder. Wouldn’t it be an issue?

Copy link
Member Author

Choose a reason for hiding this comment

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

identity depends on

  • recorder

test-utils/identity-extensions depends on

  • recorder
  • identity

every other SDK will depend on

  • recorder
  • identity
  • test-utils/identity-extensions

Copy link
Member Author

Choose a reason for hiding this comment

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

identity doesn't depend on test-utils/identity-extensions, so there should not be a problem

},
"devDependencies": {
"@azure/dev-tool": "^1.0.0",
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
"@types/chai": "^4.1.6",
"@types/mocha": "^7.0.2",
"@types/node": "^12.0.0",
"eslint": "^7.15.0",
"prettier": "^1.16.4",
"rimraf": "^3.0.0",
"rollup": "^1.16.3",
"sinon": "^9.0.2",
"typescript": "~4.2.0"
}
}
3 changes: 3 additions & 0 deletions sdk/test-utils/identity-extensions/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { makeConfig } from "@azure/dev-tool/shared-config/rollup";

export default makeConfig(require("./package.json"));
26 changes: 26 additions & 0 deletions sdk/test-utils/identity-extensions/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { ClientSecretCredential } from "@azure/identity";
import { env, isPlaybackMode } from "@azure-tools/test-recorder";
import { NoOpCredential } from "@azure-tools/test-recorder-new";
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn’t NoOpCredential be moved to this package?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, can be done


/**
* ## Credential to be used in the tests.
*
* ### In playback mode
* - returns the NoOpCredential (helps bypass the AAD traffic)
*
* ### In record/live modes
* - returns the ClientSecretCredential (expects AZURE_TENANT_ID, AZURE_CLIENT_ID, AZURE_CLIENT_SECRET in your environment or in the .env file)
* - AAD traffic won't be recorded if this credential is used.
*/
export function getTestCredential() {
HarshaNalluru marked this conversation as resolved.
Show resolved Hide resolved
return isPlaybackMode()
? new NoOpCredential()
: new ClientSecretCredential(
env["AZURE_TENANT_ID"],
env["AZURE_CLIENT_ID"],
env["AZURE_CLIENT_SECRET"]
);
}
2 changes: 2 additions & 0 deletions sdk/test-utils/identity-extensions/test/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
8 changes: 8 additions & 0 deletions sdk/test-utils/identity-extensions/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../../tsconfig.package",
"compilerOptions": {
"outDir": "./dist-esm",
"declarationDir": "./types/latest"
},
"include": ["src/**/*.ts", "test/**/*.ts"]
}
2 changes: 1 addition & 1 deletion sdk/test-utils/test-utils/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Azure test-utils client library for JavaScript

The Azure SDk for JavaSCript is composed of a multitude of repositories that attempt to deliver a common, homogenous SDK to make use of all the services that Azure can provide.
The Azure SDK for JavaScript is composed of a multitude of repositories that attempt to deliver a common, homogenous SDK to make use of all the services that Azure can provide.

This non-shipping library `@azure/test-utils` attempts to add additional testing support to libraries. It is supposed to be added only as a devDependency and should be used only for the tests of an SDK library.

Expand Down
1 change: 1 addition & 0 deletions sdk/test-utils/testing-recorder-new/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"@azure/identity": "^2.0.1",
"@azure-tools/test-recorder": "^1.0.0",
"@azure-tools/test-recorder-new": "^1.0.0",
"@azure-tools/identity-extensions": "^1.0.0",
"@azure/core-auth": "^1.3.2",
"@azure/storage-queue": "^12.6.0",
"@azure/dev-tool": "^1.0.0",
Expand Down
Loading