This is an automated email from the ASF dual-hosted git repository. eiri pushed a commit to branch prototype/fdb-encryption in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 9339e9546a2905d5a8327dedf2f932958a69b821 Author: Eric Avdey <[email protected]> AuthorDate: Fri Mar 6 16:57:52 2020 -0400 Add basic tests --- src/fabric/src/fabric2_encryption.erl | 37 +++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/fabric/src/fabric2_encryption.erl b/src/fabric/src/fabric2_encryption.erl index d9791f8..d47ef55 100644 --- a/src/fabric/src/fabric2_encryption.erl +++ b/src/fabric/src/fabric2_encryption.erl @@ -229,3 +229,40 @@ get_kek() -> unwrap_kek(WrappedKEK) -> KEK = crypto:crypto_one_time(aes_256_ctr, ?MEK, ?IV, WrappedKEK, true), {ok, KEK, WrappedKEK}. + + +-ifdef(TEST). +-include_lib("eunit/include/eunit.hrl"). + +get_unwrap_kek_test() -> + {ok, KEK, WrappedKEK} = get_kek(), + ?assertNotEqual(KEK, WrappedKEK), + ?assertEqual({ok, KEK, WrappedKEK}, unwrap_kek(WrappedKEK)). + +get_dek_test() -> + KEK = crypto:strong_rand_bytes(32), + {ok, DEK} = get_dek(KEK, <<"0001">>, <<"1-abcdefgh">>), + ?assertNotEqual(KEK, DEK), + ?assertEqual(32, byte_size(DEK)). + +encode_decode_test() -> + KEK = crypto:strong_rand_bytes(32), + {IId, DbName, DocId, DocRev, DocBody} + = {<<"dev">>, <<"db">>, <<"0001">>, <<"1-abcdefgh">>, <<"[ohai]">>}, + + {ok, EncResult} = try + do_encode(KEK, IId, DbName, DocId, DocRev, DocBody) + catch + exit:ER -> ER + end, + ?assertNotEqual(DocBody, EncResult), + + {ok, DecResult} = try + do_decode(KEK, IId, DbName, DocId, DocRev, EncResult) + catch + exit:DR -> DR + end, + ?assertEqual(DocBody, DecResult). + + +-endif.
