Skip to content

Commit

Permalink
added unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
juerg committed Dec 6, 2023
1 parent a4c8cb3 commit bda58c4
Showing 1 changed file with 152 additions and 8 deletions.
160 changes: 152 additions & 8 deletions src/test/java/com/github/jlangch/venice/modules/CryptoModuleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ public void test_ciphers_available() {
}

@Test
public void test_hash_file_1() {
public void test_hash_file_default_1() {
final Venice venice = new Venice();

// file
Expand All @@ -418,7 +418,7 @@ public void test_hash_file_1() {
}

@Test
public void test_hash_file_2() {
public void test_hash_file_default_2() {
final Venice venice = new Venice();

// string
Expand All @@ -435,7 +435,7 @@ public void test_hash_file_2() {
}

@Test
public void test_hash_file_3() {
public void test_hash_file_default_3() {
final Venice venice = new Venice();

// file-in-stream
Expand All @@ -452,7 +452,7 @@ public void test_hash_file_3() {
}

@Test
public void test_hash_file_4() {
public void test_hash_file_default_4() {
final Venice venice = new Venice();

// bytebuf
Expand All @@ -469,7 +469,75 @@ public void test_hash_file_4() {
}

@Test
public void test_verify_file_hash_1() {
public void test_hash_file_MD5_1() {
final Venice venice = new Venice();

// file
final String script =
"(do \n" +
" (load-module :crypt) \n" +
" (let [file (io/temp-file \"test-\", \".data\") \n" +
" data \"1234567890\"] \n" +
" (io/delete-file-on-exit file) \n" +
" (io/spit file data) \n" +
" (crypt/hash-file file \"salt\" \"MD5\"))) ";

assertEquals("kUucF7TqNzvEmBu/hn3xhg==", venice.eval(script));
}

@Test
public void test_hash_file_MD5_2() {
final Venice venice = new Venice();

// string
final String script =
"(do \n" +
" (load-module :crypt) \n" +
" (let [file (io/temp-file \"test-\", \".data\") \n" +
" data \"1234567890\"] \n" +
" (io/delete-file-on-exit file) \n" +
" (io/spit file data) \n" +
" (crypt/hash-file (io/file-path file) \"salt\" \"MD5\"))) ";

assertEquals("kUucF7TqNzvEmBu/hn3xhg==", venice.eval(script));
}

@Test
public void test_hash_file_MD5_3() {
final Venice venice = new Venice();

// file-in-stream
final String script =
"(do \n" +
" (load-module :crypt) \n" +
" (let [file (io/temp-file \"test-\", \".data\") \n" +
" data \"1234567890\"] \n" +
" (io/delete-file-on-exit file) \n" +
" (io/spit file data) \n" +
" (crypt/hash-file (io/file-in-stream file) \"salt\" \"MD5\"))) ";

assertEquals("kUucF7TqNzvEmBu/hn3xhg==", venice.eval(script));
}

@Test
public void test_hash_file_MD5_4() {
final Venice venice = new Venice();

// bytebuf
final String script =
"(do \n" +
" (load-module :crypt) \n" +
" (let [file (io/temp-file \"test-\", \".data\") \n" +
" data \"1234567890\"] \n" +
" (io/delete-file-on-exit file) \n" +
" (io/spit file data) \n" +
" (crypt/hash-file (io/slurp file :binary true) \"salt\" \"MD5\"))) ";

assertEquals("kUucF7TqNzvEmBu/hn3xhg==", venice.eval(script));
}

@Test
public void test_verify_file_hash_default_1() {
final Venice venice = new Venice();

// file
Expand All @@ -488,7 +556,7 @@ public void test_verify_file_hash_1() {
}

@Test
public void test_verify_file_hash_2() {
public void test_verify_file_hash_default_2() {
final Venice venice = new Venice();

// string
Expand All @@ -507,7 +575,7 @@ public void test_verify_file_hash_2() {
}

@Test
public void test_verify_file_hash_3() {
public void test_verify_file_hash_default_3() {
final Venice venice = new Venice();

// file-in-stream
Expand All @@ -526,7 +594,7 @@ public void test_verify_file_hash_3() {
}

@Test
public void test_verify_file_hash_4() {
public void test_verify_file_hash_default_4() {
final Venice venice = new Venice();

// bytebuf
Expand All @@ -544,6 +612,82 @@ public void test_verify_file_hash_4() {
assertTrue((Boolean)venice.eval(script));
}

@Test
public void test_verify_file_hash_MD5_1() {
final Venice venice = new Venice();

// file
final String script =
"(do \n" +
" (load-module :crypt) \n" +
" (let [file (io/temp-file \"test-\", \".data\") \n" +
" data \"1234567890\" \n" +
" salt \"-salt-\"] \n" +
" (io/delete-file-on-exit file) \n" +
" (io/spit file data) \n" +
" (let [hash (crypt/hash-file file salt \"MD5\")] \n" +
" (crypt/verify-file-hash file salt hash \"MD5\")))) ";

assertTrue((Boolean)venice.eval(script));
}

@Test
public void test_verify_file_hash_MD5_2() {
final Venice venice = new Venice();

// string
final String script =
"(do \n" +
" (load-module :crypt) \n" +
" (let [file (io/temp-file \"test-\", \".data\") \n" +
" data \"1234567890\" \n" +
" salt \"-salt-\"] \n" +
" (io/delete-file-on-exit file) \n" +
" (io/spit file data) \n" +
" (let [hash (crypt/hash-file file salt \"MD5\")] \n" +
" (crypt/verify-file-hash (io/file-path file) salt hash \"MD5\")))) ";

assertTrue((Boolean)venice.eval(script));
}

@Test
public void test_verify_file_hash_MD5_3() {
final Venice venice = new Venice();

// file-in-stream
final String script =
"(do \n" +
" (load-module :crypt) \n" +
" (let [file (io/temp-file \"test-\", \".data\") \n" +
" data \"1234567890\" \n" +
" salt \"-salt-\"] \n" +
" (io/delete-file-on-exit file) \n" +
" (io/spit file data) \n" +
" (let [hash (crypt/hash-file file salt \"MD5\")] \n" +
" (crypt/verify-file-hash (io/file-in-stream file) salt hash \"MD5\")))) ";

assertTrue((Boolean)venice.eval(script));
}

@Test
public void test_verify_file_hash_MD5_4() {
final Venice venice = new Venice();

// bytebuf
final String script =
"(do \n" +
" (load-module :crypt) \n" +
" (let [file (io/temp-file \"test-\", \".data\") \n" +
" data \"1234567890\" \n" +
" salt \"-salt-\"] \n" +
" (io/delete-file-on-exit file) \n" +
" (io/spit file data) \n" +
" (let [hash (crypt/hash-file file salt\"MD5\")] \n" +
" (crypt/verify-file-hash (io/slurp file :binary true) salt hash\"MD5\")))) ";

assertTrue((Boolean)venice.eval(script));
}

@Test
public void test_file_encrypt_decrypt_1() {
final Venice venice = new Venice();
Expand Down

0 comments on commit bda58c4

Please sign in to comment.