4
4
"crypto/tls"
5
5
"crypto/x509"
6
6
"fmt"
7
+ "math/big"
7
8
"net/http"
8
9
"os"
9
10
"path/filepath"
@@ -273,6 +274,22 @@ func TestKeyPairConfig(t *testing.T) {
273
274
},
274
275
err : ErrInvalidIP ,
275
276
},
277
+ {
278
+ name : "Happy Path - Serial Number provided" ,
279
+ cfg : KeyPairConfig {
280
+ Domains : []string {"example.com" },
281
+ SerialNumber : big .NewInt (123 ),
282
+ },
283
+ err : nil ,
284
+ },
285
+ {
286
+ name : "Happy Path - Common Name provided" ,
287
+ cfg : KeyPairConfig {
288
+ Domains : []string {"example.com" },
289
+ CommonName : "Example Common Name" ,
290
+ },
291
+ err : nil ,
292
+ },
276
293
}
277
294
278
295
for _ , c := range tc {
@@ -290,6 +307,34 @@ func TestKeyPairConfig(t *testing.T) {
290
307
}
291
308
})
292
309
}
310
+
311
+ t .Run ("Serial Number is correct in Key Pair" , func (t * testing.T ) {
312
+ certs , err := NewCA ().NewKeyPairFromConfig (KeyPairConfig {
313
+ Domains : []string {"example.com" },
314
+ SerialNumber : big .NewInt (123 ),
315
+ })
316
+ if err != nil {
317
+ t .Fatalf ("KeyPair Generation Failed expected nil got %v" , err )
318
+ }
319
+
320
+ if certs .cert .SerialNumber .Cmp (big .NewInt (123 )) != 0 {
321
+ t .Fatalf ("Unexpected Serial Number expected 123 got %v" , certs .cert .SerialNumber )
322
+ }
323
+ })
324
+
325
+ t .Run ("Common Name is correct in Key Pair" , func (t * testing.T ) {
326
+ certs , err := NewCA ().NewKeyPairFromConfig (KeyPairConfig {
327
+ Domains : []string {"example.com" },
328
+ CommonName : "Example Common Name" ,
329
+ })
330
+ if err != nil {
331
+ t .Fatalf ("KeyPair Generation Failed expected nil got %v" , err )
332
+ }
333
+
334
+ if certs .cert .Subject .CommonName != "Example Common Name" {
335
+ t .Fatalf ("Unexpected Common Name expected 'Example Common Name' got %v" , certs .cert .Subject .CommonName )
336
+ }
337
+ })
293
338
}
294
339
295
340
type FullFlowTestCase struct {
@@ -327,6 +372,17 @@ func TestFullFlow(t *testing.T) {
327
372
},
328
373
kpErr : nil ,
329
374
},
375
+ {
376
+ name : "Localhost IP, Domain, Serial Number, and Common Name" ,
377
+ listenAddr : "0.0.0.0" ,
378
+ kpCfg : KeyPairConfig {
379
+ IPAddresses : []string {"127.0.0.1" , "::1" },
380
+ Domains : []string {"localhost" },
381
+ SerialNumber : big .NewInt (123 ),
382
+ CommonName : "Example Common Name" ,
383
+ },
384
+ kpErr : nil ,
385
+ },
330
386
}
331
387
332
388
for _ , c := range tc {
0 commit comments