Skip to content

Commit d146457

Browse files
Peter Moodybradfitz
authored andcommitted
ssh/knownhosts: test coverage for IsHostAuthority
Change-Id: Iad24fed7cec998e02620ec0eb61658786156ba41 Reviewed-on: https://go-review.googlesource.com/42530 Reviewed-by: Brad Fitzpatrick <[email protected]> Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 8e03fc1 commit d146457

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

ssh/knownhosts/knownhosts_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,28 @@ func TestRevoked(t *testing.T) {
7676
}
7777
}
7878

79+
func TestHostAuthority(t *testing.T) {
80+
for _, m := range []struct {
81+
authorityFor string
82+
address string
83+
84+
good bool
85+
}{
86+
{authorityFor: "localhost", address: "localhost:22", good: true},
87+
{authorityFor: "localhost", address: "localhost", good: false},
88+
{authorityFor: "localhost", address: "localhost:1234", good: false},
89+
{authorityFor: "[localhost]:1234", address: "localhost:1234", good: true},
90+
{authorityFor: "[localhost]:1234", address: "localhost:22", good: false},
91+
{authorityFor: "[localhost]:1234", address: "localhost", good: false},
92+
} {
93+
db := testDB(t, `@cert-authority `+m.authorityFor+` `+edKeyStr)
94+
if ok := db.IsHostAuthority(db.lines[0].knownKey.Key, m.address); ok != m.good {
95+
t.Errorf("IsHostAuthority: authority %s, address %s, wanted good = %v, got good = %v",
96+
m.authorityFor, m.address, m.good, ok)
97+
}
98+
}
99+
}
100+
79101
func TestBracket(t *testing.T) {
80102
db := testDB(t, `[git.eclipse.org]:29418,[198.41.30.196]:29418 `+edKeyStr)
81103

0 commit comments

Comments
 (0)