-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable long running tests and use new federated credentials for testi…
…ng (#864) * WIP: Get token credential from SP * WIP: See is test provider can sign in * WIP: Remove webConfig, dont import dev into production code * WIP: Remove web entry point from package.json * Add await to the logIn * Add listing tests * Fix up resource listing test * Update service connection * Hardcode long running tests * Add some console.debug * Make token static * Test code * Add default * Add resource provider to global test * Use the resource provider instead of trying to calling it directly * Try using the key vault values * Use fetch and see response type * Dont parse response2 * wip * Add node-fetch as a resource * Make token code use function * Use service client from @azure/core-client * Final test using service client * Remove unused context * Confirm access token is being made * Leverage auth package * Add create and delete tests for Resource Groups * Comments * Import settingUtils from bundle * Import LocationListStep from bundle? * Reorganize and remove some inports from bundle * Add hasPortalUrl * See if there are any build errors * use auth refactor * update package json * use newly released auth package * use parameter * remove installing azure account * remove pretest step * remove installing azure account fr fr * remove from recommendations * reintroduce gulp * nuclear warfare * add webpack to pretest * logs * try logging error * use the new env vars with the underscore * don't swallow errors * cleanup * only set to true when doing azure federated credentials * use new branch for quick testing * use main again * refactor subscription provider logic * remove commented out code * set in the helper * make optional --------- Co-authored-by: Nathan Turinski <[email protected]>
- Loading branch information
1 parent
f05be68
commit e056095
Showing
14 changed files
with
957 additions
and
325 deletions.
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 |
---|---|---|
@@ -1,6 +1,5 @@ | ||
{ | ||
"recommendations": [ | ||
"dbaeumer.vscode-eslint", | ||
"ms-vscode.azure-account" | ||
] | ||
} |
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
Large diffs are not rendered by default.
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,42 @@ | ||
import { AzureDevOpsSubscriptionProviderInitializer, AzureSubscriptionProvider, createAzureDevOpsSubscriptionProviderFactory } from "@microsoft/vscode-azext-azureauth"; | ||
import { IActionContext } from "@microsoft/vscode-azext-utils"; | ||
import { createVSCodeAzureSubscriptionProviderFactory } from "./VSCodeAzureSubscriptionProvider"; | ||
|
||
/** | ||
* Returns a factory function that creates a subscription provider, satisfying the `AzureSubscriptionProvider` interface. | ||
* | ||
* If the `useAzureSubscriptionProvider` is set to `true`, an `AzureDevOpsSubscriptionProviderFactory` is returned. | ||
* Otherwise, a `VSCodeSubscriptionProviderFactory` is returned. | ||
* | ||
*/ | ||
export function getSubscriptionProviderFactory(activateContext?: IActionContext): () => Promise<AzureSubscriptionProvider> { | ||
// if this for a nightly test, we want to use the test subscription provider | ||
const useAzureFederatedCredentials: boolean = !/^(false|0)?$/i.test(process.env['AzCode_UseAzureFederatedCredentials'] || '') | ||
if (useAzureFederatedCredentials) { | ||
// when running tests, ensure we throw the errors and they aren't silently swallowed | ||
if (activateContext) { | ||
activateContext.errorHandling.rethrow = useAzureFederatedCredentials; | ||
} | ||
|
||
const serviceConnectionId: string | undefined = process.env['AzCode_ServiceConnectionID']; | ||
const domain: string | undefined = process.env['AzCode_ServiceConnectionDomain']; | ||
const clientId: string | undefined = process.env['AzCode_ServiceConnectionClientID']; | ||
|
||
if (!serviceConnectionId || !domain || !clientId) { | ||
throw new Error(`Using Azure DevOps federated credentials, but federated service connection is not configured\n | ||
process.env.AzCodeServiceConnectionID: ${serviceConnectionId ? "✅" : "❌"}\n | ||
process.env.AzCodeServiceConnectionDomain: ${domain ? "✅" : "❌"}\n | ||
process.env.AzCodeServiceConnectionClientID: ${clientId ? "✅" : "❌"}\n | ||
`); | ||
} | ||
|
||
const initializer: AzureDevOpsSubscriptionProviderInitializer = { | ||
serviceConnectionId, | ||
domain, | ||
clientId, | ||
} | ||
return createAzureDevOpsSubscriptionProviderFactory(initializer); | ||
} else { | ||
return createVSCodeAzureSubscriptionProviderFactory(); | ||
} | ||
} |
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,122 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { type Location } from '@azure/arm-resources-subscriptions'; | ||
import { createTestActionContext, runWithTestActionContext } from '@microsoft/vscode-azext-dev'; | ||
import { AzExtParentTreeItem, IActionContext, LocationListStep, SubscriptionItem, createResourceClient, createResourceGroup, deleteResourceGroupV2, ext, randomUtils, settingUtils } from '../../extension.bundle'; | ||
import { longRunningTestsEnabled } from "../global.test"; | ||
import assert = require("assert"); | ||
|
||
let rgName: string; | ||
let locations: Location[]; | ||
let testSubscription: SubscriptionItem; | ||
|
||
suite('Resource CRUD Operations', function (this: Mocha.Suite): void { | ||
this.timeout(7 * 60 * 1000); | ||
|
||
suiteSetup(async function (this: Mocha.Context): Promise<void> { | ||
if (!longRunningTestsEnabled) { | ||
this.skip(); | ||
} | ||
|
||
ext.testing.overrideAzureServiceFactory = undefined; | ||
ext.testing.overrideAzureSubscriptionProvider = undefined; | ||
|
||
const subscriptionTreeItems = await ext.appResourceTree.getChildren() as unknown as SubscriptionItem[]; | ||
if (subscriptionTreeItems.length > 0) { | ||
const testContext = await createTestActionContext(); | ||
testSubscription = subscriptionTreeItems[0] as SubscriptionItem; | ||
const context = { ...testContext, ...testSubscription.subscription }; | ||
locations = await LocationListStep.getLocations(context); | ||
} | ||
|
||
rgName = randomUtils.getRandomHexString(12); | ||
}); | ||
|
||
test('Create Resource Group (single)', async () => { | ||
await runWithTestActionContext('createResourceGroup', async context => { | ||
const testInputs: (string | RegExp)[] = [rgName, locations[0].displayName!]; | ||
await context.ui.runWithInputs(testInputs, async () => { | ||
await createResourceGroup(context, testSubscription); | ||
}); | ||
|
||
assert.ok(await resourceGroupExists(context, rgName)); | ||
}); | ||
}); | ||
|
||
test('Create Resource Groups (all locations)', async () => { | ||
await Promise.all(locations.map(async l => { | ||
await runWithTestActionContext('createResourceGroup', async context => { | ||
const testInputs: (string | RegExp)[] = [`${rgName}-${l.name}`, l.displayName!]; | ||
await context.ui.runWithInputs(testInputs, async () => { | ||
await createResourceGroup(context, testSubscription); | ||
}); | ||
|
||
assert.ok(await resourceGroupExists(context, `${rgName}-${l.name}`)); | ||
}); | ||
})); | ||
}); | ||
|
||
test('Get Resources', async () => { | ||
const subscriptionTreeItems = await ext.appResourceTree.getChildren(); | ||
assert.ok(subscriptionTreeItems.length > 0); | ||
for (const subscription of subscriptionTreeItems) { | ||
const groupTreeItems = await ext.appResourceTree.getChildren(subscription as AzExtParentTreeItem); | ||
await Promise.all(groupTreeItems.map(async g => { | ||
const children = await ext.appResourceTree.getChildren(g as AzExtParentTreeItem); | ||
console.log(children); | ||
})); | ||
} | ||
|
||
assert.ok(true); | ||
}); | ||
|
||
test('Delete Resource (EnterName) - Fails when invalid', async () => { | ||
await settingUtils.updateGlobalSetting('deleteConfirmation', 'EnterName'); | ||
await runWithTestActionContext('Delete Resource', async context => { | ||
await context.ui.runWithInputs([rgName, 'rgName'], async () => { | ||
try { | ||
await deleteResourceGroupV2(context); | ||
} catch (_) { | ||
console.debug('Expected error: ', _); | ||
// expected to fail here | ||
} | ||
assert.ok(await resourceGroupExists(context, rgName)); | ||
}); | ||
}); | ||
}); | ||
|
||
test('Delete Resource (EnterName)', async () => { | ||
await settingUtils.updateGlobalSetting('deleteConfirmation', 'EnterName'); | ||
await runWithTestActionContext('Delete Resource', async context => { | ||
await context.ui.runWithInputs([rgName, rgName], async () => { | ||
await deleteResourceGroupV2(context); | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
test('Delete Resource (ClickButton)', async () => { | ||
await settingUtils.updateGlobalSetting('deleteConfirmation', 'ClickButton'); | ||
const deleteArray: string[] = Array(locations.length).fill('Delete'); | ||
await runWithTestActionContext('Delete Resource', async context => { | ||
await context.ui.runWithInputs([new RegExp(`${rgName}-`), ...deleteArray], async () => { | ||
await deleteResourceGroupV2(context); | ||
}); | ||
}); | ||
|
||
assert.ok(true); | ||
}); | ||
}); | ||
|
||
async function resourceGroupExists(context: IActionContext, rgName: string): Promise<boolean> { | ||
const client = await createResourceClient([context, testSubscription.subscription]); | ||
try { | ||
await client.resourceGroups.get(rgName); | ||
return true; | ||
} catch (_) { | ||
return false; | ||
} | ||
} |
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,18 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE.md in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import * as vscode from 'vscode'; | ||
import { longRunningTestsEnabled } from '../global.test'; | ||
|
||
export const resourceGroupsToDelete: string[] = []; | ||
|
||
// Runs before all nightly tests | ||
suiteSetup(async function (this: Mocha.Context): Promise<void> { | ||
if (longRunningTestsEnabled) { | ||
this.timeout(2 * 60 * 1000); | ||
await vscode.commands.executeCommand('azureResourceGroups.logIn'); | ||
} | ||
}); | ||
|
Oops, something went wrong.