|
| 1 | +/*--------------------------------------------------------------------------------------------- |
| 2 | + * Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | + * Licensed under the MIT License. See License.txt in the project root for license information. |
| 4 | + *--------------------------------------------------------------------------------------------*/ |
| 5 | + |
| 6 | +import { type Site } from '@azure/arm-appservice'; |
| 7 | +import { DomainNameLabelScope, tryGetWebApp } from '@microsoft/vscode-azext-azureappservice'; |
| 8 | +import { runWithTestActionContext } from '@microsoft/vscode-azext-dev'; |
| 9 | +import * as assert from 'assert'; |
| 10 | +import { getRandomHexString } from '../../src/utils/fs'; |
| 11 | +import { longRunningTestsEnabled } from '../global.test'; |
| 12 | +import { getCachedTestApi } from '../utils/testApiAccess'; |
| 13 | +import { resourceGroupsToDelete, testClient } from './global.nightly.test'; |
| 14 | + |
| 15 | +/** |
| 16 | + * Tests for Domain Name Label Scope functionality in function app creation. |
| 17 | + * |
| 18 | + * DomainNameLabelScope quick pick options: |
| 19 | + * - Tenant (TenantReuse): Secure unique default hostname |
| 20 | + * - Legacy: Global default hostname |
| 21 | + * |
| 22 | + * In basic create, the domain scope is automatically set to Tenant (no prompt) |
| 23 | + * In advanced create, the user is prompted to select between Tenant or Legacy |
| 24 | + */ |
| 25 | +suite('Domain Name Label Scope', function (this: Mocha.Suite): void { |
| 26 | + this.timeout(10 * 60 * 1000); |
| 27 | + |
| 28 | + let location: string; |
| 29 | + let rgName: string; |
| 30 | + |
| 31 | + suiteSetup(async function (this: Mocha.Context): Promise<void> { |
| 32 | + if (!longRunningTestsEnabled) { |
| 33 | + this.skip(); |
| 34 | + } |
| 35 | + |
| 36 | + rgName = getRandomHexString(); |
| 37 | + resourceGroupsToDelete.push(rgName); |
| 38 | + location = 'West US 2'; |
| 39 | + }); |
| 40 | + |
| 41 | + test('Basic creation uses Tenant scope by default', async () => { |
| 42 | + const appName = getRandomHexString(); |
| 43 | + const testApi = getCachedTestApi(); |
| 44 | + |
| 45 | + const testInputs: (string | RegExp)[] = [ |
| 46 | + location, // Location |
| 47 | + appName, // App name |
| 48 | + /\.net/i, // Stack |
| 49 | + /secrets/i, // Auth type |
| 50 | + ]; |
| 51 | + |
| 52 | + await runWithTestActionContext('createFunctionApp', async context => { |
| 53 | + await context.ui.runWithInputs(testInputs, async () => { |
| 54 | + await testApi.commands.createFunctionApp(context); |
| 55 | + }); |
| 56 | + }); |
| 57 | + |
| 58 | + const createdApp: Site | undefined = await tryGetWebApp(testClient, appName, appName); |
| 59 | + assert.ok(createdApp, 'Function app should be created'); |
| 60 | + assert.equal(createdApp.autoGeneratedDomainNameLabelScope, DomainNameLabelScope.Tenant); |
| 61 | + }); |
| 62 | + |
| 63 | + test('Advanced creation with Tenant scope', async () => { |
| 64 | + const appName = getRandomHexString(); |
| 65 | + const saName = getRandomHexString().toLowerCase(); |
| 66 | + const miName = getRandomHexString(); |
| 67 | + const aiName = getRandomHexString(); |
| 68 | + const testApi = getCachedTestApi(); |
| 69 | + |
| 70 | + const testInputs: (string | RegExp)[] = [ |
| 71 | + location, // Location |
| 72 | + '$(plus) Create new resource group', // Resource Group |
| 73 | + rgName, // RG name |
| 74 | + /secure.*unique|tenant/i, // Domain scope (Tenant) |
| 75 | + appName, // App name |
| 76 | + 'Flex Consumption', // Hosting plan |
| 77 | + /\.net/i, // Stack |
| 78 | + '4096', // Instance memory |
| 79 | + '100', // Max instances |
| 80 | + 'Managed identity', // Auth type |
| 81 | + '$(plus) Create new user-assigned identity', // Create new identity |
| 82 | + miName, // Identity name |
| 83 | + '$(plus) Create new storage account', // Storage account |
| 84 | + saName, // SA name |
| 85 | + '$(plus) Create new Application Insights resource', // App Insights |
| 86 | + aiName, // AI name |
| 87 | + ]; |
| 88 | + |
| 89 | + await runWithTestActionContext('createFunctionAppAdvanced', async context => { |
| 90 | + await context.ui.runWithInputs(testInputs, async () => { |
| 91 | + await testApi.commands.createFunctionAppAdvanced(context); |
| 92 | + }); |
| 93 | + }); |
| 94 | + |
| 95 | + const createdApp: Site | undefined = await tryGetWebApp(testClient, rgName, appName); |
| 96 | + assert.ok(createdApp, 'Function app should be created with Tenant domain scope'); |
| 97 | + assert.equal(createdApp.autoGeneratedDomainNameLabelScope, DomainNameLabelScope.Tenant); |
| 98 | + }); |
| 99 | + |
| 100 | + test('Advanced creation with Legacy scope', async () => { |
| 101 | + const appName = getRandomHexString(); |
| 102 | + const saName = getRandomHexString().toLowerCase(); |
| 103 | + const miName = getRandomHexString(); |
| 104 | + const aiName = getRandomHexString(); |
| 105 | + const testApi = getCachedTestApi(); |
| 106 | + |
| 107 | + const testInputs: (string | RegExp)[] = [ |
| 108 | + location, // Location |
| 109 | + rgName, // Use existing RG |
| 110 | + /global.*default|legacy/i, // Domain scope (Legacy) |
| 111 | + appName, // App name |
| 112 | + 'Flex Consumption', // Hosting plan |
| 113 | + /\.net/i, // Stack |
| 114 | + '4096', // Instance memory |
| 115 | + '100', // Max instances |
| 116 | + 'Managed identity', // Auth type |
| 117 | + '$(plus) Create new user-assigned identity', // Create new identity |
| 118 | + miName, // Identity name |
| 119 | + '$(plus) Create new storage account', // Storage account |
| 120 | + saName, // SA name |
| 121 | + '$(plus) Create new Application Insights resource', // App Insights |
| 122 | + aiName, // AI name |
| 123 | + ]; |
| 124 | + |
| 125 | + await runWithTestActionContext('createFunctionAppAdvanced', async context => { |
| 126 | + await context.ui.runWithInputs(testInputs, async () => { |
| 127 | + await testApi.commands.createFunctionAppAdvanced(context); |
| 128 | + }); |
| 129 | + }); |
| 130 | + |
| 131 | + const createdApp: Site | undefined = await tryGetWebApp(testClient, rgName, appName); |
| 132 | + assert.ok(createdApp, 'Function app should be created with Global domain scope'); |
| 133 | + assert.equal(createdApp.autoGeneratedDomainNameLabelScope, undefined); |
| 134 | + }); |
| 135 | +}); |
0 commit comments