tests/exit-status.sh: stub test for the SSH step's phase B rollback

Aperta Adatta ai principianti
#158 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
bash, shell
Ambito
testing

Direzione di ricerca

Inizia con i test di step_firewall in tests/exit-status.sh e segui il loro schema per simulare le chiamate all’host. Aggiungi i due casi step_ssh descritti nell’issue, quindi esegui bash tests/exit-status.sh. Il lavoro è completato quando il caso di errore restituisce 1, registra la nota di rollback e chiama lo script di rollback una volta, mentre il caso di successo restituisce 0 senza chiamarlo.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

claude enhancement priority: medium size: S

Why

#106 makes phase B of step_ssh() (closing the old SSH port once the operator confirmed the new one) roll back when the second restart_ssh fails. At that point the 10-minute rollback timer is already stopped, so this rollback is the only thing between a failed restart and a server with no sshd. Nothing tests it yet: tests/exit-status.sh does not run step_ssh, and the e2e VMs cannot make only the second restart fail (#127 covers the phase A paths).

Raised in the review of #106: https://github.com/exceev-consulting/server-prep/pull/106#discussion_r4418985351

What to do (after #106 is merged)

Add a block to tests/exit-status.sh, in the style of the step_firewall tests, that runs the real step_ssh with every host call replaced:

  • CURRENT_SSH_PORTS=22 and SSH_PORT=822 (so phase B runs), DRY_RUN=0, INTERACTIVE=0, BACKUP_DIR in the test's temp folder.
  • getent returns a home in the temp folder with one key in .ssh/authorized_keys.
  • write_sshd_config only sets STEP_CHANGED=1; backup_file, run and sleep do nothing; sshd returns 0; ss prints LISTEN; ufw prints nothing.
  • restart_ssh succeeds the first time and fails the second time.
  • bash is a function that only records its arguments, so the rollback script never really runs (remove it with unset -f bash right after).

Check that the step returns 1, that STEP_NOTES contains "phase B restart failed, rolled back", and that the rollback script was called exactly once. A second case where restart_ssh always succeeds should return 0 and never call the rollback script.

Acceptance criteria

  • bash tests/exit-status.sh runs both cases and passes.
  • Changing the phase B line back to a bare restart_ssh makes the test fail.
  • No real systemctl, ufw, sshd or rollback script runs during the test.
Lingua principale
Shell
Stelle
2
Fork
3
Merge medio
2g 14m
PR unite (30g)
47

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di exceev-consulting/server-prep

Tutte le issue di exceev-consulting/server-prep

Issue simili

Altre issue su Shell/Bash

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.