2006-12-16 00:42:13 +00:00
|
|
|
/*
|
2014-06-01 08:46:42 +02:00
|
|
|
* Copyright (c) 2006-2014 Erik Ekman <yarrick@kryo.se>,
|
|
|
|
* 2006-2009 Bjorn Andersson <flex@kryo.se>
|
2006-12-16 00:42:13 +00:00
|
|
|
*
|
2014-08-07 21:14:10 +02:00
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
2006-12-16 00:42:13 +00:00
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <check.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "encoding.h"
|
|
|
|
#include "test.h"
|
|
|
|
|
2009-09-20 08:43:49 +00:00
|
|
|
#define TUPLES 4
|
|
|
|
|
|
|
|
static struct tuple
|
2006-12-16 00:42:13 +00:00
|
|
|
{
|
2007-06-09 16:57:33 +00:00
|
|
|
char *a;
|
|
|
|
char *b;
|
|
|
|
} dottests[] = {
|
2008-07-12 20:57:30 +00:00
|
|
|
{ "aaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
2008-12-27 00:40:30 +00:00
|
|
|
"aaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaa"},
|
|
|
|
{ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
|
|
|
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa."},
|
2009-01-16 18:51:54 +00:00
|
|
|
{ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
|
|
|
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"},
|
2007-06-09 16:57:33 +00:00
|
|
|
{ "abc123", "abc123" },
|
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
START_TEST(test_inline_dotify)
|
|
|
|
{
|
|
|
|
char temp[1024];
|
|
|
|
char *b;
|
|
|
|
|
2009-09-20 08:43:49 +00:00
|
|
|
memset(temp, 0, sizeof(temp));
|
|
|
|
strcpy(temp, dottests[_i].a);
|
|
|
|
b = temp;
|
|
|
|
inline_dotify(b, sizeof(temp));
|
2007-06-09 16:57:33 +00:00
|
|
|
|
2021-08-24 23:07:36 +02:00
|
|
|
ck_assert_str_eq(dottests[_i].b, temp);
|
2007-06-09 16:57:33 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST(test_inline_undotify)
|
|
|
|
{
|
|
|
|
char temp[1024];
|
|
|
|
char *b;
|
|
|
|
|
2009-09-20 08:43:49 +00:00
|
|
|
memset(temp, 0, sizeof(temp));
|
|
|
|
strcpy(temp, dottests[_i].b);
|
|
|
|
b = temp;
|
|
|
|
inline_undotify(b, sizeof(temp));
|
|
|
|
|
2021-08-24 23:07:36 +02:00
|
|
|
ck_assert_str_eq(dottests[_i].a, temp);
|
2009-09-20 08:43:49 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST(test_build_hostname)
|
|
|
|
{
|
|
|
|
char data[256];
|
|
|
|
char buf[1024];
|
|
|
|
char *topdomain = "a.c";
|
|
|
|
int buflen;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(data); i++) {
|
|
|
|
data[i] = i & 0xFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
buflen = sizeof(buf);
|
2014-06-01 08:34:18 +02:00
|
|
|
|
2009-09-20 08:43:49 +00:00
|
|
|
for (i = 1; i < sizeof(data); i++) {
|
2017-03-11 20:44:08 -08:00
|
|
|
int len = build_hostname(buf, buflen, data, i, topdomain, &base32_ops, sizeof(buf));
|
2007-06-09 16:57:33 +00:00
|
|
|
|
2020-07-23 22:31:53 +02:00
|
|
|
ck_assert(len <= i);
|
|
|
|
ck_assert_msg(strstr(buf, "..") == NULL,
|
|
|
|
"Found double dots when encoding data len %d! buf: %s", i, buf);
|
2007-06-09 16:57:33 +00:00
|
|
|
}
|
2006-12-16 00:42:13 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
TCase *
|
|
|
|
test_encoding_create_tests()
|
|
|
|
{
|
|
|
|
TCase *tc;
|
|
|
|
|
|
|
|
tc = tcase_create("Encoding");
|
2009-09-20 08:43:49 +00:00
|
|
|
tcase_add_loop_test(tc, test_inline_dotify, 0, TUPLES);
|
|
|
|
tcase_add_loop_test(tc, test_inline_undotify, 0, TUPLES);
|
|
|
|
tcase_add_test(tc, test_build_hostname);
|
2006-12-16 00:42:13 +00:00
|
|
|
|
|
|
|
return tc;
|
|
|
|
}
|