Search in sources :

Example 1 with Base64DecodingKmsStub

use of com.google.cloud.solutions.autotokenize.testing.stubs.kms.Base64DecodingKmsStub in project auto-data-tokenize by GoogleCloudPlatform.

the class EncryptionPipelineErrorTest method test.

public void test(ImmutableList<String> extraArgs, Class<? extends Exception> expectedException, Consumer<ThrowableSubject> checks) {
    var args = makeArgsWithExtraOptions(extraArgs);
    var options = PipelineOptionsFactory.fromArgs(args).as(EncryptionPipelineOptions.class);
    var pipeline = new EncryptionPipeline(options, TestPipeline.create(), null, makeSecretsClient(), KeyManagementServiceClient.create(new Base64DecodingKmsStub("")), new FixedClearTextKeySetExtractor(options.getTinkEncryptionKeySetJson()));
    var exception = assertThrows(expectedException, pipeline::run);
    checks.accept(assertThat(exception));
}
Also used : Base64DecodingKmsStub(com.google.cloud.solutions.autotokenize.testing.stubs.kms.Base64DecodingKmsStub) FixedClearTextKeySetExtractor(com.google.cloud.solutions.autotokenize.encryptors.FixedClearTextKeySetExtractor)

Example 2 with Base64DecodingKmsStub

use of com.google.cloud.solutions.autotokenize.testing.stubs.kms.Base64DecodingKmsStub in project auto-data-tokenize by GoogleCloudPlatform.

the class EncryptionPipelineTest method buildPipeline_valid.

@Test
public void buildPipeline_valid() throws Exception {
    makeDlpStub();
    Truth.assertThat(Sets.difference(Set.copyOf(expectedSchema.getFields()), Set.copyOf(inputSchema.getFields())).size()).isAtLeast(1);
    // Perform the Encryption pipeline
    new EncryptionPipeline(pipelineOptions, testPipeline, dlpClientFactory, secretsClient, KeyManagementServiceClient.create(new Base64DecodingKmsStub(pipelineOptions.getMainKmsKeyUri())), new FixedClearTextKeySetExtractor(pipelineOptions.getTinkEncryptionKeySetJson())).run().waitUntilFinish();
    // Verify the output Avro file
    PCollection<GenericRecord> encryptedRecords = readPipeline.apply(AvroIO.readGenericRecords(expectedSchema).from(pipelineOptions.getOutputDirectory() + "/*"));
    PAssert.that(encryptedRecords).satisfies(new RecordsCountMatcher<>(expectedRecordsCount));
    if (configParameters.containsKey("expectedRecordsAvro")) {
        var expectedRecords = TestResourceLoader.classPath().forAvro().readFile(configParameters.get("expectedRecordsAvro")).loadAllRecords();
        PAssert.that(encryptedRecords).containsInAnyOrder(expectedRecords);
    }
    readPipeline.run();
}
Also used : Base64DecodingKmsStub(com.google.cloud.solutions.autotokenize.testing.stubs.kms.Base64DecodingKmsStub) FixedClearTextKeySetExtractor(com.google.cloud.solutions.autotokenize.encryptors.FixedClearTextKeySetExtractor) GenericRecord(org.apache.avro.generic.GenericRecord) Test(org.junit.Test)

Aggregations

FixedClearTextKeySetExtractor (com.google.cloud.solutions.autotokenize.encryptors.FixedClearTextKeySetExtractor)2 Base64DecodingKmsStub (com.google.cloud.solutions.autotokenize.testing.stubs.kms.Base64DecodingKmsStub)2 GenericRecord (org.apache.avro.generic.GenericRecord)1 Test (org.junit.Test)1