@@ -40,15 +40,42 @@ var _ = Describe("notation cert", func() {
4040 MatchKeyWords (
4141 "Successfully deleted" ,
4242 )
43+
44+ trustStorePath := vhost .AbsolutePath (NotationDirName , TrustStoreDirName , "x509" , TrustStoreTypeCA , "e2e" )
45+ if _ , err := os .Stat (trustStorePath ); err == nil {
46+ Fail (fmt .Sprintf ("empty trust store directory %s should be deleted" , trustStorePath ))
47+ }
4348 })
4449 })
4550
46- It ("delete a specfic cert" , func () {
51+ It ("delete a specific cert and the empty trust store directory " , func () {
4752 Host (BaseOptions (), func (notation * utils.ExecOpts , artifact * Artifact , vhost * utils.VirtualHost ) {
4853 notation .Exec ("cert" , "delete" , "--type" , "ca" , "--store" , "e2e" , "e2e.crt" , "-y" ).
4954 MatchKeyWords (
5055 "Successfully deleted e2e.crt from trust store e2e of type ca" ,
5156 )
57+
58+ trustStorePath := vhost .AbsolutePath (NotationDirName , TrustStoreDirName , "x509" , TrustStoreTypeCA , "e2e" )
59+ if _ , err := os .Stat (trustStorePath ); err == nil {
60+ Fail (fmt .Sprintf ("empty trust store directory %s should be deleted" , trustStorePath ))
61+ }
62+ })
63+ })
64+
65+ It ("delete a specific cert from trust store containing more than one certificates" , func () {
66+ Host (BaseOptions (), func (notation * utils.ExecOpts , artifact * Artifact , vhost * utils.VirtualHost ) {
67+ notation .Exec ("cert" , "add" , "--type" , "ca" , "--store" , "e2e" , filepath .Join (NotationE2ELocalKeysDir , "expired_e2e.crt" )).
68+ MatchKeyWords ("Successfully added following certificates" )
69+
70+ notation .Exec ("cert" , "delete" , "--type" , "ca" , "--store" , "e2e" , "expired_e2e.crt" , "-y" ).
71+ MatchKeyWords (
72+ "Successfully deleted expired_e2e.crt from trust store e2e of type ca" ,
73+ )
74+
75+ trustStorePath := vhost .AbsolutePath (NotationDirName , TrustStoreDirName , "x509" , TrustStoreTypeCA , "e2e" )
76+ if _ , err := os .Stat (trustStorePath ); err != nil {
77+ Fail (fmt .Sprintf ("trust store directory %s should still exist" , trustStorePath ))
78+ }
5279 })
5380 })
5481
@@ -58,6 +85,32 @@ var _ = Describe("notation cert", func() {
5885 MatchErrKeyWords (
5986 "failed to delete the certificate file" ,
6087 )
88+
89+ trustStorePath := vhost .AbsolutePath (NotationDirName , TrustStoreDirName , "x509" , TrustStoreTypeCA , "e2e" )
90+ if _ , err := os .Stat (trustStorePath ); err != nil {
91+ Fail (fmt .Sprintf ("trust store directory %s should still exist" , trustStorePath ))
92+ }
93+ })
94+ })
95+
96+ It ("delete a specific cert but failed to delete the empty trust store directory" , func () {
97+ Host (BaseOptions (), func (notation * utils.ExecOpts , artifact * Artifact , vhost * utils.VirtualHost ) {
98+ trustStorePath := vhost .AbsolutePath (NotationDirName , TrustStoreDirName , "x509" , TrustStoreTypeCA , "e2e" )
99+
100+ // Remove read permission for trustStorePath
101+ if err := os .Chmod (trustStorePath , 0300 ); err != nil {
102+ Fail (err .Error ())
103+ }
104+ defer os .Chmod (trustStorePath , 0700 )
105+
106+ notation .Exec ("cert" , "delete" , "--type" , "ca" , "--store" , "e2e" , "e2e.crt" , "-y" ).
107+ MatchKeyWords (
108+ "Successfully deleted e2e.crt from trust store e2e of type ca" ,
109+ ).
110+ MatchErrKeyWords (
111+ fmt .Sprintf ("Warning: failed to check if the trust store directory %s is empty" , trustStorePath ),
112+ "permission denied" ,
113+ )
61114 })
62115 })
63116
@@ -129,6 +182,11 @@ var _ = Describe("notation cert", func() {
129182 "Successfully deleted certificate file:" , "e2e-test.crt" ,
130183 "Cleanup completed successfully" ,
131184 )
185+
186+ trustStorePath := vhost .AbsolutePath (NotationDirName , TrustStoreDirName , "x509" , TrustStoreTypeCA , "e2e-test" )
187+ if _ , err := os .Stat (trustStorePath ); err == nil {
188+ Fail (fmt .Sprintf ("empty trust store directory %s should be deleted" , trustStorePath ))
189+ }
132190 })
133191 })
134192
@@ -153,6 +211,11 @@ var _ = Describe("notation cert", func() {
153211 "Successfully deleted certificate file:" , "e2e-test.crt" ,
154212 "Cleanup completed successfully" ,
155213 )
214+
215+ trustStorePath := vhost .AbsolutePath (NotationDirName , TrustStoreDirName , "x509" , TrustStoreTypeCA , "e2e-test" )
216+ if _ , err := os .Stat (trustStorePath ); err == nil {
217+ Fail (fmt .Sprintf ("empty trust store directory %s should be deleted" , trustStorePath ))
218+ }
156219 })
157220 })
158221
@@ -195,6 +258,11 @@ var _ = Describe("notation cert", func() {
195258 "Successfully deleted certificate file:" , "e2e-test.crt" ,
196259 "Cleanup completed successfully" ,
197260 )
261+
262+ trustStorePath := vhost .AbsolutePath (NotationDirName , TrustStoreDirName , "x509" , TrustStoreTypeCA , "e2e-test" )
263+ if _ , err := os .Stat (trustStorePath ); err == nil {
264+ Fail (fmt .Sprintf ("empty trust store directory %s should be deleted" , trustStorePath ))
265+ }
198266 })
199267 })
200268
@@ -221,6 +289,10 @@ var _ = Describe("notation cert", func() {
221289 MatchKeyWords (
222290 "Successfully deleted e2e-test.crt from trust store e2e-test of type ca" ,
223291 )
292+ trustStorePath := vhost .AbsolutePath (NotationDirName , TrustStoreDirName , "x509" , TrustStoreTypeCA , "e2e-test" )
293+ if _ , err := os .Stat (trustStorePath ); err == nil {
294+ Fail (fmt .Sprintf ("empty trust store directory %s should be deleted" , trustStorePath ))
295+ }
224296
225297 notation .Exec ("cert" , "cleanup-test" , "e2e-test" , "-y" ).
226298 MatchKeyWords (
@@ -249,6 +321,11 @@ var _ = Describe("notation cert", func() {
249321 "Successfully deleted certificate file:" , "e2e-test.crt" ,
250322 "Cleanup completed successfully" ,
251323 )
324+
325+ trustStorePath := vhost .AbsolutePath (NotationDirName , TrustStoreDirName , "x509" , TrustStoreTypeCA , "e2e-test" )
326+ if _ , err := os .Stat (trustStorePath ); err == nil {
327+ Fail (fmt .Sprintf ("empty trust store directory %s should be deleted" , trustStorePath ))
328+ }
252329 })
253330 })
254331
@@ -268,6 +345,11 @@ var _ = Describe("notation cert", func() {
268345 fmt .Sprintf ("Certificate file %s does not exist" , localCertPath ),
269346 "Cleanup completed successfully" ,
270347 )
348+
349+ trustStorePath := vhost .AbsolutePath (NotationDirName , TrustStoreDirName , "x509" , TrustStoreTypeCA , "e2e-test" )
350+ if _ , err := os .Stat (trustStorePath ); err == nil {
351+ Fail (fmt .Sprintf ("empty trust store directory %s should be deleted" , trustStorePath ))
352+ }
271353 })
272354 })
273355
@@ -302,6 +384,11 @@ var _ = Describe("notation cert", func() {
302384 "failed to delete certificate e2e-test.crt from trust store e2e-test of type ca" ,
303385 "permission denied" ,
304386 )
387+
388+ trustStorePath := vhost .AbsolutePath (NotationDirName , TrustStoreDirName , "x509" , TrustStoreTypeCA , "e2e-test" )
389+ if _ , err := os .Stat (trustStorePath ); err != nil {
390+ Fail (fmt .Sprintf ("trust store directory %s should still exist" , trustStorePath ))
391+ }
305392 })
306393 })
307394
@@ -318,6 +405,11 @@ var _ = Describe("notation cert", func() {
318405 "failed to remove key e2e-test from the key list" ,
319406 "permission denied" ,
320407 )
408+
409+ trustStorePath := vhost .AbsolutePath (NotationDirName , TrustStoreDirName , "x509" , TrustStoreTypeCA , "e2e-test" )
410+ if _ , err := os .Stat (trustStorePath ); err == nil {
411+ Fail (fmt .Sprintf ("empty trust store directory %s should be deleted" , trustStorePath ))
412+ }
321413 })
322414 })
323415
@@ -334,6 +426,11 @@ var _ = Describe("notation cert", func() {
334426 fmt .Sprintf ("failed to delete key file %s" , filepath .Join (localKeysDir , "e2e-test.key" )),
335427 "permission denied" ,
336428 )
429+
430+ trustStorePath := vhost .AbsolutePath (NotationDirName , TrustStoreDirName , "x509" , TrustStoreTypeCA , "e2e-test" )
431+ if _ , err := os .Stat (trustStorePath ); err == nil {
432+ Fail (fmt .Sprintf ("empty trust store directory %s should be deleted" , trustStorePath ))
433+ }
337434 })
338435 })
339436})
0 commit comments