mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-07-09 16:00:59 +00:00
parent
58ece3c1b8
commit
d52231855d
6 changed files with 501 additions and 133 deletions
|
|
@ -924,6 +924,38 @@ func TestRootInstallAutoRegisterPrefersJsonTokenForm(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestRootInstallAutoRegisterRotatesExistingDeterministicToken(t *testing.T) {
|
||||
content, err := os.ReadFile(filepath.Join("..", "..", "install.sh"))
|
||||
if err != nil {
|
||||
t.Fatalf("read root install.sh: %v", err)
|
||||
}
|
||||
script := string(content)
|
||||
|
||||
required := []string{
|
||||
`pve_token_already_exists_error() {`,
|
||||
`create_pve_auto_register_token() {`,
|
||||
`create_pve_auto_register_token "$token_name" token_output token_status`,
|
||||
`pve_token_already_exists_error "$token_output"`,
|
||||
`pveum user token remove pulse-monitor@pve "$token_name"`,
|
||||
`Existing Proxmox monitoring token '${token_name}' found; rotating it so Pulse receives a fresh secret`,
|
||||
}
|
||||
for _, needle := range required {
|
||||
if !strings.Contains(script, needle) {
|
||||
t.Fatalf("install.sh missing deterministic token rotation contract: %s", needle)
|
||||
}
|
||||
}
|
||||
|
||||
alreadyExistsIdx := strings.Index(script, `pve_token_already_exists_error "$token_output"`)
|
||||
removeIdx := strings.Index(script, `pveum user token remove pulse-monitor@pve "$token_name"`)
|
||||
retryIdx := strings.LastIndex(script, `create_pve_auto_register_token "$token_name" token_output token_status`)
|
||||
if alreadyExistsIdx < 0 || removeIdx < 0 || retryIdx < 0 || !(alreadyExistsIdx < removeIdx && removeIdx < retryIdx) {
|
||||
t.Fatalf("expected existing-token detection to remove then retry token creation (exists=%d remove=%d retry=%d)", alreadyExistsIdx, removeIdx, retryIdx)
|
||||
}
|
||||
if strings.Contains(script, `pveum user token remove pulse-monitor@pve`) && !strings.Contains(script, `pve_token_already_exists_error "$token_output"`) {
|
||||
t.Fatalf("token removal must stay gated by an explicit existing-token create error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRootInstallDeployAgentScriptsDeploysSignatureSidecars(t *testing.T) {
|
||||
extractDir := t.TempDir()
|
||||
installDir := t.TempDir()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue