summaryrefslogtreecommitdiff
path: root/regress/unittests
diff options
context:
space:
mode:
Diffstat (limited to 'regress/unittests')
-rw-r--r--regress/unittests/Makefile4
-rw-r--r--regress/unittests/Makefile.inc10
-rw-r--r--regress/unittests/bitmap/Makefile4
-rw-r--r--regress/unittests/hostkeys/Makefile4
-rw-r--r--regress/unittests/kex/Makefile4
-rw-r--r--regress/unittests/match/Makefile10
-rw-r--r--regress/unittests/match/tests.c113
-rw-r--r--regress/unittests/sshbuf/Makefile2
-rw-r--r--regress/unittests/sshkey/Makefile4
-rw-r--r--regress/unittests/utf8/Makefile4
-rw-r--r--regress/unittests/utf8/tests.c7
11 files changed, 142 insertions, 24 deletions
diff --git a/regress/unittests/Makefile b/regress/unittests/Makefile
index 0a95d4b20..e70b16644 100644
--- a/regress/unittests/Makefile
+++ b/regress/unittests/Makefile
@@ -1,5 +1,5 @@
1# $OpenBSD: Makefile,v 1.6 2016/05/26 19:14:25 schwarze Exp $ 1# $OpenBSD: Makefile,v 1.7 2016/08/19 06:44:13 djm Exp $
2REGRESS_FAIL_EARLY= yes 2REGRESS_FAIL_EARLY= yes
3SUBDIR= test_helper sshbuf sshkey bitmap kex hostkeys utf8 3SUBDIR= test_helper sshbuf sshkey bitmap kex hostkeys utf8 match
4 4
5.include <bsd.subdir.mk> 5.include <bsd.subdir.mk>
diff --git a/regress/unittests/Makefile.inc b/regress/unittests/Makefile.inc
index 7385e2ba3..3d9eaba5c 100644
--- a/regress/unittests/Makefile.inc
+++ b/regress/unittests/Makefile.inc
@@ -1,4 +1,4 @@
1# $OpenBSD: Makefile.inc,v 1.6 2015/07/01 23:11:18 djm Exp $ 1# $OpenBSD: Makefile.inc,v 1.9 2016/11/01 13:43:27 tb Exp $
2 2
3.include <bsd.own.mk> 3.include <bsd.own.mk>
4.include <bsd.obj.mk> 4.include <bsd.obj.mk>
@@ -49,11 +49,15 @@ DPADD+=${.CURDIR}/../test_helper/libtest_helper.a
49 49
50.if exists(${.CURDIR}/${SSHREL}/lib/${__objdir}) 50.if exists(${.CURDIR}/${SSHREL}/lib/${__objdir})
51LDADD+=-L${.CURDIR}/${SSHREL}/lib/${__objdir} -lssh 51LDADD+=-L${.CURDIR}/${SSHREL}/lib/${__objdir} -lssh
52DPADD+=${.CURDIR}/${SSHREL}/lib/${__objdir}/libssh.a 52LIBSSH=${.CURDIR}/${SSHREL}/lib/${__objdir}/libssh.a
53.else 53.else
54LDADD+=-L${.CURDIR}/${SSHREL}/lib -lssh 54LDADD+=-L${.CURDIR}/${SSHREL}/lib -lssh
55DPADD+=${.CURDIR}/${SSHREL}/lib/libssh.a 55LIBSSH=${.CURDIR}/${SSHREL}/lib/libssh.a
56.endif 56.endif
57DPADD+=${LIBSSH}
58${PROG}: ${LIBSSH}
59${LIBSSH}:
60 cd ${.CURDIR}/${SSHREL} && ${MAKE} lib
57 61
58LDADD+= -lcrypto 62LDADD+= -lcrypto
59DPADD+= ${LIBCRYPTO} 63DPADD+= ${LIBCRYPTO}
diff --git a/regress/unittests/bitmap/Makefile b/regress/unittests/bitmap/Makefile
index b704d22d6..bd21949f8 100644
--- a/regress/unittests/bitmap/Makefile
+++ b/regress/unittests/bitmap/Makefile
@@ -1,6 +1,4 @@
1# $OpenBSD: Makefile,v 1.1 2015/01/15 07:36:28 djm Exp $ 1# $OpenBSD: Makefile,v 1.3 2016/11/01 13:43:27 tb Exp $
2
3TEST_ENV= "MALLOC_OPTIONS=AFGJPRX"
4 2
5PROG=test_bitmap 3PROG=test_bitmap
6SRCS=tests.c 4SRCS=tests.c
diff --git a/regress/unittests/hostkeys/Makefile b/regress/unittests/hostkeys/Makefile
index f52a85fb1..ae3c342bd 100644
--- a/regress/unittests/hostkeys/Makefile
+++ b/regress/unittests/hostkeys/Makefile
@@ -1,6 +1,4 @@
1# $OpenBSD: Makefile,v 1.1 2015/02/16 22:18:34 djm Exp $ 1# $OpenBSD: Makefile,v 1.3 2016/11/01 13:43:27 tb Exp $
2
3TEST_ENV= "MALLOC_OPTIONS=AFGJPRX"
4 2
5PROG=test_hostkeys 3PROG=test_hostkeys
6SRCS=tests.c test_iterate.c 4SRCS=tests.c test_iterate.c
diff --git a/regress/unittests/kex/Makefile b/regress/unittests/kex/Makefile
index 6532cb00a..7ed312675 100644
--- a/regress/unittests/kex/Makefile
+++ b/regress/unittests/kex/Makefile
@@ -1,6 +1,4 @@
1# $OpenBSD: Makefile,v 1.2 2015/01/24 10:39:21 miod Exp $ 1# $OpenBSD: Makefile,v 1.4 2016/11/01 13:43:27 tb Exp $
2
3TEST_ENV= "MALLOC_OPTIONS=AFGJPRX"
4 2
5PROG=test_kex 3PROG=test_kex
6SRCS=tests.c test_kex.c 4SRCS=tests.c test_kex.c
diff --git a/regress/unittests/match/Makefile b/regress/unittests/match/Makefile
new file mode 100644
index 000000000..bd4aed844
--- /dev/null
+++ b/regress/unittests/match/Makefile
@@ -0,0 +1,10 @@
1# $OpenBSD: Makefile,v 1.3 2016/11/01 13:43:27 tb Exp $
2
3PROG=test_match
4SRCS=tests.c
5REGRESS_TARGETS=run-regress-${PROG}
6
7run-regress-${PROG}: ${PROG}
8 env ${TEST_ENV} ./${PROG}
9
10.include <bsd.regress.mk>
diff --git a/regress/unittests/match/tests.c b/regress/unittests/match/tests.c
new file mode 100644
index 000000000..7ff319c16
--- /dev/null
+++ b/regress/unittests/match/tests.c
@@ -0,0 +1,113 @@
1/* $OpenBSD: tests.c,v 1.3 2016/09/21 17:03:54 djm Exp $ */
2/*
3 * Regress test for matching functions
4 *
5 * Placed in the public domain
6 */
7
8#include "includes.h"
9
10#include <sys/types.h>
11#include <sys/param.h>
12#include <stdio.h>
13#ifdef HAVE_STDINT_H
14#include <stdint.h>
15#endif
16#include <stdlib.h>
17#include <string.h>
18
19#include "../test_helper/test_helper.h"
20
21#include "match.h"
22
23void
24tests(void)
25{
26 TEST_START("match_pattern");
27 ASSERT_INT_EQ(match_pattern("", ""), 1);
28 ASSERT_INT_EQ(match_pattern("", "aaa"), 0);
29 ASSERT_INT_EQ(match_pattern("aaa", ""), 0);
30 ASSERT_INT_EQ(match_pattern("aaa", "aaaa"), 0);
31 ASSERT_INT_EQ(match_pattern("aaaa", "aaa"), 0);
32 TEST_DONE();
33
34 TEST_START("match_pattern wildcard");
35 ASSERT_INT_EQ(match_pattern("", "*"), 1);
36 ASSERT_INT_EQ(match_pattern("a", "?"), 1);
37 ASSERT_INT_EQ(match_pattern("aa", "a?"), 1);
38 ASSERT_INT_EQ(match_pattern("a", "*"), 1);
39 ASSERT_INT_EQ(match_pattern("aa", "a*"), 1);
40 ASSERT_INT_EQ(match_pattern("aa", "?*"), 1);
41 ASSERT_INT_EQ(match_pattern("aa", "**"), 1);
42 ASSERT_INT_EQ(match_pattern("aa", "?a"), 1);
43 ASSERT_INT_EQ(match_pattern("aa", "*a"), 1);
44 ASSERT_INT_EQ(match_pattern("ba", "a?"), 0);
45 ASSERT_INT_EQ(match_pattern("ba", "a*"), 0);
46 ASSERT_INT_EQ(match_pattern("ab", "?a"), 0);
47 ASSERT_INT_EQ(match_pattern("ab", "*a"), 0);
48 TEST_DONE();
49
50 TEST_START("match_pattern_list");
51 ASSERT_INT_EQ(match_pattern_list("", "", 0), 0); /* no patterns */
52 ASSERT_INT_EQ(match_pattern_list("", "*", 0), 1);
53 ASSERT_INT_EQ(match_pattern_list("", "!*", 0), -1);
54 ASSERT_INT_EQ(match_pattern_list("", "!a,*", 0), 1);
55 ASSERT_INT_EQ(match_pattern_list("", "*,!a", 0), 1);
56 ASSERT_INT_EQ(match_pattern_list("", "a,!*", 0), -1);
57 ASSERT_INT_EQ(match_pattern_list("", "!*,a", 0), -1);
58 ASSERT_INT_EQ(match_pattern_list("a", "", 0), 0);
59 ASSERT_INT_EQ(match_pattern_list("a", "*", 0), 1);
60 ASSERT_INT_EQ(match_pattern_list("a", "!*", 0), -1);
61 ASSERT_INT_EQ(match_pattern_list("a", "!a", 0), -1);
62 /* XXX negated ASSERT_INT_EQ(match_pattern_list("a", "!b", 0), 1); */
63 ASSERT_INT_EQ(match_pattern_list("a", "!a,*", 0), -1);
64 ASSERT_INT_EQ(match_pattern_list("b", "!a,*", 0), 1);
65 ASSERT_INT_EQ(match_pattern_list("a", "*,!a", 0), -1);
66 ASSERT_INT_EQ(match_pattern_list("b", "*,!a", 0), 1);
67 ASSERT_INT_EQ(match_pattern_list("a", "a,!*", 0), -1);
68 ASSERT_INT_EQ(match_pattern_list("b", "a,!*", 0), -1);
69 ASSERT_INT_EQ(match_pattern_list("a", "a,!a", 0), -1);
70 /* XXX negated ASSERT_INT_EQ(match_pattern_list("b", "a,!a", 0), 1); */
71 ASSERT_INT_EQ(match_pattern_list("a", "!*,a", 0), -1);
72 ASSERT_INT_EQ(match_pattern_list("b", "!*,a", 0), -1);
73 TEST_DONE();
74
75 TEST_START("match_pattern_list lowercase");
76 ASSERT_INT_EQ(match_pattern_list("abc", "ABC", 0), 0);
77 ASSERT_INT_EQ(match_pattern_list("ABC", "abc", 0), 0);
78 ASSERT_INT_EQ(match_pattern_list("abc", "ABC", 1), 1);
79 ASSERT_INT_EQ(match_pattern_list("ABC", "abc", 1), 0);
80 TEST_DONE();
81
82 TEST_START("addr_match_list");
83 ASSERT_INT_EQ(addr_match_list("127.0.0.1", "127.0.0.1/44"), -2);
84 ASSERT_INT_EQ(addr_match_list(NULL, "127.0.0.1/44"), -2);
85 ASSERT_INT_EQ(addr_match_list("a", "*"), 0);
86 ASSERT_INT_EQ(addr_match_list("127.0.0.1", "*"), 1);
87 ASSERT_INT_EQ(addr_match_list(NULL, "*"), 0);
88 ASSERT_INT_EQ(addr_match_list("127.0.0.1", "127.0.0.1"), 1);
89 ASSERT_INT_EQ(addr_match_list("127.0.0.1", "127.0.0.2"), 0);
90 ASSERT_INT_EQ(addr_match_list("127.0.0.1", "!127.0.0.1"), -1);
91 /* XXX negated ASSERT_INT_EQ(addr_match_list("127.0.0.1", "!127.0.0.2"), 1); */
92 ASSERT_INT_EQ(addr_match_list("127.0.0.255", "127.0.0.0/24"), 1);
93 ASSERT_INT_EQ(addr_match_list("127.0.1.1", "127.0.0.0/24"), 0);
94 ASSERT_INT_EQ(addr_match_list("127.0.0.1", "127.0.0.0/24"), 1);
95 ASSERT_INT_EQ(addr_match_list("127.0.0.1", "127.0.1.0/24"), 0);
96 ASSERT_INT_EQ(addr_match_list("127.0.0.1", "!127.0.0.0/24"), -1);
97 /* XXX negated ASSERT_INT_EQ(addr_match_list("127.0.0.1", "!127.0.1.0/24"), 1); */
98 ASSERT_INT_EQ(addr_match_list("127.0.0.1", "10.0.0.1,!127.0.0.1"), -1);
99 ASSERT_INT_EQ(addr_match_list("127.0.0.1", "!127.0.0.1,10.0.0.1"), -1);
100 ASSERT_INT_EQ(addr_match_list("127.0.0.1", "10.0.0.1,127.0.0.2"), 0);
101 ASSERT_INT_EQ(addr_match_list("127.0.0.1", "127.0.0.2,10.0.0.1"), 0);
102 /* XXX negated ASSERT_INT_EQ(addr_match_list("127.0.0.1", "10.0.0.1,!127.0.0.2"), 1); */
103 /* XXX negated ASSERT_INT_EQ(addr_match_list("127.0.0.1", "!127.0.0.2,10.0.0.1"), 1); */
104 TEST_DONE();
105
106/*
107 * XXX TODO
108 * int match_host_and_ip(const char *, const char *, const char *);
109 * int match_user(const char *, const char *, const char *, const char *);
110 * char *match_list(const char *, const char *, u_int *);
111 * int addr_match_cidr_list(const char *, const char *);
112 */
113}
diff --git a/regress/unittests/sshbuf/Makefile b/regress/unittests/sshbuf/Makefile
index 85f99ac38..69b27566b 100644
--- a/regress/unittests/sshbuf/Makefile
+++ b/regress/unittests/sshbuf/Makefile
@@ -1,4 +1,4 @@
1# $OpenBSD: Makefile,v 1.1 2014/04/30 05:32:00 djm Exp $ 1# $OpenBSD: Makefile,v 1.5 2016/11/01 13:43:27 tb Exp $
2 2
3PROG=test_sshbuf 3PROG=test_sshbuf
4SRCS=tests.c 4SRCS=tests.c
diff --git a/regress/unittests/sshkey/Makefile b/regress/unittests/sshkey/Makefile
index 1bcd26676..cfbfcf8f1 100644
--- a/regress/unittests/sshkey/Makefile
+++ b/regress/unittests/sshkey/Makefile
@@ -1,6 +1,4 @@
1# $OpenBSD: Makefile,v 1.1 2014/06/24 01:14:18 djm Exp $ 1# $OpenBSD: Makefile,v 1.4 2016/11/01 13:43:27 tb Exp $
2
3TEST_ENV= "MALLOC_OPTIONS=AFGJPRX"
4 2
5PROG=test_sshkey 3PROG=test_sshkey
6SRCS=tests.c test_sshkey.c test_file.c test_fuzz.c common.c 4SRCS=tests.c test_sshkey.c test_file.c test_fuzz.c common.c
diff --git a/regress/unittests/utf8/Makefile b/regress/unittests/utf8/Makefile
index 150ea2f2e..a975264fc 100644
--- a/regress/unittests/utf8/Makefile
+++ b/regress/unittests/utf8/Makefile
@@ -1,6 +1,4 @@
1# $OpenBSD: Makefile,v 1.2 2016/05/30 12:14:08 schwarze Exp $ 1# $OpenBSD: Makefile,v 1.4 2016/11/01 13:43:27 tb Exp $
2
3TEST_ENV= "MALLOC_OPTIONS=CFGJPRSUX"
4 2
5PROG=test_utf8 3PROG=test_utf8
6SRCS=tests.c 4SRCS=tests.c
diff --git a/regress/unittests/utf8/tests.c b/regress/unittests/utf8/tests.c
index fad2ec279..31f9fe9c3 100644
--- a/regress/unittests/utf8/tests.c
+++ b/regress/unittests/utf8/tests.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tests.c,v 1.2 2016/05/30 12:05:56 schwarze Exp $ */ 1/* $OpenBSD: tests.c,v 1.3 2016/12/19 04:55:18 djm Exp $ */
2/* 2/*
3 * Regress test for the utf8.h *mprintf() API 3 * Regress test for the utf8.h *mprintf() API
4 * 4 *
@@ -6,10 +6,12 @@
6 * and placed in the public domain. 6 * and placed in the public domain.
7 */ 7 */
8 8
9#include "includes.h"
10
9#include <locale.h> 11#include <locale.h>
10#include <string.h> 12#include <string.h>
11 13
12#include "test_helper.h" 14#include "../test_helper/test_helper.h"
13 15
14#include "utf8.h" 16#include "utf8.h"
15 17
@@ -63,7 +65,6 @@ tests(void)
63 TEST_DONE(); 65 TEST_DONE();
64 66
65 badarg(); 67 badarg();
66 one("null", NULL, 8, 6, 6, "(null)");
67 one("empty", "", 2, 0, 0, ""); 68 one("empty", "", 2, 0, 0, "");
68 one("ascii", "x", -2, -2, -2, "x"); 69 one("ascii", "x", -2, -2, -2, "x");
69 one("newline", "a\nb", -2, -2, -2, "a\nb"); 70 one("newline", "a\nb", -2, -2, -2, "a\nb");