public virtual void ImageMagickEnvVarIsExplicitlySpecified() {
     String compareExec = SystemUtil.GetEnvironmentVariable(ImageMagickHelper.MAGICK_COMPARE_ENVIRONMENT_VARIABLE
         );
     if (compareExec == null) {
         compareExec = SystemUtil.GetEnvironmentVariable(ImageMagickHelper.MAGICK_COMPARE_ENVIRONMENT_VARIABLE_LEGACY
             );
     }
     ImageMagickHelper imageMagickHelper = new ImageMagickHelper(compareExec);
     NUnit.Framework.Assert.IsNotNull(imageMagickHelper.GetCliExecutionCommand());
 }
        public virtual void GhostScriptEnvVarIsExplicitlySpecified()
        {
            String gsExec = SystemUtil.GetEnvironmentVariable(GhostscriptHelper.GHOSTSCRIPT_ENVIRONMENT_VARIABLE);

            if (gsExec == null)
            {
                gsExec = SystemUtil.GetEnvironmentVariable(GhostscriptHelper.GHOSTSCRIPT_ENVIRONMENT_VARIABLE_LEGACY);
            }
            GhostscriptHelper ghostscriptHelper = new GhostscriptHelper(gsExec);

            NUnit.Framework.Assert.IsNotNull(ghostscriptHelper.GetCliExecutionCommand());
        }
Exemple #3
0
 public ImageHandlerUtil()
 {
     gsExec      = SystemUtil.GetEnvironmentVariable(GHOSTSCRIPT_ENVIRONMENT_VARIABLE);
     compareExec = SystemUtil.GetEnvironmentVariable(MAGICK_COMPARE_ENVIRONMENT_VARIABLE);
     if (gsExec == null)
     {
         gsExec = SystemUtil.GetEnvironmentVariable(GHOSTSCRIPT_ENVIRONMENT_VARIABLE_LEGACY);
     }
     if (compareExec == null)
     {
         compareExec = SystemUtil.GetEnvironmentVariable(MAGICK_COMPARE_ENVIRONMENT_VARIABLE_LEGACY);
     }
 }
        public virtual void GhostScriptIsExplicitlySpecified()
        {
            String gsExec = SystemUtil.GetEnvironmentVariable(ImageHandlerUtil.GHOSTSCRIPT_ENVIRONMENT_VARIABLE);

            if (gsExec == null)
            {
                gsExec = SystemUtil.GetEnvironmentVariable(ImageHandlerUtil.GHOSTSCRIPT_ENVIRONMENT_VARIABLE_LEGACY);
            }
            ImageHandlerUtil imageHandlerUtil = new ImageHandlerUtil();

            imageHandlerUtil.SetGsExec(gsExec);
            NUnit.Framework.Assert.IsNotNull(imageHandlerUtil.GetGsExec());
            NUnit.Framework.Assert.IsTrue(imageHandlerUtil.IsVersionCommandExecutable(ImageHandlerUtil.GHOSTSCRIPT_KEYWORD
                                                                                      ));
        }
 public ImageMagickHelper(String newCompareExec)
 {
     compareExec = newCompareExec;
     if (compareExec == null)
     {
         compareExec = SystemUtil.GetEnvironmentVariable(MAGICK_COMPARE_ENVIRONMENT_VARIABLE);
         if (compareExec == null)
         {
             compareExec = SystemUtil.GetEnvironmentVariable(MAGICK_COMPARE_ENVIRONMENT_VARIABLE_LEGACY);
         }
     }
     if (!CliCommandUtil.IsVersionCommandExecutable(compareExec, MAGICK_COMPARE_KEYWORD))
     {
         throw new ArgumentException(IoExceptionMessage.COMPARE_COMMAND_SPECIFIED_INCORRECTLY);
     }
 }
 public GhostscriptHelper(String newGsExec)
 {
     gsExec = newGsExec;
     if (gsExec == null)
     {
         gsExec = SystemUtil.GetEnvironmentVariable(GHOSTSCRIPT_ENVIRONMENT_VARIABLE);
         if (gsExec == null)
         {
             gsExec = SystemUtil.GetEnvironmentVariable(GHOSTSCRIPT_ENVIRONMENT_VARIABLE_LEGACY);
         }
     }
     if (!CliCommandUtil.IsVersionCommandExecutable(gsExec, GHOSTSCRIPT_KEYWORD))
     {
         throw new ArgumentException(IoExceptionMessage.GS_ENVIRONMENT_VARIABLE_IS_NOT_SPECIFIED);
     }
 }
        public virtual void ImageMagickIsExplicitlySpecified()
        {
            String compareExec = SystemUtil.GetEnvironmentVariable(ImageHandlerUtil.MAGICK_COMPARE_ENVIRONMENT_VARIABLE
                                                                   );

            if (compareExec == null)
            {
                compareExec = SystemUtil.GetEnvironmentVariable(ImageHandlerUtil.MAGICK_COMPARE_ENVIRONMENT_VARIABLE_LEGACY
                                                                );
            }
            ImageHandlerUtil imageHandlerUtil = new ImageHandlerUtil();

            imageHandlerUtil.SetCompareExec(compareExec);
            NUnit.Framework.Assert.IsNotNull(imageHandlerUtil.GetCompareExec());
            NUnit.Framework.Assert.IsTrue(imageHandlerUtil.IsVersionCommandExecutable(ImageHandlerUtil.MAGICK_COMPARE_KEYWORD
                                                                                      ));
        }
Exemple #8
0
        public virtual void DSaferParamInGhostScriptHelperTest()
        {
            String cmpPdf = sourceFolder + "maliciousPsInvokingCalcExe.ps";
            String maliciousPsInvokingCalcExe = destinationFolder + "maliciousPsInvokingCalcExe.png";
            int    majorVersion = 0;
            int    minorVersion = 0;
            bool   isWindows    = IdentifyOsType().ToLowerInvariant().Contains("win");

            if (isWindows)
            {
                String gsExec = SystemUtil.GetEnvironmentVariable(GhostscriptHelper.GHOSTSCRIPT_ENVIRONMENT_VARIABLE);
                if (gsExec == null)
                {
                    gsExec = SystemUtil.GetEnvironmentVariable(GhostscriptHelper.GHOSTSCRIPT_ENVIRONMENT_VARIABLE_LEGACY);
                }
                String[] pathParts = iText.IO.Util.StringUtil.Split(gsExec, "\\d\\.\\d\\d");
                for (int i = 0; i < pathParts.Length; i++)
                {
                    gsExec = gsExec.Replace(pathParts[i], "");
                }
                String[] version = iText.IO.Util.StringUtil.Split(gsExec, "\\.");
                majorVersion = Convert.ToInt32(version[0], System.Globalization.CultureInfo.InvariantCulture);
                minorVersion = Convert.ToInt32(version[1], System.Globalization.CultureInfo.InvariantCulture);
            }
            try {
                GhostscriptHelper ghostscriptHelper = new GhostscriptHelper();
                ghostscriptHelper.RunGhostScriptImageGeneration(cmpPdf, destinationFolder, "maliciousPsInvokingCalcExe.png"
                                                                );
                if (isWindows)
                {
                    NUnit.Framework.Assert.IsTrue((majorVersion > 9 || (majorVersion == 9 && minorVersion >= 50)));
                }
            }
            catch (GhostscriptHelper.GhostscriptExecutionException) {
                if (isWindows)
                {
                    NUnit.Framework.Assert.IsTrue((majorVersion < 9 || (majorVersion == 9 && minorVersion < 50)));
                }
            }
            NUnit.Framework.Assert.IsFalse(FileUtil.FileExists(maliciousPsInvokingCalcExe));
        }
        public virtual void RunProcessAndWaitWithWorkingDirectoryTest()
        {
            String imageMagickPath = SystemUtil.GetEnvironmentVariable(ImageMagickHelper.MAGICK_COMPARE_ENVIRONMENT_VARIABLE);

            if (imageMagickPath == null)
            {
                imageMagickPath = SystemUtil.GetEnvironmentVariable(ImageMagickHelper.MAGICK_COMPARE_ENVIRONMENT_VARIABLE_LEGACY);
            }
            String inputImage = "image.jpg";
            String cmpImage   = "cmp_image.jpg";
            String diff       = DESTINATION_FOLDER + "diff_differentImages.png";

            StringBuilder currCompareParams = new StringBuilder();

            currCompareParams
            .Append("'")
            .Append(inputImage).Append("' '")
            .Append(cmpImage).Append("' '")
            .Append(diff).Append("'");
            bool result = SystemUtil.RunProcessAndWait(imageMagickPath, currCompareParams.ToString(), SOURCE_FOLDER);

            NUnit.Framework.Assert.False(result);
            NUnit.Framework.Assert.True(FileUtil.FileExists(diff));
        }