Delete a forwarded opening the way ufw accepts it, and read a fresh machine's resolver as not in use — both measured on a lab machine (hq ADR 0100)
This commit is contained in:
@@ -2,6 +2,7 @@ package bootstrap
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -13,8 +14,8 @@ import (
|
||||
// and listener it counted.
|
||||
|
||||
// Lines as `ss -Hltunp` prints them. The ssh, samba, loopback and proxy lines are captured from a
|
||||
// real machine; the resolver, DHCP and time lines are written in the same shape for the processes a
|
||||
// fresh machine runs, and still need measuring against one.
|
||||
// real machine; the resolver, DHCP and time lines are written in the same shape. What a fresh machine
|
||||
// actually runs is measured in testdata/fresh-machine-listeners.txt.
|
||||
const inUseSockets = `tcp LISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=1188536,fd=6))
|
||||
tcp LISTEN 0 128 [::]:22 [::]:* users:(("sshd",pid=1188536,fd=7))
|
||||
tcp LISTEN 0 32 127.0.0.1:53 0.0.0.0:* users:(("dnsmasq",pid=1189392,fd=7))
|
||||
@@ -97,3 +98,25 @@ func TestARerunOfGenesisIsNotAMachineInUse(t *testing.T) {
|
||||
t.Errorf("what an earlier genesis raised was counted as a machine in use: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAFreshlyInstalledMachineAsMeasuredIsNotInUse(t *testing.T) {
|
||||
// Captured with `ss -Hltunp` on a freshly installed lab machine: its resolver listens on TCP on
|
||||
// every address, which the record's words alone would count.
|
||||
raw, err := os.ReadFile("testdata/fresh-machine-listeners.txt")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
run := func(ctx context.Context, name string, args ...string) (string, error) {
|
||||
if name == "ss" {
|
||||
return string(raw), nil
|
||||
}
|
||||
return "", nil
|
||||
}
|
||||
containers, listeners, err := InUse(context.Background(), run, func(string) bool { return false })
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(containers) != 0 || len(listeners) != 0 {
|
||||
t.Errorf("a fresh machine read as in use: containers %v, listeners %v", containers, listeners)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user