Skip to content

Commit 8d393f0

Browse files
authored
Move identity variable setting into test-resources-pre.ps1 (Azure#27049)
Updating the identity live tests to remove logic and env setting from yaml in favor of a dedicated keyvault config and powershell script. This will make it possible to improve local and sovereign cloud testing, and make cross-language config updates more easily. Related: Azure/azure-sdk-for-net#38473
1 parent fd26f02 commit 8d393f0

File tree

2 files changed

+54
-19
lines changed

2 files changed

+54
-19
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'Medium')]
2+
param (
3+
# Captures any arguments from eng/New-TestResources.ps1 not declared here (no parameter errors).
4+
[Parameter(ValueFromRemainingArguments = $true)]
5+
$RemainingArguments
6+
)
7+
8+
if (!$CI) {
9+
# TODO: Remove this once auto-cloud config downloads are supported locally
10+
Write-Host "Skipping cert setup in local testing mode"
11+
return
12+
}
13+
14+
if ($EnvironmentVariables -eq $null -or $EnvironmentVariables.Count -eq 0) {
15+
throw "EnvironmentVariables must be set in the calling script New-TestResources.ps1"
16+
}
17+
18+
$tmp = $env:TEMP ? $env:TEMP : [System.IO.Path]::GetTempPath()
19+
$pfxPath = Join-Path $tmp "test.pfx"
20+
$pemPath = Join-Path $tmp "test.pem"
21+
$sniPath = Join-Path $tmp "testsni.pfx"
22+
$sniPemPath = Join-Path $tmp "testsni.pem"
23+
24+
Write-Host "Creating identity test files: $pfxPath $pemPath $sniPath $sniPemPath"
25+
26+
# javascript wants to read \n escaped as \\n which does not match the certificate pattern regex in the identity sdk
27+
# Convert to real newlines before writing to the file
28+
$pemContents = $EnvironmentVariables['PEM_CONTENTS'] -replace "\n","`n"
29+
$sniPemContents = $EnvironmentVariables['SNI_PEM_CONTENTS'] -replace "\n","`n"
30+
Set-Content -Path $pemPath -Value $pemContents
31+
Set-Content -Path $sniPemPath -Value $sniPemContents
32+
[System.Convert]::FromBase64String($EnvironmentVariables['PFX_CONTENTS']) | Set-Content -Path $pfxPath -AsByteStream
33+
[System.Convert]::FromBase64String($EnvironmentVariables['SNI_CONTENTS']) | Set-Content -Path $sniPath -AsByteStream
34+
35+
# Set for pipeline
36+
Write-Host "##vso[task.setvariable variable=IDENTITY_SP_CERT_PFX;]$pfxPath"
37+
Write-Host "##vso[task.setvariable variable=IDENTITY_SP_CERT_PEM;]$pemPath"
38+
Write-Host "##vso[task.setvariable variable=IDENTITY_SP_CERT_SNI;]$sniPath"
39+
Write-Host "##vso[task.setvariable variable=IDENTITY_SP_CERT_SNI_PEM;]$sniPemPath"
40+
# Set for local
41+
$env:IDENTITY_SP_CERT_PFX = $pfxPath
42+
$env:IDENTITY_SP_CERT_PEM = $pemPath
43+
$env:IDENTITY_SP_CERT_SNI = $sniPath
44+
$env:IDENTITY_SP_CERT_SNI_PEM = $sniPemPath

sdk/identity/identity/tests.yml

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,14 @@ stages:
77
ServiceDirectory: identity
88
TimeoutInMinutes: 120
99
SupportedClouds: 'Public,UsGov,China,Canary'
10-
PreSteps:
11-
- pwsh: |
12-
[System.Convert]::FromBase64String($env:PFX_CONTENTS) | Set-Content -Path $(Agent.TempDirectory)/test.pfx -AsByteStream
13-
Set-Content -Path $(Agent.TempDirectory)/test.pem -Value $env:PEM_CONTENTS
14-
[System.Convert]::FromBase64String($env:SNI_CONTENTS) | Set-Content -Path $(Agent.TempDirectory)/testsni.pfx -AsByteStream
15-
Set-Content -Path $(Agent.TempDirectory)/testsni.pem -Value $env:SNI_PEM_CONTENTS
16-
env:
17-
PFX_CONTENTS: $(net-identity-spcert-pfx)
18-
PEM_CONTENTS: $(net-identity-spcert-pem)
19-
SNI_CONTENTS: $(net-identity-spcert-sni)
20-
SNI_PEM_CONTENTS: $(net-identity-spcert-sni-pem)
10+
CloudConfig:
11+
Public:
12+
SubscriptionConfigurations:
13+
- $(sub-config-azure-cloud-test-resources)
14+
# Contains alternate tenant, AAD app and cert info for testing
15+
- $(sub-config-identity-test-resources)
16+
- $(sub-config-identity-test-resources-js)
2117
EnvVars:
22-
AZURE_CLIENT_ID: $(aad-azure-sdk-test-client-id)
23-
AZURE_TENANT_ID: $(aad-azure-sdk-test-tenant-id)
24-
AZURE_CLIENT_SECRET: $(aad-azure-sdk-test-client-secret)
25-
IDENTITY_SP_CERT_PFX: $(Agent.TempDirectory)/test.pfx
26-
IDENTITY_SP_CERT_PEM: $(Agent.TempDirectory)/test.pem
27-
IDENTITY_SP_CERT_SNI: $(Agent.TempDirectory)/testsni.pfx
28-
IDENTITY_SP_CERT_SNI_PEM: $(Agent.TempDirectory)/testsni.pem
29-
IDENTITY_PEM_CONTENTS: $(net-identity-spcert-pem)
18+
AZURE_CLIENT_ID: $(IDENTITY_CLIENT_ID)
19+
AZURE_CLIENT_SECRET: $(IDENTITY_CLIENT_SECRET)
20+
AZURE_TENANT_ID: $(IDENTITY_TENANT_ID)

0 commit comments

Comments
 (0)