summaryrefslogtreecommitdiff
path: root/regress/unittests
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2019-07-15 13:12:02 +0000
committerDamien Miller <djm@mindrot.org>2019-07-15 23:21:18 +1000
commit477e2a3be8b10df76e8d76f0427b043280d73d68 (patch)
treea66dfb29bb834c0429b92ab9abd6fd8d1eb43c38 /regress/unittests
parenteb0d8e708a1f958aecd2d6e2ff2450af488d4c2a (diff)
upstream: unit tests for sshbuf_cmp() and sshbuf_find(); ok markus
OpenBSD-Regress-ID: b52d36bc3ab6dc158c1e59a9a4735f821cf9e1fd
Diffstat (limited to 'regress/unittests')
-rw-r--r--regress/unittests/sshbuf/test_sshbuf_misc.c55
1 files changed, 53 insertions, 2 deletions
diff --git a/regress/unittests/sshbuf/test_sshbuf_misc.c b/regress/unittests/sshbuf/test_sshbuf_misc.c
index 762a6c31c..19c1f25bb 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.2 2016/05/03 13:48:33 djm Exp $ */ 1/* $OpenBSD: test_sshbuf_misc.c,v 1.3 2019/07/15 13:12:02 djm Exp $ */
2/* 2/*
3 * Regress test for sshbuf.h buffer API 3 * Regress test for sshbuf.h buffer API
4 * 4 *
@@ -19,6 +19,7 @@
19#include "../test_helper/test_helper.h" 19#include "../test_helper/test_helper.h"
20 20
21#include "sshbuf.h" 21#include "sshbuf.h"
22#include "ssherr.h"
22 23
23void sshbuf_misc_tests(void); 24void sshbuf_misc_tests(void);
24 25
@@ -26,7 +27,7 @@ void
26sshbuf_misc_tests(void) 27sshbuf_misc_tests(void)
27{ 28{
28 struct sshbuf *p1; 29 struct sshbuf *p1;
29 char tmp[512], *p; 30 char tmp[512], msg[] = "imploring ping silence ping over", *p;
30 FILE *out; 31 FILE *out;
31 size_t sz; 32 size_t sz;
32 33
@@ -163,5 +164,55 @@ sshbuf_misc_tests(void)
163 ASSERT_PTR_EQ(p, NULL); 164 ASSERT_PTR_EQ(p, NULL);
164 sshbuf_free(p1); 165 sshbuf_free(p1);
165 TEST_DONE(); 166 TEST_DONE();
167
168 TEST_START("sshbuf_cmp");
169 p1 = sshbuf_from(msg, sizeof(msg) - 1);
170 ASSERT_PTR_NE(p1, NULL);
171 ASSERT_INT_EQ(sshbuf_cmp(p1, 0, "i", 1), 0);
172 ASSERT_INT_EQ(sshbuf_cmp(p1, 0, "j", 1), SSH_ERR_INVALID_FORMAT);
173 ASSERT_INT_EQ(sshbuf_cmp(p1, 0, "imploring", 9), 0);
174 ASSERT_INT_EQ(sshbuf_cmp(p1, 0, "implored", 9), SSH_ERR_INVALID_FORMAT);
175 ASSERT_INT_EQ(sshbuf_cmp(p1, 10, "ping", 4), 0);
176 ASSERT_INT_EQ(sshbuf_cmp(p1, 10, "ring", 4), SSH_ERR_INVALID_FORMAT);
177 ASSERT_INT_EQ(sshbuf_cmp(p1, 28, "over", 4), 0);
178 ASSERT_INT_EQ(sshbuf_cmp(p1, 28, "rove", 4), SSH_ERR_INVALID_FORMAT);
179 ASSERT_INT_EQ(sshbuf_cmp(p1, 28, "overt", 5),
180 SSH_ERR_MESSAGE_INCOMPLETE);
181 ASSERT_INT_EQ(sshbuf_cmp(p1, 32, "ping", 4),
182 SSH_ERR_MESSAGE_INCOMPLETE);
183 ASSERT_INT_EQ(sshbuf_cmp(p1, 1000, "silence", 7),
184 SSH_ERR_MESSAGE_INCOMPLETE);
185 ASSERT_INT_EQ(sshbuf_cmp(p1, 0, msg, sizeof(msg) - 1), 0);
186 TEST_DONE();
187
188 TEST_START("sshbuf_find");
189 p1 = sshbuf_from(msg, sizeof(msg) - 1);
190 ASSERT_PTR_NE(p1, NULL);
191 ASSERT_INT_EQ(sshbuf_find(p1, 0, "i", 1, &sz), 0);
192 ASSERT_SIZE_T_EQ(sz, 0);
193 ASSERT_INT_EQ(sshbuf_find(p1, 0, "j", 1, &sz), SSH_ERR_INVALID_FORMAT);
194 ASSERT_INT_EQ(sshbuf_find(p1, 0, "imploring", 9, &sz), 0);
195 ASSERT_SIZE_T_EQ(sz, 0);
196 ASSERT_INT_EQ(sshbuf_find(p1, 0, "implored", 9, &sz),
197 SSH_ERR_INVALID_FORMAT);
198 ASSERT_INT_EQ(sshbuf_find(p1, 3, "ping", 4, &sz), 0);
199 ASSERT_SIZE_T_EQ(sz, 10);
200 ASSERT_INT_EQ(sshbuf_find(p1, 11, "ping", 4, &sz), 0);
201 ASSERT_SIZE_T_EQ(sz, 23);
202 ASSERT_INT_EQ(sshbuf_find(p1, 20, "over", 4, &sz), 0);
203 ASSERT_SIZE_T_EQ(sz, 28);
204 ASSERT_INT_EQ(sshbuf_find(p1, 28, "over", 4, &sz), 0);
205 ASSERT_SIZE_T_EQ(sz, 28);
206 ASSERT_INT_EQ(sshbuf_find(p1, 28, "rove", 4, &sz),
207 SSH_ERR_INVALID_FORMAT);
208 ASSERT_INT_EQ(sshbuf_find(p1, 28, "overt", 5, &sz),
209 SSH_ERR_MESSAGE_INCOMPLETE);
210 ASSERT_INT_EQ(sshbuf_find(p1, 32, "ping", 4, &sz),
211 SSH_ERR_MESSAGE_INCOMPLETE);
212 ASSERT_INT_EQ(sshbuf_find(p1, 1000, "silence", 7, &sz),
213 SSH_ERR_MESSAGE_INCOMPLETE);
214 ASSERT_INT_EQ(sshbuf_find(p1, 0, msg + 1, sizeof(msg) - 2, &sz), 0);
215 ASSERT_SIZE_T_EQ(sz, 1);
216 TEST_DONE();
166} 217}
167 218