summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--regress/unittests/misc/Makefile16
-rw-r--r--regress/unittests/misc/tests.c79
2 files changed, 95 insertions, 0 deletions
diff --git a/regress/unittests/misc/Makefile b/regress/unittests/misc/Makefile
new file mode 100644
index 000000000..06e954cb8
--- /dev/null
+++ b/regress/unittests/misc/Makefile
@@ -0,0 +1,16 @@
1# $OpenBSD: Makefile,v 1.1 2019/04/28 22:53:26 dtucker Exp $
2
3PROG=test_misc
4SRCS=tests.c
5
6# From usr.bin/ssh/Makefile.inc
7SRCS+=sshbuf.c sshbuf-getput-basic.c ssherr.c log.c xmalloc.c misc.c
8# From usr/bin/ssh/sshd/Makefile
9SRCS+=atomicio.c cleanup.c fatal.c
10
11REGRESS_TARGETS=run-regress-${PROG}
12
13run-regress-${PROG}: ${PROG}
14 env ${TEST_ENV} ./${PROG}
15
16.include <bsd.regress.mk>
diff --git a/regress/unittests/misc/tests.c b/regress/unittests/misc/tests.c
new file mode 100644
index 000000000..ed775ebbd
--- /dev/null
+++ b/regress/unittests/misc/tests.c
@@ -0,0 +1,79 @@
1/* $OpenBSD: tests.c,v 1.1 2019/04/28 22:53:26 dtucker Exp $ */
2/*
3 * Regress test for misc helper functions.
4 *
5 * Placed in the public domain.
6 */
7
8#include <sys/types.h>
9#include <sys/param.h>
10#include <stdio.h>
11#include <stdint.h>
12#include <stdlib.h>
13#include <string.h>
14
15#include "test_helper.h"
16
17#include "misc.h"
18
19void
20tests(void)
21{
22 int port;
23 char *user, *host, *path;
24
25 TEST_START("misc_parse_user_host_path");
26 ASSERT_INT_EQ(parse_user_host_path("someuser@some.host:some/path",
27 &user, &host, &path), 0);
28 ASSERT_STRING_EQ(user, "someuser");
29 ASSERT_STRING_EQ(host, "some.host");
30 ASSERT_STRING_EQ(path, "some/path");
31 free(user); free(host); free(path);
32 TEST_DONE();
33
34 TEST_START("misc_parse_user_ipv4_path");
35 ASSERT_INT_EQ(parse_user_host_path("someuser@1.22.33.144:some/path",
36 &user, &host, &path), 0);
37 ASSERT_STRING_EQ(user, "someuser");
38 ASSERT_STRING_EQ(host, "1.22.33.144");
39 ASSERT_STRING_EQ(path, "some/path");
40 free(user); free(host); free(path);
41 TEST_DONE();
42
43 TEST_START("misc_parse_user_[ipv4]_path");
44 ASSERT_INT_EQ(parse_user_host_path("someuser@[1.22.33.144]:some/path",
45 &user, &host, &path), 0);
46 ASSERT_STRING_EQ(user, "someuser");
47 ASSERT_STRING_EQ(host, "1.22.33.144");
48 ASSERT_STRING_EQ(path, "some/path");
49 free(user); free(host); free(path);
50 TEST_DONE();
51
52 TEST_START("misc_parse_user_[ipv4]_nopath");
53 ASSERT_INT_EQ(parse_user_host_path("someuser@[1.22.33.144]:",
54 &user, &host, &path), 0);
55 ASSERT_STRING_EQ(user, "someuser");
56 ASSERT_STRING_EQ(host, "1.22.33.144");
57 ASSERT_STRING_EQ(path, ".");
58 free(user); free(host); free(path);
59 TEST_DONE();
60
61 TEST_START("misc_parse_user_ipv6_path");
62 ASSERT_INT_EQ(parse_user_host_path("someuser@[::1]:some/path",
63 &user, &host, &path), 0);
64 ASSERT_STRING_EQ(user, "someuser");
65 ASSERT_STRING_EQ(host, "::1");
66 ASSERT_STRING_EQ(path, "some/path");
67 free(user); free(host); free(path);
68 TEST_DONE();
69
70 TEST_START("misc_parse_uri");
71 ASSERT_INT_EQ(parse_uri("ssh", "ssh://someuser@some.host:22/some/path",
72 &user, &host, &port, &path), 0);
73 ASSERT_STRING_EQ(user, "someuser");
74 ASSERT_STRING_EQ(host, "some.host");
75 ASSERT_INT_EQ(port, 22);
76 ASSERT_STRING_EQ(path, "some/path");
77 free(user); free(host); free(path);
78 TEST_DONE();
79}