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 bda58c4 commit 8815e7d
Showing 1 changed file with 288 additions and 0 deletions.
288 changes: 288 additions & 0 deletions src/test/java/com/github/jlangch/venice/modules/CryptoModuleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,142 @@ public void test_hash_file_MD5_4() {
assertEquals("kUucF7TqNzvEmBu/hn3xhg==", venice.eval(script));
}

@Test
public void test_hash_file_SHA1_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\" \"SHA-1\"))) ";

assertEquals("uhAVLkBSJ7kyuYmYQfREs6A7+/A=", venice.eval(script));
}

@Test
public void test_hash_file_SHA1_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\" \"SHA-1\"))) ";

assertEquals("uhAVLkBSJ7kyuYmYQfREs6A7+/A=", venice.eval(script));
}

@Test
public void test_hash_file_SHA1_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\" \"SHA-1\"))) ";

assertEquals("uhAVLkBSJ7kyuYmYQfREs6A7+/A=", venice.eval(script));
}

@Test
public void test_hash_file_SHA1_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\" \"SHA-1\")))";

assertEquals("uhAVLkBSJ7kyuYmYQfREs6A7+/A=", venice.eval(script));
}

@Test
public void test_hash_file_SHA512_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\" \"SHA-512\"))) ";

assertEquals("qFUlDmCuGAA8Y8qKrjMd4mUdQYau4Cs6gTcYs39oRF0wuOG46oLfi/7nUbHd0IH2uiBe+xUzjcsAT4CImO/liw==", venice.eval(script));
}

@Test
public void test_hash_file_SHA512_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\" \"SHA-512\")))";

assertEquals("qFUlDmCuGAA8Y8qKrjMd4mUdQYau4Cs6gTcYs39oRF0wuOG46oLfi/7nUbHd0IH2uiBe+xUzjcsAT4CImO/liw==", venice.eval(script));
}

@Test
public void test_hash_file_SHA512_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\" \"SHA-512\")))";

assertEquals("qFUlDmCuGAA8Y8qKrjMd4mUdQYau4Cs6gTcYs39oRF0wuOG46oLfi/7nUbHd0IH2uiBe+xUzjcsAT4CImO/liw==", venice.eval(script));
}

@Test
public void test_hash_file_SHA512_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\" \"SHA-512\")))";

assertEquals("qFUlDmCuGAA8Y8qKrjMd4mUdQYau4Cs6gTcYs39oRF0wuOG46oLfi/7nUbHd0IH2uiBe+xUzjcsAT4CImO/liw==", venice.eval(script));
}

@Test
public void test_verify_file_hash_default_1() {
final Venice venice = new Venice();
Expand Down Expand Up @@ -688,6 +824,158 @@ public void test_verify_file_hash_MD5_4() {
assertTrue((Boolean)venice.eval(script));
}

@Test
public void test_verify_file_hash_SHA1_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 \"SHA-1\")] \n" +
" (crypt/verify-file-hash file salt hash \"SHA-1\")))) ";

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

@Test
public void test_verify_file_hash_SHA1_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 \"SHA-1\")] \n" +
" (crypt/verify-file-hash (io/file-path file) salt hash \"SHA-1\")))) ";

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

@Test
public void test_verify_file_hash_SHA1_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 \"SHA-1\")] \n" +
" (crypt/verify-file-hash (io/file-in-stream file) salt hash \"SHA-1\")))) ";

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

@Test
public void test_verify_file_hash_SHA1_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\"SHA-1\")] \n" +
" (crypt/verify-file-hash (io/slurp file :binary true) salt hash\"SHA-1\")))) ";

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

@Test
public void test_verify_file_hash_SHA512_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 \"SHA-512\")] \n" +
" (crypt/verify-file-hash file salt hash \"SHA-512\")))) ";

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

@Test
public void test_verify_file_hash_SHA512_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 \"SHA-512\")] \n" +
" (crypt/verify-file-hash (io/file-path file) salt hash \"SHA-512\")))) ";

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

@Test
public void test_verify_file_hash_SHA512_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 \"SHA-512\")] \n" +
" (crypt/verify-file-hash (io/file-in-stream file) salt hash \"SHA-512\")))) ";

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

@Test
public void test_verify_file_hash_SHA512_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\"SHA-512\")] \n" +
" (crypt/verify-file-hash (io/slurp file :binary true) salt hash\"SHA-512\")))) ";

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

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

0 comments on commit 8815e7d

Please sign in to comment.