Example #1
0
        public void ProtectWithScreenReaderRestrictions(
            [Values(
                 FileAuthentication.Password /*,
                                              * Ignore: http://stackoverflow.com/questions/40045745/itextsharp-object-reference-error-on-pdfstamper-for-certificate-protected-file
                                              * FileAuthentication.CertificateFile,
                                              * FileAuthentication.CertificateStore*/)] FileAuthentication protectAuth,
            [Values(
                 true,
                 false)] bool allowScreenReaders)
        {
            string inputFilePath  = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.ChangeProtection.Resources.Protect.pdf", this.inputDirectory);
            string outputFilePath = Path.Combine(this.outputDirectory, "Protect.pdf");

            FunctionDesigner designer = ProviderHelpers.CreateDesigner <ChangeProtectionProvider>();

            ConfigureInputFileFunctionValues(designer, FileAuthentication.None, inputFilePath);
            ConfigureProtectFunctionValues(designer, protectAuth, Encryption.AES256, true, true, allowScreenReaders: allowScreenReaders);
            designer.Properties[Pdf.Common.PropertyNames.OutputFilePath].Value = outputFilePath;

            var tester = new FunctionTester <ChangeProtectionProvider>();

            tester.Execute(designer.GetProperties(), designer.GetParameters());

            PdfComparer.AssertProtection(outputFilePath, protectAuth, this.authenticationManager, true, true,
                                         expectedAllowScreenReaders: allowScreenReaders);

            if (protectAuth == FileAuthentication.Password)
            {
                using (var permissionsAuthHelper = new AuthenticationManager(permissionsPassword))
                {
                    PdfComparer.AssertProtectionAllRights(outputFilePath, FileAuthentication.Password, permissionsAuthHelper, true, true);
                }
            }
        }
Example #2
0
        public void ProtectWithPrintRestrictions(
            [Values(
                 FileAuthentication.Password /*,
                                              * Ignore: http://stackoverflow.com/questions/40045745/itextsharp-object-reference-error-on-pdfstamper-for-certificate-protected-file
                                              * FileAuthentication.CertificateFile,
                                              * FileAuthentication.CertificateStore*/)] FileAuthentication protectAuth,
            [Values(
                 Printing.None,
                 Printing.LowResolution,
                 Printing.HighResolution)] Printing printing)
        {
            string inputFilePath  = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.ChangeProtection.Resources.Protect.pdf", this.inputDirectory);
            string outputFilePath = Path.Combine(this.outputDirectory, "Protect.pdf");

            FunctionDesigner designer = ProviderHelpers.CreateDesigner <ChangeProtectionProvider>();

            ConfigureInputFileFunctionValues(designer, FileAuthentication.None, inputFilePath);
            ConfigureProtectFunctionValues(designer, protectAuth, Encryption.AES256, true, true, printing: printing);
            designer.Properties[Pdf.Common.PropertyNames.OutputFilePath].Value = outputFilePath;

            var tester = new FunctionTester <ChangeProtectionProvider>();

            tester.Execute(designer.GetProperties(), designer.GetParameters());

            bool allowDegradedPrinting = false;
            bool allowPrinting         = false;

            switch (printing)
            {
            case Printing.None:
                break;

            case Printing.LowResolution:
                allowDegradedPrinting = true;
                break;

            case Printing.HighResolution:
                allowDegradedPrinting = true;
                allowPrinting         = true;
                break;

            default:
                throw new NotSupportedException("Invalid Printing specified.");
            }

            PdfComparer.AssertProtection(outputFilePath, protectAuth, this.authenticationManager, true, true,
                                         expectedAllowDegradedPrinting: allowDegradedPrinting,
                                         expectedAllowPrinting: allowPrinting);

            if (protectAuth == FileAuthentication.Password)
            {
                using (var permissionsAuthHelper = new AuthenticationManager(permissionsPassword))
                {
                    PdfComparer.AssertProtectionAllRights(outputFilePath, FileAuthentication.Password, permissionsAuthHelper, true, true);
                }
            }
        }
Example #3
0
        public void ProtectWithNoRestrictions(
            [Values(
                 FileAuthentication.Password,
                 FileAuthentication.CertificateFile,
                 FileAuthentication.CertificateStore)] FileAuthentication protectAuth)
        {
            string inputFilePath  = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.ChangeProtection.Resources.Protect.pdf", this.inputDirectory);
            string outputFilePath = Path.Combine(this.outputDirectory, "Protect.pdf");

            FunctionDesigner designer = ProviderHelpers.CreateDesigner <ChangeProtectionProvider>();

            ConfigureInputFileFunctionValues(designer, FileAuthentication.None, inputFilePath);
            ConfigureProtectFunctionValues(designer, protectAuth, Encryption.AES256, true);
            designer.Properties[Pdf.Common.PropertyNames.OutputFilePath].Value = outputFilePath;

            var tester = new FunctionTester <ChangeProtectionProvider>();

            tester.Execute(designer.GetProperties(), designer.GetParameters());

            PdfComparer.AssertProtectionAllRights(outputFilePath, protectAuth, this.authenticationManager, true, true);
        }
Example #4
0
        public void ProtectWithChangeRestrictions(
            [Values(
                 FileAuthentication.Password /*,
                                              * Ignore: http://stackoverflow.com/questions/40045745/itextsharp-object-reference-error-on-pdfstamper-for-certificate-protected-file
                                              * FileAuthentication.CertificateFile,
                                              * FileAuthentication.CertificateStore*/)] FileAuthentication protectAuth,
            [Values(
                 Changes.None,
                 Changes.Assembly,
                 Changes.FillIn,
                 Changes.AnnotateAndFillIn,
                 Changes.AnyExpectExtract)] Changes changes)
        {
            string inputFilePath  = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.PdfOperations.Resources.Protect.pdf", this.inputDirectory);
            string outputFilePath = Path.Combine(this.outputDirectory, "Protect.pdf");

            FunctionDesigner designer = ProviderHelpers.CreateDesigner <PdfOperationsProvider>();

            ConfigureInputFileFunctionValues(designer, FileAuthentication.None, inputFilePath);
            ConfigureProtectFunctionValues(designer, protectAuth, Encryption.AES256, true, true, changes: changes);
            designer.Properties[PropertyNames.OutputFilePath].Value = outputFilePath;

            var tester = new FunctionTester <PdfOperationsProvider>();

            tester.Execute(designer.GetProperties(), designer.GetParameters());

            bool allowAssembly          = false;
            bool allowFillIn            = false;
            bool allowModifyAnnotations = false;
            bool allowModifyContents    = false;

            switch (changes)
            {
            case Changes.None:
                break;

            case Changes.Assembly:
                allowAssembly = true;
                break;

            case Changes.FillIn:
                allowFillIn = true;
                break;

            case Changes.AnnotateAndFillIn:
                allowModifyAnnotations = true;
                allowFillIn            = true;
                break;

            case Changes.AnyExpectExtract:
                allowModifyContents    = true;
                allowModifyAnnotations = true;
                allowFillIn            = true;
                break;

            default:
                throw new NotSupportedException("Invalid Changes specified.");
            }

            PdfComparer.AssertProtection(outputFilePath, protectAuth, this.authenticationManager, true, true,
                                         expectedAllowAssembly: allowAssembly,
                                         expectedAllowFillIn: allowFillIn,
                                         expectedAllowModifyAnnotations: allowModifyAnnotations,
                                         expectedAllowModifyContents: allowModifyContents);

            if (protectAuth == FileAuthentication.Password)
            {
                using (var permissionsAuthHelper = new AuthenticationManager(permissionsPassword))
                {
                    PdfComparer.AssertProtectionAllRights(outputFilePath, FileAuthentication.Password, permissionsAuthHelper, true, true);
                }
            }
        }