summaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorGeorge McCollister <George.McCollister@gmail.com>2012-06-19 12:36:28 -0500
committerStephen Gallagher <sgallagh@redhat.com>2012-06-26 09:01:26 -0400
commite07a94a66985b674c5df11ca466792902164c4e2 (patch)
treef6e3443b5665c2a73f56a6dde999f21d25338473 /src/tests
parent9dadbd5cac8b25a198633508a27747039be43c34 (diff)
downloadsssd-e07a94a66985b674c5df11ca466792902164c4e2.tar.gz
sssd-e07a94a66985b674c5df11ca466792902164c4e2.tar.bz2
sssd-e07a94a66985b674c5df11ca466792902164c4e2.zip
libcrypto fully implemented
Implemented working versions of the following functions for libcrypto: sss_base64_encode sss_base64_decode sss_hmac_sha1 sss_password_encrypt sss_password_decrypt test_encrypt_decrypt now expects EOK from libcrypto. test_hmac_sha1 now expects EOK from libcrypto. Added test_base64_encode to test base64 encoding implementation. Added test_base64_decode to test base64 decoding implementation. Signed-off-by: George McCollister <George.McCollister@gmail.com>
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/crypto-tests.c46
1 files changed, 40 insertions, 6 deletions
diff --git a/src/tests/crypto-tests.c b/src/tests/crypto-tests.c
index 045f4262..0492a384 100644
--- a/src/tests/crypto-tests.c
+++ b/src/tests/crypto-tests.c
@@ -60,10 +60,8 @@ START_TEST(test_encrypt_decrypt)
int ret;
int expected;
-#ifdef HAVE_NSS
+#if defined(HAVE_NSS) || defined(HAVE_LIBCRYPTO)
expected = EOK;
-#elif HAVE_LIBCRYPTO
- expected = ENOSYS;
#else
#error Unknown crypto back end
#endif
@@ -108,10 +106,8 @@ START_TEST(test_hmac_sha1)
int ret, expected;
int i;
-#ifdef HAVE_NSS
+#if defined(HAVE_NSS) || defined(HAVE_LIBCRYPTO)
expected = EOK;
-#elif HAVE_LIBCRYPTO
- expected = ENOSYS;
#else
#error Unknown crypto back end
#endif
@@ -126,6 +122,42 @@ START_TEST(test_hmac_sha1)
}
END_TEST
+START_TEST(test_base64_encode)
+{
+ const unsigned char obfbuf[] = "test";
+ const char expected[] = "dGVzdA==";
+ char *obfpwd = NULL;
+
+ test_ctx = talloc_new(NULL);
+ fail_if(test_ctx == NULL);
+ /* Base64 encode the buffer */
+ obfpwd = sss_base64_encode(test_ctx, obfbuf, strlen((const char*)obfbuf));
+ fail_if(obfpwd == NULL);
+ fail_if(strcmp(obfpwd,expected) != 0);
+
+ talloc_free(test_ctx);
+}
+END_TEST
+
+START_TEST(test_base64_decode)
+{
+ unsigned char *obfbuf = NULL;
+ size_t obflen;
+ const char b64encoded[] = "dGVzdA==";
+ const unsigned char expected[] = "test";
+
+ test_ctx = talloc_new(NULL);
+ fail_if(test_ctx == NULL);
+ /* Base64 decode the buffer */
+ obfbuf = sss_base64_decode(test_ctx, b64encoded, &obflen);
+ fail_if(!obfbuf);
+ fail_if(obflen != strlen((const char*)expected));
+ fail_if(memcmp(obfbuf, expected, obflen) != 0);
+
+ talloc_free(test_ctx);
+}
+END_TEST
+
Suite *crypto_suite(void)
{
Suite *s = suite_create("sss_crypto");
@@ -138,6 +170,8 @@ Suite *crypto_suite(void)
#endif
tcase_add_test(tc, test_encrypt_decrypt);
tcase_add_test(tc, test_hmac_sha1);
+ tcase_add_test(tc, test_base64_encode);
+ tcase_add_test(tc, test_base64_decode);
/* Add all test cases to the test suite */
suite_add_tcase(s, tc);