This repository has been archived by the owner on Mar 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
integration-test.ps1
104 lines (77 loc) · 3.21 KB
/
integration-test.ps1
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
## ---------------------------------------------------
## Complete end to end integration test of the SDK
## ---------------------------------------------------
#
# Sample command line:
#
# PowerShell:
# PS> .\integration-test.ps1 -thumbprint B1478FCA1B2C9E6DDDE288A676B5395F67BCDF36 -commonName "localhost" -url https://localhost:4443
#
param(
# A certificate that can be used to secure the token and our communication
[Parameter(Mandatory=$true, HelpMessage="Thumbprint of the certificate to use for HTTP/TLS, for encryption, and for signing.")]
[string]$thumbprint = $null,
# common name of the certificate specified by $thumbprint
[string]$commonName = "localhost",
# URL of the local sestest server
[string]$url = "https://localhost:4443"
)
#
## NOTE: the server name from $url MUST MATCH (allowing for wildcards) the common name of the certificate
## So if the URL is for "localhost" the certificate common name must also specify "localhost"
if ($thumbprint -eq $null) {
Write-Output "Please define $thumbprint to identify which certificate to use for the test."
exit -1;
}
function Write-TaskName($subtaskName) {
$divider = "-" * ($subtaskName.Length + 4)
Write-Output "`r`n$divider`r`n $subtaskName`r`n$divider`r`n"
}
# ----------------------------------------------------------------------
Write-TaskName "Generating Token"
.\sestest.ps1 generate --vmid "fu" --application-id contosoapp --sign $thumbprint --encrypt $thumbprint --token-file token.txt
if ($LASTEXITCODE -ne 0) {
Write-Output "Failed to generate token (Error code $LASTEXITCODE)"
exit
}
# ----------------------------------------------------------------------
Write-TaskName "Display Token"
$env:AZ_BATCH_SOFTWARE_ENTITLEMENT_TOKEN = (get-content token.txt)
Write-Output $env:AZ_BATCH_SOFTWARE_ENTITLEMENT_TOKEN
# ----------------------------------------------------------------------
Write-TaskName "Start Software Entitlement Server"
$command = ".\sestest.ps1 server --connection $thumbprint --sign $thumbprint --encrypt $thumbprint --exit-after-request --log-file server.log --log-file-level debug"
start-process powershell -argument $command
Write-Output "Server started successfully."
# ----------------------------------------------------------------------
Write-TaskName "Wait for server to be up"
function check-serverActive {
$address = [System.Net.IPAddress]('127.0.0.1')
$port = 4443
$client = New-Object System.Net.Sockets.TcpClient
try {
$client.Connect($address, $port);
return $true
}
catch {
return $false
}
finally {
$client.Dispose();
}
}
$ready = check-serverActive
while (!$ready) {
Write-Output "Waiting ..."
$ready = check-serverActive
}
Write-Output "Server now active"
# ----------------------------------------------------------------------
Write-TaskName "Verify Token"
.\sesclient --url $url --thumbprint $thumbprint --common-name $commonName --token $env:AZ_BATCH_SOFTWARE_ENTITLEMENT_TOKEN --application contosoapp
if ($LASTEXITCODE -ne 0) {
Write-Output "Token did not verify (Error code $LASTEXITCODE)"
Write-Output "(You'll need to manually stop the server.)"
} else {
Write-Output "Token verified ok"
}