motiv-labs / janus

An API Gateway written in Go
https://hellofresh.gitbooks.io/janus
MIT License
2.8k stars 320 forks source link

API should validate empty upstreams target #251

Closed rafaeljesus closed 6 years ago

rafaeljesus commented 6 years ago

The API should validate empty upstreams target field

Reproduction Steps:

  1. Run janus server
  2. Send Post request to /apis to create a new proxy definition, where the json doesn't contains upstreams attribute

Expected behavior: API should run validations for upstreams field

Validation 1

When I send POST /apis With proxy definition

{
    "name": "test",
    "proxy": {
        "listen_path": "/example/*"
    }
}

Then API shoukd respond 400 And response json contains error: "proxy.upstreams field is required"

Validation 2

When I send POST /apis With proxy definition

{
    "name": "test",
    "proxy": {
        "listen_path": "/example/*",
                 "upstreams": {
                        "target": ""    
                 } 
    }
}

Then API shoukd respond 400 And response json contains error: "proxy.upstreams.target field is required"

Validation 3

When I send POST /apis With proxy definition

{
    "name": "test",
    "proxy": {
        "listen_path": "/example/*",
                 "upstreams": {
                        "target": "foo.io"    
                 } 
    }
}

Then API shoukd respond 400 And response json contains error: "proxy.upstreams.target field is invalid"

Janus version: latest OS and version: [Mac Sierra 10.12.6]