weldr: make URL mandatory part of a new source

Sources without URL are useless. Make it mandatory.

Fixes: https://github.com/osbuild/osbuild-composer/issues/951
This commit is contained in:
Martin Sehnoutka 2020-09-04 10:26:46 +02:00 committed by Tom Gundersen
parent 951e5e66b6
commit 396c2cedce
2 changed files with 5 additions and 0 deletions

View file

@ -599,6 +599,8 @@ func (api *API) sourceNewHandler(writer http.ResponseWriter, request *http.Reque
err = errors_package.New("'name' field is missing from request")
} else if len(source.GetType()) == 0 {
err = errors_package.New("'type' field is missing from request")
} else if len(source.SourceConfig().URL) == 0 {
err = errors_package.New("'url' field is missing from request")
}
}

View file

@ -823,6 +823,9 @@ func TestSourcesNew(t *testing.T) {
// Bad JSON, missing quote after name
{"POST", "/api/v0/projects/source/new", `{"name: "fish","url": "https://download.opensuse.org/repositories/shells:/fish:/release:/3/Fedora_29/","type": "yum-baseurl","check_ssl": false,"check_gpg": false}`, http.StatusBadRequest, `{"errors": [{"id": "ProjectsError","msg": "Problem parsing POST body: invalid character 'f' after object key"}],"status":false}`},
{"POST", "/api/v0/projects/source/new", `{"name": "fish","url": "https://download.opensuse.org/repositories/shells:/fish:/release:/3/Fedora_29/","type": "yum-baseurl","check_ssl": false,"check_gpg": false}`, http.StatusOK, `{"status":true}`},
{"POST", "/api/v0/projects/source/new", `{"url": "https://download.opensuse.org/repositories/shells:/fish:/release:/3/Fedora_29/","type": "yum-baseurl","check_ssl": false,"check_gpg": false}`, http.StatusBadRequest, `{"errors": [{"id": "ProjectsError","msg": "Problem parsing POST body: 'name' field is missing from request"}],"status":false}`},
{"POST", "/api/v0/projects/source/new", `{"name": "fish", "type": "yum-baseurl","check_ssl": false,"check_gpg": false}`, http.StatusBadRequest, `{"errors": [{"id": "ProjectsError","msg": "Problem parsing POST body: 'url' field is missing from request"}],"status":false}`},
{"POST", "/api/v0/projects/source/new", `{"name": "fish", "url": "https://download.opensuse.org/repositories/shells:/fish:/release:/3/Fedora_29/","check_ssl": false,"check_gpg": false}`, http.StatusBadRequest, `{"errors": [{"id": "ProjectsError","msg": "Problem parsing POST body: 'type' field is missing from request"}],"status":false}`},
}
for _, c := range cases {