summaryrefslogtreecommitdiff
path: root/regress/unittests
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2016-08-06 10:49:58 +0100
committerColin Watson <cjwatson@debian.org>2016-08-06 10:49:58 +0100
commita8ed8d256b2e2c05b0c15565a7938028c5192277 (patch)
tree87abbdc914a38b43e4e5bb9581ad1f46eabbf88e /regress/unittests
parentf0329aac23c61e1a5197d6d57349a63f459bccb0 (diff)
parent99522ba7ec6963a05c04a156bf20e3ba3605987c (diff)
Import openssh_7.3p1.orig.tar.gz
Diffstat (limited to 'regress/unittests')
-rw-r--r--regress/unittests/Makefile4
-rw-r--r--regress/unittests/sshbuf/test_sshbuf_misc.c31
-rw-r--r--regress/unittests/sshkey/test_sshkey.c4
-rw-r--r--regress/unittests/test_helper/Makefile3
-rw-r--r--regress/unittests/utf8/Makefile12
-rw-r--r--regress/unittests/utf8/tests.c82
6 files changed, 129 insertions, 7 deletions
diff --git a/regress/unittests/Makefile b/regress/unittests/Makefile
index d3d90823f..0a95d4b20 100644
--- a/regress/unittests/Makefile
+++ b/regress/unittests/Makefile
@@ -1,5 +1,5 @@
1# $OpenBSD: Makefile,v 1.5 2015/02/16 22:21:03 djm Exp $ 1# $OpenBSD: Makefile,v 1.6 2016/05/26 19:14:25 schwarze Exp $
2REGRESS_FAIL_EARLY= yes 2REGRESS_FAIL_EARLY= yes
3SUBDIR= test_helper sshbuf sshkey bitmap kex hostkeys 3SUBDIR= test_helper sshbuf sshkey bitmap kex hostkeys utf8
4 4
5.include <bsd.subdir.mk> 5.include <bsd.subdir.mk>
diff --git a/regress/unittests/sshbuf/test_sshbuf_misc.c b/regress/unittests/sshbuf/test_sshbuf_misc.c
index f155491a0..762a6c31c 100644
--- a/regress/unittests/sshbuf/test_sshbuf_misc.c
+++ b/regress/unittests/sshbuf/test_sshbuf_misc.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: test_sshbuf_misc.c,v 1.1 2014/04/30 05:32:00 djm Exp $ */ 1/* $OpenBSD: test_sshbuf_misc.c,v 1.2 2016/05/03 13:48:33 djm Exp $ */
2/* 2/*
3 * Regress test for sshbuf.h buffer API 3 * Regress test for sshbuf.h buffer API
4 * 4 *
@@ -134,5 +134,34 @@ sshbuf_misc_tests(void)
134 ASSERT_U32_EQ(PEEK_U32(sshbuf_ptr(p1)), 0xd00fd00f); 134 ASSERT_U32_EQ(PEEK_U32(sshbuf_ptr(p1)), 0xd00fd00f);
135 sshbuf_free(p1); 135 sshbuf_free(p1);
136 TEST_DONE(); 136 TEST_DONE();
137
138 TEST_START("sshbuf_dup_string");
139 p1 = sshbuf_new();
140 ASSERT_PTR_NE(p1, NULL);
141 /* Check empty buffer */
142 p = sshbuf_dup_string(p1);
143 ASSERT_PTR_NE(p, NULL);
144 ASSERT_SIZE_T_EQ(strlen(p), 0);
145 free(p);
146 /* Check buffer with string */
147 ASSERT_INT_EQ(sshbuf_put(p1, "quad1", strlen("quad1")), 0);
148 p = sshbuf_dup_string(p1);
149 ASSERT_PTR_NE(p, NULL);
150 ASSERT_SIZE_T_EQ(strlen(p), strlen("quad1"));
151 ASSERT_STRING_EQ(p, "quad1");
152 free(p);
153 /* Check buffer with terminating nul */
154 ASSERT_INT_EQ(sshbuf_put(p1, "\0", 1), 0);
155 p = sshbuf_dup_string(p1);
156 ASSERT_PTR_NE(p, NULL);
157 ASSERT_SIZE_T_EQ(strlen(p), strlen("quad1"));
158 ASSERT_STRING_EQ(p, "quad1");
159 free(p);
160 /* Check buffer with data after nul (expect failure) */
161 ASSERT_INT_EQ(sshbuf_put(p1, "quad2", strlen("quad2")), 0);
162 p = sshbuf_dup_string(p1);
163 ASSERT_PTR_EQ(p, NULL);
164 sshbuf_free(p1);
165 TEST_DONE();
137} 166}
138 167
diff --git a/regress/unittests/sshkey/test_sshkey.c b/regress/unittests/sshkey/test_sshkey.c
index 1f160d1a7..1476dc2e3 100644
--- a/regress/unittests/sshkey/test_sshkey.c
+++ b/regress/unittests/sshkey/test_sshkey.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: test_sshkey.c,v 1.9 2015/12/07 02:20:46 djm Exp $ */ 1/* $OpenBSD: test_sshkey.c,v 1.10 2016/05/02 09:52:00 djm Exp $ */
2/* 2/*
3 * Regress test for sshkey.h key management API 3 * Regress test for sshkey.h key management API
4 * 4 *
@@ -455,7 +455,7 @@ sshkey_tests(void)
455 put_opt(k1->cert->extensions, "permit-X11-forwarding", NULL); 455 put_opt(k1->cert->extensions, "permit-X11-forwarding", NULL);
456 put_opt(k1->cert->extensions, "permit-agent-forwarding", NULL); 456 put_opt(k1->cert->extensions, "permit-agent-forwarding", NULL);
457 ASSERT_INT_EQ(sshkey_from_private(k2, &k1->cert->signature_key), 0); 457 ASSERT_INT_EQ(sshkey_from_private(k2, &k1->cert->signature_key), 0);
458 ASSERT_INT_EQ(sshkey_certify(k1, k2), 0); 458 ASSERT_INT_EQ(sshkey_certify(k1, k2, NULL), 0);
459 b = sshbuf_new(); 459 b = sshbuf_new();
460 ASSERT_PTR_NE(b, NULL); 460 ASSERT_PTR_NE(b, NULL);
461 ASSERT_INT_EQ(sshkey_putb(k1, b), 0); 461 ASSERT_INT_EQ(sshkey_putb(k1, b), 0);
diff --git a/regress/unittests/test_helper/Makefile b/regress/unittests/test_helper/Makefile
index 5b3894cbf..78026e653 100644
--- a/regress/unittests/test_helper/Makefile
+++ b/regress/unittests/test_helper/Makefile
@@ -1,9 +1,8 @@
1# $OpenBSD: Makefile,v 1.2 2015/01/20 22:58:57 djm Exp $ 1# $OpenBSD: Makefile,v 1.3 2016/07/04 18:01:44 guenther Exp $
2 2
3LIB= test_helper 3LIB= test_helper
4SRCS= test_helper.c fuzz.c 4SRCS= test_helper.c fuzz.c
5 5
6DEBUGLIBS= no
7NOPROFILE= yes 6NOPROFILE= yes
8NOPIC= yes 7NOPIC= yes
9 8
diff --git a/regress/unittests/utf8/Makefile b/regress/unittests/utf8/Makefile
new file mode 100644
index 000000000..150ea2f2e
--- /dev/null
+++ b/regress/unittests/utf8/Makefile
@@ -0,0 +1,12 @@
1# $OpenBSD: Makefile,v 1.2 2016/05/30 12:14:08 schwarze Exp $
2
3TEST_ENV= "MALLOC_OPTIONS=CFGJPRSUX"
4
5PROG=test_utf8
6SRCS=tests.c
7REGRESS_TARGETS=run-regress-${PROG}
8
9run-regress-${PROG}: ${PROG}
10 env ${TEST_ENV} ./${PROG}
11
12.include <bsd.regress.mk>
diff --git a/regress/unittests/utf8/tests.c b/regress/unittests/utf8/tests.c
new file mode 100644
index 000000000..fad2ec279
--- /dev/null
+++ b/regress/unittests/utf8/tests.c
@@ -0,0 +1,82 @@
1/* $OpenBSD: tests.c,v 1.2 2016/05/30 12:05:56 schwarze Exp $ */
2/*
3 * Regress test for the utf8.h *mprintf() API
4 *
5 * Written by Ingo Schwarze <schwarze@openbsd.org> in 2016
6 * and placed in the public domain.
7 */
8
9#include <locale.h>
10#include <string.h>
11
12#include "test_helper.h"
13
14#include "utf8.h"
15
16void badarg(void);
17void one(const char *, const char *, int, int, int, const char *);
18
19void
20badarg(void)
21{
22 char buf[16];
23 int len, width;
24
25 width = 1;
26 TEST_START("utf8_badarg");
27 len = snmprintf(buf, sizeof(buf), &width, "\377");
28 ASSERT_INT_EQ(len, -1);
29 ASSERT_STRING_EQ(buf, "");
30 ASSERT_INT_EQ(width, 0);
31 TEST_DONE();
32}
33
34void
35one(const char *name, const char *mbs, int width,
36 int wantwidth, int wantlen, const char *wants)
37{
38 char buf[16];
39 int *wp;
40 int len;
41
42 if (wantlen == -2)
43 wantlen = strlen(wants);
44 (void)strlcpy(buf, "utf8_", sizeof(buf));
45 (void)strlcat(buf, name, sizeof(buf));
46 TEST_START(buf);
47 wp = wantwidth == -2 ? NULL : &width;
48 len = snmprintf(buf, sizeof(buf), wp, "%s", mbs);
49 ASSERT_INT_EQ(len, wantlen);
50 ASSERT_STRING_EQ(buf, wants);
51 ASSERT_INT_EQ(width, wantwidth);
52 TEST_DONE();
53}
54
55void
56tests(void)
57{
58 char *loc;
59
60 TEST_START("utf8_setlocale");
61 loc = setlocale(LC_CTYPE, "en_US.UTF-8");
62 ASSERT_PTR_NE(loc, NULL);
63 TEST_DONE();
64
65 badarg();
66 one("null", NULL, 8, 6, 6, "(null)");
67 one("empty", "", 2, 0, 0, "");
68 one("ascii", "x", -2, -2, -2, "x");
69 one("newline", "a\nb", -2, -2, -2, "a\nb");
70 one("cr", "a\rb", -2, -2, -2, "a\rb");
71 one("tab", "a\tb", -2, -2, -2, "a\tb");
72 one("esc", "\033x", -2, -2, -2, "\\033x");
73 one("inv_badbyte", "\377x", -2, -2, -2, "\\377x");
74 one("inv_nocont", "\341x", -2, -2, -2, "\\341x");
75 one("inv_nolead", "a\200b", -2, -2, -2, "a\\200b");
76 one("sz_ascii", "1234567890123456", -2, -2, 16, "123456789012345");
77 one("sz_esc", "123456789012\033", -2, -2, 16, "123456789012");
78 one("width_ascii", "123", 2, 2, -1, "12");
79 one("width_double", "a\343\201\201", 2, 1, -1, "a");
80 one("double_fit", "a\343\201\201", 3, 3, 4, "a\343\201\201");
81 one("double_spc", "a\343\201\201", 4, 3, 4, "a\343\201\201");
82}