diff --git a/java/src/test/java/de/gdata/test/integration/RealApiIntegrationTests.java b/java/src/test/java/de/gdata/test/integration/RealApiIntegrationTests.java index 6cf717b9..22888530 100644 --- a/java/src/test/java/de/gdata/test/integration/RealApiIntegrationTests.java +++ b/java/src/test/java/de/gdata/test/integration/RealApiIntegrationTests.java @@ -21,6 +21,7 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import de.gdata.test.unit.Sha256Test; import de.gdata.vaas.ClientCredentialsGrantAuthenticator; import de.gdata.vaas.IAuthenticator; import de.gdata.vaas.ResourceOwnerPasswordGrantAuthenticator; @@ -207,9 +208,7 @@ public void forSha256MultipleUnknownHash() throws Exception { @Test public void forFileSingleMaliciousFile() throws Exception { - var eicar = "X5O!P%@AP[4\\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*"; - var tmpFile = Path.of(System.getProperty("java.io.tmpdir"), "eicar.txt"); - Files.writeString(tmpFile, eicar); + var tmpFile = Sha256Test.writeEicar(); var vaas = this.getVaasWithCredentials(); var sha256 = new Sha256(tmpFile); @@ -224,9 +223,7 @@ public void forFileSingleMaliciousFile() @Test public void forFileSingleMaliciousFileWithVerdictRequestAttributes() throws Exception { - var eicar = "X5O!P%@AP[4\\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*"; - var tmpFile = Path.of(System.getProperty("java.io.tmpdir"), "eicar.txt"); - Files.writeString(tmpFile, eicar); + var tmpFile = Sha256Test.writeEicar(); var vaas = this.getVaasWithCredentials(); var sha256 = new Sha256(tmpFile); diff --git a/java/src/test/java/de/gdata/test/unit/Sha256Test.java b/java/src/test/java/de/gdata/test/unit/Sha256Test.java index 3cafd363..275b632d 100644 --- a/java/src/test/java/de/gdata/test/unit/Sha256Test.java +++ b/java/src/test/java/de/gdata/test/unit/Sha256Test.java @@ -5,6 +5,11 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.security.NoSuchAlgorithmException; + public class Sha256Test { @Test public void fromValidSha256() { @@ -29,4 +34,21 @@ public void fromInvalidSha256() { new Sha256("1000020f89134d831f48541b2d8ec39397bc99fccf4cc86a3861257dbe6d819d0"); }); } + + @Test + public void getValue_returnsSha256() throws IOException, NoSuchAlgorithmException { + var tmpFile = writeEicar(); + + var sha256 = new Sha256(tmpFile); + Files.deleteIfExists(tmpFile); + + assertEquals("275a021bbfb6489e54d471899f7db9d1663fc695ec2fe2a2c4538aabf651fd0f", sha256.getValue()); + } + + public static Path writeEicar() throws IOException { + var eicar = "X5O!P%@AP[4\\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*"; + var tmpFile = Path.of(System.getProperty("java.io.tmpdir"), "eicar.txt"); + Files.writeString(tmpFile, eicar); + return tmpFile; + } }