invalid-port.t 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #
  2. # Licensed to the Apache Software Foundation (ASF) under one or more
  3. # contributor license agreements. See the NOTICE file distributed with
  4. # this work for additional information regarding copyright ownership.
  5. # The ASF licenses this file to You under the Apache License, Version 2.0
  6. # (the "License"); you may not use this file except in compliance with
  7. # the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. #
  17. use t::APISIX 'no_plan';
  18. no_root_location();
  19. run_tests();
  20. __DATA__
  21. === TEST 1: set upstream with a invalid node port
  22. --- config
  23. location /t {
  24. content_by_lua_block {
  25. local t = require("lib.test_admin").test
  26. local code, body = t('/apisix/admin/upstreams/1',
  27. ngx.HTTP_PUT,
  28. [[{
  29. "nodes": [{
  30. "port": 65536,
  31. "host": "127.0.0.1",
  32. "weight": 1
  33. }],
  34. "type": "roundrobin"
  35. }]]
  36. )
  37. ngx.status = code
  38. ngx.say(body)
  39. }
  40. }
  41. --- request
  42. GET /t
  43. --- error_code: 400
  44. --- response_body_like
  45. {"error_msg":"invalid configuration: property \\\"nodes\\\" validation failed: object matches none of the required"}
  46. === TEST 2: set upstream with a node port greater than 65535
  47. --- config
  48. location /t {
  49. content_by_lua_block {
  50. local t = require("lib.test_admin").test
  51. local code, body = t('/apisix/admin/upstreams/1',
  52. ngx.HTTP_PUT,
  53. [[{
  54. "nodes": {
  55. "127.0.0.1:65536": 1
  56. }
  57. }]]
  58. )
  59. ngx.status = code
  60. ngx.say(body)
  61. }
  62. }
  63. --- request
  64. GET /t
  65. --- error_code: 400
  66. --- response_body_like
  67. {"error_msg":"invalid port 65536"}
  68. === TEST 3: set upstream with a node port less than 1
  69. --- config
  70. location /t {
  71. content_by_lua_block {
  72. local t = require("lib.test_admin").test
  73. local code, body = t('/apisix/admin/upstreams/1',
  74. ngx.HTTP_PUT,
  75. [[{
  76. "nodes": {
  77. "127.0.0.1:0": 1
  78. }
  79. }]]
  80. )
  81. ngx.status = code
  82. ngx.say(body)
  83. }
  84. }
  85. --- request
  86. GET /t
  87. --- error_code: 400
  88. --- response_body_like
  89. {"error_msg":"invalid port 0"}