From f0d437220d5c76f6b09dee5c5744397549fc3813 Mon Sep 17 00:00:00 2001 From: Lukas Slebodnik Date: Tue, 31 Jul 2018 20:44:16 +0000 Subject: [PATCH] crypto-tests: Add unit test for s3crypt_sha512 Resolves: https://pagure.io/SSSD/sssd/issue/3791 Merges: https://pagure.io/SSSD/sssd/pull-request/3792 Reviewed-by: Jakub Hrozek --- src/tests/crypto-tests.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/tests/crypto-tests.c b/src/tests/crypto-tests.c index 2e826a41b3c1302b87c7136cc37b7c4df02a0584..6f5e22a878ad9e40b73b23915d08395b3f6f2e3d 100644 --- a/src/tests/crypto-tests.c +++ b/src/tests/crypto-tests.c @@ -201,6 +201,37 @@ START_TEST(test_sss_encrypt_decrypt) } END_TEST +START_TEST(test_s3crypt_sha512) +{ + int ret; + char *salt; + char *userhash; + char *comphash; + const char *password = "password123"; + const char *expected_hash = "$6$tU67Q/9h3tm5WJ.U$aL9gjCfiSZQewHTI6A4/MHCVWrMCiJZ.gNXEIw6HO39XGbg.s2nTyGlYXeoQyQtDll3XSbIZN41fJEC3v7ELy0"; + + test_ctx = talloc_new(NULL); + fail_if(test_ctx == NULL); + + ret = s3crypt_gen_salt(test_ctx, &salt); + fail_if(ret != 0); + + ret = s3crypt_sha512(test_ctx, password, salt, &userhash); + fail_if(ret != 0); + + ret = s3crypt_sha512(test_ctx, password, userhash, &comphash); + fail_if(ret != 0); + ck_assert_str_eq(userhash, comphash); + talloc_free(comphash); + + ret = s3crypt_sha512(test_ctx, password, expected_hash, &comphash); + fail_if(ret != 0); + ck_assert_str_eq(expected_hash, comphash); + + talloc_free(test_ctx); +} +END_TEST + Suite *crypto_suite(void) { Suite *s = suite_create("sss_crypto"); @@ -216,6 +247,7 @@ Suite *crypto_suite(void) tcase_add_test(tc, test_base64_encode); tcase_add_test(tc, test_base64_decode); tcase_add_test(tc, test_sss_encrypt_decrypt); + tcase_add_test(tc, test_s3crypt_sha512); /* Add all test cases to the test suite */ suite_add_tcase(s, tc); -- 2.14.4