[openssh-commits] [openssh] 01/03: upstream commit

git+noreply at mindrot.org git+noreply at mindrot.org
Tue Aug 23 17:00:09 AEST 2016


This is an automated email from the git hooks/post-receive script.

djm pushed a commit to branch master
in repository openssh.

commit 114efe2bc0dd2842d997940a833f115e6fc04854
Author: djm at openbsd.org <djm at openbsd.org>
Date:   Fri Aug 19 06:44:13 2016 +0000

    upstream commit
    
    add tests for matching functions
    
    Upstream-Regress-ID: 0869d4f5c5d627c583c6a929d69c17d5dd65882c
---
 regress/unittests/Makefile       |  4 +-
 regress/unittests/match/Makefile | 12 ++++++
 regress/unittests/match/tests.c  | 84 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 98 insertions(+), 2 deletions(-)

diff --git a/regress/unittests/Makefile b/regress/unittests/Makefile
index 0a95d4b..e70b166 100644
--- a/regress/unittests/Makefile
+++ b/regress/unittests/Makefile
@@ -1,5 +1,5 @@
-#	$OpenBSD: Makefile,v 1.6 2016/05/26 19:14:25 schwarze Exp $
+#	$OpenBSD: Makefile,v 1.7 2016/08/19 06:44:13 djm Exp $
 REGRESS_FAIL_EARLY= yes
-SUBDIR=	test_helper sshbuf sshkey bitmap kex hostkeys utf8
+SUBDIR=	test_helper sshbuf sshkey bitmap kex hostkeys utf8 match
 
 .include <bsd.subdir.mk>
diff --git a/regress/unittests/match/Makefile b/regress/unittests/match/Makefile
new file mode 100644
index 0000000..dc802f5
--- /dev/null
+++ b/regress/unittests/match/Makefile
@@ -0,0 +1,12 @@
+#	$OpenBSD: Makefile,v 1.1 2016/08/19 06:44:13 djm Exp $
+
+TEST_ENV=      "MALLOC_OPTIONS=AFGJPRX"
+
+PROG=test_match
+SRCS=tests.c
+REGRESS_TARGETS=run-regress-${PROG}
+
+run-regress-${PROG}: ${PROG}
+	env ${TEST_ENV} ./${PROG}
+
+.include <bsd.regress.mk>
diff --git a/regress/unittests/match/tests.c b/regress/unittests/match/tests.c
new file mode 100644
index 0000000..aaca546
--- /dev/null
+++ b/regress/unittests/match/tests.c
@@ -0,0 +1,84 @@
+/* 	$OpenBSD: tests.c,v 1.1 2016/08/19 06:44:13 djm Exp $ */
+/*
+ * Regress test for matching functions
+ *
+ * Placed in the public domain
+ */
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "test_helper.h"
+
+#include "match.h"
+
+void
+tests(void)
+{
+	TEST_START("match_pattern");
+	ASSERT_INT_EQ(match_pattern("", ""), 1);
+	ASSERT_INT_EQ(match_pattern("", "aaa"), 0);
+	ASSERT_INT_EQ(match_pattern("aaa", ""), 0);
+	ASSERT_INT_EQ(match_pattern("aaa", "aaaa"), 0);
+	ASSERT_INT_EQ(match_pattern("aaaa", "aaa"), 0);
+	TEST_DONE();
+
+	TEST_START("match_pattern wildcard");
+	ASSERT_INT_EQ(match_pattern("", "*"), 1);
+	ASSERT_INT_EQ(match_pattern("a", "?"), 1);
+	ASSERT_INT_EQ(match_pattern("aa", "a?"), 1);
+	ASSERT_INT_EQ(match_pattern("a", "*"), 1);
+	ASSERT_INT_EQ(match_pattern("aa", "a*"), 1);
+	ASSERT_INT_EQ(match_pattern("aa", "?*"), 1);
+	ASSERT_INT_EQ(match_pattern("aa", "**"), 1);
+	ASSERT_INT_EQ(match_pattern("aa", "?a"), 1);
+	ASSERT_INT_EQ(match_pattern("aa", "*a"), 1);
+	ASSERT_INT_EQ(match_pattern("ba", "a?"), 0);
+	ASSERT_INT_EQ(match_pattern("ba", "a*"), 0);
+	ASSERT_INT_EQ(match_pattern("ab", "?a"), 0);
+	ASSERT_INT_EQ(match_pattern("ab", "*a"), 0);
+	TEST_DONE();
+
+	TEST_START("match_pattern_list");
+	ASSERT_INT_EQ(match_pattern_list("", "", 0), 0); /* no patterns */
+	ASSERT_INT_EQ(match_pattern_list("", "*", 0), 1);
+	ASSERT_INT_EQ(match_pattern_list("", "!*", 0), -1);
+	ASSERT_INT_EQ(match_pattern_list("", "!a,*", 0), 1);
+	ASSERT_INT_EQ(match_pattern_list("", "*,!a", 0), 1);
+	ASSERT_INT_EQ(match_pattern_list("", "a,!*", 0), -1);
+	ASSERT_INT_EQ(match_pattern_list("", "!*,a", 0), -1);
+	ASSERT_INT_EQ(match_pattern_list("a", "", 0), 0);
+	ASSERT_INT_EQ(match_pattern_list("a", "*", 0), 1);
+	ASSERT_INT_EQ(match_pattern_list("a", "!*", 0), -1);
+	ASSERT_INT_EQ(match_pattern_list("a", "!a,*", 0), -1);
+	ASSERT_INT_EQ(match_pattern_list("b", "!a,*", 0), 1);
+	ASSERT_INT_EQ(match_pattern_list("a", "*,!a", 0), -1);
+	ASSERT_INT_EQ(match_pattern_list("b", "*,!a", 0), 1);
+	ASSERT_INT_EQ(match_pattern_list("a", "a,!*", 0), -1);
+	ASSERT_INT_EQ(match_pattern_list("b", "a,!*", 0), -1);
+	ASSERT_INT_EQ(match_pattern_list("a", "!*,a", 0), -1);
+	ASSERT_INT_EQ(match_pattern_list("b", "!*,a", 0), -1);
+	TEST_DONE();
+
+	TEST_START("match_pattern_list lowercase");
+	ASSERT_INT_EQ(match_pattern_list("abc", "ABC", 0), 0);
+	ASSERT_INT_EQ(match_pattern_list("ABC", "abc", 0), 0);
+	ASSERT_INT_EQ(match_pattern_list("abc", "ABC", 1), 1);
+	ASSERT_INT_EQ(match_pattern_list("ABC", "abc", 1), 0);
+	TEST_DONE();
+
+/*
+ * XXX TODO
+ * int      match_host_and_ip(const char *, const char *, const char *);
+ * int      match_user(const char *, const char *, const char *, const char *);
+ * char    *match_list(const char *, const char *, u_int *);
+ * int      addr_match_list(const char *, const char *);
+ * int      addr_match_cidr_list(const char *, const char *);
+ */
+
+}
+

-- 
To stop receiving notification emails like this one, please contact
djm at mindrot.org.


More information about the openssh-commits mailing list