Skip to content

Commit

Permalink
Eskip check fails on empty URL on network backend. (#2524)
Browse files Browse the repository at this point in the history
* Eskip check fails on empty URL on network backend. (#2524)

Signed-off-by: Xavi Ivars <[email protected]>
  • Loading branch information
xavivars authored Aug 18, 2023
1 parent 65016ea commit e5e23a8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
17 changes: 16 additions & 1 deletion cmd/eskip/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,23 @@ func checkRepeatedRouteIds(routes []*eskip.Route) error {
ids := map[string]bool{}
for _, route := range routes {
if ids[route.Id] {
return errors.New("Repeating route with id " + route.Id)
return fmt.Errorf("repeating route with id %s", route.Id)
}
ids[route.Id] = true
}
return nil
}

func checkEmptyBackends(routes []*eskip.Route) error {
for _, route := range routes {
if route.BackendType == eskip.NetworkBackend && route.Backend == "" {
return fmt.Errorf("route has empty backend: %s", route.Id)
}
}

return nil
}

// load and parse routes, ignore parse errors.
func loadRoutesUnchecked(in *medium) []*eskip.Route {
lr, _ := loadRoutes(in)
Expand All @@ -104,6 +114,11 @@ func checkCmd(a cmdArgs) error {
return err
}

err = checkEmptyBackends(routes)
if err != nil {
return err
}

return checkRepeatedRouteIds(routes)
}

Expand Down
15 changes: 15 additions & 0 deletions cmd/eskip/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,21 @@ func TestCheckRepeatingRouteIds(t *testing.T) {
}
}

func TestCheckEmptyBackend(t *testing.T) {
const name = "testFile"

err := withFile(name, `foo: Method("POST") -> "https://www.example1.org";empty: Method("POST") -> "";`, func(_ *os.File) {
err := checkCmd(cmdArgs{in: &medium{typ: file, path: name}})
if err == nil || err.Error() != "route has empty backend: empty" {
t.Error("Expected an error for empty backend")
}
})

if err != nil {
t.Error(err)
}
}

func TestCheckEtcdInvalid(t *testing.T) {
if testing.Short() {
t.Skip()
Expand Down

0 comments on commit e5e23a8

Please sign in to comment.