weldr: Return an error when an empty blueprint is received
The JSON and TOML parsers differ in how they handle an empty body so check for a ContentLength of zero first and return a "Missing blueprint" error to the client. Includes updated tests for the JSON path, and new tests for empty TOML blueprints.
This commit is contained in:
parent
77fd2a0d8b
commit
7bd020ca11
2 changed files with 48 additions and 2 deletions
|
|
@ -74,7 +74,7 @@ func TestBlueprintsNew(t *testing.T) {
|
|||
{"POST", "/api/v0/blueprints/new", `{"name":"test","description":"Test","packages":[],"version":""}`, http.StatusOK, `{"status":true}`},
|
||||
{"POST", "/api/v0/blueprints/new", `{"name":"test","description":"Test","packages":[{"name":"httpd","version":"2.4.*"}],"version":"0.0.0"}`, http.StatusOK, `{"status":true}`},
|
||||
{"POST", "/api/v0/blueprints/new", `{"name":"test","description":"Test","packages:}`, http.StatusBadRequest, `{"status":false,"errors":[{"id":"BlueprintsError","msg":"400 Bad Request: The browser (or proxy) sent a request that this server could not understand: unexpected EOF"}]}`},
|
||||
{"POST", "/api/v0/blueprints/new", ``, http.StatusBadRequest, `{"status":false,"errors":[{"id":"BlueprintsError","msg":"400 Bad Request: The browser (or proxy) sent a request that this server could not understand: EOF"}]}`},
|
||||
{"POST", "/api/v0/blueprints/new", ``, http.StatusBadRequest, `{"status":false,"errors":[{"id":"BlueprintsError","msg":"Missing blueprint"}]}`},
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
|
|
@ -106,6 +106,20 @@ version = "2.4.*"`
|
|||
}
|
||||
}
|
||||
|
||||
func TestBlueprintsEmptyToml(t *testing.T) {
|
||||
req := httptest.NewRequest("POST", "/api/v0/blueprints/new", bytes.NewReader(nil))
|
||||
req.Header.Set("Content-Type", "text/x-toml")
|
||||
recorder := httptest.NewRecorder()
|
||||
|
||||
api, _ := createWeldrAPI(rpmmd_mock.BaseFixture)
|
||||
api.ServeHTTP(recorder, req)
|
||||
|
||||
r := recorder.Result()
|
||||
if r.StatusCode != http.StatusBadRequest {
|
||||
t.Fatalf("unexpected status %v", r.StatusCode)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBlueprintsInvalidToml(t *testing.T) {
|
||||
blueprint := `
|
||||
name = "test"
|
||||
|
|
@ -139,7 +153,7 @@ func TestBlueprintsWorkspaceJSON(t *testing.T) {
|
|||
}{
|
||||
{"POST", "/api/v0/blueprints/workspace", `{"name":"test","description":"Test","packages":[{"name":"systemd","version":"123"}],"version":"0.0.0"}`, http.StatusOK, `{"status":true}`},
|
||||
{"POST", "/api/v0/blueprints/workspace", `{"name":"test","description":"Test","packages:}`, http.StatusBadRequest, `{"status":false,"errors":[{"id":"BlueprintsError","msg":"400 Bad Request: The browser (or proxy) sent a request that this server could not understand: unexpected EOF"}]}`},
|
||||
{"POST", "/api/v0/blueprints/workspace", ``, http.StatusBadRequest, `{"status":false,"errors":[{"id":"BlueprintsError","msg":"400 Bad Request: The browser (or proxy) sent a request that this server could not understand: EOF"}]}`},
|
||||
{"POST", "/api/v0/blueprints/workspace", ``, http.StatusBadRequest, `{"status":false,"errors":[{"id":"BlueprintsError","msg":"Missing blueprint"}]}`},
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
|
|
@ -171,6 +185,20 @@ version = "2.4.*"`
|
|||
}
|
||||
}
|
||||
|
||||
func TestBlueprintsWorkspaceEmptyTOML(t *testing.T) {
|
||||
req := httptest.NewRequest("POST", "/api/v0/blueprints/workspace", bytes.NewReader(nil))
|
||||
req.Header.Set("Content-Type", "text/x-toml")
|
||||
recorder := httptest.NewRecorder()
|
||||
|
||||
api, _ := createWeldrAPI(rpmmd_mock.BaseFixture)
|
||||
api.ServeHTTP(recorder, req)
|
||||
|
||||
r := recorder.Result()
|
||||
if r.StatusCode != http.StatusBadRequest {
|
||||
t.Fatalf("unexpected status %v", r.StatusCode)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBlueprintsWorkspaceInvalidTOML(t *testing.T) {
|
||||
blueprint := `
|
||||
name = "test"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue