weldr: Adding sources with empty name should return an error

Currently, if a TOML source is added with no name, or the source is
incorrectly inside a [section] it will add an empty source, causing
depsolving to crash.

This adds tests for 'name' and 'type' fields as a minimum requirement,
and returns an API error if they are empty or missing.

This also includes unit and integration tests.

Closes PR#462
This commit is contained in:
Brian C. Lane 2020-04-03 10:30:45 -07:00 committed by Tom Gundersen
parent 58c16f1e6d
commit 0eb3bfe89a
3 changed files with 53 additions and 0 deletions

View file

@ -109,6 +109,25 @@ func TestPOSTInvalidTOMLSourceV0(t *testing.T) {
require.False(t, resp.Status, "did not return an error")
}
// POST a wrong TOML source
func TestPOSTWrongTOMLSourceV0(t *testing.T) {
// Should not have a [] section
source := `
[package-repo-toml-v0]
name = "package-repo-toml-v0"
url = "file://REPO-PATH
type = "yum-baseurl"
proxy = "https://proxy-url/"
check_ssl = true
check_gpg = true
gpgkey_urls = ["https://url/path/to/gpg-key"]
`
resp, err := PostTOMLSourceV0(testState.socket, source)
require.NoError(t, err, "POST source failed with a client error")
require.False(t, resp.Status, "did not return an error")
}
// list sources
func TestListSourcesV0(t *testing.T) {
sources := []string{`{