-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Unified Recorder] New
test-utils
package for test credential (#19423)
* Fix retry handling for Session Not Found errors * Update sdk/cosmosdb/cosmos/test/internal/session.spec.ts Co-authored-by: Zachary Foster <[email protected]> * Update CODEOWNERS for Application Insights (#17055) * Add link to documentation (#18291) * Update AzureIdentityExamples.md (#18958) Rename function to match the credential being used * new package for test credential * revert unrelated changes * unrelated changes * lock file * Update sdk/test-utils/identity-extensions/CHANGELOG.md * Update sdk/test-utils/identity-extensions/CHANGELOG.md * Update sdk/test-utils/identity-extensions/package.json * Update sdk/test-utils/identity-extensions/package.json * Move NoOpCredential to identity extensions package * Update sdk/test-utils/identity-extensions/README.md Co-authored-by: Will Temple <[email protected]> * Update sdk/test-utils/identity-extensions/README.md Co-authored-by: Will Temple <[email protected]> * Update sdk/test-utils/identity-extensions/README.md Co-authored-by: Will Temple <[email protected]> * Update sdk/test-utils/identity-extensions/README.md Co-authored-by: Will Temple <[email protected]> * Update sdk/test-utils/identity-extensions/src/index.ts Co-authored-by: Will Temple <[email protected]> * renames * changelog * more updates * ysage in readme * unused in package.json * TokenCredentialOptions optional Co-authored-by: Steve Faulkner <[email protected]> Co-authored-by: Zachary Foster <[email protected]> Co-authored-by: omziv <[email protected]> Co-authored-by: Dina Berry <[email protected]> Co-authored-by: Philip Gai <[email protected]> Co-authored-by: Will Temple <[email protected]>
- Loading branch information
1 parent
4550b69
commit e2eea7e
Showing
17 changed files
with
242 additions
and
17 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,4 @@ | ||
{ | ||
"plugins": ["@azure/azure-sdk"], | ||
"extends": ["plugin:@azure/azure-sdk/azure-sdk-base"] | ||
} |
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,8 @@ | ||
# Release History | ||
|
||
## 1.0.0 (#Unreleased) | ||
|
||
### 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) |
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,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. |
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,45 @@ | ||
# Azure Tools - Test Credential | ||
|
||
This library provides a `TokenCredential` implementation for testing Azure SDK packages. | ||
|
||
## Getting started | ||
|
||
### Installation | ||
|
||
Add this library as a dev dependency in your project. | ||
|
||
> rush add -p @azure-tools/test-credential --dev | ||
## Key concepts | ||
|
||
### Usage | ||
```ts | ||
import { createTestCredential } from "@azure-tools/test-credential"; | ||
|
||
const credential = createTestCredential(); | ||
``` | ||
|
||
This library provides the credential to be used in the tests | ||
|
||
In playback mode | ||
|
||
- returns a `NoOpCredential` (does not make a request to AAD and produces a fake access_token) | ||
|
||
In record/live modes | ||
|
||
- returns a `ClientSecretCredential` from `@azure/identity` (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. | ||
|
||
## 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-credential%2FREADME.png) |
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,70 @@ | ||
{ | ||
"name": "@azure-tools/test-credential", | ||
"version": "1.0.0", | ||
"sdk-type": "utility", | ||
"description": "Test utilities library that provides the test credential", | ||
"main": "dist/index.js", | ||
"module": "dist-esm/src/index.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-credential/README.md", | ||
"sideEffects": false, | ||
"private": true, | ||
"dependencies": { | ||
"@azure/core-auth": "^1.3.2", | ||
"@azure-tools/test-recorder": "^1.0.0", | ||
"@azure/identity": "^2.0.1" | ||
}, | ||
"devDependencies": { | ||
"@azure/dev-tool": "^1.0.0", | ||
"@azure/eslint-plugin-azure-sdk": "^3.0.0", | ||
"@types/node": "^12.0.0", | ||
"eslint": "^7.15.0", | ||
"prettier": "^1.16.4", | ||
"rimraf": "^3.0.0", | ||
"rollup": "^1.16.3", | ||
"typescript": "~4.2.0" | ||
} | ||
} |
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,3 @@ | ||
import { makeConfig } from "@azure/dev-tool/shared-config/rollup"; | ||
|
||
export default makeConfig(require("./package.json")); |
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,29 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import { ClientSecretCredential, TokenCredentialOptions } from "@azure/identity"; | ||
import { env, isPlaybackMode } from "@azure-tools/test-recorder"; | ||
import { NoOpCredential } from "./noOpCredential"; | ||
|
||
/** | ||
* ## 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 createTestCredential(options?: TokenCredentialOptions) { | ||
return isPlaybackMode() | ||
? new NoOpCredential() | ||
: new ClientSecretCredential( | ||
env["AZURE_TENANT_ID"], | ||
env["AZURE_CLIENT_ID"], | ||
env["AZURE_CLIENT_SECRET"], | ||
options | ||
); | ||
} | ||
|
||
export { NoOpCredential }; |
File renamed without changes.
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,2 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. |
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,8 @@ | ||
{ | ||
"extends": "../../../tsconfig.package", | ||
"compilerOptions": { | ||
"outDir": "./dist-esm", | ||
"declarationDir": "./types/latest" | ||
}, | ||
"include": ["src/**/*.ts", "test/**/*.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
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