summaryrefslogtreecommitdiffstats
path: root/contrib/ntp/tests/libntp/ssl_init.c
diff options
context:
space:
mode:
authordelphij <delphij@FreeBSD.org>2015-07-15 19:21:26 +0000
committerdelphij <delphij@FreeBSD.org>2015-07-15 19:21:26 +0000
commit2a25cee78ab1d37e7d2bc40ae675646974d99f56 (patch)
treeb0302ac4be59e104f4e1e54014561a1389397192 /contrib/ntp/tests/libntp/ssl_init.c
parenta0741a75537b2e0514472ac3b28afc55a7846c30 (diff)
downloadFreeBSD-src-2a25cee78ab1d37e7d2bc40ae675646974d99f56.zip
FreeBSD-src-2a25cee78ab1d37e7d2bc40ae675646974d99f56.tar.gz
MFC r280849,280915-280916,281015-281016,282097,282408,282415,283542,
284864,285169-285170,285435: ntp 4.2.8p3. Relnotes: yes Approved by: re (?)
Diffstat (limited to 'contrib/ntp/tests/libntp/ssl_init.c')
-rw-r--r--contrib/ntp/tests/libntp/ssl_init.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/contrib/ntp/tests/libntp/ssl_init.c b/contrib/ntp/tests/libntp/ssl_init.c
new file mode 100644
index 0000000..fe22414
--- /dev/null
+++ b/contrib/ntp/tests/libntp/ssl_init.c
@@ -0,0 +1,58 @@
+#include "config.h"
+
+#include "ntp.h"
+
+#ifdef OPENSSL
+# include "openssl/err.h"
+# include "openssl/rand.h"
+# include "openssl/evp.h"
+#endif
+
+#include "unity.h"
+
+
+static const size_t TEST_MD5_DIGEST_LENGTH = 16;
+static const size_t TEST_SHA1_DIGEST_LENGTH = 20;
+
+
+// keytype_from_text()
+void test_MD5KeyTypeWithoutDigestLength() {
+ TEST_ASSERT_EQUAL(KEY_TYPE_MD5, keytype_from_text("MD5", NULL));
+}
+
+void test_MD5KeyTypeWithDigestLength() {
+ size_t digestLength;
+ size_t expected = TEST_MD5_DIGEST_LENGTH;
+
+ TEST_ASSERT_EQUAL(KEY_TYPE_MD5, keytype_from_text("MD5", &digestLength));
+ TEST_ASSERT_EQUAL(expected, digestLength);
+}
+
+
+void test_SHA1KeyTypeWithDigestLength() {
+#ifdef OPENSSL
+ size_t digestLength;
+ size_t expected = TEST_SHA1_DIGEST_LENGTH;
+
+ TEST_ASSERT_EQUAL(NID_sha, keytype_from_text("SHA", &digestLength));
+ TEST_ASSERT_EQUAL(expected, digestLength);
+ /* OPENSSL */
+#else
+ TEST_IGNORE_MESSAGE("Skipping because OPENSSL isn't defined");
+#endif
+}
+
+
+// keytype_name()
+void test_MD5KeyName() {
+ TEST_ASSERT_EQUAL_STRING("MD5", keytype_name(KEY_TYPE_MD5));
+}
+
+void test_SHA1KeyName() {
+#ifdef OPENSSL
+ TEST_ASSERT_EQUAL_STRING("SHA", keytype_name(NID_sha));
+#else
+ TEST_IGNORE_MESSAGE("Skipping because OPENSSL isn't defined");
+#endif /* OPENSSL */
+}
+
OpenPOWER on IntegriCloud