badreq.cc 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. *
  3. * Copyright 2015 gRPC authors.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * 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. */
  18. #include <string.h>
  19. #include <grpc/grpc.h>
  20. #include "src/core/lib/surface/server.h"
  21. #include "test/core/bad_client/bad_client.h"
  22. #include "test/core/end2end/cq_verifier.h"
  23. #define PFX_STR \
  24. "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" \
  25. "\x00\x00\x00\x04\x00\x00\x00\x00\x00" /* settings frame */
  26. static void verifier(grpc_server* server, grpc_completion_queue* cq,
  27. void* /*registered_method*/) {
  28. while (grpc_core::Server::FromC(server)->HasOpenConnections()) {
  29. GPR_ASSERT(grpc_completion_queue_next(
  30. cq, grpc_timeout_milliseconds_to_deadline(20), nullptr)
  31. .type == GRPC_QUEUE_TIMEOUT);
  32. }
  33. }
  34. int main(int argc, char** argv) {
  35. grpc::testing::TestEnvironment env(argc, argv);
  36. grpc_init();
  37. /* invalid content type */
  38. GRPC_RUN_BAD_CLIENT_TEST(
  39. verifier, nullptr,
  40. PFX_STR
  41. "\x00\x00\xc2\x01\x04\x00\x00\x00\x01"
  42. "\x10\x05:path\x08/foo/bar"
  43. "\x10\x07:scheme\x04http"
  44. "\x10\x07:method\x04POST"
  45. "\x10\x0a:authority\x09localhost"
  46. "\x10\x0c"
  47. "content-type\x09text/html"
  48. "\x10\x14grpc-accept-encoding\x15identity,deflate,gzip"
  49. "\x10\x02te\x08trailers"
  50. "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)",
  51. GRPC_BAD_CLIENT_DISCONNECT);
  52. /* invalid te */
  53. GRPC_RUN_BAD_CLIENT_TEST(
  54. verifier, nullptr,
  55. PFX_STR
  56. "\x00\x00\xcb\x01\x04\x00\x00\x00\x01"
  57. "\x10\x05:path\x08/foo/bar"
  58. "\x10\x07:scheme\x04http"
  59. "\x10\x07:method\x04POST"
  60. "\x10\x0a:authority\x09localhost"
  61. "\x10\x0c"
  62. "content-type\x10"
  63. "application/grpc"
  64. "\x10\x14grpc-accept-encoding\x15identity,deflate,gzip"
  65. "\x10\x02te\x0a"
  66. "frobnicate"
  67. "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)",
  68. GRPC_BAD_CLIENT_DISCONNECT);
  69. /* two path headers */
  70. GRPC_RUN_BAD_CLIENT_TEST(
  71. verifier, nullptr,
  72. PFX_STR
  73. "\x00\x00\xd9\x01\x04\x00\x00\x00\x01"
  74. "\x10\x05:path\x08/foo/bar"
  75. "\x10\x05:path\x08/foo/bah"
  76. "\x10\x07:scheme\x04http"
  77. "\x10\x07:method\x04POST"
  78. "\x10\x0a:authority\x09localhost"
  79. "\x10\x0c"
  80. "content-type\x10"
  81. "application/grpc"
  82. "\x10\x14grpc-accept-encoding\x15identity,deflate,gzip"
  83. "\x10\x02te\x08trailers"
  84. "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)",
  85. GRPC_BAD_CLIENT_DISCONNECT);
  86. /* bad accept-encoding algorithm */
  87. GRPC_RUN_BAD_CLIENT_TEST(
  88. verifier, nullptr,
  89. PFX_STR
  90. "\x00\x00\xd2\x01\x04\x00\x00\x00\x01"
  91. "\x10\x05:path\x08/foo/bar"
  92. "\x10\x07:scheme\x04http"
  93. "\x10\x07:method\x04POST"
  94. "\x10\x0a:authority\x09localhost"
  95. "\x10\x0c"
  96. "content-type\x10"
  97. "application/grpc"
  98. "\x10\x14grpc-accept-encoding\x1enobody-knows-the-trouble-i-see"
  99. "\x10\x02te\x08trailers"
  100. "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)",
  101. GRPC_BAD_CLIENT_DISCONNECT);
  102. /* bad grpc-encoding algorithm */
  103. GRPC_RUN_BAD_CLIENT_TEST(
  104. verifier, nullptr,
  105. PFX_STR
  106. "\x00\x00\xf5\x01\x04\x00\x00\x00\x01"
  107. "\x10\x05:path\x08/foo/bar"
  108. "\x10\x07:scheme\x04http"
  109. "\x10\x07:method\x04POST"
  110. "\x10\x0a:authority\x09localhost"
  111. "\x10\x0c"
  112. "content-type\x10"
  113. "application/grpc"
  114. "\x10\x14grpc-accept-encoding\x15identity,deflate,gzip"
  115. "\x10\x0dgrpc-encoding\x1cyou-dont-know-how-to-do-this"
  116. "\x10\x02te\x08trailers"
  117. "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)",
  118. GRPC_BAD_CLIENT_DISCONNECT);
  119. grpc_shutdown();
  120. return 0;
  121. }