test_sasl_mechanism.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright 2007 - 2021, Alan Antonuk and the rabbitmq-c contributors.
  2. // SPDX-License-Identifier: mit
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <amqp_socket.h>
  7. static void parse_success(amqp_bytes_t mechanisms,
  8. amqp_sasl_method_enum method) {
  9. if (!sasl_mechanism_in_list(mechanisms, method)) {
  10. fprintf(stderr, "Expected to find mechanism in list, but didn't: %s\n",
  11. (char *)mechanisms.bytes);
  12. abort();
  13. }
  14. }
  15. static void parse_fail(amqp_bytes_t mechanisms, amqp_sasl_method_enum method) {
  16. if (sasl_mechanism_in_list(mechanisms, method)) {
  17. fprintf(stderr,
  18. "Expected the mechanism not on the list, but it was present: %s\n",
  19. (char *)mechanisms.bytes);
  20. abort();
  21. }
  22. }
  23. int main(void) {
  24. parse_success(amqp_cstring_bytes("DIGEST-MD5 CRAM-MD5 LOGIN PLAIN"),
  25. AMQP_SASL_METHOD_PLAIN);
  26. parse_fail(amqp_cstring_bytes("DIGEST-MD5 CRAM-MD5 LOGIN PLAIN"),
  27. AMQP_SASL_METHOD_EXTERNAL);
  28. parse_success(amqp_cstring_bytes("DIGEST-MD5 CRAM-MD5 EXTERNAL"),
  29. AMQP_SASL_METHOD_EXTERNAL);
  30. parse_fail(amqp_cstring_bytes("DIGEST-MD5 CRAM-MD5 EXTERNAL"),
  31. AMQP_SASL_METHOD_PLAIN);
  32. return 0;
  33. }