Skip to content

Commit 3ca30eb

Browse files
committed
Merge branch 'preview' of https://github.com/Azure/azure-powershell into addRC3
2 parents 0beade3 + 082c27e commit 3ca30eb

File tree

29 files changed

+4846
-487
lines changed

29 files changed

+4846
-487
lines changed

build.proj

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -210,22 +210,22 @@
210210
<CallTarget Targets="BuildSetupTest"/>
211211
<!-- moved copy tasks -->
212212

213-
<Exec Command="&quot;$(PowerShellCommand)&quot; -NonInteractive -NoLogo -NoProfile -Command &quot;. $(LibraryToolsFolder)\UpdateModules.ps1 $(Configuration) $(Scope) -Profile Latest &quot; " Condition="'$(Latest)' == 'true' "/>
214-
<Exec Command="&quot;$(PowerShellCommand)&quot; -NonInteractive -NoLogo -NoProfile -Command &quot;. $(LibraryToolsFolder)\UpdateModules.ps1 $(Configuration) $(Scope) -Profile Stack &quot; " Condition="'$(Stack)' == 'true' "/>
213+
<Exec Command="&quot;$(PowerShellCommand)&quot; -NonInteractive -NoLogo -NoProfile -Command &quot;. $(LibraryToolsFolder)\UpdateModules.ps1 $(Configuration) $(Scope) -Profile Latest &quot; " Condition="'$(Latest)' == 'true' and '$(CodeSign)' == 'false'"/>
214+
<Exec Command="&quot;$(PowerShellCommand)&quot; -NonInteractive -NoLogo -NoProfile -Command &quot;. $(LibraryToolsFolder)\UpdateModules.ps1 $(Configuration) $(Scope) -Profile Stack &quot; " Condition="'$(Stack)' == 'true' and '$(CodeSign)' == 'false'"/>
215215
<!-- Copying shortcut to be signed -->
216216
<Copy SourceFiles="$(LibraryRoot)tools\AzureRM\AzureRM.psd1"
217217
DestinationFolder="$(LibrarySourceFolder)\Package\$(Configuration)" Condition= " '$(NetCore)' == 'false' and '$(Latest)' == 'true'"/>
218218
<Copy SourceFiles="$(LibraryRoot)tools\AzureRM\AzureRM.psm1"
219-
DestinationFolder="$(LibrarySourceFolder)\Package\$(Configuration)" Condition= " '$(NetCore)' == 'false' and '$(Latest)' == 'true'"/>
219+
DestinationFolder="$(LibrarySourceFolder)\Package\$(Configuration)" Condition= " '$(NetCore)' == 'false' and '$(Latest)' == 'true' and '$(CodeSign)' == 'false'"/>
220220

221221
<Copy SourceFiles="$(LibrarySourceFolder)\StackAdmin\AzureRM\AzureRM.psd1"
222222
DestinationFolder="$(LibrarySourceFolder)\Stack\$(Configuration)" Condition= " '$(NetCore)' == 'false' and '$(Stack)' == 'true' "/>
223223
<Copy SourceFiles="$(LibrarySourceFolder)\StackAdmin\AzureRM\AzureRM.psm1"
224-
DestinationFolder="$(LibrarySourceFolder)\Stack\$(Configuration)" Condition= " '$(NetCore)' == 'false' and '$(Stack)' == 'true' "/>
224+
DestinationFolder="$(LibrarySourceFolder)\Stack\$(Configuration)" Condition= " '$(NetCore)' == 'false' and '$(Stack)' == 'true' and '$(CodeSign)' == 'false'"/>
225225
<Copy SourceFiles="$(LibrarySourceFolder)\StackAdmin\AzureStack\AzureStack.psd1"
226226
DestinationFolder="$(LibrarySourceFolder)\Stack\$(Configuration)" Condition= " '$(NetCore)' == 'false' and '$(Stack)' == 'true' "/>
227227
<Copy SourceFiles="$(LibrarySourceFolder)\StackAdmin\AzureStack\AzureStack.psm1"
228-
DestinationFolder="$(LibrarySourceFolder)\Stack\$(Configuration)" Condition= " '$(NetCore)' == 'false' and '$(Stack)' == 'true' "/>
228+
DestinationFolder="$(LibrarySourceFolder)\Stack\$(Configuration)" Condition= " '$(NetCore)' == 'false' and '$(Stack)' == 'true' and '$(CodeSign)' == 'false'"/>
229229

230230
<Copy SourceFiles="$(LibraryRoot)setup\Setup\RemoveGalleryModules.ps1"
231231
DestinationFolder="$(LibrarySourceFolder)\Package\$(Configuration)"
@@ -381,18 +381,6 @@
381381
<DelaySignedAssembliesToSign Include="$(LibrarySourceFolder)\Stack\$(Configuration)\**\Microsoft*Azure*Commands*.dll" Condition="'$(Stack)' == 'true' " />
382382
<DelaySignedAssembliesToSign Include="$(LibrarySourceFolder)\Stack\$(Configuration)\**\Microsoft.Azure.Common.Extensions.dll" Condition="'$(Stack)' == 'true' " />
383383
<DelaySignedAssembliesToSign Include="$(LibrarySourceFolder)\Stack\$(Configuration)\**\Microsoft.Azure.Management.Sql.Legacy.dll" Condition="'$(Stack)' == 'true' " />
384-
385-
<ScriptsToSign Include="$(LibrarySourceFolder)\Package\$(Configuration)\**\*.ps1" Condition="'$(Latest)' == 'true' " />
386-
<ScriptsToSign Include="$(LibrarySourceFolder)\Package\$(Configuration)\**\*.psm1" Condition="'$(Latest)' == 'true' " />
387-
<ScriptsToSign Include="$(LibrarySourceFolder)\Package\$(Configuration)\**\*.ps1xml" Condition="'$(Latest)' == 'true' " />
388-
<ScriptsToSign Include="$(LibrarySourceFolder)\Package\$(Configuration)\**\*.js" Condition="'$(Latest)' == 'true' " />
389-
<ScriptsToSign Include="$(LibraryRoot)setup\Setup\*.ps1" Condition="'$(Latest)' == 'true' "/>
390-
391-
<ScriptsToSign Include="$(LibrarySourceFolder)\Stack\$(Configuration)\**\*.ps1" Condition="'$(Stack)' == 'true' "/>
392-
<ScriptsToSign Include="$(LibrarySourceFolder)\Stack\$(Configuration)\**\*.psm1" Condition="'$(Stack)' == 'true' " />
393-
<ScriptsToSign Include="$(LibrarySourceFolder)\Stack\$(Configuration)\**\*.ps1xml" Condition="'$(Stack)' == 'true' " />
394-
<ScriptsToSign Include="$(LibrarySourceFolder)\Stack\$(Configuration)\**\*.js" Condition="'$(Stack)' == 'true' " />
395-
<!-- <ScriptsToSign Include="$(LibraryRoot)stacksetup\Setup\*.ps1" Condition="'$(Stack)' == 'true' " /> -->
396384
</ItemGroup>
397385

398386
<Message Importance="high" Text="$(LibrarySourceFolder)\Package\$(Configuration) does not contains any files to sign. Code sign will skip."
@@ -417,6 +405,39 @@
417405
ToolsPath="$(CIToolsPath)"
418406
Condition="!$(DelaySign) and '@(DelaySignedAssembliesToSign)' != ''"/>
419407

408+
<ValidateStrongNameSignatureTask
409+
WindowsSdkPath="$(WindowsSdkPath)"
410+
Assembly="%(DelaySignedAssembliesToSign.Identity)"
411+
ExpectedTokenSignature="$(StrongNameToken)"
412+
ExpectedDelaySigned="false"
413+
ContinueOnError="false"
414+
Condition="!$(DelaySign) and '@(DelaySignedAssembliesToSign)' != ''"/>
415+
416+
<Exec Command="&quot;$(PowerShellCommand)&quot; -NonInteractive -NoLogo -NoProfile -Command &quot;. $(LibraryToolsFolder)\UpdateModules.ps1 $(Configuration) $(Scope) -Profile Latest &quot; " Condition="'$(Latest)' == 'true' "/>
417+
<Exec Command="&quot;$(PowerShellCommand)&quot; -NonInteractive -NoLogo -NoProfile -Command &quot;. $(LibraryToolsFolder)\UpdateModules.ps1 $(Configuration) $(Scope) -Profile Stack &quot; " Condition="'$(Stack)' == 'true' "/>
418+
419+
<!-- Copying shortcut to be signed -->
420+
<Copy SourceFiles="$(LibraryRoot)tools\AzureRM\AzureRM.psm1"
421+
DestinationFolder="$(LibrarySourceFolder)\Package\$(Configuration)" Condition= " '$(NetCore)' == 'false' and '$(Latest)' == 'true' "/>
422+
<Copy SourceFiles="$(LibrarySourceFolder)\StackAdmin\AzureRM\AzureRM.psm1"
423+
DestinationFolder="$(LibrarySourceFolder)\Stack\$(Configuration)" Condition= " '$(NetCore)' == 'false' and '$(Stack)' == 'true' "/>
424+
<Copy SourceFiles="$(LibrarySourceFolder)\StackAdmin\AzureStack\AzureStack.psm1"
425+
DestinationFolder="$(LibrarySourceFolder)\Stack\$(Configuration)" Condition= " '$(NetCore)' == 'false' and '$(Stack)' == 'true' "/>
426+
427+
<ItemGroup>
428+
<ScriptsToSign Include="$(LibrarySourceFolder)\Package\$(Configuration)\**\*.ps1" Condition="'$(Latest)' == 'true' " />
429+
<ScriptsToSign Include="$(LibrarySourceFolder)\Package\$(Configuration)\**\*.psm1" Condition="'$(Latest)' == 'true' " />
430+
<ScriptsToSign Include="$(LibrarySourceFolder)\Package\$(Configuration)\**\*.ps1xml" Condition="'$(Latest)' == 'true' " />
431+
<ScriptsToSign Include="$(LibrarySourceFolder)\Package\$(Configuration)\**\*.js" Condition="'$(Latest)' == 'true' " />
432+
<ScriptsToSign Include="$(LibraryRoot)setup\Setup\*.ps1" Condition="'$(Latest)' == 'true' "/>
433+
434+
<ScriptsToSign Include="$(LibrarySourceFolder)\Stack\$(Configuration)\**\*.ps1" Condition="'$(Stack)' == 'true' "/>
435+
<ScriptsToSign Include="$(LibrarySourceFolder)\Stack\$(Configuration)\**\*.psm1" Condition="'$(Stack)' == 'true' " />
436+
<ScriptsToSign Include="$(LibrarySourceFolder)\Stack\$(Configuration)\**\*.ps1xml" Condition="'$(Stack)' == 'true' " />
437+
<ScriptsToSign Include="$(LibrarySourceFolder)\Stack\$(Configuration)\**\*.js" Condition="'$(Stack)' == 'true' " />
438+
<!-- <ScriptsToSign Include="$(LibraryRoot)stacksetup\Setup\*.ps1" Condition="'$(Stack)' == 'true' " /> -->
439+
</ItemGroup>
440+
420441
<CodeSigningTask
421442
Description="Microsoft Azure PowerShell"
422443
Keywords="Microsoft Azure PowerShell"
@@ -428,14 +449,6 @@
428449
ToolsPath="$(CIToolsPath)"
429450
Condition="!$(DelaySign) and '@(ScriptsToSign)' != ''"/>
430451

431-
<ValidateStrongNameSignatureTask
432-
WindowsSdkPath="$(WindowsSdkPath)"
433-
Assembly="%(DelaySignedAssembliesToSign.Identity)"
434-
ExpectedTokenSignature="$(StrongNameToken)"
435-
ExpectedDelaySigned="false"
436-
ContinueOnError="false"
437-
Condition="!$(DelaySign) and '@(DelaySignedAssembliesToSign)' != ''"/>
438-
439452
<!-- We cannot verify .js files using Get-AuthenticodeSignature -->
440453
<VerifyAuthenticodeSignatureTask ProbingDirectory="$(PackageDirectory)\$(Configuration)"
441454
FileFilterPattern="microsoft.*.dll;system.*.dll;*.ps1;*.psm1;*.ps1xml;PowerShellSetup.Test.dll" Condition="'$(Latest)' == 'true'">

documentation/Using-Azure-TestFramework.md

Lines changed: 96 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,100 @@
11
# Using Microsoft.Rest.ClientRuntime.Azure.TestFramework #
22

3-
1. Getting Started
4-
2. Accquring TestFramework
5-
3. Setup prior to Record/Playback tests
6-
1. Environment Variables
7-
2. Playback Test
8-
3. Record Test with Interactive login using OrgId
9-
4. Record Test with ServicePrincipal
10-
4. Record/Playback tests
11-
5. Change Test Environment settings at run-time
12-
6. Troubleshooting
13-
7. Supported Key=Value pairs in ConnectionString
14-
8. Environment Variable Reference
15-
16-
## 1. Getting Started
3+
- [Getting Started](#getting-started)
4+
- [Acquiring TestFramework](#acquiring-testframework)
5+
- [Setup prior to Record/Playback tests](#setup-prior-to-record-or-playback-of-tests)
6+
- [New-TestCredential](#new-testcredential)
7+
- [Create New Service Principal](#create-new-service-principal)
8+
- [Use Existing Service Principal](#use-existing-service-principal)
9+
- [UserId](#userid)
10+
- [Set-TestEnvironment](#set-testenvironment)
11+
- [Existing Service Principal](#existing-service-principal)
12+
- [UserId](#userid)
13+
- [Manually Set Environment Variables](#manually-set-environment-variables)
14+
- [Environment Variables](#environment-variables)
15+
- [Playback Test](#playback-test)
16+
- [Record Test with Interactive login using OrgId](#record-test-with-interactive-login-using-orgid)
17+
- [Record Test with ServicePrincipal](#record-test-with-serviceprincipal)
18+
- [Record/Playback tests](#record-or-playback-tests)
19+
- [Change Test Environment settings at run-time](#change-test-environment-settings-at-run-time)
20+
- [Troubleshooting](#troubleshooting)
21+
- [Supported Key Value pairs in ConnectionString](#supported-key-value-pairs-in-connectionstring)
22+
- [Environment Variable Reference](#supported-environment-in-test-framework)
23+
24+
## Getting Started
1725
1. Double click .\tools\PS-VSPrompt shortcut
18-
1. This starts VS Dev command prompt in PowerShell
26+
1. This starts VS Dev command prompt in PowerShell in the azure-powershell/tools directory
1927
2. Import module that helps in performing basic repository tasks
20-
1. Import-Module Repo-Tasks.psd1
21-
2. Type Get-Command -Module Repo-Tasks to see list of cmdlets
22-
3. Get-Help <CommandName> to get help on individual commands.
28+
1. Import-Module .\Repo-Tasks.psd1
2329

24-
## 2. Accquring TestFramework
30+
## Acquiring TestFramework
2531

2632
TestFramework is available on NuGet at https://www.nuget.org/packages/Microsoft.Rest.ClientRuntime.Azure.TestFramework/ .
2733

2834
Instructions to manually download it are available on NuGet. However TestFramework will be downloaded automatically as part of the build process, so manually downloading it should generally be unnecessary.
2935

30-
## 3. Setup prior to Record/Playback of tests
36+
## Setup prior to Record or Playback of tests
3137

32-
In order to Record/Playback a test, you need to setup a connection string that consists various key/value pairs that provides information to the test environment.
38+
In order to Record/Playback a test, you need to setup a connection string that consists of various key/value pairs that provides information to the test environment. You have three options to set up the connection string: run the [New-TestCredential cmdlet](#new-testcredential) (recommended), run the [Set-TestEnvironment cmdlet](#set-testenvironment), or [manually set the environment variables](#manually-set-environment-variables).
3339

34-
#### 3.1 Environment Variables
40+
### New-TestCredential
41+
42+
This cmdlet, located in Repo-Tasks, will allow you to create a credentials file (located in C:/Users/\<currentuser\>/.azure/testcredentials.json) that will be used to set the environment variable when scenario tests are run. This credentials file will be used in all future sessions unless it is deleted or the environment variables are manually set.
43+
44+
#### Create New Service Principal
45+
46+
Using a Service Principal is the preferred option for recording tests because it works with both .NET Framework and .NET Core. In order to create a new Service Principal run this command with a unused ServicePrincipal display name:
47+
48+
```powershell
49+
New-TestCredential -ServicePrincipalDisplayName "ScenarioTestCredentials" -ServicePrincipalSecret `
50+
"testpassword" -SubscriptionId <subscriptionId> -TenantId <tenantId> -RecordMode "Record"
51+
```
52+
53+
This command will create a new Service Principal, set the correct role assignment for this Service Principal based upon the subscription provided, and place the Service Principal id and secret into the credentials file.
54+
55+
#### Use Existing Service Principal
56+
57+
If you would like to use an existing Service Principal, run this command with an existing ServicePrincipal display name and secret:
58+
59+
```powershell
60+
New-TestCredential -ServicePrincipalDisplayName "Existing Service Principal" -ServicePrincipalSecret `
61+
"testpassword" -SubscriptionId <subscriptionId> -TenantId <tenantId> -RecordMode "Record"
62+
```
63+
64+
#### UserId
65+
66+
This is no longer the preferred option because it only works when running on .NET Framework. When running on .NET Core you may get an error like `Interactive Login is supported only in NET45 projects`. Additionally, you will have to manually log in when running the scenario tests rather than being automatically validated.
67+
68+
```powershell
69+
New-TestCredential -UserId "[email protected]" -SubscriptionId <subscriptionId> `
70+
-TenantId <tenantId> -RecordMode "Record"
71+
```
72+
73+
### Set-TestEnvironment
74+
75+
This cmdlet, located in Repo-Tasks, will directly set the environment variable for the session.
76+
77+
#### Existing Service Principal
78+
79+
This is the preferred option for recording tests because it works with both .NET Framework and .NET Core.
80+
81+
```powershell
82+
Set-TestEnvironment -ServicePrincipalId <servicePrincipalId> -ServicePrincipalSecret `
83+
"testpassword" -SubscriptionId <subscriptionId> -TenantId <tenantId> -RecordMode "Record"
84+
```
85+
86+
#### UserId
87+
88+
This is no longer the preferred option because it only works when running on .NET Framework. When running on .NET Core you may get an error like `Interactive Login is supported only in NET45 projects`.
89+
90+
```powershell
91+
Set-TestEnvironment -UserId "[email protected]" -SubscriptionId <subscriptionId> `
92+
-TenantId <tenantId> -RecordMode "Record"
93+
```
94+
95+
### Manually Set Environment Variables
96+
97+
#### Environment Variables
3598

3699
> TEST_CSM_ORGID_AUTHENTICATION
37100
@@ -41,14 +104,14 @@ This is the connection string that determined how to connect to Azure. This incl
41104
42105
This specifies whether test framework will `Record` test sessions or `Playback` previously recorded test sessions.
43106

44-
#### 3.2 Playback Test
107+
#### Playback Test
45108

46109
The default mode is Playback mode, so no setting up of connection string is required. You can optionally set environment variables:
47110

48111
TEST_CSM_ORGID_AUTHENTICATION=
49112
AZURE_TEST_MODE=Playback
50113

51-
#### 3.3 Record Test with Interactive login using OrgId
114+
#### Record Test with Interactive login using OrgId
52115

53116
This is no longer the preferred option because it only works when running on .NET Framework. When running on .NET Core you may get an error like `Interactive Login is supported only in NET45 projects`.
54117

@@ -57,9 +120,9 @@ To use this option, set the following environment variables before starting Visu
57120
TEST_CSM_ORGID_AUTHENTICATION=SubscriptionId={SubId};UserId={orgId};AADTenant={tenantId};Environment={env};HttpRecorderMode=Record;
58121
AZURE_TEST_MODE=Record
59122

60-
#### 3.4 Record Test with ServicePrincipal
123+
#### Record Test with ServicePrincipal
61124

62-
This is the preferred option for record because it works with both .NET Framework and .NET Core.
125+
This is the preferred option for recording tests because it works with both .NET Framework and .NET Core.
63126

64127
To create a service principal, follow the [Azure AD guide to create a Application Service Principal](https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal#create-an-active-directory-application). The application type should be `Web app / API` and the sign-on URL value is irrelevant (you can set any value).
65128

@@ -79,14 +142,14 @@ To use this option, set the following environment variable before starting Visua
79142
TEST_CSM_ORGID_AUTHENTICATION=SubscriptionId={SubId};ServicePrincipal={clientId};ServicePrincipalSecret={clientSecret};AADTenant={tenantId};Environment={env};HttpRecorderMode=Record;
80143
AZURE_TEST_MODE=Record
81144

82-
## 4. Record/Playback Tests
145+
## Record or Playback Tests
83146

84147
1. Run the test and make sure that you got a generated .json file that matches the test name in the bin folder under *SessionRecords folder
85148
2. Copy SessionRecords folder inside the test project and add all *.json files in Visual Studio setting "Copy to Output Directory" property to "Copy if newer"
86149
3. To assure that the records work fine, delete the connection string (default mode is Playback mode) OR change HttpRecorderMode within the connection string to "Playback"
87150

88-
## 5. Change Test Environment settings at run-time
89-
#### 1. Once you set your connection string, you can add or update key/value settings
151+
## Change Test Environment settings at run-time
152+
#### Once you set your connection string, you can add or update key/value settings
90153

91154
Add new key/value pair
92155
TestEnvironment.ConnectionString.KeyValuePairs.Add("Foo", "FooValue");
@@ -100,7 +163,7 @@ To use this option, set the following environment variable before starting Visua
100163
###Note:###
101164
Changing the above properties at run-time has the potential to hard code few things in your tests. Best practice would be to use these properties to change values at run-time from immediate window at run-time and avoid hard-coding certain values.
102165

103-
## 6. Troubleshooting
166+
## Troubleshooting
104167

105168
#### Issue: exceptions in Microsoft.Azure.Test.HttpRecorder
106169

@@ -112,7 +175,7 @@ In order to debug test set the following environment variables before starting V
112175

113176
TEST_CSM_ORGID_AUTHENTICATION=SubscriptionId={SubId};UserId={orgId};AADTenant={tenantId};Environment={env};HttpRecorderMode=Record;
114177

115-
#### 7.1 Supported Key=Value pairs in Connectionstring
178+
## Supported Key Value pairs in ConnectionString
116179
* ManagementCertificate
117180
* SubscriptionId
118181
* AADTenant
@@ -134,9 +197,9 @@ In order to debug test set the following environment variables before starting V
134197
* AADAuthEndpoint
135198
* GraphTokenAudienceUri
136199

137-
## 8. Supported Environment in Test framework (Azure environments)
200+
## Supported Environment in Test framework
138201

139-
#### 8.1 Default Environments and associated Uri
202+
#### Default Environments and associated Uri
140203

141204
##### Environment = Prod
142205

0 commit comments

Comments
 (0)