@@ -96,20 +96,15 @@ func TestParse(t *testing.T) {
96
96
expNumAuthorities : 1 ,
97
97
},
98
98
{
99
- name : "Parse empty bytes should fail " ,
100
- path : "testdata/empty.pem" ,
101
- expErrContains : "x509bundle: cannot parse certificate: no PEM blocks found" ,
99
+ name : "Parse empty bytes should result in empty bundle " ,
100
+ path : "testdata/empty.pem" ,
101
+ expNumAuthorities : 0 ,
102
102
},
103
103
{
104
104
name : "Parse non-PEM bytes should fail" ,
105
105
path : "testdata/not-pem.pem" ,
106
106
expErrContains : "x509bundle: cannot parse certificate: no PEM blocks found" ,
107
107
},
108
- {
109
- name : "Parse should fail if no certificate block is is found" ,
110
- path : "testdata/key.pem" ,
111
- expErrContains : "x509bundle: no certificates found" ,
112
- },
113
108
{
114
109
name : "Parse a corrupted certificate should fail" ,
115
110
path : "testdata/corrupted.pem" ,
@@ -155,9 +150,9 @@ func TestParseRaw(t *testing.T) {
155
150
expNumAuthorities : 1 ,
156
151
},
157
152
{
158
- name : "Parse should fail if no certificate block is is found" ,
159
- path : "testdata/key .pem" ,
160
- expErrContains : "x509bundle: no certificates found" ,
153
+ name : "Parse should not fail if no certificate block is is found" ,
154
+ path : "testdata/empty .pem" ,
155
+ expNumAuthorities : 0 ,
161
156
},
162
157
}
163
158
@@ -322,6 +317,10 @@ func loadRawCertificates(t *testing.T, path string) []byte {
322
317
certsBytes , err := os .ReadFile (path )
323
318
require .NoError (t , err )
324
319
320
+ if len (certsBytes ) == 0 {
321
+ return []byte {}
322
+ }
323
+
325
324
certs , err := pemutil .ParseCertificates (certsBytes )
326
325
require .NoError (t , err )
327
326
0 commit comments