* For caddy v1 in our org This RP changes all imports for caddyserver/caddy to coredns/caddy. This is the v1 code of caddy. For the coredns/caddy repo the following changes have been made: * anything not needed by us is deleted * all `telemetry` stuff is deleted * all its import paths are also changed to point to coredns/caddy * the v1 branch has been moved to the master branch * a v1.1.0 tag has been added to signal the latest release Signed-off-by: Miek Gieben <miek@miek.nl> * Fix imports Signed-off-by: Miek Gieben <miek@miek.nl> * Group coredns/caddy with out plugins Signed-off-by: Miek Gieben <miek@miek.nl> * remove this file Signed-off-by: Miek Gieben <miek@miek.nl> * Relax import ordering github.com/coredns is now also a coredns dep, this makes github.com/coredns/caddy fit more natural in the list. Signed-off-by: Miek Gieben <miek@miek.nl> * Fix final import Signed-off-by: Miek Gieben <miek@miek.nl>
75 lines
1.7 KiB
Go
75 lines
1.7 KiB
Go
package sign
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/coredns/caddy"
|
|
)
|
|
|
|
func TestParse(t *testing.T) {
|
|
tests := []struct {
|
|
input string
|
|
shouldErr bool
|
|
exp *Signer
|
|
}{
|
|
{`sign testdata/db.miek.nl miek.nl {
|
|
key file testdata/Kmiek.nl.+013+59725
|
|
}`,
|
|
false,
|
|
&Signer{
|
|
keys: []Pair{},
|
|
origin: "miek.nl.",
|
|
dbfile: "testdata/db.miek.nl",
|
|
directory: "/var/lib/coredns",
|
|
signedfile: "db.miek.nl.signed",
|
|
},
|
|
},
|
|
{`sign testdata/db.miek.nl example.org {
|
|
key file testdata/Kmiek.nl.+013+59725
|
|
directory testdata
|
|
}`,
|
|
false,
|
|
&Signer{
|
|
keys: []Pair{},
|
|
origin: "example.org.",
|
|
dbfile: "testdata/db.miek.nl",
|
|
directory: "testdata",
|
|
signedfile: "db.example.org.signed",
|
|
},
|
|
},
|
|
// errors
|
|
{`sign db.example.org {
|
|
key file /etc/coredns/keys/Kexample.org
|
|
}`,
|
|
true,
|
|
nil,
|
|
},
|
|
}
|
|
for i, tc := range tests {
|
|
c := caddy.NewTestController("dns", tc.input)
|
|
sign, err := parse(c)
|
|
|
|
if err == nil && tc.shouldErr {
|
|
t.Fatalf("Test %d expected errors, but got no error", i)
|
|
}
|
|
if err != nil && !tc.shouldErr {
|
|
t.Fatalf("Test %d expected no errors, but got '%v'", i, err)
|
|
}
|
|
if tc.shouldErr {
|
|
continue
|
|
}
|
|
signer := sign.signers[0]
|
|
if x := signer.origin; x != tc.exp.origin {
|
|
t.Errorf("Test %d expected %s as origin, got %s", i, tc.exp.origin, x)
|
|
}
|
|
if x := signer.dbfile; x != tc.exp.dbfile {
|
|
t.Errorf("Test %d expected %s as dbfile, got %s", i, tc.exp.dbfile, x)
|
|
}
|
|
if x := signer.directory; x != tc.exp.directory {
|
|
t.Errorf("Test %d expected %s as directory, got %s", i, tc.exp.directory, x)
|
|
}
|
|
if x := signer.signedfile; x != tc.exp.signedfile {
|
|
t.Errorf("Test %d expected %s as signedfile, got %s", i, tc.exp.signedfile, x)
|
|
}
|
|
}
|
|
}
|