public async Task Unexpected_480_with_errorCode_on_POST()
        {
            mockServer
            .Given(Request.Create().WithPath("/PCCIS/V1/MarkupBurner").UsingPost())
            .RespondWith(Response.Create()
                         .WithStatusCode(480)
                         .WithHeader("Content-Type", "application/json")
                         .WithBody("{\"errorCode\":\"ServerOnFire\",\"errorDetails\":{\"in\":\"body\",\"at\":\"input.admin.enableTurboMode\"}}"));

            string expectedMessage = @"Remote server returned an error: ServerOnFire {
  ""in"": ""body"",
  ""at"": ""input.admin.enableTurboMode""
}";

            await UtilAssert.ThrowsExceptionWithMessageAsync <RestApiErrorException>(
                async() => { await prizmDocServer.BurnMarkupAsync("documents/confidential-contacts.pdf", "documents/confidential-contacts.pdf.markup.json"); },
                expectedMessage);
        }
        public async Task BurnMarkupAsync_fails_with_a_useful_error_message_when_the_source_document_is_unusable()
        {
            PrizmDocServerClient prizmDocServer = Util.CreatePrizmDocServerClient();

            await UtilAssert.ThrowsExceptionWithMessageAsync <RestApiErrorException>(
                async() =>
            {
                await prizmDocServer.BurnMarkupAsync("documents/corrupted-page-count.pdf", "documents/confidential-contacts.pdf.markup.json");
            }, "The remote server was unable to burn the markup file into the document. It is possible there is a problem with the markup JSON or with the document itself.");
        }
예제 #3
0
        public async Task BurnMarkupAsync_fails_with_a_useful_error_message_when_the_markup_json_file_contains_content_which_does_not_pass_schema_validation()
        {
            PrizmDocServerClient prizmDocServer = Util.CreatePrizmDocServerClient();

            await UtilAssert.ThrowsExceptionWithMessageAsync <RestApiErrorException>(
                async() =>
            {
                await prizmDocServer.BurnMarkupAsync("documents/confidential-contacts.pdf", "documents/content-fails-schema-validation.markup.json");
            }, "The remote server rejected the given markup JSON because it contained content which did not conform to its allowed markup JSON schema. See the markup JSON schema documentation for your version of PrizmDoc Viewer (such as https://help.accusoft.com/PrizmDoc/latest/HTML/webframe.html#markup-json-specification.html).");
        }
예제 #4
0
        public async Task BurnMarkupAsync_fails_with_a_useful_error_message_when_the_markup_json_file_is_not_actually_JSON()
        {
            PrizmDocServerClient prizmDocServer = Util.CreatePrizmDocServerClient();

            await UtilAssert.ThrowsExceptionWithMessageAsync <RestApiErrorException>(
                async() =>
            {
                await prizmDocServer.BurnMarkupAsync("documents/confidential-contacts.pdf", "documents/example.docx");
            }, "The remote server was unable to burn the markup file into the document. It is possible there is a problem with the markup JSON or with the document itself.");
        }
예제 #5
0
        public async Task Can_use_local_file_paths_for_both_document_and_markup_JSON()
        {
            // Arrange
            PrizmDocServerClient prizmDocServer = Util.CreatePrizmDocServerClient();

            // Act
            RemoteWorkFile result = await prizmDocServer.BurnMarkupAsync("documents/confidential-contacts.pdf", "documents/confidential-contacts.pdf.markup.json");

            // Assert
            await result.SaveAsync("burned.pdf");

            await this.AssertRedactionOccurredFor(result);
        }
예제 #6
0
        public async Task BurnMarkupAsync_fails_with_a_useful_error_message_when_the_source_document_cannot_be_found()
        {
            PrizmDocServerClient prizmDocServer = Util.CreatePrizmDocServerClient();

            AffinitySession affinitySession    = Util.RestClient.CreateAffinitySession();
            RemoteWorkFile  existingMarkupFile = await affinitySession.UploadAsync("documents/confidential-contacts.pdf.markup.json");

            RemoteWorkFile nonExistentSourceDocument = new RemoteWorkFile(affinitySession, "non-existent-id", existingMarkupFile.AffinityToken, "pdf");

            await UtilAssert.ThrowsExceptionWithMessageAsync <RestApiErrorException>(
                async() =>
            {
                await prizmDocServer.BurnMarkupAsync(nonExistentSourceDocument, existingMarkupFile);
            }, "Could not use the given RemoteWorkFile as the source document: the work file resource could not be found on the remote server. It may have expired.");
        }
예제 #7
0
        public async Task Can_use_RemoteWorkFile_for_document_and_local_file_path_for_markup_JSON()
        {
            // Arrange
            PrizmDocServerClient prizmDocServer = Util.CreatePrizmDocServerClient();

            AffinitySession affinitySession = Util.RestClient.CreateAffinitySession();
            RemoteWorkFile  document        = await affinitySession.UploadAsync("documents/confidential-contacts.pdf");

            // Act
            RemoteWorkFile result = await prizmDocServer.BurnMarkupAsync(document, "documents/confidential-contacts.pdf.markup.json");

            // Assert
            await result.SaveAsync("burned.pdf");

            await this.AssertRedactionOccurredFor(result);
        }
        public async Task Unexpected_200_with_errorCode_on_GET()
        {
            mockServer
            .Given(Request.Create().WithPath("/PCCIS/V1/MarkupBurner/fake-process-id").UsingGet())
            .RespondWith(Response.Create()
                         .WithStatusCode(200)
                         .WithHeader("Content-Type", "application/json")
                         .WithBody("{\"processId\":\"fake-process-id\",\"expirationDateTime\":\"2020-01-06T16:50:45.637Z\",\"input\":{\"documentFileId\":\"fake-file-id\",\"markupFileId\":\"fake-file-id\"},\"state\":\"error\",\"percentComplete\":100,\"errorCode\":\"ServerOnFire\",\"errorDetails\":{\"temperature\":999}}"));

            string expectedMessage = @"Remote server returned an error: ServerOnFire {
  ""temperature"": 999
}";

            await UtilAssert.ThrowsExceptionWithMessageAsync <RestApiErrorException>(
                async() => { await prizmDocServer.BurnMarkupAsync("documents/confidential-contacts.pdf", "documents/confidential-contacts.pdf.markup.json"); },
                expectedMessage);
        }
예제 #9
0
        public async Task Can_use_RemoteWorkFile_instances_with_different_affinity()
        {
            // Arrange
            PrizmDocServerClient prizmDocServer = Util.CreatePrizmDocServerClient();

            AffinitySession session1 = Util.RestClient.CreateAffinitySession();
            AffinitySession session2 = Util.RestClient.CreateAffinitySession();

            RemoteWorkFile document = await session1.UploadAsync("documents/confidential-contacts.pdf");

            RemoteWorkFile markupJson = await session2.UploadAsync("documents/confidential-contacts.pdf.markup.json");

            Assert.AreNotEqual(document.AffinityToken, markupJson.AffinityToken);

            // Act
            RemoteWorkFile result = await prizmDocServer.BurnMarkupAsync(document, markupJson);

            // Assert
            await result.SaveAsync("burned.pdf");

            await this.AssertRedactionOccurredFor(result);
        }
예제 #10
0
        private static async Task MainAsync()
        {
            // Delete any existing output file before we get started.
            File.Delete("redacted.pdf");

            var prizmDocServer = new PrizmDocServerClient(Environment.GetEnvironmentVariable("BASE_URL"), Environment.GetEnvironmentVariable("API_KEY"));

            // -----------------------------------------------------------------
            // Step 1: Create markup JSON containing definitions of the areas we
            //         want to redact.
            // -----------------------------------------------------------------

            // Define a rule which will create a redaction for any text in a
            // document which looks like a social security number (###-##-####),
            // and use the text "(b)(6)" in the center of the redaction
            // rectangle as the reason for redaction.
            var ssnRule = new RegexRedactionMatchRule(@"\d\d\d-\d\d-\d\d\d\d")
            {
                RedactWith = new RedactionCreationOptions()
                {
                    Reason = "(b)(6)",
                },
            };

            // Define a rule which will create a redaction for any text in a
            // document which looks like an email address (this is a very basic
            // regex, matching things like [email protected]) and use the
            // text "(b)(6)" in the center of the redaction rectangle as
            // the reason for redaction.
            var emailRule = new RegexRedactionMatchRule(@"\S+@\S+\.\S+")
            {
                RedactWith = new RedactionCreationOptions()
                {
                    Reason = "(b)(6)",
                },
            };

            // Define a rule which will create a redaction for all occurrences
            // of "Bruce Wayne" in a document, use the text "(b)(1)" in the
            // center of the redaction rectangle as the reason for redaction,
            // customize various colors used, and attach some arbitrary
            // key/value string data to all redaction definitions which are
            // created. This arbitrary data will be present in the output markup
            // JSON file.
            var bruceWayneRule = new RegexRedactionMatchRule(@"Bruce Wayne")
            {
                RedactWith = new RedactionCreationOptions()
                {
                    Reason          = "(b)(1)",
                    FontColor       = "#FDE311",
                    FillColor       = "#000080",
                    BorderColor     = "#000000",
                    BorderThickness = 2,

                    // This arbitrary data will simply be present in the generated markup JSON.
                    Data = new Dictionary <string, string>
                    {
                        { "arbitrary-key-1", "arbitrary-value-1" },
                        { "arbitrary-key-2", "arbitrary-value-2" },
                    },
                },
            };

            var rules = new[] { ssnRule, emailRule, bruceWayneRule };

            // Automatically create a markup.json file with redaction
            // definitions based upon regular expression rules for a given
            // document. Any text in the document which matches one of the regex
            // rules will have a redaction definition created for that portion
            // of the document. The output markup.json file with its redaction
            // definitions can later be burned into the document.
            RemoteWorkFile markupJson = await prizmDocServer.CreateRedactionsAsync("confidential-contacts.pdf", rules);

            // -----------------------------------------------------------------
            // Step 2: Burn the markup JSON into the original document,
            //         producing a new, redacted PDF.
            // -----------------------------------------------------------------
            RemoteWorkFile redactedPdf = await prizmDocServer.BurnMarkupAsync("confidential-contacts.pdf", markupJson);

            // Save the result to "redacted.pdf"
            await redactedPdf.SaveAsync("redacted.pdf");
        }