Skip to content

Commit ac0909b

Browse files
committed
Adding masking for all integration test scripts
1 parent 114df0a commit ac0909b

5 files changed

Lines changed: 220 additions & 59 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ Desktop.ini
3838
# Local testing output (use --output .local-extract for local runs)
3939
.local-extract*/
4040

41-
# Log files for integration tests
41+
# Files for integration tests
4242
tests/integration/all-resource-types/logs/**
43+
tests/integration/all-resource-types/extracted-artifacts/**
4344

4445
# Environment variables
4546
.env

tests/integration/all-resource-types/Deploy-SourceApim.ps1

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,21 @@ param(
4646
[ValidateSet('Developer', 'Premium', 'StandardV2', 'PremiumV2')]
4747
[string]$SkuName = 'StandardV2',
4848

49-
[switch]$Destroy
49+
[switch]$Destroy,
50+
51+
[ValidateSet('trace', 'debug', 'info', 'warn', 'error', 'silent')]
52+
[string]$LogLevel = 'info'
5053
)
5154

5255
$ErrorActionPreference = 'Stop'
56+
$maskingHelpers = Join-Path $PSScriptRoot 'Masking.Helpers.ps1'
57+
. $maskingHelpers
5358

5459
# ---------------------------------------------------------------------------
5560
# Destroy path
5661
# ---------------------------------------------------------------------------
5762
if ($Destroy) {
58-
Write-Host "🗑️ Deleting resource group '$ResourceGroupName'..." -ForegroundColor Yellow
63+
Write-Host "🗑️ Deleting resource group '$(Mask-Identifier -Value $ResourceGroupName)'..." -ForegroundColor Yellow
5964
az group delete --name $ResourceGroupName --yes --no-wait
6065
Write-Host "✅ Deletion initiated (async). Resource group will be removed shortly." -ForegroundColor Green
6166
exit 0
@@ -78,7 +83,7 @@ if (-not $account) {
7883
}
7984

8085
$subscriptionId = $account.id
81-
Write-Host " Subscription: $($account.name) ($subscriptionId)" -ForegroundColor Gray
86+
Write-Host " Subscription: $($account.name) ($(Mask-SubscriptionId -Value $subscriptionId))" -ForegroundColor Gray
8287

8388
# Register required resource providers
8489
Write-Host "📋 Registering required resource providers..." -ForegroundColor Cyan
@@ -124,7 +129,7 @@ if (-not $allRegistered) {
124129
Write-Host " ✅ Resource providers ready" -ForegroundColor Green
125130

126131
# Create resource group if needed
127-
Write-Host "📦 Ensuring resource group '$ResourceGroupName' exists in '$Location'..." -ForegroundColor Cyan
132+
Write-Host "📦 Ensuring resource group '$(Mask-Identifier -Value $ResourceGroupName)' exists in '$Location'..." -ForegroundColor Cyan
128133
az group create --name $ResourceGroupName --location $Location --output none
129134

130135
# Deploy Bicep template
@@ -158,10 +163,11 @@ Write-Host ""
158163
Write-Host "APIOps CLI extract command:" -ForegroundColor Cyan
159164
Write-Host ""
160165
Write-Host " npx apiops extract \"
161-
Write-Host " --subscription-id $($outputs.subscriptionId.value) \"
162-
Write-Host " --resource-group $($outputs.resourceGroupName.value) \"
166+
Write-Host " --subscription-id $(Mask-SubscriptionId -Value $outputs.subscriptionId.value) \"
167+
Write-Host " --resource-group $(Mask-Identifier -Value $outputs.resourceGroupName.value) \"
163168
Write-Host " --service-name $($outputs.apimServiceName.value) \"
164-
Write-Host " --output-dir ./extracted"
169+
Write-Host " --output-dir ./extracted \"
170+
Write-Host " --log-level $LogLevel"
165171
Write-Host ""
166172
Write-Host "Gateway URL: $($outputs.gatewayUrl.value)" -ForegroundColor Gray
167173
Write-Host "Workspace deployed: $($outputs.workspaceDeployed.value)" -ForegroundColor Gray
@@ -178,6 +184,7 @@ $outputObj = @{
178184
workspaceDeployed = $outputs.workspaceDeployed.value
179185
gatewayDeployed = $outputs.gatewayDeployed.value
180186
skuName = $outputs.skuName.value
187+
logLevel = $LogLevel
181188
}
182189

183190
# Write to GitHub Actions output if running in CI
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<#
2+
.SYNOPSIS
3+
Deploys the target APIM instance for round-trip integration testing.
4+
5+
.DESCRIPTION
6+
Creates a resource group and deploys the target-apim.bicep template,
7+
provisioning a clean APIM instance used as the publish target.
8+
9+
.PARAMETER ResourceGroupName
10+
Name of the Azure resource group to create or update.
11+
12+
.PARAMETER PublisherEmail
13+
Publisher email required by the APIM deployment.
14+
15+
.PARAMETER Location
16+
Azure region. Default: eastus2.
17+
18+
.PARAMETER SkuName
19+
APIM SKU. Default: StandardV2. Allowed: Developer, Premium, StandardV2, PremiumV2.
20+
#>
21+
22+
[CmdletBinding()]
23+
param(
24+
[Parameter(Mandatory)]
25+
[string]$ResourceGroupName,
26+
27+
[Parameter(Mandatory = $true)]
28+
[string]$PublisherEmail,
29+
30+
[string]$Location = 'eastus2',
31+
32+
[ValidateSet('Developer', 'Premium', 'StandardV2', 'PremiumV2')]
33+
[string]$SkuName = 'StandardV2'
34+
)
35+
36+
$ErrorActionPreference = 'Stop'
37+
$maskingHelpers = Join-Path $PSScriptRoot 'Masking.Helpers.ps1'
38+
. $maskingHelpers
39+
40+
$bicepFile = Join-Path $PSScriptRoot 'target-apim.bicep'
41+
42+
if (-not (Test-Path $bicepFile)) {
43+
Write-Error "Bicep file not found at: $bicepFile"
44+
}
45+
46+
Write-Host "Starting target APIM deployment..."
47+
Write-Host "Resource Group: $(Mask-Identifier -Value $ResourceGroupName)"
48+
Write-Host "SKU: $SkuName"
49+
Write-Host "Location: $Location"
50+
51+
Write-Host "Creating resource group..."
52+
az group create --name $ResourceGroupName --location $Location --output none
53+
if ($LASTEXITCODE -ne 0) {
54+
throw "Failed to create target resource group"
55+
}
56+
57+
Write-Host "Deploying target-apim.bicep (this takes 30-45 minutes)..."
58+
$raw = az deployment group create `
59+
--resource-group $ResourceGroupName `
60+
--name "target-apim-$(Get-Date -Format 'yyyyMMddHHmmss')" `
61+
--template-file $bicepFile `
62+
--parameters skuName=$SkuName location=$Location publisherEmail=$PublisherEmail `
63+
--output json
64+
65+
if ($LASTEXITCODE -ne 0) {
66+
throw "Target APIM deployment failed"
67+
}
68+
69+
$result = $raw | ConvertFrom-Json
70+
if (-not $result.properties.outputs) {
71+
throw "Target deployment returned no outputs"
72+
}
73+
74+
Write-Host "✅ Target APIM deployed successfully: $($result.properties.outputs.apimServiceName.value)"
75+
76+
return $result.properties.outputs
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
$EnableMasking = $true # Set to $false only for local debugging.
2+
3+
function Mask-Identifier {
4+
param(
5+
[string]$Value,
6+
[int]$Prefix = 6,
7+
[int]$Suffix = 4
8+
)
9+
10+
if (-not $EnableMasking) {
11+
return $Value
12+
}
13+
14+
if ([string]::IsNullOrWhiteSpace($Value)) {
15+
return '<empty>'
16+
}
17+
18+
if ($Value.Length -le ($Prefix + $Suffix)) {
19+
return ('*' * $Value.Length)
20+
}
21+
22+
return "{0}...{1}" -f $Value.Substring(0, $Prefix), $Value.Substring($Value.Length - $Suffix)
23+
}
24+
25+
function Mask-SubscriptionId {
26+
param([string]$Value)
27+
return Mask-Identifier -Value $Value -Prefix 8 -Suffix 4
28+
}
29+
30+
function Protect-LogLine {
31+
param(
32+
[string]$Line,
33+
[hashtable]$Replacements
34+
)
35+
36+
if (-not $EnableMasking -or [string]::IsNullOrEmpty($Line) -or -not $Replacements) {
37+
return $Line
38+
}
39+
40+
$protectedLine = $Line
41+
foreach ($entry in $Replacements.GetEnumerator()) {
42+
if ([string]::IsNullOrEmpty($entry.Key) -or [string]::IsNullOrEmpty($entry.Value)) {
43+
continue
44+
}
45+
46+
$protectedLine = $protectedLine.Replace($entry.Key, $entry.Value)
47+
}
48+
49+
return $protectedLine
50+
}
51+
52+
function Invoke-MaskedApiopsCommand {
53+
param(
54+
[scriptblock]$Command,
55+
[hashtable]$Replacements
56+
)
57+
58+
& $Command 2>&1 | ForEach-Object {
59+
$message = $_.ToString()
60+
Write-Host (Protect-LogLine -Line $message -Replacements $Replacements)
61+
}
62+
63+
return $LASTEXITCODE
64+
}

0 commit comments

Comments
 (0)