Commit 71a69b25 authored by Geoff Simmons's avatar Geoff Simmons

REST API: test error response for /v1/pems.

parent 64ccf633
......@@ -83,6 +83,15 @@ var (
ModTime: time.Date(2020, 7, 27, 9, 51, 0, 0, time.UTC),
}
invalidFile = &pem.File{
Namespace: "invalid",
Name: "crt",
UID: "9396fc87-23eb-480a-8437-f9767df13ed8",
ResourceVersion: "123456",
Size: 132,
ModTime: time.Date(2020, 7, 28, 6, 9, 0, 0, time.UTC),
}
expWhiskeyCrt = pem.Crt{
Version: 3,
SN: "2f:6d:d8:e4:83:f0:e7:44:4d:3a:cc:97:52:0e:18:93:d7:a5:1f:0d",
......@@ -325,6 +334,47 @@ func TestAllPems(t *testing.T) {
if len(allInfo) != 0 {
t.Fatalf("GET /v1/pems len(slice) got %d want 0", len(allInfo))
}
files.Files["invalid/crt"] = invalidFile
req = httptest.NewRequest(http.MethodGet, "/v1/pems", nil)
rr = httptest.NewRecorder()
hndlr.ServeHTTP(rr, req)
if rr.Code != http.StatusInternalServerError {
t.Errorf("GET /v1/pems status: got %d want %d", rr.Code,
http.StatusInternalServerError)
}
if rr.Header().Get("Content-Type") != problemContentType {
t.Errorf("GET /v1/pems Content-Type: got %s want %s",
rr.Header().Get("Content-Type"), problemContentType)
}
bodylen := len(rr.Body.String())
if rr.Header().Get("Content-Length") != strconv.Itoa(bodylen) {
t.Errorf("GET /v1/pems Content-Length: got %s want %d",
rr.Header().Get("Content-Length"), bodylen)
}
problem := &Problem{}
if err = json.Unmarshal(rr.Body.Bytes(), problem); err != nil {
t.Fatalf("GET /v1/pems body unmarshal: %v", err)
}
if problem.Type != errPemsReadErr.Type {
t.Errorf("GET /v1/pems problem type: got %s want %s",
problem.Type, errPemsReadErr.Type)
}
if problem.Title != errPemsReadErr.Title {
t.Errorf("GET /v1/pems problem title: got %s want %s",
problem.Title, errPemsReadErr.Title)
}
if len(problem.Detail) == 0 {
t.Error("GET /v1/pems problem detail empty")
}
if problem.Status != http.StatusInternalServerError {
t.Errorf("GET /v1/pems problem status: got %d want %d",
problem.Status, http.StatusInternalServerError)
}
if !errInstancePattern.Match([]byte(problem.Instance)) {
t.Errorf("GET /v1/pems problem instance: "+
"got %s want /log/errors/N", problem.Instance)
}
}
func TestAllPems405(t *testing.T) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment