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