[Git][NTPsec/ntpsec][master] tests/decodenetnum: test for /etc/services and port names.

Gary E. Miller gitlab at mg.gitlab.com
Thu Apr 13 19:46:31 UTC 2017


Gary E. Miller pushed to branch master at NTPsec / ntpsec


Commits:
25a240c2 by Gary E. Miller at 2017-04-13T12:45:28-07:00
tests/decodenetnum: test for /etc/services and port names.

Some overly lean jails fail to supply /etc/services.

- - - - -


1 changed file:

- tests/libntp/decodenetnum.c


Changes:

=====================================
tests/libntp/decodenetnum.c
=====================================
--- a/tests/libntp/decodenetnum.c
+++ b/tests/libntp/decodenetnum.c
@@ -1,3 +1,7 @@
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
 #include "config.h"
 #include "ntp_stdlib.h"
 
@@ -13,6 +17,18 @@ TEST_TEAR_DOWN(decodenetnum) {}
 #include "sockaddrtest.h"
 
 
+TEST(decodenetnum, Services) {
+	const char *str = "/etc/services";
+        int ret;
+
+        /* try to open /etc/services for read */
+        ret = open(str, O_RDONLY);
+	TEST_ASSERT_NOT_EQUAL(-1, ret);
+        if ( -1 != ret) {
+		close(ret);
+        }
+}
+
 TEST(decodenetnum, IPv4AddressOnly) {
 	const char *str = "192.0.2.1";
         int ret;
@@ -28,6 +44,7 @@ TEST(decodenetnum, IPv4AddressOnly) {
 	TEST_ASSERT_TRUE(IsEqualS(&expected, &actual));
 }
 
+/* test with numeric port */
 TEST(decodenetnum, IPv4AddressWithPort) {
 	const char *str = "192.0.2.2:2000";
 	sockaddr_u actual;
@@ -43,6 +60,22 @@ TEST(decodenetnum, IPv4AddressWithPort) {
 	TEST_ASSERT_TRUE(IsEqualS(&expected, &actual));
 }
 
+/* test for named port */
+TEST(decodenetnum, IPv4AddressWithPort2) {
+	const char *str = "192.168.2.2:ntp";
+	sockaddr_u actual;
+        int ret;
+
+	sockaddr_u expected;
+	SET_AF(&expected, AF_INET);
+	PSOCK_ADDR4(&expected)->s_addr = inet_addr("192.168.2.2");
+	SET_PORT(&expected, 123);
+
+	ret = decodenetnum(str, &actual);
+	TEST_ASSERT_EQUAL_INT(0, ret);
+	TEST_ASSERT_TRUE(IsEqualS(&expected, &actual));
+}
+
 TEST(decodenetnum, IPv6AddressOnly) {
         int ret;
 	const struct in6_addr address = {{{
@@ -115,8 +148,10 @@ TEST(decodenetnum, IllegalCharInPort) {
 }
 
 TEST_GROUP_RUNNER(decodenetnum) {
+	RUN_TEST_CASE(decodenetnum, Services);
 	RUN_TEST_CASE(decodenetnum, IPv4AddressOnly);
 	RUN_TEST_CASE(decodenetnum, IPv4AddressWithPort);
+	RUN_TEST_CASE(decodenetnum, IPv4AddressWithPort2);
 	RUN_TEST_CASE(decodenetnum, IPv6AddressOnly);
 	RUN_TEST_CASE(decodenetnum, IPv6AddressWithPort);
 	RUN_TEST_CASE(decodenetnum, IllegalAddress);



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/25a240c2ef230ee4af9f9f9bcd314ca5a1156c62

---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/25a240c2ef230ee4af9f9f9bcd314ca5a1156c62
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170413/7a8d4cda/attachment.html>


More information about the vc mailing list