forked from openservicemesh/osm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcertificate_test.go
46 lines (35 loc) · 1.27 KB
/
certificate_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package debugger
import (
"net/http/httptest"
"testing"
"time"
"github.com/golang/mock/gomock"
tassert "github.com/stretchr/testify/assert"
"github.com/openservicemesh/osm/pkg/certificate"
"github.com/openservicemesh/osm/pkg/certificate/providers/tresor"
)
// Tests getCertificateHandler through HTTP handler returns a certificate stringified
func TestGetCertHandler(t *testing.T) {
assert := tassert.New(t)
mockCtrl := gomock.NewController(t)
mock := NewMockCertificateManagerDebugger(mockCtrl)
ds := DebugConfig{
certDebugger: mock,
}
testCert, err := tresor.NewCA("commonName", 1*time.Hour, "Country", "Locale", "Org")
assert.Nil(err)
// mock expected cert
mock.EXPECT().ListIssuedCertificates().Return([]*certificate.Certificate{
testCert,
})
handler := ds.getCertHandler()
responseRecorder := httptest.NewRecorder()
handler.ServeHTTP(responseRecorder, nil)
actualResponseBody := responseRecorder.Body.String()
assert.Contains(actualResponseBody, "Common Name")
assert.Contains(actualResponseBody, "Valid Until")
assert.Contains(actualResponseBody, "Cert Chain (SHA256)")
assert.Contains(actualResponseBody, "x509.SignatureAlgorithm")
assert.Contains(actualResponseBody, "x509.PublicKeyAlgorithm")
assert.Contains(actualResponseBody, "x509.SerialNumber")
}