grpc-proxy-unary.t 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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_long_string();
  19. no_root_location();
  20. no_shuffle();
  21. add_block_preprocessor(sub {
  22. my ($block) = @_;
  23. if (!$block->request) {
  24. $block->set_value("request", "GET /t");
  25. }
  26. if (!$block->no_error_log && !$block->error_log) {
  27. $block->set_value("no_error_log", "[error]\n[alert]");
  28. }
  29. });
  30. run_tests;
  31. __DATA__
  32. === TEST 1: Unary API gRPC proxy
  33. --- http2
  34. --- apisix_yaml
  35. routes:
  36. -
  37. id: 1
  38. uris:
  39. - /helloworld.Greeter/SayHello
  40. methods: [
  41. POST
  42. ]
  43. upstream:
  44. scheme: grpc
  45. nodes:
  46. "127.0.0.1:10051": 1
  47. type: roundrobin
  48. #END
  49. --- exec
  50. grpcurl -import-path ./t/grpc_server_example/proto -proto helloworld.proto -plaintext -d '{"name":"apisix"}' 127.0.0.1:1984 helloworld.Greeter.SayHello
  51. --- response_body
  52. {
  53. "message": "Hello apisix"
  54. }
  55. === TEST 2: Unary API gRPC proxy test [the old way]
  56. --- http2
  57. --- apisix_yaml
  58. routes:
  59. -
  60. id: 1
  61. uris:
  62. - /helloworld.Greeter/SayHello
  63. methods: [
  64. POST
  65. ]
  66. upstream:
  67. scheme: grpc
  68. nodes:
  69. "127.0.0.1:10051": 1
  70. type: roundrobin
  71. #END
  72. --- exec
  73. grpcurl -import-path ./t/grpc_server_example/proto -proto helloworld.proto -plaintext -d '{"name":"apisix"}' 127.0.0.1:1984 helloworld.Greeter.SayHello
  74. --- response_body
  75. {
  76. "message": "Hello apisix"
  77. }
  78. === TEST 3: Unary API grpcs proxy test
  79. --- http2
  80. --- apisix_yaml
  81. routes:
  82. -
  83. id: 1
  84. uris:
  85. - /helloworld.Greeter/SayHello
  86. methods: [
  87. POST
  88. ]
  89. upstream:
  90. scheme: grpcs
  91. nodes:
  92. "127.0.0.1:10052": 1
  93. type: roundrobin
  94. #END
  95. --- exec
  96. grpcurl -import-path ./t/grpc_server_example/proto -proto helloworld.proto -plaintext -d '{"name":"apisix"}' 127.0.0.1:1984 helloworld.Greeter.SayHello
  97. --- response_body
  98. {
  99. "message": "Hello apisix"
  100. }
  101. === TEST 4: Unary API gRPC proxy with tls
  102. --- http2
  103. --- apisix_yaml
  104. ssls:
  105. -
  106. id: 1
  107. cert: "-----BEGIN CERTIFICATE-----\nMIIEojCCAwqgAwIBAgIJAK253pMhgCkxMA0GCSqGSIb3DQEBCwUAMFYxCzAJBgNV\nBAYTAkNOMRIwEAYDVQQIDAlHdWFuZ0RvbmcxDzANBgNVBAcMBlpodUhhaTEPMA0G\nA1UECgwGaXJlc3R5MREwDwYDVQQDDAh0ZXN0LmNvbTAgFw0xOTA2MjQyMjE4MDVa\nGA8yMTE5MDUzMTIyMTgwNVowVjELMAkGA1UEBhMCQ04xEjAQBgNVBAgMCUd1YW5n\nRG9uZzEPMA0GA1UEBwwGWmh1SGFpMQ8wDQYDVQQKDAZpcmVzdHkxETAPBgNVBAMM\nCHRlc3QuY29tMIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAyCM0rqJe\ncvgnCfOw4fATotPwk5Ba0gC2YvIrO+gS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k5oFDebimuSk\nlQkv1pXUOqh+xSAwk5v88dBAfh2dnnSa8HFN3oz+ZfQYtnBcc4DR1y2X+fVNgr3i\nnxruU2gsAIPFRnmvwKPc1YIH9A6kIzqaoNt1f9VM243D6fNzkO4uztWEApBkkJgR\n4s/yOjp6ovS9JG1NMXWjXQPcwTq3sQVLnAHxZRJmOvx69UmK4QKBwFYXXjeXiU3d\nbcrPfe6qNGjfzK+BkhWznuFUMbuxyZWDYQD5yb6ukUosrj7pmZv3BxKcKCvmONU+\nCHgIXB+hG+R9S2mCcH1qBQoP/RSm+TUzS/Bl2UeuhnFZh2jSZQy3OwryUi6nhF0u\nLDzMI/6aO1ggsI23Ri0Y9ZtqVKczTkxzdQKR9xvoNBUufjimRlS80sJCEB3Qm20S\nwzarryret/7GFW1/3cz+hTj9/d45i25zArr3Pocfpur5mfz3fJO8jg==\n-----END RSA PRIVATE KEY-----\n"
  109. sni: test.com
  110. routes:
  111. -
  112. id: 1
  113. uris:
  114. - /helloworld.Greeter/SayHello
  115. methods: [
  116. POST
  117. ]
  118. upstream:
  119. scheme: grpc
  120. nodes:
  121. "127.0.0.1:10051": 1
  122. type: roundrobin
  123. #END
  124. --- exec
  125. grpcurl -import-path ./t/grpc_server_example/proto -proto helloworld.proto -insecure -d '{"name":"apisix"}' test.com:1994 helloworld.Greeter.SayHello
  126. --- response_body
  127. {
  128. "message": "Hello apisix"
  129. }