mirror of
https://github.com/Qortal/qortal.git
synced 2025-07-23 04:36:50 +00:00
Take a hash of the previous state's directory structure and file contents, and then include that hash in the patch metadata (when creating a new patch). This allows the integrity of the layers to be validated as each one is applied.
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
package org.qortal.test.arbitrary;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.qortal.arbitrary.ArbitraryDataDigest;
|
||||
import org.qortal.repository.DataException;
|
||||
import org.qortal.test.common.Common;
|
||||
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class ArbitraryDataDigestTests extends Common {
|
||||
|
||||
@Before
|
||||
public void beforeTest() throws DataException {
|
||||
Common.useDefaultSettings();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDirectoryDigest() throws IOException {
|
||||
Path dataPath = Paths.get("src/test/resources/arbitrary/demo1");
|
||||
String expectedHash58 = "59dw8CgVybcHAUL5GYgYUUfFffVVhiMKZLCnULPKT6oC";
|
||||
|
||||
// Ensure directory exists
|
||||
assertTrue(dataPath.toFile().exists());
|
||||
assertTrue(dataPath.toFile().isDirectory());
|
||||
|
||||
// Compute a hash
|
||||
ArbitraryDataDigest digest = new ArbitraryDataDigest(dataPath);
|
||||
digest.compute();
|
||||
assertEquals(expectedHash58, digest.getHash58());
|
||||
|
||||
// Write a random file to .qortal/cache to ensure it isn't being included in the digest function
|
||||
// We exclude all .qortal files from the digest since they can be different with each build, and
|
||||
// we only care about the actual user files
|
||||
FileWriter fileWriter = new FileWriter(Paths.get(dataPath.toString(), ".qortal", "cache").toString());
|
||||
fileWriter.append(UUID.randomUUID().toString());
|
||||
fileWriter.close();
|
||||
|
||||
// Recompute the hash
|
||||
digest = new ArbitraryDataDigest(dataPath);
|
||||
digest.compute();
|
||||
assertEquals(expectedHash58, digest.getHash58());
|
||||
|
||||
// Now compute the hash 100 more times to ensure it's always the same
|
||||
for (int i=0; i<100; i++) {
|
||||
digest = new ArbitraryDataDigest(dataPath);
|
||||
digest.compute();
|
||||
assertEquals(expectedHash58, digest.getHash58());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -1,4 +1,4 @@
|
||||
package org.qortal.test;
|
||||
package org.qortal.test.arbitrary;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -10,7 +10,7 @@ import java.util.Random;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class DataTests extends Common {
|
||||
public class ArbitraryDataFileTests extends Common {
|
||||
|
||||
@Before
|
||||
public void beforeTest() throws DataException {
|
1
src/test/resources/arbitrary/demo1/.qortal/cache
Normal file
1
src/test/resources/arbitrary/demo1/.qortal/cache
Normal file
@@ -0,0 +1 @@
|
||||
2ea5a99a-3b85-4f1f-a259-436787f90bd1
|
1
src/test/resources/arbitrary/demo1/dir1/dir2/lorem5.txt
Normal file
1
src/test/resources/arbitrary/demo1/dir1/dir2/lorem5.txt
Normal file
@@ -0,0 +1 @@
|
||||
Pellentesque laoreet laoreet dui ut volutpat.
|
1
src/test/resources/arbitrary/demo1/dir1/lorem4.txt
Normal file
1
src/test/resources/arbitrary/demo1/dir1/lorem4.txt
Normal file
@@ -0,0 +1 @@
|
||||
Sed non lacus ante.
|
1
src/test/resources/arbitrary/demo1/lorem1.txt
Normal file
1
src/test/resources/arbitrary/demo1/lorem1.txt
Normal file
@@ -0,0 +1 @@
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
1
src/test/resources/arbitrary/demo1/lorem2.txt
Normal file
1
src/test/resources/arbitrary/demo1/lorem2.txt
Normal file
@@ -0,0 +1 @@
|
||||
Quisque viverra neque quis eros dapibus
|
1
src/test/resources/arbitrary/demo1/lorem3.txt
Normal file
1
src/test/resources/arbitrary/demo1/lorem3.txt
Normal file
@@ -0,0 +1 @@
|
||||
Sed ac magna pretium, suscipit mauris sed, ultrices nunc.
|
1
src/test/resources/arbitrary/demo2/dir1/dir2/lorem5.txt
Normal file
1
src/test/resources/arbitrary/demo2/dir1/dir2/lorem5.txt
Normal file
@@ -0,0 +1 @@
|
||||
Pellentesque laoreet laoreet dui ut volutpat.
|
1
src/test/resources/arbitrary/demo2/dir1/lorem4.txt
Normal file
1
src/test/resources/arbitrary/demo2/dir1/lorem4.txt
Normal file
@@ -0,0 +1 @@
|
||||
Sed non lacus ante.
|
1
src/test/resources/arbitrary/demo2/lorem1.txt
Normal file
1
src/test/resources/arbitrary/demo2/lorem1.txt
Normal file
@@ -0,0 +1 @@
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
1
src/test/resources/arbitrary/demo2/lorem2.txt
Normal file
1
src/test/resources/arbitrary/demo2/lorem2.txt
Normal file
@@ -0,0 +1 @@
|
||||
Quisque viverra neque quis eros dapibus
|
1
src/test/resources/arbitrary/demo2/lorem3.txt
Normal file
1
src/test/resources/arbitrary/demo2/lorem3.txt
Normal file
@@ -0,0 +1 @@
|
||||
Sed ac magna pretium, suscipit mauris sed, ultrices nunc.
|
Reference in New Issue
Block a user