Blame tests/test_hostcheck.c

Packit 12c978
/*
Packit 12c978
 * Copyright 2014 Michael Steinert
Packit 12c978
 *
Packit 12c978
 * Permission is hereby granted, free of charge, to any person
Packit 12c978
 * obtaining a copy of this software and associated documentation
Packit 12c978
 * files (the "Software"), to deal in the Software without
Packit 12c978
 * restriction, including without limitation the rights to use, copy,
Packit 12c978
 * modify, merge, publish, distribute, sublicense, and/or sell copies
Packit 12c978
 * of the Software, and to permit persons to whom the Software is
Packit 12c978
 * furnished to do so, subject to the following conditions:
Packit 12c978
 *
Packit 12c978
 * The above copyright notice and this permission notice shall be
Packit 12c978
 * included in all copies or substantial portions of the Software.
Packit 12c978
 *
Packit 12c978
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Packit 12c978
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Packit 12c978
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Packit 12c978
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
Packit 12c978
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
Packit 12c978
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
Packit 12c978
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
Packit 12c978
 * SOFTWARE.
Packit 12c978
 */
Packit 12c978
Packit 12c978
#ifdef HAVE_CONFIG_H
Packit 12c978
#include "config.h"
Packit 12c978
#endif
Packit 12c978
Packit 12c978
#include "amqp_hostcheck.h"
Packit 12c978
Packit 12c978
#include <stdio.h>
Packit 12c978
#include <stdlib.h>
Packit 12c978
Packit 12c978
static void hostcheck_success(const char *match_pattern, const char *url) {
Packit 12c978
  int ok;
Packit 12c978
Packit 12c978
  ok = amqp_hostcheck(match_pattern, url);
Packit 12c978
  if (!ok) {
Packit 12c978
    fprintf(stderr, "Expected hostname check to pass, but didn't: %s (%s)\n",
Packit 12c978
            url, match_pattern);
Packit 12c978
    abort();
Packit 12c978
  }
Packit 12c978
Packit 12c978
  fprintf(stdout, "ok: [success] %s, %s\n", url, match_pattern);
Packit 12c978
}
Packit 12c978
Packit 12c978
static void hostcheck_fail(const char *match_pattern, const char *url) {
Packit 12c978
  int ok;
Packit 12c978
Packit 12c978
  ok = amqp_hostcheck(match_pattern, url);
Packit 12c978
  if (ok) {
Packit 12c978
    fprintf(stderr, "Expected hostname check to fail, but didn't: %s (%s)\n",
Packit 12c978
            url, match_pattern);
Packit 12c978
    abort();
Packit 12c978
  }
Packit 12c978
Packit 12c978
  fprintf(stdout, "ok: [fail] %s, %s\n", url, match_pattern);
Packit 12c978
}
Packit 12c978
Packit 12c978
int main(void) {
Packit 12c978
  hostcheck_success("www.rabbitmq.com", "www.rabbitmq.com");
Packit 12c978
  hostcheck_success("www.rabbitmq.com", "wWw.RaBbItMq.CoM");
Packit 12c978
  hostcheck_success("*.rabbitmq.com", "wWw.RaBbItMq.CoM");
Packit 12c978
  hostcheck_fail("rabbitmq.com", "www.rabbitmq.com");
Packit 12c978
  hostcheck_success("*.rabbitmq.com", "www.rabbitmq.com");
Packit 12c978
  hostcheck_fail("*.com", "www.rabbitmq.com");
Packit 12c978
  hostcheck_fail("*.rabbitmq.com", "long.url.rabbitmq.com");
Packit 12c978
  hostcheck_success("*.url.rabbitmq.com", "long.url.rabbitmq.com");
Packit 12c978
Packit 12c978
  return 0;
Packit 12c978
}