forked from juju/juju
-
Notifications
You must be signed in to change notification settings - Fork 0
/
audit_test.go
116 lines (91 loc) · 3.43 KB
/
audit_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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Copyright 2016 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package audit_test
import (
"time"
"github.com/juju/errors"
"github.com/juju/testing"
jc "github.com/juju/testing/checkers"
"github.com/juju/utils"
"github.com/juju/version"
gc "gopkg.in/check.v1"
"github.com/juju/juju/audit"
)
type auditSuite struct {
testing.IsolationSuite
}
var _ = gc.Suite(&auditSuite{})
func (s *auditSuite) TestValidate_EmptyModelUUIDErrors(c *gc.C) {
invalidEntry := validEntry()
invalidEntry.ModelUUID = ""
validationErr := invalidEntry.Validate()
c.Check(validationErr, jc.Satisfies, errors.IsNotValid)
c.Check(validationErr, gc.ErrorMatches, "ModelUUID not assigned")
}
func (s *auditSuite) TestValidate_InvalidModelUUIDErrors(c *gc.C) {
invalidEntry := validEntry()
invalidEntry.ModelUUID = "."
validationErr := invalidEntry.Validate()
c.Check(validationErr, jc.Satisfies, errors.IsNotValid)
c.Check(validationErr, gc.ErrorMatches, "ModelUUID not valid")
}
func (s *auditSuite) TestValidate_EmptyTimestampErrors(c *gc.C) {
invalidEntry := validEntry()
invalidEntry.Timestamp = time.Time{}
validationErr := invalidEntry.Validate()
c.Check(validationErr, jc.Satisfies, errors.IsNotValid)
c.Check(validationErr, gc.ErrorMatches, "Timestamp not assigned")
}
func (s *auditSuite) TestValidate_NonUTCTimestampInvalid(c *gc.C) {
invalidEntry := validEntry()
invalidEntry.Timestamp = invalidEntry.Timestamp.In(time.FixedZone("x", 3600))
validationErr := invalidEntry.Validate()
c.Check(validationErr, jc.Satisfies, errors.IsNotValid)
c.Check(validationErr, gc.ErrorMatches, "must be set to UTC: Timestamp not valid")
}
func (s *auditSuite) TestValidate_NilOriginIPErrors(c *gc.C) {
invalidEntry := validEntry()
invalidEntry.RemoteAddress = ""
validationErr := invalidEntry.Validate()
c.Check(validationErr, jc.Satisfies, errors.IsNotValid)
c.Check(validationErr, gc.ErrorMatches, "RemoteAddress not assigned")
}
func (s *auditSuite) TestValidate_EmptyOriginTypeErrors(c *gc.C) {
invalidEntry := validEntry()
invalidEntry.OriginType = ""
validationErr := invalidEntry.Validate()
c.Check(validationErr, jc.Satisfies, errors.IsNotValid)
c.Check(validationErr, gc.ErrorMatches, "OriginType not assigned")
}
func (s *auditSuite) TestValidate_EmptyOriginNameErrors(c *gc.C) {
invalidEntry := validEntry()
invalidEntry.OriginName = ""
validationErr := invalidEntry.Validate()
c.Check(validationErr, jc.Satisfies, errors.IsNotValid)
c.Check(validationErr, gc.ErrorMatches, "OriginName not assigned")
}
func (s *auditSuite) TestValidate_EmptyOperationErrors(c *gc.C) {
invalidEntry := validEntry()
invalidEntry.Operation = ""
validationErr := invalidEntry.Validate()
c.Check(validationErr, jc.Satisfies, errors.IsNotValid)
c.Check(validationErr, gc.ErrorMatches, "Operation not assigned")
}
func (s *auditSuite) TestValidate_EmptyJujuServerVersionErrors(c *gc.C) {
invalidEntry := validEntry()
invalidEntry.JujuServerVersion = version.Zero
validationErr := invalidEntry.Validate()
c.Check(validationErr, jc.Satisfies, errors.IsNotValid)
c.Check(validationErr, gc.ErrorMatches, "JujuServerVersion not assigned")
}
func validEntry() audit.AuditEntry {
return audit.AuditEntry{
JujuServerVersion: version.MustParse("1.0.0"),
ModelUUID: utils.MustNewUUID().String(),
Timestamp: time.Now().UTC(),
RemoteAddress: "8.8.8.8",
OriginType: ".",
OriginName: ".",
Operation: ".",
}
}