MCPcopy Create free account
hub / github.com/CrunchyData/postgres-operator / TestRootIsInvalid

Function TestRootIsInvalid

internal/pki/pki_test.go:137–205  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

135}
136
137func TestRootIsInvalid(t *testing.T) {
138 t.Run("NoCertificate", func(t *testing.T) {
139 assert.Assert(t, !RootIsValid(nil))
140 assert.Assert(t, !RootIsValid(&RootCertificateAuthority{}))
141
142 root, err := NewRootCertificateAuthority()
143 assert.NilError(t, err)
144
145 root.Certificate = Certificate{}
146 assert.Assert(t, !RootIsValid(root))
147 })
148
149 t.Run("NoPrivateKey", func(t *testing.T) {
150 root, err := NewRootCertificateAuthority()
151 assert.NilError(t, err)
152
153 root.PrivateKey = PrivateKey{}
154 assert.Assert(t, !RootIsValid(root))
155 })
156
157 t.Run("WrongPrivateKey", func(t *testing.T) {
158 root, err := NewRootCertificateAuthority()
159 assert.NilError(t, err)
160
161 other, err := NewRootCertificateAuthority()
162 assert.NilError(t, err)
163
164 root.PrivateKey = other.PrivateKey
165 assert.Assert(t, !RootIsValid(root))
166 })
167
168 t.Run("NotAuthority", func(t *testing.T) {
169 root, err := NewRootCertificateAuthority()
170 assert.NilError(t, err)
171
172 leaf, err := root.GenerateLeafCertificate("", nil)
173 assert.NilError(t, err)
174
175 assert.Assert(t, !RootIsValid((*RootCertificateAuthority)(leaf)))
176 })
177
178 t.Run("TooEarly", func(t *testing.T) {
179 original := currentTime
180 t.Cleanup(func() { currentTime = original })
181
182 currentTime = func() time.Time {
183 return time.Now().Add(time.Hour * 24) // tomorrow
184 }
185
186 root, err := NewRootCertificateAuthority()
187 assert.NilError(t, err)
188
189 assert.Assert(t, !RootIsValid(root))
190 })
191
192 t.Run("Expired", func(t *testing.T) {
193 original := currentTime
194 t.Cleanup(func() { currentTime = original })

Callers

nothing calls this directly

Calls 5

RootIsValidFunction · 0.85
CleanupMethod · 0.80
AddMethod · 0.45

Tested by

no test coverage detected