@@ -374,6 +374,67 @@ defmodule RigApi.V1.APIsTest do
374374 }
375375 end
376376
377+ test "should return 400 when 'endpoint' has 'path' and 'path_regex' set at the same time" do
378+ endpoints = [
379+ % {
380+ "id" => @ invalid_config_id <> "1" ,
381+ "method" => "GET" ,
382+ "path" => "/" ,
383+ "path_regex" => "/"
384+ }
385+ ]
386+
387+ new_api = ProxyConfig . create_proxy_config ( @ invalid_config_id , endpoints )
388+ conn = build_conn ( ) |> put ( "/v1/apis/#{ @ invalid_config_id } " , new_api )
389+ response = json_response ( conn , 400 )
390+
391+ assert response == % {
392+ "invalid-config/invalid-config1" => [
393+ % { "path, path_regex" => "You can't set path and path_regex at the same time" }
394+ ]
395+ }
396+ end
397+
398+ test "should return 400 when when 'path' is set, but incorrect" do
399+ endpoints = [
400+ % {
401+ "id" => @ invalid_config_id <> "1" ,
402+ "method" => "GET" ,
403+ "path" => ""
404+ }
405+ ]
406+
407+ new_api = ProxyConfig . create_proxy_config ( @ invalid_config_id , endpoints )
408+ conn = build_conn ( ) |> put ( "/v1/apis/#{ @ invalid_config_id } " , new_api )
409+ response = json_response ( conn , 400 )
410+
411+ assert response == % {
412+ "invalid-config/invalid-config1" => [
413+ % { "path" => "must have a length of at least 1" }
414+ ]
415+ }
416+ end
417+
418+ test "should return 400 when when 'path_regex' is set, but incorrect" do
419+ endpoints = [
420+ % {
421+ "id" => @ invalid_config_id <> "1" ,
422+ "method" => "GET" ,
423+ "path_regex" => ""
424+ }
425+ ]
426+
427+ new_api = ProxyConfig . create_proxy_config ( @ invalid_config_id , endpoints )
428+ conn = build_conn ( ) |> put ( "/v1/apis/#{ @ invalid_config_id } " , new_api )
429+ response = json_response ( conn , 400 )
430+
431+ assert response == % {
432+ "invalid-config/invalid-config1" => [
433+ % { "path_regex" => "must have a length of at least 1" }
434+ ]
435+ }
436+ end
437+
377438 test "should return 400 when target is set to kafka or kinesis, but topic is not" do
378439 # kinesis topic not set
379440 endpoints = [
0 commit comments