Skip to content

Commit

Permalink
fixed ssl schema (apache/apisix#10323)
Browse files Browse the repository at this point in the history
  • Loading branch information
isman-usoh committed May 10, 2024
1 parent 397c0cb commit da8e71e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 24 deletions.
14 changes: 12 additions & 2 deletions api/internal/handler/ssl/ssl.go
Expand Up @@ -198,6 +198,18 @@ func (h *Handler) List(c droplet.Context) (interface{}, error) {
for _, item := range ret.Rows {
ssl := &entity.SSL{}
_ = utils.ObjectClone(item, ssl)

if ssl.Cert != "" {
certDERBlock, _ := pem.Decode([]byte(ssl.Cert))
if certDERBlock != nil {
x509Cert, err := x509.ParseCertificate(certDERBlock.Bytes)
if err == nil {
ssl.ValidityStart = x509Cert.NotBefore.Unix()
ssl.ValidityEnd = x509Cert.NotAfter.Unix()
}
}
}

ssl.Key = ""
ssl.Keys = nil
list = append(list, ssl)
Expand Down Expand Up @@ -383,8 +395,6 @@ func ParseCert(crt, key string) (*entity.SSL, error) {

ssl.Snis = snis
ssl.Key = key
ssl.ValidityStart = x509Cert.NotBefore.Unix()
ssl.ValidityEnd = x509Cert.NotAfter.Unix()
ssl.Cert = crt

return &ssl, nil
Expand Down
44 changes: 22 additions & 22 deletions api/internal/handler/ssl/ssl_test.go
Expand Up @@ -289,8 +289,8 @@ func TestSSL_Create(t *testing.T) {
"version": "v2",
},
Snis: []string{"test2.com", "*.test2.com"},
ValidityStart: 1586038672,
ValidityEnd: 4739638672,
ValidityStart: 0,
ValidityEnd: 0,
Status: 1,
},
wantInput: &entity.SSL{
Expand All @@ -305,8 +305,8 @@ func TestSSL_Create(t *testing.T) {
"version": "v2",
},
Snis: []string{"test2.com", "*.test2.com"},
ValidityStart: 1586038672,
ValidityEnd: 4739638672,
ValidityStart: 0,
ValidityEnd: 0,
Status: 1,
},
wantRet: &entity.SSL{
Expand All @@ -321,8 +321,8 @@ func TestSSL_Create(t *testing.T) {
"version": "v2",
},
Snis: []string{"test2.com", "*.test2.com"},
ValidityStart: 1586038672,
ValidityEnd: 4739638672,
ValidityStart: 0,
ValidityEnd: 0,
Status: 1,
},
wantErr: nil,
Expand All @@ -349,8 +349,8 @@ func TestSSL_Create(t *testing.T) {
"version": "v2",
},
Snis: []string{"test2.com", "*.test2.com"},
ValidityStart: 1586038672,
ValidityEnd: 4739638672,
ValidityStart: 0,
ValidityEnd: 0,
Status: 1,
},
wantErr: fmt.Errorf("create failed"),
Expand Down Expand Up @@ -420,8 +420,8 @@ func TestSSL_Update(t *testing.T) {
"version": "v2",
},
Snis: []string{"test2.com", "*.test2.com"},
ValidityStart: 1586038672,
ValidityEnd: 4739638672,
ValidityStart: 0,
ValidityEnd: 0,
Status: 1,
},
wantInput: &entity.SSL{
Expand All @@ -436,8 +436,8 @@ func TestSSL_Update(t *testing.T) {
"version": "v2",
},
Snis: []string{"test2.com", "*.test2.com"},
ValidityStart: 1586038672,
ValidityEnd: 4739638672,
ValidityStart: 0,
ValidityEnd: 0,
Status: 1,
},
wantRet: &entity.SSL{
Expand All @@ -452,8 +452,8 @@ func TestSSL_Update(t *testing.T) {
"version": "v2",
},
Snis: []string{"test2.com", "*.test2.com"},
ValidityStart: 1586038672,
ValidityEnd: 4739638672,
ValidityStart: 0,
ValidityEnd: 0,
Status: 1,
},
},
Expand Down Expand Up @@ -562,8 +562,8 @@ func TestSSL_Patch(t *testing.T) {
"version": "v2",
},
Snis: []string{"test2.com", "*.test2.com"},
ValidityStart: 1586038672,
ValidityEnd: 4739638672,
ValidityStart: 0,
ValidityEnd: 0,
Status: 1,
},
giveInput: &PatchInput{
Expand Down Expand Up @@ -598,8 +598,8 @@ func TestSSL_Patch(t *testing.T) {
"version": "v2",
},
Snis: []string{"test2.com", "*.test2.com"},
ValidityStart: 1586038672,
ValidityEnd: 4739638672,
ValidityStart: 0,
ValidityEnd: 0,
Status: 1,
},
getCalled: true,
Expand All @@ -623,8 +623,8 @@ func TestSSL_Patch(t *testing.T) {
"version": "v2",
},
Snis: []string{"test2.com", "*.test2.com"},
ValidityStart: 1586038672,
ValidityEnd: 4739638672,
ValidityStart: 0,
ValidityEnd: 0,
Status: 1,
},
wantInput: &entity.SSL{
Expand Down Expand Up @@ -654,8 +654,8 @@ func TestSSL_Patch(t *testing.T) {
"version": "v2",
},
Snis: []string{"test2.com", "*.test2.com"},
ValidityStart: 1586038672,
ValidityEnd: 4739638672,
ValidityStart: 0,
ValidityEnd: 0,
Status: 1,
},
getCalled: true,
Expand Down

0 comments on commit da8e71e

Please sign in to comment.