Skip to content

Commit

Permalink
fix: ssl test
Browse files Browse the repository at this point in the history
Signed-off-by: Fatih USTA <[email protected]>
  • Loading branch information
fatihusta committed May 30, 2024
1 parent c3ba292 commit 7a61f1c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 48 deletions.
12 changes: 8 additions & 4 deletions api/internal/handler/ssl/ssl.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,10 @@ func (h *Handler) List(c droplet.Context) (interface{}, error) {
ssl := &entity.SSL{}
_ = utils.ObjectClone(item, ssl)
x509_validity, _ := x509CertValidity(ssl.Cert)
ssl.ValidityStart = x509_validity.NotBefore
ssl.ValidityEnd = x509_validity.NotAfter
if x509_validity != nil {
ssl.ValidityStart = x509_validity.NotBefore
ssl.ValidityEnd = x509_validity.NotAfter
}
ssl.Key = ""
ssl.Keys = nil
list = append(list, ssl)
Expand Down Expand Up @@ -455,8 +457,10 @@ func (h *Handler) Validate(c droplet.Context) (interface{}, error) {
}

x509_validity, _ := x509CertValidity(input.Cert)
ssl.ValidityStart = x509_validity.NotBefore
ssl.ValidityEnd = x509_validity.NotAfter
if x509_validity != nil {
ssl.ValidityStart = x509_validity.NotBefore
ssl.ValidityEnd = x509_validity.NotAfter
}

return ssl, nil
}
Expand Down
66 changes: 22 additions & 44 deletions api/internal/handler/ssl/ssl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,8 @@ func TestSSL_Create(t *testing.T) {
"env": "production",
"version": "v2",
},
Snis: []string{"test2.com", "*.test2.com"},
ValidityStart: 1586038672,
ValidityEnd: 4739638672,
Status: 1,
Snis: []string{"test2.com", "*.test2.com"},
Status: 1,
},
wantInput: &entity.SSL{
BaseInfo: entity.BaseInfo{
Expand All @@ -304,10 +302,8 @@ func TestSSL_Create(t *testing.T) {
"env": "production",
"version": "v2",
},
Snis: []string{"test2.com", "*.test2.com"},
ValidityStart: 1586038672,
ValidityEnd: 4739638672,
Status: 1,
Snis: []string{"test2.com", "*.test2.com"},
Status: 1,
},
wantRet: &entity.SSL{
BaseInfo: entity.BaseInfo{
Expand All @@ -320,10 +316,8 @@ func TestSSL_Create(t *testing.T) {
"env": "production",
"version": "v2",
},
Snis: []string{"test2.com", "*.test2.com"},
ValidityStart: 1586038672,
ValidityEnd: 4739638672,
Status: 1,
Snis: []string{"test2.com", "*.test2.com"},
Status: 1,
},
wantErr: nil,
},
Expand All @@ -348,10 +342,8 @@ func TestSSL_Create(t *testing.T) {
"env": "production",
"version": "v2",
},
Snis: []string{"test2.com", "*.test2.com"},
ValidityStart: 1586038672,
ValidityEnd: 4739638672,
Status: 1,
Snis: []string{"test2.com", "*.test2.com"},
Status: 1,
},
wantErr: fmt.Errorf("create failed"),
wantRet: handler.SpecCodeResponse(fmt.Errorf("create failed")),
Expand Down Expand Up @@ -419,10 +411,8 @@ func TestSSL_Update(t *testing.T) {
"env": "production",
"version": "v2",
},
Snis: []string{"test2.com", "*.test2.com"},
ValidityStart: 1586038672,
ValidityEnd: 4739638672,
Status: 1,
Snis: []string{"test2.com", "*.test2.com"},
Status: 1,
},
wantInput: &entity.SSL{
BaseInfo: entity.BaseInfo{
Expand All @@ -435,10 +425,8 @@ func TestSSL_Update(t *testing.T) {
"env": "production",
"version": "v2",
},
Snis: []string{"test2.com", "*.test2.com"},
ValidityStart: 1586038672,
ValidityEnd: 4739638672,
Status: 1,
Snis: []string{"test2.com", "*.test2.com"},
Status: 1,
},
wantRet: &entity.SSL{
BaseInfo: entity.BaseInfo{
Expand All @@ -451,10 +439,8 @@ func TestSSL_Update(t *testing.T) {
"env": "production",
"version": "v2",
},
Snis: []string{"test2.com", "*.test2.com"},
ValidityStart: 1586038672,
ValidityEnd: 4739638672,
Status: 1,
Snis: []string{"test2.com", "*.test2.com"},
Status: 1,
},
},
{
Expand Down Expand Up @@ -561,10 +547,8 @@ func TestSSL_Patch(t *testing.T) {
"env": "production",
"version": "v2",
},
Snis: []string{"test2.com", "*.test2.com"},
ValidityStart: 1586038672,
ValidityEnd: 4739638672,
Status: 1,
Snis: []string{"test2.com", "*.test2.com"},
Status: 1,
},
giveInput: &PatchInput{
ID: "ssl1",
Expand Down Expand Up @@ -597,10 +581,8 @@ func TestSSL_Patch(t *testing.T) {
"env": "production",
"version": "v2",
},
Snis: []string{"test2.com", "*.test2.com"},
ValidityStart: 1586038672,
ValidityEnd: 4739638672,
Status: 1,
Snis: []string{"test2.com", "*.test2.com"},
Status: 1,
},
getCalled: true,
},
Expand All @@ -622,10 +604,8 @@ func TestSSL_Patch(t *testing.T) {
"env": "production",
"version": "v2",
},
Snis: []string{"test2.com", "*.test2.com"},
ValidityStart: 1586038672,
ValidityEnd: 4739638672,
Status: 1,
Snis: []string{"test2.com", "*.test2.com"},
Status: 1,
},
wantInput: &entity.SSL{
BaseInfo: entity.BaseInfo{
Expand Down Expand Up @@ -653,10 +633,8 @@ func TestSSL_Patch(t *testing.T) {
"env": "production",
"version": "v2",
},
Snis: []string{"test2.com", "*.test2.com"},
ValidityStart: 1586038672,
ValidityEnd: 4739638672,
Status: 1,
Snis: []string{"test2.com", "*.test2.com"},
Status: 1,
},
getCalled: true,
},
Expand Down

0 comments on commit 7a61f1c

Please sign in to comment.