Skip to content

Commit 20ac5c5

Browse files
authored
fix automated quickstart, ops verify panic, getZiti (#3736)
* don't auth the client api, update getZiti.ps1 to allow version and check hashes, update oidc to yield better error * quickstart automated tests were passing erroneously * fix quickstart auto test
1 parent 7e557b0 commit 20ac5c5

File tree

5 files changed

+99
-20
lines changed

5 files changed

+99
-20
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ jobs:
160160
timeout-minutes: 5
161161
shell: bash
162162
run: |
163-
go test -v -tags "quickstart automated" ./ziti/cmd/edge/...;
163+
go test -v -tags "quickstart automated" ./ziti/run/...;
164164
165165
- name: Run Unit and Integration Tests
166166
if: ${{ vars.ZITI_SKIP_INTEGRATION_TESTS != 'true' }}

quickstart/docker/image/getZiti.ps1

Lines changed: 74 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
<#
22
.SYNOPSIS
3-
Gets the latest ziti from github and adds it to your path
3+
Gets ziti from github and adds it to your path
44
55
.DESCRIPTION
66
This script will:
7-
- detect the latest version of ziti
8-
- download the latest version of ziti into the folder of your choice, defaulting to $env:userprofile.ziti\bin)
7+
- detect the requested version of ziti from github, defaulting to latest
8+
- download the selected version of ziti into the folder of your choice, defaulting to $env:userprofile.ziti\bin)
99
- unzip the downloaded file
1010
- optionally add the extracted path to your path if executed with a "dot" as in: . getLatestZiti.ps1
1111
12+
.PARAMETER Version
13+
Optional ziti release tag, e.g. v2.0.0-pre8. If omitted, latest is used.
14+
15+
.PARAMETER NonInteractive
16+
Skip all prompts, using defaults (install to $env:USERPROFILE\.ziti\bin and add to session PATH).
17+
1218
.INPUTS
1319
None.
1420
@@ -17,7 +23,15 @@ None. If "dot sourced" this script will add the resultant directory to your path
1723
1824
.EXAMPLE
1925
PS> . .\getZiti.ps1
26+
27+
.EXAMPLE
28+
PS> . .\getZiti.ps1 -Version v2.0.0-pre8
2029
#>
30+
param(
31+
[string]$Version,
32+
[switch]$NonInteractive
33+
)
34+
2135
Add-Type -AssemblyName System.Runtime.InteropServices
2236

2337
$osDescription = [System.Runtime.InteropServices.RuntimeInformation]::OSDescription
@@ -31,8 +45,7 @@ if($arch -match "x64") {
3145
if($osDescription.ToLower() -match "windows") {
3246
$matchFilter="ziti-windows-$arch"
3347
} elseif($osDescription.ToLower() -match "darwin") {
34-
$matchFilter="ziti-darwin-amd64"
35-
#todo: replace $arch some day
48+
$matchFilter="ziti-darwin-$arch"
3649
} elseif($osDescription.ToLower() -match "linux") {
3750
$matchFilter="ziti-linux-$arch"
3851
} else {
@@ -41,16 +54,34 @@ if($osDescription.ToLower() -match "windows") {
4154
}
4255
$dirSeparator = [System.IO.Path]::DirectorySeparatorChar
4356
$pathSeparator = [System.IO.Path]::PathSeparator
44-
$latestFromGitHub=(irm https://api.github.com/repos/openziti/ziti/releases/latest)
45-
$version=($latestFromGitHub.tag_name)
46-
$zitidl=($latestFromGitHub).assets | where {$_.browser_download_url -Match "$matchFilter.*"}
57+
58+
if([string]::IsNullOrWhiteSpace($Version)) {
59+
$releaseFromGitHub = irm https://api.github.com/repos/openziti/ziti/releases/latest
60+
} else {
61+
$releaseFromGitHub = irm "https://api.github.com/repos/openziti/ziti/releases/tags/$Version"
62+
}
63+
64+
$version=($releaseFromGitHub.tag_name)
65+
$zitidl=($releaseFromGitHub).assets | where {$_.browser_download_url -Match "$matchFilter.*"}
4766
$downloadUrl=($zitidl.browser_download_url)
4867
$name=$zitidl.name
68+
$checksumAsset=($releaseFromGitHub).assets | where {$_.name -eq "checksums.sha256.txt"}
69+
$checksumUrl=($checksumAsset.browser_download_url)
70+
71+
if([string]::IsNullOrWhiteSpace($downloadUrl)) {
72+
Write-Error "No matching asset found for version '$version' using filter '$matchFilter'"
73+
return
74+
}
75+
4976
$homeDirectory = [System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::UserProfile)
5077
$defaultFolder="$homeDirectory${dirSeparator}.ziti${dirSeparator}bin"
51-
$toDir=$(Read-Host "Where should ziti be installed? [default: ${defaultfolder}]")
52-
if($toDir.Trim() -eq "") {
53-
$toDir=("${defaultfolder}")
78+
if($NonInteractive) {
79+
$toDir=$defaultFolder
80+
} else {
81+
$toDir=$(Read-Host "Where should ziti be installed? [default: ${defaultfolder}]")
82+
if($toDir.Trim() -eq "") {
83+
$toDir=("${defaultfolder}")
84+
}
5485
}
5586

5687
$zipFile="${toDir}${dirSeparator}${name}"
@@ -67,6 +98,30 @@ if($(Test-Path -Path $zipFile -PathType Leaf)) {
6798
$ProgressPreference=$SavedProgressPreference
6899
}
69100

101+
if(-not [string]::IsNullOrWhiteSpace($checksumUrl)) {
102+
Write-Output "Verifying checksum..."
103+
$checksumContent = (irm $checksumUrl)
104+
$expectedLine = $checksumContent -split "`n" | where { $_ -match [regex]::Escape($name) }
105+
if($expectedLine) {
106+
$expectedHash = ($expectedLine -split "\s+")[0].ToUpper()
107+
if($osDescription.ToLower() -match "windows") {
108+
$actualHash = (Get-FileHash -Algorithm SHA256 -Path $zipFile).Hash.ToUpper()
109+
} else {
110+
$actualHash = (sha256sum $zipFile -split "\s+")[0].ToUpper()
111+
}
112+
if($actualHash -ne $expectedHash) {
113+
Write-Error "Checksum mismatch for $name! Expected $expectedHash but got $actualHash. Aborting."
114+
Remove-Item -Force $zipFile
115+
return
116+
}
117+
Write-Output "Checksum verified."
118+
} else {
119+
Write-Warning "Could not find checksum entry for '$name' in checksums.sha256.txt. Proceeding without verification."
120+
}
121+
} else {
122+
Write-Warning "No checksums.sha256.txt asset found in release. Proceeding without verification."
123+
}
124+
70125
if($osDescription.ToLower() -match "windows") {
71126
Expand-Archive -Path $zipFile -DestinationPath "${toDir}${dirSeparator}${version}" -ErrorAction SilentlyContinue
72127
} else {
@@ -78,12 +133,16 @@ if($osDescription.ToLower() -match "windows") {
78133
Write-Output " "
79134
Write-Output "Extracted binaries to ${toDir}${dirSeparator}${version}${dirSeparator}ziti"
80135
Write-Output " "
81-
$addToPath=$(Read-Host "Would you like to add ziti to this session's path? [default: Y]")
82-
if($addToPath.Trim() -eq "") {
83-
$addToPath=("Y")
136+
if($NonInteractive) {
137+
$addToPath="Y"
138+
} else {
139+
$addToPath=$(Read-Host "Would you like to add ziti to this session's path? [default: Y]")
140+
if($addToPath.Trim() -eq "") {
141+
$addToPath=("Y")
142+
}
84143
}
85144

86145
if($addToPath -ilike "y*") {
87146
$env:PATH+="$pathSeparator${toDir}${dirSeparator}${version}"
88147
Write-Output "ziti added to your path!"
89-
}
148+
}

ziti/cmd/edge/login.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ func (o *LoginOptions) NewClientApiClient() (*rest_client_api_client.ZitiEdgeCli
201201
nc = o.client
202202
} else {
203203
var newClientErr error
204-
nc, newClientErr = o.newHttpClient(true)
204+
nc, newClientErr = o.newHttpClient(false)
205205
if newClientErr != nil {
206206
return nil, newClientErr
207207
}

ziti/cmd/ops/verify/ext-jwt-signer/oidc/oidc.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,12 @@ func NewOidcVerificationCmd(out io.Writer, errOut io.Writer, initialContext cont
346346
}
347347

348348
log.Infof("found external JWT signer")
349+
if s.ExternalAuthURL == nil {
350+
return errors.New("external JWT signer has no externalAuthURL configured")
351+
}
352+
if s.ClientID == nil {
353+
return errors.New("external JWT signer has no clientId configured")
354+
}
349355
opts.Issuer = *s.ExternalAuthURL
350356
opts.ClientID = *s.ClientID
351357
log.Infof(" - issuer: %s", safeValue(s.ExternalAuthURL))

ziti/run/quickstart_automated_test.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package run
55
import (
66
"context"
77
"fmt"
8+
"net"
89
"os"
910
"testing"
1011
"time"
@@ -28,17 +29,30 @@ func TestEdgeQuickstartAutomated(t *testing.T) {
2829
ctrlUrl := fmt.Sprintf("https://%s:%s", ctrlAddy, ctrlPort)
2930

3031
cmdComplete := make(chan error)
31-
go waitForController(ctrlUrl, cmdComplete)
32-
timeout, _ := time.ParseDuration("20s")
32+
go waitForController(ctx, ctrlUrl, cmdComplete)
33+
timeout, _ := time.ParseDuration("90s")
3334
select {
3435
case e := <-cmdComplete:
3536
//completed, check for error
3637
if e != nil {
3738
t.Fatal(e)
3839
}
39-
expectedTestDuration, _ := time.ParseDuration("60s")
40+
expectedTestDuration, _ := time.ParseDuration("120s")
4041
log.Info("controller online")
4142
go func() {
43+
routerAddy := helpers.GetCtrlEdgeAdvertisedAddress()
44+
routerPort := helpers.GetZitiEdgeRouterPort()
45+
routerAddr := net.JoinHostPort(routerAddy, routerPort)
46+
log.Infof("waiting for router at %s", routerAddr)
47+
for {
48+
conn, err := net.DialTimeout("tcp", routerAddr, 2*time.Second)
49+
if err == nil {
50+
_ = conn.Close()
51+
log.Infof("router online at %s", routerAddr)
52+
break
53+
}
54+
time.Sleep(500 * time.Millisecond)
55+
}
4256
performQuickstartTest(t)
4357
log.Info("Operation completed")
4458
cmdComplete <- nil

0 commit comments

Comments
 (0)