test_hostcheck.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright 2014 Michael Steinert
  3. *
  4. * Permission is hereby granted, free of charge, to any person
  5. * obtaining a copy of this software and associated documentation
  6. * files (the "Software"), to deal in the Software without
  7. * restriction, including without limitation the rights to use, copy,
  8. * modify, merge, publish, distribute, sublicense, and/or sell copies
  9. * of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be
  13. * included in all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  19. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  20. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22. * SOFTWARE.
  23. */
  24. #ifdef HAVE_CONFIG_H
  25. #include "config.h"
  26. #endif
  27. #include "amqp_hostcheck.h"
  28. #include <stdio.h>
  29. #include <stdlib.h>
  30. static void hostcheck_success(const char *match_pattern, const char *url) {
  31. int ok;
  32. ok = amqp_hostcheck(match_pattern, url);
  33. if (!ok) {
  34. fprintf(stderr, "Expected hostname check to pass, but didn't: %s (%s)\n",
  35. url, match_pattern);
  36. abort();
  37. }
  38. fprintf(stdout, "ok: [success] %s, %s\n", url, match_pattern);
  39. }
  40. static void hostcheck_fail(const char *match_pattern, const char *url) {
  41. int ok;
  42. ok = amqp_hostcheck(match_pattern, url);
  43. if (ok) {
  44. fprintf(stderr, "Expected hostname check to fail, but didn't: %s (%s)\n",
  45. url, match_pattern);
  46. abort();
  47. }
  48. fprintf(stdout, "ok: [fail] %s, %s\n", url, match_pattern);
  49. }
  50. int main(void) {
  51. hostcheck_success("www.rabbitmq.com", "www.rabbitmq.com");
  52. hostcheck_success("www.rabbitmq.com", "wWw.RaBbItMq.CoM");
  53. hostcheck_success("*.rabbitmq.com", "wWw.RaBbItMq.CoM");
  54. hostcheck_fail("rabbitmq.com", "www.rabbitmq.com");
  55. hostcheck_success("*.rabbitmq.com", "www.rabbitmq.com");
  56. hostcheck_fail("*.com", "www.rabbitmq.com");
  57. hostcheck_fail("*.rabbitmq.com", "long.url.rabbitmq.com");
  58. hostcheck_success("*.url.rabbitmq.com", "long.url.rabbitmq.com");
  59. return 0;
  60. }