Skip to content

Commit 7a61f1c

Browse files
committed
fix: ssl test
Signed-off-by: Fatih USTA <[email protected]>
1 parent c3ba292 commit 7a61f1c

File tree

2 files changed

+30
-48
lines changed

2 files changed

+30
-48
lines changed

api/internal/handler/ssl/ssl.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,10 @@ func (h *Handler) List(c droplet.Context) (interface{}, error) {
199199
ssl := &entity.SSL{}
200200
_ = utils.ObjectClone(item, ssl)
201201
x509_validity, _ := x509CertValidity(ssl.Cert)
202-
ssl.ValidityStart = x509_validity.NotBefore
203-
ssl.ValidityEnd = x509_validity.NotAfter
202+
if x509_validity != nil {
203+
ssl.ValidityStart = x509_validity.NotBefore
204+
ssl.ValidityEnd = x509_validity.NotAfter
205+
}
204206
ssl.Key = ""
205207
ssl.Keys = nil
206208
list = append(list, ssl)
@@ -455,8 +457,10 @@ func (h *Handler) Validate(c droplet.Context) (interface{}, error) {
455457
}
456458

457459
x509_validity, _ := x509CertValidity(input.Cert)
458-
ssl.ValidityStart = x509_validity.NotBefore
459-
ssl.ValidityEnd = x509_validity.NotAfter
460+
if x509_validity != nil {
461+
ssl.ValidityStart = x509_validity.NotBefore
462+
ssl.ValidityEnd = x509_validity.NotAfter
463+
}
460464

461465
return ssl, nil
462466
}

api/internal/handler/ssl/ssl_test.go

+22-44
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,8 @@ func TestSSL_Create(t *testing.T) {
288288
"env": "production",
289289
"version": "v2",
290290
},
291-
Snis: []string{"test2.com", "*.test2.com"},
292-
ValidityStart: 1586038672,
293-
ValidityEnd: 4739638672,
294-
Status: 1,
291+
Snis: []string{"test2.com", "*.test2.com"},
292+
Status: 1,
295293
},
296294
wantInput: &entity.SSL{
297295
BaseInfo: entity.BaseInfo{
@@ -304,10 +302,8 @@ func TestSSL_Create(t *testing.T) {
304302
"env": "production",
305303
"version": "v2",
306304
},
307-
Snis: []string{"test2.com", "*.test2.com"},
308-
ValidityStart: 1586038672,
309-
ValidityEnd: 4739638672,
310-
Status: 1,
305+
Snis: []string{"test2.com", "*.test2.com"},
306+
Status: 1,
311307
},
312308
wantRet: &entity.SSL{
313309
BaseInfo: entity.BaseInfo{
@@ -320,10 +316,8 @@ func TestSSL_Create(t *testing.T) {
320316
"env": "production",
321317
"version": "v2",
322318
},
323-
Snis: []string{"test2.com", "*.test2.com"},
324-
ValidityStart: 1586038672,
325-
ValidityEnd: 4739638672,
326-
Status: 1,
319+
Snis: []string{"test2.com", "*.test2.com"},
320+
Status: 1,
327321
},
328322
wantErr: nil,
329323
},
@@ -348,10 +342,8 @@ func TestSSL_Create(t *testing.T) {
348342
"env": "production",
349343
"version": "v2",
350344
},
351-
Snis: []string{"test2.com", "*.test2.com"},
352-
ValidityStart: 1586038672,
353-
ValidityEnd: 4739638672,
354-
Status: 1,
345+
Snis: []string{"test2.com", "*.test2.com"},
346+
Status: 1,
355347
},
356348
wantErr: fmt.Errorf("create failed"),
357349
wantRet: handler.SpecCodeResponse(fmt.Errorf("create failed")),
@@ -419,10 +411,8 @@ func TestSSL_Update(t *testing.T) {
419411
"env": "production",
420412
"version": "v2",
421413
},
422-
Snis: []string{"test2.com", "*.test2.com"},
423-
ValidityStart: 1586038672,
424-
ValidityEnd: 4739638672,
425-
Status: 1,
414+
Snis: []string{"test2.com", "*.test2.com"},
415+
Status: 1,
426416
},
427417
wantInput: &entity.SSL{
428418
BaseInfo: entity.BaseInfo{
@@ -435,10 +425,8 @@ func TestSSL_Update(t *testing.T) {
435425
"env": "production",
436426
"version": "v2",
437427
},
438-
Snis: []string{"test2.com", "*.test2.com"},
439-
ValidityStart: 1586038672,
440-
ValidityEnd: 4739638672,
441-
Status: 1,
428+
Snis: []string{"test2.com", "*.test2.com"},
429+
Status: 1,
442430
},
443431
wantRet: &entity.SSL{
444432
BaseInfo: entity.BaseInfo{
@@ -451,10 +439,8 @@ func TestSSL_Update(t *testing.T) {
451439
"env": "production",
452440
"version": "v2",
453441
},
454-
Snis: []string{"test2.com", "*.test2.com"},
455-
ValidityStart: 1586038672,
456-
ValidityEnd: 4739638672,
457-
Status: 1,
442+
Snis: []string{"test2.com", "*.test2.com"},
443+
Status: 1,
458444
},
459445
},
460446
{
@@ -561,10 +547,8 @@ func TestSSL_Patch(t *testing.T) {
561547
"env": "production",
562548
"version": "v2",
563549
},
564-
Snis: []string{"test2.com", "*.test2.com"},
565-
ValidityStart: 1586038672,
566-
ValidityEnd: 4739638672,
567-
Status: 1,
550+
Snis: []string{"test2.com", "*.test2.com"},
551+
Status: 1,
568552
},
569553
giveInput: &PatchInput{
570554
ID: "ssl1",
@@ -597,10 +581,8 @@ func TestSSL_Patch(t *testing.T) {
597581
"env": "production",
598582
"version": "v2",
599583
},
600-
Snis: []string{"test2.com", "*.test2.com"},
601-
ValidityStart: 1586038672,
602-
ValidityEnd: 4739638672,
603-
Status: 1,
584+
Snis: []string{"test2.com", "*.test2.com"},
585+
Status: 1,
604586
},
605587
getCalled: true,
606588
},
@@ -622,10 +604,8 @@ func TestSSL_Patch(t *testing.T) {
622604
"env": "production",
623605
"version": "v2",
624606
},
625-
Snis: []string{"test2.com", "*.test2.com"},
626-
ValidityStart: 1586038672,
627-
ValidityEnd: 4739638672,
628-
Status: 1,
607+
Snis: []string{"test2.com", "*.test2.com"},
608+
Status: 1,
629609
},
630610
wantInput: &entity.SSL{
631611
BaseInfo: entity.BaseInfo{
@@ -653,10 +633,8 @@ func TestSSL_Patch(t *testing.T) {
653633
"env": "production",
654634
"version": "v2",
655635
},
656-
Snis: []string{"test2.com", "*.test2.com"},
657-
ValidityStart: 1586038672,
658-
ValidityEnd: 4739638672,
659-
Status: 1,
636+
Snis: []string{"test2.com", "*.test2.com"},
637+
Status: 1,
660638
},
661639
getCalled: true,
662640
},

0 commit comments

Comments
 (0)