-
Notifications
You must be signed in to change notification settings - Fork 0
/
leaf_test.go
81 lines (69 loc) · 1.91 KB
/
leaf_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright 2020 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package pki_test
import (
"net"
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
"github.com/juju/juju/pki"
pkitest "github.com/juju/juju/pki/test"
"github.com/juju/juju/testing"
)
type LeafSuite struct {
}
var _ = gc.Suite(&LeafSuite{})
func (l *LeafSuite) TestLeafHasDNSNames(c *gc.C) {
authority, err := pkitest.NewTestAuthority()
c.Assert(err, jc.ErrorIsNil)
tests := []struct {
CertDNSNames []string
CheckDNSNames []string
Result bool
}{
{
CertDNSNames: []string{"juju-apiserver", "mongodb"},
CheckDNSNames: []string{"juju-apiserver"},
Result: true,
},
{
CertDNSNames: []string{"juju-apiserver", "mongodb"},
CheckDNSNames: []string{"juju-apiserver", "mongodb"},
Result: true,
},
{
CertDNSNames: []string{"juju-apiserver", "mongodb"},
CheckDNSNames: []string{"juju-apiserver1", "mongodb"},
Result: false,
},
}
for _, test := range tests {
leaf, err := authority.LeafRequestForGroup(pki.DefaultLeafGroup).
AddDNSNames(test.CertDNSNames...).
Commit()
c.Assert(err, jc.ErrorIsNil)
c.Assert(pki.LeafHasDNSNames(leaf, test.CheckDNSNames), gc.Equals,
test.Result)
}
}
func (l *LeafSuite) TestLeafIPAddresses(c *gc.C) {
authority, err := pkitest.NewTestAuthority()
c.Assert(err, jc.ErrorIsNil)
tests := []struct {
CertIPAddresses []net.IP
CheckIPAddresses []net.IP
Result bool
}{
{
CertIPAddresses: []net.IP{net.ParseIP("fe80::abcd:1")},
CheckIPAddresses: []net.IP{net.ParseIP("fe80::abcd:1")},
Result: true,
},
}
for _, test := range tests {
leaf, err := authority.LeafRequestForGroup(pki.DefaultLeafGroup).
AddIPAddresses(test.CertIPAddresses...).
Commit()
c.Assert(err, jc.ErrorIsNil)
c.Assert(leaf.Certificate().IPAddresses, testing.IPsEqual, test.CheckIPAddresses)
}
}