github.com/hellofresh/janus@v0.0.0-20230925145208-ce8de8183c67/features/Proxy.feature (about) 1 Feature: Proxy requests to upstream. 2 3 Background: 4 Given request JWT token is valid admin token 5 6 Scenario: Proxy request to existing mock service 7 Given request JSON payload: 8 """ 9 { 10 "name":"example", 11 "active":true, 12 "proxy":{ 13 "preserve_host":false, 14 "listen_path":"/example/*", 15 "upstreams":{ 16 "balancing":"roundrobin", 17 "targets":[ 18 { 19 "target":"http://localhost:9089/hello-world" 20 } 21 ] 22 }, 23 "strip_path":false, 24 "append_path":false, 25 "methods":[ 26 "GET" 27 ] 28 }, 29 "health_check":{ 30 "url":"https://example.com/status" 31 } 32 } 33 """ 34 When I request "/apis" API path with "POST" method 35 Then I should receive 201 response code 36 And header "Location" should be "/apis/example" 37 38 Given request JSON payload: 39 """ 40 { 41 "name":"posts", 42 "active":true, 43 "proxy":{ 44 "preserve_host":false, 45 "listen_path":"/posts/*", 46 "upstreams":{ 47 "balancing":"roundrobin", 48 "targets":[ 49 { 50 "target":"http://localhost:9089/posts" 51 } 52 ] 53 }, 54 "strip_path":true, 55 "append_path":false, 56 "methods":[ 57 "ALL" 58 ], 59 "hosts":[ 60 "hellofresh.*" 61 ] 62 }, 63 "plugins":[ 64 { 65 "name":"cors", 66 "enabled":true, 67 "config":{ 68 "domains":[ 69 "*" 70 ], 71 "methods":[ 72 "GET", 73 "POST", 74 "PUT", 75 "PATCH", 76 "DELETE" 77 ], 78 "request_headers":[ 79 "Origin", 80 "Authorization", 81 "Content-Type" 82 ], 83 "exposed_headers":[ 84 "X-Debug-Token", 85 "X-Debug-Token-Link" 86 ] 87 } 88 }, 89 { 90 "name":"rate_limit", 91 "enabled":true, 92 "config":{ 93 "limit":"10-S", 94 "policy":"local" 95 } 96 }, 97 { 98 "name":"oauth2", 99 "enabled":true, 100 "config":{ 101 "server_name":"local" 102 } 103 }, 104 { 105 "name":"compression", 106 "enabled":true 107 } 108 ] 109 } 110 """ 111 When I request "/apis" API path with "POST" method 112 Then I should receive 201 response code 113 And header "Location" should be "/apis/posts" 114 115 Given request JSON payload: 116 """ 117 { 118 "name":"posts-public", 119 "active":true, 120 "proxy":{ 121 "preserve_host":false, 122 "listen_path":"/posts-public/*", 123 "upstreams":{ 124 "balancing":"roundrobin", 125 "targets":[ 126 { 127 "target":"http://localhost:9089/posts" 128 } 129 ] 130 }, 131 "strip_path":true, 132 "append_path":false, 133 "methods":[ 134 "ALL" 135 ] 136 }, 137 "plugins":[ 138 { 139 "name":"cors", 140 "enabled":true, 141 "config":{ 142 "domains":[ 143 "*" 144 ], 145 "methods":[ 146 "GET", 147 "POST", 148 "PUT", 149 "PATCH", 150 "DELETE" 151 ], 152 "request_headers":[ 153 "Origin", 154 "Authorization", 155 "Content-Type" 156 ], 157 "exposed_headers":[ 158 "X-Debug-Token", 159 "X-Debug-Token-Link" 160 ] 161 } 162 }, 163 { 164 "name":"rate_limit", 165 "enabled":true, 166 "config":{ 167 "limit":"10-S", 168 "policy":"local" 169 } 170 }, 171 { 172 "name":"oauth2", 173 "enabled":true, 174 "config":{ 175 "server_name":"local" 176 } 177 }, 178 { 179 "name":"compression", 180 "enabled":true 181 } 182 ] 183 } 184 """ 185 When I request "/apis" API path with "POST" method 186 Then I should receive 201 response code 187 And header "Location" should be "/apis/posts-public" 188 189 When I request "/example" path with "GET" method 190 Then I should receive 200 response code 191 And response JSON body has "hello" path with value 'world' 192 193 When I request "/example/nested/path" path with "GET" method 194 Then I should receive 200 response code 195 And response JSON body has "hello" path with value 'world' 196 197 When I request "/posts" path with "GET" method 198 Then I should receive 404 response code 199 And the response should contain "no API found with those values" 200 201 When I request "/posts-public" path with "GET" method 202 Then I should receive 200 response code 203 And response JSON body is an array of length 100 204 205 When I request "/posts-public/nested/path" path with "GET" method 206 Then I should receive 404 response code 207 208 Given request JSON payload: 209 """ 210 { 211 "name":"one-parameter", 212 "active":true, 213 "proxy":{ 214 "preserve_host":false, 215 "listen_path":"/api/recipes/{id:[\\da-f]{24}}", 216 "upstreams":{ 217 "balancing":"roundrobin", 218 "targets":[ 219 { 220 "target":"http://localhost:9089/recipes/{id}" 221 } 222 ] 223 }, 224 "strip_path":false, 225 "append_path":false, 226 "methods":[ 227 "GET" 228 ] 229 }, 230 "health_check":{ 231 "url":"https://example.com/status" 232 } 233 } 234 """ 235 When I request "/apis" API path with "POST" method 236 Then I should receive 201 response code 237 238 And I request "/api/recipes/5252b1b5301bbf46038b473f" path with "GET" method 239 Then I should receive 200 response code 240 And the response should contain "I'm a slug" 241 242 Given request JSON payload: 243 """ 244 { 245 "name":"two-parameters", 246 "active":true, 247 "proxy":{ 248 "preserve_host":false, 249 "listen_path":"/api/recipes/{recipeId:[\\da-f]{24}}/menus/{menuId:[\\da-f]{24}}", 250 "upstreams":{ 251 "balancing":"roundrobin", 252 "targets":[ 253 { 254 "target":"http://localhost:9089/recipes/{recipeId}/menus/{menuId}" 255 } 256 ] 257 }, 258 "strip_path":false, 259 "append_path":false, 260 "methods":[ 261 "GET" 262 ] 263 }, 264 "health_check":{ 265 "url":"https://example.com/status" 266 } 267 } 268 """ 269 When I request "/apis" API path with "POST" method 270 Then I should receive 201 response code 271 272 And I request "/api/recipes/5252b1b5301bbf46038b473f/menus/6362b1b5301bbf46038b4766" path with "GET" method 273 Then I should receive 200 response code 274 And the response should contain "A menu description" 275 276 Given request JSON payload: 277 """ 278 { 279 "name":"dynamic-host", 280 "active":true, 281 "proxy":{ 282 "preserve_host":false, 283 "listen_path":"/{service}/example", 284 "upstreams":{ 285 "balancing":"roundrobin", 286 "targets":[ 287 { 288 "target":"http://{service}:9089/hello-world" 289 } 290 ] 291 }, 292 "strip_path":false, 293 "append_path":false, 294 "methods":[ 295 "GET" 296 ] 297 }, 298 "health_check":{ 299 "url":"https://example.com/status" 300 } 301 } 302 """ 303 When I request "/apis" API path with "POST" method 304 Then I should receive 201 response code 305 And header "Location" should be "/apis/dynamic-host" 306 307 When I request "/unknown/example" path with "GET" method 308 Then I should receive 502 response code 309 310 And I request "/localhost/example" path with "GET" method 311 Then I should receive 200 response code