-
Notifications
You must be signed in to change notification settings - Fork 47
Azure Resources API (v4) client tools tests #1308
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
Open
MicroFish91
wants to merge
14
commits into
mwf/v4-tests
Choose a base branch
from
mwf/v4-client-tests
base: mwf/v4-tests
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
bb725ac
Add client related tests
MicroFish91 d0eab17
Merge branch 'mwf/v4-tests' of https://github.com/microsoft/vscode-az…
MicroFish91 fb297bd
Merge branch 'mwf/v4-tests' of https://github.com/microsoft/vscode-az…
MicroFish91 f22c0dc
Merge branch 'mwf/v4-tests' of https://github.com/microsoft/vscode-az…
MicroFish91 18db77c
Merge branch 'mwf/v4-tests' of https://github.com/microsoft/vscode-az…
MicroFish91 90fe885
Escape the symbol
MicroFish91 dbc30e6
Update a comment
MicroFish91 50026aa
Update another comment
MicroFish91 1b7eef5
Merge branch 'mwf/v4-tests' of https://github.com/microsoft/vscode-az…
MicroFish91 7807894
Merge with mwf/v4-tests
MicroFish91 62c9615
Remove extension bundle references
MicroFish91 5d0e4ad
Fix lint warning
MicroFish91 20380f4
Merge branch 'mwf/v4-tests' of https://github.com/microsoft/vscode-az…
MicroFish91 475dfb0
Lint stuff
MicroFish91 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,92 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All rights reserved. | ||
| * Licensed under the MIT License. See License.txt in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| import * as assert from "assert"; | ||
| import { AzureExtensionApi, AzureResourcesApiRequestContext, AzureResourcesApiRequestError, AzureResourcesApiRequestErrorCode, AzureResourcesExtensionApi, prepareAzureResourcesApiRequest } from "../../../api/src"; | ||
| import { CustomRequestDependenciesContext } from "../../../api/src/auth/apiRequest/AzureResourcesApiRequestContext"; | ||
| import { AzExtUUIDCredentialManager } from "../../../api/src/auth/credentialManager/AzExtUUIDCredentialManager"; | ||
| import { createMockAuthApi } from "./mockAuthApi"; | ||
|
|
||
| const clientExtensionId: string = 'ms-azuretools.vscode-azurecontainerapps'; | ||
|
|
||
| suite('Azure Resources API client-side request tests', async () => { | ||
| test('prepareAzureResourcesApiRequest should successfully enable the handshake & return available APIs if on the allow list', async () => { | ||
| let receivedResourcesApis: (AzureExtensionApi | AzureResourcesExtensionApi | undefined)[] = []; | ||
|
|
||
| await new Promise<void>((resolve) => { | ||
| const timeout = setTimeout(resolve, 5000); | ||
|
|
||
| const requestContext: AzureResourcesApiRequestContext = { | ||
| clientExtensionId, | ||
| azureResourcesApiVersions: ['0.0.1', '^2.0.0'], | ||
| onDidReceiveAzureResourcesApis: (azureResourcesApis: (AzureExtensionApi | AzureResourcesExtensionApi | undefined)[]) => { | ||
| clearTimeout(timeout); | ||
| receivedResourcesApis = azureResourcesApis; | ||
| resolve(); | ||
| }, | ||
| onApiRequestError: () => { | ||
| clearTimeout(timeout); | ||
| resolve(); | ||
| }, | ||
| }; | ||
|
|
||
| const coreClientExtensionApi: AzureExtensionApi = { | ||
| apiVersion: '1.0.0', | ||
| }; | ||
|
|
||
| // Inject an external manager so the two preparation calls that follow will point to the same one | ||
| (requestContext as CustomRequestDependenciesContext).credentialManager = new AzExtUUIDCredentialManager(); | ||
|
|
||
| // For testing, it is necessary to wire up both the client and host api provider to represent the parties on each side of the handshake. | ||
| // The prepare call needs to happen twice in order to set this scenario up - once to generate the client API for the host to point to, | ||
| // and then once more to pass that client to the host API for the final handshake method to point to. | ||
| // | ||
| // NOTE: This is not normally necessary since VS Code's API normally manages extension exports; however, this is not something we can rely on | ||
| // during tests because we need to be able to point to our own mocked APIs (which requires us to swap out the native VS Code extension provider). | ||
|
|
||
| const { clientApi } = prepareAzureResourcesApiRequest(requestContext, coreClientExtensionApi); | ||
| const hostApi = createMockAuthApi({ clientApiProvider: { getApi: () => clientApi } }); | ||
| (requestContext as CustomRequestDependenciesContext).hostApiProvider = { getApi: () => hostApi }; | ||
|
|
||
| const { requestResourcesApis } = prepareAzureResourcesApiRequest(requestContext, clientApi); | ||
| requestResourcesApis(); | ||
| }); | ||
|
|
||
| assert.equal(receivedResourcesApis[0]?.apiVersion, '0.0.1'); | ||
| assert.match(receivedResourcesApis[1]?.apiVersion ?? '', /^2\./); | ||
| }); | ||
|
|
||
| test('prepareAzureResourcesApiRequest should return an error if not on the allow list', async () => { | ||
| let receivedError: AzureResourcesApiRequestError | undefined; | ||
|
|
||
| await new Promise<void>((resolve) => { | ||
| const timeout = setTimeout(resolve, 5000); | ||
|
|
||
| const requestContext: AzureResourcesApiRequestContext = { | ||
| clientExtensionId: 'extension1', | ||
| azureResourcesApiVersions: ['0.0.1', '^2.0.0'], | ||
| onDidReceiveAzureResourcesApis: () => { | ||
| clearTimeout(timeout); | ||
| resolve(); | ||
| }, | ||
| onApiRequestError: (error: AzureResourcesApiRequestError) => { | ||
| clearTimeout(timeout); | ||
| receivedError = error; | ||
| resolve(); | ||
| } | ||
| }; | ||
|
|
||
| const coreClientExtensionApi: AzureExtensionApi = { | ||
| apiVersion: '1.0.0', | ||
| }; | ||
|
|
||
| // We don't need to wire up the custom test api providers as we expect the initial call to fail before the host ever tries to reach back out to the client | ||
| const { requestResourcesApis } = prepareAzureResourcesApiRequest(requestContext, coreClientExtensionApi); | ||
| requestResourcesApis(); | ||
| }); | ||
|
|
||
| assert.equal(receivedError?.code, AzureResourcesApiRequestErrorCode.HostCreateSessionFailed); | ||
| }); | ||
| }); |
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.
Uh oh!
There was an error while loading. Please reload this page.