Simplify the Ghostryde API

First step of RDE encoding refactoring.

Creates a single InputStream (OutputStream) to decode (encode) Ghostryde files.
This replaces the 3 InputStreams (OutputStreams) that were needed before.

Also removes a lot of classes, and removes the "injection" of the Ghostryde
class. It's an encoding, there's no point in injecting it.

Finally, removed the buffer-size configuration and replaced with a static final
const value. It's just a buffer size - it doesn't actually affect much. There
are much more "important" fields that weren't configured (such as the
compression algorithm and whether or not to do integrity checks)

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=202319102
This commit is contained in:
guyben 2018-06-27 09:10:19 -07:00 committed by Ben McIlwain
parent bee3d6a5a4
commit 6ff48b7dae
15 changed files with 347 additions and 589 deletions

View file

@ -19,7 +19,6 @@ import static com.google.common.truth.Truth.assertWithMessage;
import static google.registry.testing.GcsTestingUtils.readGcsFile;
import static google.registry.testing.SystemInfo.hasCommand;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.joda.time.DateTimeZone.UTC;
import static org.junit.Assume.assumeTrue;
import com.google.appengine.tools.cloudstorage.GcsFilename;
@ -101,7 +100,6 @@ public class BrdaCopyActionTest extends ShardableTestCase {
@Before
public void before() throws Exception {
action.gcsUtils = gcsUtils;
action.ghostryde = new Ghostryde(23);
action.pgpCompressionFactory = new RydePgpCompressionOutputStreamFactory(() -> 1024);
action.pgpEncryptionFactory = new RydePgpEncryptionOutputStreamFactory(() -> 1024);
action.pgpFileFactory = new RydePgpFileOutputStreamFactory(() -> 1024);
@ -116,8 +114,7 @@ public class BrdaCopyActionTest extends ShardableTestCase {
action.stagingDecryptionKey = decryptKey;
byte[] xml = DEPOSIT_XML.read();
GcsTestingUtils.writeGcsFile(gcsService, STAGE_FILE,
Ghostryde.encode(xml, encryptKey, "lobster.xml", new DateTime(UTC)));
GcsTestingUtils.writeGcsFile(gcsService, STAGE_FILE, Ghostryde.encode(xml, encryptKey));
GcsTestingUtils.writeGcsFile(gcsService, STAGE_LENGTH_FILE,
Long.toString(xml.length).getBytes(UTF_8));
}

View file

@ -34,7 +34,6 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import org.bouncycastle.openpgp.PGPPublicKey;
import org.joda.time.DateTime;
import org.junit.Rule;
import org.junit.experimental.theories.DataPoints;
import org.junit.experimental.theories.Theories;
@ -61,18 +60,6 @@ public class GhostrydeGpgIntegrationTest extends ShardableTestCase {
new GpgCommand("gpg2"),
};
@DataPoints
public static BufferSize[] bufferSizes = new BufferSize[] {
new BufferSize(1),
new BufferSize(7),
};
@DataPoints
public static Filename[] filenames = new Filename[] {
new Filename("lol.txt"),
// new Filename("(◕‿◕).txt"), // gpg displays this with zany hex characters.
};
@DataPoints
public static Content[] contents = new Content[] {
new Content("(◕‿◕)"),
@ -82,21 +69,16 @@ public class GhostrydeGpgIntegrationTest extends ShardableTestCase {
};
@Theory
public void test(GpgCommand cmd, BufferSize bufferSize, Filename filename, Content content)
throws Exception {
public void test(GpgCommand cmd, Content content) throws Exception {
assumeTrue(hasCommand(cmd.get() + " --version"));
Keyring keyring = new FakeKeyringModule().get();
PGPPublicKey publicKey = keyring.getRdeStagingEncryptionKey();
File file = new File(gpg.getCwd(), "love.gpg");
byte[] data = content.get().getBytes(UTF_8);
DateTime mtime = DateTime.parse("1984-12-18T00:30:00Z");
Ghostryde ghost = new Ghostryde(bufferSize.get());
try (OutputStream output = new FileOutputStream(file);
Ghostryde.Encryptor encryptor = ghost.openEncryptor(output, publicKey);
Ghostryde.Compressor kompressor = ghost.openCompressor(encryptor);
OutputStream os = ghost.openOutput(kompressor, filename.get(), mtime)) {
os.write(data);
OutputStream ghostrydeEncoder = Ghostryde.encoder(output, publicKey)) {
ghostrydeEncoder.write(data);
}
Process pid = gpg.exec(cmd.get(), "--list-packets", "--keyid-format", "long", file.getPath());
@ -106,13 +88,13 @@ public class GhostrydeGpgIntegrationTest extends ShardableTestCase {
assertThat(stdout).contains(":compressed packet:");
assertThat(stdout).contains(":encrypted data packet:");
assertThat(stdout).contains("version 3, algo 1, keyid A59C132F3589A1D5");
assertThat(stdout).contains("name=\"" + filename.get() + "\"");
assertThat(stdout).contains("name=\"" + Ghostryde.INNER_FILENAME + "\"");
assertThat(stderr).contains("encrypted with 2048-bit RSA key, ID A59C132F3589A1D5");
pid = gpg.exec(cmd.get(), "--use-embedded-filename", file.getPath());
stderr = CharStreams.toString(new InputStreamReader(pid.getErrorStream(), UTF_8));
assertWithMessage(stderr).that(pid.waitFor()).isEqualTo(0);
File dataFile = new File(gpg.getCwd(), filename.get());
File dataFile = new File(gpg.getCwd(), Ghostryde.INNER_FILENAME);
assertThat(dataFile.exists()).isTrue();
assertThat(slurp(dataFile)).isEqualTo(content.get());
}
@ -133,30 +115,6 @@ public class GhostrydeGpgIntegrationTest extends ShardableTestCase {
}
}
private static class BufferSize {
private final int value;
BufferSize(int value) {
this.value = value;
}
int get() {
return value;
}
}
private static class Filename {
private final String value;
Filename(String value) {
this.value = value;
}
String get() {
return value;
}
}
private static class Content {
private final String value;

View file

@ -26,17 +26,17 @@ import static org.junit.Assume.assumeThat;
import com.google.common.io.ByteStreams;
import google.registry.keyring.api.Keyring;
import google.registry.rde.Ghostryde.DecodeResult;
import google.registry.testing.BouncyCastleProviderRule;
import google.registry.testing.FakeKeyringModule;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Base64;
import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPKeyPair;
import org.bouncycastle.openpgp.PGPPrivateKey;
import org.bouncycastle.openpgp.PGPPublicKey;
import org.joda.time.DateTime;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
@ -53,18 +53,6 @@ public class GhostrydeTest {
@Rule
public final BouncyCastleProviderRule bouncy = new BouncyCastleProviderRule();
@DataPoints
public static BufferSize[] bufferSizes = new BufferSize[] {
new BufferSize(1),
new BufferSize(7),
};
@DataPoints
public static Filename[] filenames = new Filename[] {
new Filename("lol.txt"),
// new Filename("(◕‿◕).txt"), // gpg displays this with zany hex characters.
};
@DataPoints
public static Content[] contents = new Content[] {
new Content("hi"),
@ -75,46 +63,34 @@ public class GhostrydeTest {
};
@Theory
public void testSimpleApi(Filename filename, Content content) throws Exception {
public void testSimpleApi(Content content) throws Exception {
Keyring keyring = new FakeKeyringModule().get();
byte[] data = content.get().getBytes(UTF_8);
DateTime mtime = DateTime.parse("1984-12-18T00:30:00Z");
PGPPublicKey publicKey = keyring.getRdeStagingEncryptionKey();
PGPPrivateKey privateKey = keyring.getRdeStagingDecryptionKey();
byte[] blob = Ghostryde.encode(data, publicKey, filename.get(), mtime);
DecodeResult result = Ghostryde.decode(blob, privateKey);
byte[] blob = Ghostryde.encode(data, publicKey);
byte[] result = Ghostryde.decode(blob, privateKey);
assertThat(result.getName()).isEqualTo(filename.get());
assertThat(result.getModified()).isEqualTo(mtime);
assertThat(new String(result.getData(), UTF_8)).isEqualTo(content.get());
assertThat(new String(result, UTF_8)).isEqualTo(content.get());
}
@Theory
public void testStreamingApi(BufferSize bufferSize, Filename filename, Content content)
throws Exception {
public void testStreamingApi(Content content) throws Exception {
Keyring keyring = new FakeKeyringModule().get();
byte[] data = content.get().getBytes(UTF_8);
DateTime mtime = DateTime.parse("1984-12-18T00:30:00Z");
PGPPublicKey publicKey = keyring.getRdeStagingEncryptionKey();
PGPPrivateKey privateKey = keyring.getRdeStagingDecryptionKey();
Ghostryde ghost = new Ghostryde(bufferSize.get());
ByteArrayOutputStream bsOut = new ByteArrayOutputStream();
try (Ghostryde.Encryptor encryptor = ghost.openEncryptor(bsOut, publicKey);
Ghostryde.Compressor kompressor = ghost.openCompressor(encryptor);
OutputStream output = ghost.openOutput(kompressor, filename.get(), mtime)) {
output.write(data);
try (OutputStream encoder = Ghostryde.encoder(bsOut, publicKey)) {
encoder.write(data);
}
ByteArrayInputStream bsIn = new ByteArrayInputStream(bsOut.toByteArray());
bsOut.reset();
try (Ghostryde.Decryptor decryptor = ghost.openDecryptor(bsIn, privateKey);
Ghostryde.Decompressor decompressor = ghost.openDecompressor(decryptor);
Ghostryde.Input input = ghost.openInput(decompressor)) {
assertThat(input.getName()).isEqualTo(filename.get());
assertThat(input.getModified()).isEqualTo(mtime);
ByteStreams.copy(input, bsOut);
try (InputStream decoder = Ghostryde.decoder(bsIn, privateKey)) {
ByteStreams.copy(decoder, bsOut);
}
assertThat(bsOut.size()).isEqualTo(data.length);
@ -122,51 +98,20 @@ public class GhostrydeTest {
}
@Theory
public void testEncryptOnly(Content content) throws Exception {
public void testStreamingApi_withSize(Content content) throws Exception {
Keyring keyring = new FakeKeyringModule().get();
byte[] data = content.get().getBytes(UTF_8);
PGPPublicKey publicKey = keyring.getRdeStagingEncryptionKey();
PGPPrivateKey privateKey = keyring.getRdeStagingDecryptionKey();
Ghostryde ghost = new Ghostryde(1024);
ByteArrayOutputStream bsOut = new ByteArrayOutputStream();
try (Ghostryde.Encryptor encryptor = ghost.openEncryptor(bsOut, publicKey)) {
encryptor.write(data);
ByteArrayOutputStream lenOut = new ByteArrayOutputStream();
try (OutputStream encoder = Ghostryde.encoder(bsOut, publicKey, lenOut)) {
encoder.write(data);
}
ByteArrayInputStream bsIn = new ByteArrayInputStream(bsOut.toByteArray());
bsOut.reset();
try (Ghostryde.Decryptor decryptor = ghost.openDecryptor(bsIn, privateKey)) {
ByteStreams.copy(decryptor, bsOut);
}
assertThat(new String(bsOut.toByteArray(), UTF_8)).isEqualTo(content.get());
}
@Theory
public void testEncryptCompressOnly(Content content) throws Exception {
Keyring keyring = new FakeKeyringModule().get();
PGPPublicKey publicKey = keyring.getRdeStagingEncryptionKey();
PGPPrivateKey privateKey = keyring.getRdeStagingDecryptionKey();
byte[] data = content.get().getBytes(UTF_8);
Ghostryde ghost = new Ghostryde(1024);
ByteArrayOutputStream bsOut = new ByteArrayOutputStream();
try (Ghostryde.Encryptor encryptor = ghost.openEncryptor(bsOut, publicKey);
Ghostryde.Compressor kompressor = ghost.openCompressor(encryptor)) {
kompressor.write(data);
}
assertThat(new String(bsOut.toByteArray(), UTF_8)).isNotEqualTo(content.get());
ByteArrayInputStream bsIn = new ByteArrayInputStream(bsOut.toByteArray());
bsOut.reset();
try (Ghostryde.Decryptor decryptor = ghost.openDecryptor(bsIn, privateKey);
Ghostryde.Decompressor decompressor = ghost.openDecompressor(decryptor)) {
ByteStreams.copy(decompressor, bsOut);
}
assertThat(new String(bsOut.toByteArray(), UTF_8)).isEqualTo(content.get());
assertThat(Ghostryde.readLength(new ByteArrayInputStream(lenOut.toByteArray())))
.isEqualTo(data.length);
assertThat(Long.parseLong(new String(lenOut.toByteArray(), UTF_8))).isEqualTo(data.length);
}
@Theory
@ -177,26 +122,22 @@ public class GhostrydeTest {
PGPPublicKey publicKey = keyring.getRdeStagingEncryptionKey();
PGPPrivateKey privateKey = keyring.getRdeStagingDecryptionKey();
byte[] data = content.get().getBytes(UTF_8);
DateTime mtime = DateTime.parse("1984-12-18T00:30:00Z");
Ghostryde ghost = new Ghostryde(1024);
ByteArrayOutputStream bsOut = new ByteArrayOutputStream();
try (Ghostryde.Encryptor encryptor = ghost.openEncryptor(bsOut, publicKey);
Ghostryde.Compressor kompressor = ghost.openCompressor(encryptor);
OutputStream output = ghost.openOutput(kompressor, "lol", mtime)) {
output.write(data);
try (OutputStream encoder = Ghostryde.encoder(bsOut, publicKey)) {
encoder.write(data);
}
byte[] ciphertext = bsOut.toByteArray();
korruption(ciphertext, ciphertext.length / 2);
korruption(ciphertext, ciphertext.length - 1);
ByteArrayInputStream bsIn = new ByteArrayInputStream(ciphertext);
IllegalStateException thrown =
assertThrows(
IllegalStateException.class,
() -> {
try (Ghostryde.Decryptor decryptor = ghost.openDecryptor(bsIn, privateKey)) {
ByteStreams.copy(decryptor, ByteStreams.nullOutputStream());
try (InputStream decoder = Ghostryde.decoder(bsIn, privateKey)) {
ByteStreams.copy(decoder, ByteStreams.nullOutputStream());
}
});
assertThat(thrown).hasMessageThat().contains("tampering");
@ -210,14 +151,10 @@ public class GhostrydeTest {
PGPPublicKey publicKey = keyring.getRdeStagingEncryptionKey();
PGPPrivateKey privateKey = keyring.getRdeStagingDecryptionKey();
byte[] data = content.get().getBytes(UTF_8);
DateTime mtime = DateTime.parse("1984-12-18T00:30:00Z");
Ghostryde ghost = new Ghostryde(1024);
ByteArrayOutputStream bsOut = new ByteArrayOutputStream();
try (Ghostryde.Encryptor encryptor = ghost.openEncryptor(bsOut, publicKey);
Ghostryde.Compressor kompressor = ghost.openCompressor(encryptor);
OutputStream output = ghost.openOutput(kompressor, "lol", mtime)) {
output.write(data);
try (OutputStream encoder = Ghostryde.encoder(bsOut, publicKey)) {
encoder.write(data);
}
byte[] ciphertext = bsOut.toByteArray();
@ -227,28 +164,58 @@ public class GhostrydeTest {
assertThrows(
PGPException.class,
() -> {
try (Ghostryde.Decryptor decryptor = ghost.openDecryptor(bsIn, privateKey)) {
ByteStreams.copy(decryptor, ByteStreams.nullOutputStream());
try (InputStream decoder = Ghostryde.decoder(bsIn, privateKey)) {
ByteStreams.copy(decoder, ByteStreams.nullOutputStream());
}
});
}
@Test
public void testFullEncryption() throws Exception {
// Check that the full encryption hasn't changed. All the other tests check that encrypting and
// decrypting results in the original data, but not whether the encryption method has changed.
FakeKeyringModule keyringModule = new FakeKeyringModule();
PGPKeyPair dsa = keyringModule.get("rde-unittest@registry.test", ENCRYPT);
PGPPrivateKey privateKey = dsa.getPrivateKey();
// Encryption is inconsistent because it uses a random state. But decryption is consistent!
//
// If the encryption has legitimately changed - uncomment the following code, and copy the new
// encryptedInputBase64 from the test error:
//
// assertThat(
// Base64.getMimeEncoder()
// .encodeToString(
// Ghostryde.encode("Some data!!!111!!!".getBytes(UTF_8), dsa.getPublicKey())))
// .isEqualTo("expect error");
String encryptedInputBase64 =
" hQEMA6WcEy81iaHVAQgAnn9bS6IOCTW2uZnITPWH8zIYr6K7YJslv38c4YU5eQqVhHC5PN0NhM2l\n"
+ " i89U3lUE6gp3DdEEbTbugwXCHWyRL4fYTlpiHZjBn2vZdSS21EAG+q1XuTaD8DTjkC2G060/sW6i\n"
+ " 0gSIkksqgubbSVZTxHEqh92tv35KCqiYc52hjKZIIGI8FHhpJOtDa3bhMMad8nrMy3vbv5LiYNh5\n"
+ " j3DUCFhskU8Ldi1vBfXIonqUNLBrD/R471VVJyQ3NoGQTVUF9uXLoy+2dL0oBLc1Avj1XNP5PQ08\n"
+ " MWlqmezkLdY0oHnQqTHYhYDxRo/Sw7xO1GLwWR11rcx/IAJloJbKSHTFeNJUAcKFnKvPDwBk3nnr\n"
+ " uR505HtOj/tZDT5weVjhrlnmWXzaBRmYASy6PXZu6KzTbPUQTf4JeeJWdyw7glLMr2WPdMVPGZ8e\n"
+ " gcFAjSJZjZlqohZyBUpP\n";
byte[] result =
Ghostryde.decode(Base64.getMimeDecoder().decode(encryptedInputBase64), privateKey);
assertThat(new String(result, UTF_8)).isEqualTo("Some data!!!111!!!");
}
@Test
public void testFailure_keyMismatch() throws Exception {
FakeKeyringModule keyringModule = new FakeKeyringModule();
byte[] data = "Fanatics have their dreams, wherewith they weave.".getBytes(UTF_8);
DateTime mtime = DateTime.parse("1984-12-18T00:30:00Z");
PGPKeyPair dsa1 = keyringModule.get("rde-unittest@registry.test", ENCRYPT);
PGPKeyPair dsa2 = keyringModule.get("rde-unittest-dsa@registry.test", ENCRYPT);
PGPPublicKey publicKey = dsa1.getPublicKey();
PGPPrivateKey privateKey = dsa2.getPrivateKey();
Ghostryde ghost = new Ghostryde(1024);
ByteArrayOutputStream bsOut = new ByteArrayOutputStream();
try (Ghostryde.Encryptor encryptor = ghost.openEncryptor(bsOut, publicKey);
Ghostryde.Compressor kompressor = ghost.openCompressor(encryptor);
OutputStream output = ghost.openOutput(kompressor, "lol", mtime)) {
output.write(data);
try (OutputStream encoder = Ghostryde.encoder(bsOut, publicKey)) {
encoder.write(data);
}
ByteArrayInputStream bsIn = new ByteArrayInputStream(bsOut.toByteArray());
@ -256,8 +223,8 @@ public class GhostrydeTest {
assertThrows(
PGPException.class,
() -> {
try (Ghostryde.Decryptor decryptor = ghost.openDecryptor(bsIn, privateKey)) {
ByteStreams.copy(decryptor, ByteStreams.nullOutputStream());
try (InputStream decoder = Ghostryde.decoder(bsIn, privateKey)) {
ByteStreams.copy(decoder, ByteStreams.nullOutputStream());
}
});
assertThat(thrown)
@ -270,7 +237,6 @@ public class GhostrydeTest {
public void testFailure_keyCorruption() throws Exception {
FakeKeyringModule keyringModule = new FakeKeyringModule();
byte[] data = "Fanatics have their dreams, wherewith they weave.".getBytes(UTF_8);
DateTime mtime = DateTime.parse("1984-12-18T00:30:00Z");
PGPKeyPair rsa = keyringModule.get("rde-unittest@registry.test", ENCRYPT);
PGPPublicKey publicKey = rsa.getPublicKey();
@ -282,17 +248,14 @@ public class GhostrydeTest {
rsa.getPrivateKey().getPublicKeyPacket(),
rsa.getPrivateKey().getPrivateKeyDataPacket());
Ghostryde ghost = new Ghostryde(1024);
ByteArrayOutputStream bsOut = new ByteArrayOutputStream();
try (Ghostryde.Encryptor encryptor = ghost.openEncryptor(bsOut, publicKey);
Ghostryde.Compressor kompressor = ghost.openCompressor(encryptor);
OutputStream output = ghost.openOutput(kompressor, "lol", mtime)) {
output.write(data);
try (OutputStream encoder = Ghostryde.encoder(bsOut, publicKey)) {
encoder.write(data);
}
ByteArrayInputStream bsIn = new ByteArrayInputStream(bsOut.toByteArray());
try (Ghostryde.Decryptor decryptor = ghost.openDecryptor(bsIn, privateKey)) {
ByteStreams.copy(decryptor, ByteStreams.nullOutputStream());
try (InputStream decoder = Ghostryde.decoder(bsIn, privateKey)) {
ByteStreams.copy(decoder, ByteStreams.nullOutputStream());
}
}
@ -304,30 +267,6 @@ public class GhostrydeTest {
}
}
private static class BufferSize {
private final int value;
BufferSize(int value) {
this.value = value;
}
int get() {
return value;
}
}
private static class Filename {
private final String value;
Filename(String value) {
this.value = value;
}
String get() {
return value;
}
}
private static class Content {
private final String value;

View file

@ -26,7 +26,6 @@ import static google.registry.testing.GcsTestingUtils.writeGcsFile;
import static google.registry.testing.JUnitBackports.assertThrows;
import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
import static javax.servlet.http.HttpServletResponse.SC_OK;
import static org.joda.time.DateTimeZone.UTC;
import static org.joda.time.Duration.standardDays;
import static org.joda.time.Duration.standardSeconds;
import static org.mockito.Matchers.any;
@ -105,7 +104,6 @@ public class RdeReportActionTest {
reporter.retrier = new Retrier(new FakeSleeper(new FakeClock()), 3);
RdeReportAction action = new RdeReportAction();
action.gcsUtils = new GcsUtils(gcsService, 1024);
action.ghostryde = new Ghostryde(1024);
action.response = response;
action.bucket = "tub";
action.tld = "test";
@ -125,10 +123,7 @@ public class RdeReportActionTest {
Cursor.create(RDE_REPORT, DateTime.parse("2006-06-06TZ"), Registry.get("test")));
persistResource(
Cursor.create(RDE_UPLOAD, DateTime.parse("2006-06-07TZ"), Registry.get("test")));
writeGcsFile(
gcsService,
reportFile,
Ghostryde.encode(REPORT_XML.read(), encryptKey, "darkside.xml", DateTime.now(UTC)));
writeGcsFile(gcsService, reportFile, Ghostryde.encode(REPORT_XML.read(), encryptKey));
}
@Test

View file

@ -136,7 +136,6 @@ public class RdeStagingActionTest extends MapreduceTestCase<RdeStagingAction> {
new FakeLockHandler(true),
0, // gcsBufferSize
"rde-bucket", // bucket
31337, // ghostrydeBufferSize
Duration.standardHours(1), // lockTimeout
PgpHelper.convertPublicKeyToBytes(encryptKey), // stagingKeyBytes
false); // lenient
@ -330,9 +329,9 @@ public class RdeStagingActionTest extends MapreduceTestCase<RdeStagingAction> {
action.run();
executeTasksUntilEmpty("mapreduce", clock);
XjcRdeDeposit deposit = unmarshal(
XjcRdeDeposit.class,
Ghostryde.decode(readGcsFile(gcsService, XML_FILE), decryptKey).getData());
XjcRdeDeposit deposit =
unmarshal(
XjcRdeDeposit.class, Ghostryde.decode(readGcsFile(gcsService, XML_FILE), decryptKey));
XjcRdeHeader header = extractAndRemoveContentWithType(XjcRdeHeader.class, deposit);
assertThat(header.getTld()).isEqualTo("lol");
@ -361,9 +360,9 @@ public class RdeStagingActionTest extends MapreduceTestCase<RdeStagingAction> {
action.run();
executeTasksUntilEmpty("mapreduce", clock);
XjcRdeDeposit deposit = unmarshal(
XjcRdeDeposit.class,
Ghostryde.decode(readGcsFile(gcsService, XML_FILE), decryptKey).getData());
XjcRdeDeposit deposit =
unmarshal(
XjcRdeDeposit.class, Ghostryde.decode(readGcsFile(gcsService, XML_FILE), decryptKey));
assertThat(deposit.getType()).isEqualTo(XjcRdeDepositTypeType.FULL);
assertThat(deposit.getId()).isEqualTo(RdeUtil.timestampToId(DateTime.parse("2000-01-01TZ")));
assertThat(deposit.getWatermark()).isEqualTo(DateTime.parse("2000-01-01TZ"));
@ -403,9 +402,9 @@ public class RdeStagingActionTest extends MapreduceTestCase<RdeStagingAction> {
action.run();
executeTasksUntilEmpty("mapreduce", clock);
XjcRdeDeposit deposit = unmarshal(
XjcRdeDeposit.class,
Ghostryde.decode(readGcsFile(gcsService, XML_FILE), decryptKey).getData());
XjcRdeDeposit deposit =
unmarshal(
XjcRdeDeposit.class, Ghostryde.decode(readGcsFile(gcsService, XML_FILE), decryptKey));
XjcRdeRegistrar registrar1 = extractAndRemoveContentWithType(XjcRdeRegistrar.class, deposit);
XjcRdeRegistrar registrar2 = extractAndRemoveContentWithType(XjcRdeRegistrar.class, deposit);
XjcRdeHeader header = extractAndRemoveContentWithType(XjcRdeHeader.class, deposit);
@ -492,9 +491,9 @@ public class RdeStagingActionTest extends MapreduceTestCase<RdeStagingAction> {
for (GcsFilename filename : asList(
new GcsFilename("rde-bucket", "fop_1971-01-01_full_S1_R0.xml.ghostryde"),
new GcsFilename("rde-bucket", "fop_1971-01-05_thin_S1_R0.xml.ghostryde"))) {
XjcRdeDeposit deposit = unmarshal(
XjcRdeDeposit.class,
Ghostryde.decode(readGcsFile(gcsService, filename), decryptKey).getData());
XjcRdeDeposit deposit =
unmarshal(
XjcRdeDeposit.class, Ghostryde.decode(readGcsFile(gcsService, filename), decryptKey));
XjcRdeRegistrar registrar1 = extractAndRemoveContentWithType(XjcRdeRegistrar.class, deposit);
XjcRdeRegistrar registrar2 = extractAndRemoveContentWithType(XjcRdeRegistrar.class, deposit);
XjcRdeHeader header = extractAndRemoveContentWithType(XjcRdeHeader.class, deposit);
@ -524,9 +523,9 @@ public class RdeStagingActionTest extends MapreduceTestCase<RdeStagingAction> {
executeTasksUntilEmpty("mapreduce", clock);
GcsFilename filename = new GcsFilename("rde-bucket", "fop_2000-01-01_full_S1_R0.xml.ghostryde");
XjcRdeDeposit deposit = unmarshal(
XjcRdeDeposit.class,
Ghostryde.decode(readGcsFile(gcsService, filename), decryptKey).getData());
XjcRdeDeposit deposit =
unmarshal(
XjcRdeDeposit.class, Ghostryde.decode(readGcsFile(gcsService, filename), decryptKey));
XjcRdeDomain domain = extractAndRemoveContentWithType(XjcRdeDomain.class, deposit);
XjcRdeIdn firstIdn = extractAndRemoveContentWithType(XjcRdeIdn.class, deposit);
XjcRdeHeader header = extractAndRemoveContentWithType(XjcRdeHeader.class, deposit);
@ -566,7 +565,7 @@ public class RdeStagingActionTest extends MapreduceTestCase<RdeStagingAction> {
action.run();
executeTasksUntilEmpty("mapreduce", clock);
byte[] deposit = Ghostryde.decode(readGcsFile(gcsService, XML_FILE), decryptKey).getData();
byte[] deposit = Ghostryde.decode(readGcsFile(gcsService, XML_FILE), decryptKey);
assertThat(Integer.parseInt(new String(readGcsFile(gcsService, LENGTH_FILE), UTF_8)))
.isEqualTo(deposit.length);
}
@ -818,7 +817,7 @@ public class RdeStagingActionTest extends MapreduceTestCase<RdeStagingAction> {
private String readXml(String objectName) throws IOException, PGPException {
GcsFilename file = new GcsFilename("rde-bucket", objectName);
return new String(Ghostryde.decode(readGcsFile(gcsService, file), decryptKey).getData(), UTF_8);
return new String(Ghostryde.decode(readGcsFile(gcsService, file), decryptKey), UTF_8);
}
private <T extends XjcRdeContentType>

View file

@ -187,7 +187,6 @@ public class RdeUploadActionTest {
RdeUploadAction action = new RdeUploadAction();
action.clock = clock;
action.gcsUtils = new GcsUtils(gcsService, BUFFER_SIZE);
action.ghostryde = new Ghostryde(BUFFER_SIZE);
action.lazyJsch =
() ->
JSchModule.provideJSch(
@ -239,18 +238,12 @@ public class RdeUploadActionTest {
createTld("tld");
PGPPublicKey encryptKey = new FakeKeyringModule().get().getRdeStagingEncryptionKey();
writeGcsFile(gcsService, GHOSTRYDE_FILE,
Ghostryde.encode(DEPOSIT_XML.read(), encryptKey, "lobster.xml", clock.nowUtc()));
writeGcsFile(gcsService, GHOSTRYDE_R1_FILE,
Ghostryde.encode(DEPOSIT_XML.read(), encryptKey, "lobster.xml", clock.nowUtc()));
writeGcsFile(gcsService, LENGTH_FILE,
Long.toString(DEPOSIT_XML.size()).getBytes(UTF_8));
writeGcsFile(gcsService, LENGTH_R1_FILE,
Long.toString(DEPOSIT_XML.size()).getBytes(UTF_8));
writeGcsFile(gcsService, REPORT_FILE,
Ghostryde.encode(REPORT_XML.read(), encryptKey, "dieform.xml", clock.nowUtc()));
writeGcsFile(gcsService, REPORT_R1_FILE,
Ghostryde.encode(REPORT_XML.read(), encryptKey, "dieform.xml", clock.nowUtc()));
writeGcsFile(gcsService, GHOSTRYDE_FILE, Ghostryde.encode(DEPOSIT_XML.read(), encryptKey));
writeGcsFile(gcsService, GHOSTRYDE_R1_FILE, Ghostryde.encode(DEPOSIT_XML.read(), encryptKey));
writeGcsFile(gcsService, LENGTH_FILE, Long.toString(DEPOSIT_XML.size()).getBytes(UTF_8));
writeGcsFile(gcsService, LENGTH_R1_FILE, Long.toString(DEPOSIT_XML.size()).getBytes(UTF_8));
writeGcsFile(gcsService, REPORT_FILE, Ghostryde.encode(REPORT_XML.read(), encryptKey));
writeGcsFile(gcsService, REPORT_R1_FILE, Ghostryde.encode(REPORT_XML.read(), encryptKey));
ofy()
.transact(
() -> {