02e3e0315d
RFC2136 dynamic-DNS updater. Watches a records file (inotify) and new interface addresses and pushes TSIG-signed updates to BIND per zone, sending only the delta. Native miekg/dns (structured per-zone RCODEs), local status API + facter fact, systemd unit, nfpm RPM, Woodpecker CI. Replaces the puppet dns-update shell script; keeps the same records-file and TSIG-key contract.
40 lines
968 B
Go
40 lines
968 B
Go
package tsig
|
|
|
|
import "testing"
|
|
|
|
func TestParse(t *testing.T) {
|
|
in := `key "client-update" {
|
|
algorithm hmac-sha256;
|
|
secret "dGVzdHNlY3JldA==";
|
|
};`
|
|
k, err := Parse(in)
|
|
if err != nil {
|
|
t.Fatalf("Parse: %v", err)
|
|
}
|
|
if k.Name != "client-update." {
|
|
t.Errorf("name=%q want client-update.", k.Name)
|
|
}
|
|
if k.Algorithm != "hmac-sha256." {
|
|
t.Errorf("algorithm=%q want hmac-sha256.", k.Algorithm)
|
|
}
|
|
if k.Secret != "dGVzdHNlY3JldA==" {
|
|
t.Errorf("secret=%q", k.Secret)
|
|
}
|
|
if m := k.SecretMap(); m["client-update."] != k.Secret {
|
|
t.Errorf("SecretMap=%v", m)
|
|
}
|
|
}
|
|
|
|
func TestParseErrors(t *testing.T) {
|
|
for _, in := range []string{
|
|
`nonsense`,
|
|
`key "x" { algorithm hmac-sha256; };`, // no secret
|
|
`key "x" { secret "abc"; };`, // no algorithm
|
|
`key "x" { algorithm hmac-whirlpool; secret "a"; };`, // unsupported algo
|
|
} {
|
|
if _, err := Parse(in); err == nil {
|
|
t.Errorf("expected error for %q", in)
|
|
}
|
|
}
|
|
}
|