-
Notifications
You must be signed in to change notification settings - Fork 729
Expand file tree
/
Copy pathtest.ps1
More file actions
113 lines (94 loc) · 4.35 KB
/
test.ps1
File metadata and controls
113 lines (94 loc) · 4.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env pwsh
# A Windows domain user should be able to run this against a feed in an AAD-back AzDO org
# and all scenarios should succeed non-interactively.
param(
[Parameter(Mandatory = $true, Position = 0)]
[string]$TestFeed
)
if ([string]::IsNullOrEmpty($TestFeed)) {
Write-Host "Please specify an AzDO organization package feed URL as the first parameter." -ForegroundColor Red
exit 1
}
$env:NUGET_CREDENTIALPROVIDER_MSAL_FILECACHE_ENABLED = "true"
$env:NUGET_CREDENTIALPROVIDER_MSAL_FILECACHE_LOCATION = Join-Path ([System.IO.Path]::GetTempPath()) "msal.cache"
if (Test-Path $env:NUGET_CREDENTIALPROVIDER_MSAL_FILECACHE_LOCATION) {
Remove-Item $env:NUGET_CREDENTIALPROVIDER_MSAL_FILECACHE_LOCATION -Force
}
function Test-Frameworks {
param(
[string]$TestFeedUrl
)
if ($IsWindows) {
$frameworks = @("net481", "net6.0", "net8.0")
} else {
$frameworks = @("net6.0", "net8.0")
}
foreach ($framework in $frameworks) {
# Clean up credential cache files
$credProviderPath = Join-Path ([Environment]::GetFolderPath('LocalApplicationData')) "MicrosoftCredentialProvider" "*.dat"
if (Test-Path $credProviderPath) {
Write-Host "Removing credential cache files at $credProviderPath" -ForegroundColor Yellow
Remove-Item $credProviderPath -Force -ErrorAction SilentlyContinue
}
if (Test-Path $env:NUGET_CREDENTIALPROVIDER_MSAL_FILECACHE_LOCATION) {
Write-Host "Removing MSAL file cache at $env:NUGET_CREDENTIALPROVIDER_MSAL_FILECACHE_LOCATION" -ForegroundColor Yellow
Remove-Item $env:NUGET_CREDENTIALPROVIDER_MSAL_FILECACHE_LOCATION -Force -ErrorAction SilentlyContinue
}
Write-Host "Testing $framework with NUGET_CREDENTIALPROVIDER_MSAL_ALLOW_BROKER=$env:NUGET_CREDENTIALPROVIDER_MSAL_ALLOW_BROKER" -ForegroundColor Cyan
$logFile = "test.$framework"
if ($env:NUGET_CREDENTIALPROVIDER_MSAL_ALLOW_BROKER -eq "true") {
$logFile += ".withbroker"
} else {
$logFile += ".nobroker"
}
if ($env:ARTIFACTS_CREDENTIALPROVIDER_RETURN_ENTRA_TOKENS -eq "true") {
$logFile += ".entratoken"
}
$logFile = "$logFile.log"
# Point the file logger at the same log file so it captures full diagnostics
$env:ARTIFACTS_CREDENTIALPROVIDER_LOG_PATH = (Join-Path $PSScriptRoot $logFile)
$projectPath = Join-Path "CredentialProvider.Microsoft" "CredentialProvider.Microsoft.csproj"
$command = "dotnet run --no-restore --no-build -f $framework --project $projectPath -- -C -U $TestFeedUrl -V Debug -R"
Write-Host $command -ForegroundColor Gray
# Execute the command (file logger captures full diagnostics via ARTIFACTS_CREDENTIALPROVIDER_LOG_PATH)
try {
& dotnet run --no-restore --no-build -f $framework --project $projectPath -- -C -U $TestFeedUrl -V Debug -R | Out-Null
$exitCode = $LASTEXITCODE
}
catch {
$exitCode = 1
Write-Host "Command execution failed: $_" -ForegroundColor Red
}
if ($exitCode -ne 0) {
Write-Host "Previous command execution failed: $exitCode" -ForegroundColor Red
return $exitCode
}
}
return 0
}
Write-Host "Testing MSAL with Entra Token Opt-in" -ForegroundColor Green
$env:NUGET_CREDENTIALPROVIDER_MSAL_ALLOW_BROKER = "true"
$env:ARTIFACTS_CREDENTIALPROVIDER_RETURN_ENTRA_TOKENS = "true"
$result = Test-Frameworks -TestFeedUrl $TestFeed
if ($result -ne 0) {
Write-Host "Failed: $result" -ForegroundColor Red
exit $result
}
Write-Host "Testing MSAL without broker" -ForegroundColor Green
$env:NUGET_CREDENTIALPROVIDER_MSAL_ALLOW_BROKER = "false"
$env:ARTIFACTS_CREDENTIALPROVIDER_RETURN_ENTRA_TOKENS = "false"
$result = Test-Frameworks -TestFeedUrl $TestFeed
if ($result -ne 0) {
Write-Host "Failed: $result" -ForegroundColor Red
exit $result
}
Write-Host "Testing MSAL with broker" -ForegroundColor Green
$env:NUGET_CREDENTIALPROVIDER_MSAL_ALLOW_BROKER = "true"
$env:ARTIFACTS_CREDENTIALPROVIDER_RETURN_ENTRA_TOKENS = "false"
$result = Test-Frameworks -TestFeedUrl $TestFeed
if ($result -ne 0) {
Write-Host "Failed: $result" -ForegroundColor Red
exit $result
}
Write-Host "All tests passed!" -ForegroundColor Green
exit 0