Пример #1
0
        public ScriptPluginTests()
        {
            log = new Mock.Services.LogService(true);
            iis = new Mock.Clients.MockIISClient();
            cs  = new Mock.Services.CertificateService();
            var tempPath = Infrastructure.Directory.Temp();

            batchPath = new FileInfo(tempPath.FullName + "\\create.bat");
            File.WriteAllText(batchPath.FullName, "echo hello %1");

            psPath = new FileInfo(tempPath.FullName + "\\create.ps1");
            File.WriteAllText(psPath.FullName,
                              $"$arg = $($args[0])\n" +
                              $"if ($arg -ne $null -and $arg -ne \"world\") " +
                              $"{{ " +
                              $"  Write-Error \"Wrong: $arg\" " +
                              $"}} else {{" +
                              $"  Write-Host \"Hello $arg\" " +
                              $"}}"
                              );

            psNamedPath = new FileInfo(tempPath.FullName + "\\createnamed.ps1");
            File.WriteAllText(psNamedPath.FullName,
                              $"param([Parameter(Mandatory)][string]$What)\n" +
                              $"if ($What -ne \"world\") " +
                              $"{{ " +
                              $"  Write-Error \"Wrong: $What\" " +
                              $"}} else {{ " +
                              $"  Write-Host \"Hello $What\"" +
                              $"}}"
                              );
        }
Пример #2
0
        public void TurnOnOff()
        {
            // Create encrypted value
            var plain       = "---BLA---";
            var plainString = new ProtectedString(plain);
            var encrypted   = plainString.DiskValue(true);

            Assert.IsTrue(encrypted != null);

            // Read back
            var log      = new Mock.Services.LogService(false);
            var readBack = new ProtectedString(encrypted ?? "", log);

            Assert.AreEqual(plain, readBack.Value);

            // Turn off encryption
            var turnOff      = new ProtectedString(encrypted ?? "", log);
            var turnOffValue = turnOff.DiskValue(false);

            Assert.IsTrue(turnOffValue != null);

            // Read back turned off value
            var readBack2 = new ProtectedString(turnOffValue ?? "", log);

            Assert.AreEqual(readBack2.Value, plain);
        }
Пример #3
0
        private void TestScript(string script, string parameters)
        {
            log = new Mock.Services.LogService(true);
            var renewal      = new Renewal();
            var storeOptions = new CertificateStoreOptions();
            var store        = new CertificateStore(log, iis, storeOptions);
            var oldCert      = cs.RequestCertificate(null, RunLevel.Unattended, renewal, new Target()
            {
                CommonName = "test.local"
            }, null);
            var newCert = cs.RequestCertificate(null, RunLevel.Unattended, renewal, new Target()
            {
                CommonName = "test.local"
            }, null);

            newCert.StoreInfo.Add(typeof(CertificateStore), new StoreInfo()
            {
            });
            var options = new ScriptOptions
            {
                Script           = script,
                ScriptParameters = parameters
            };
            var installer = new Script(renewal, options, log);

            installer.Install(new[] { store }, newCert, oldCert);
        }
Пример #4
0
        public void Regular()
        {
            var tempFile = Path.GetTempFileName();

            try
            {
                File.WriteAllText(tempFile, Csr);
                var csrOptions = new CsrOptions()
                {
                    CsrFile = tempFile
                };
                var log       = new Mock.Services.LogService(false);
                var pem       = new PemService();
                var csrPlugin = new Csr(log, pem, csrOptions);
                var target    = csrPlugin.Generate().Result;
                Assert.IsNotNull(target);
                Assert.IsFalse(target is INull);
                Assert.IsTrue(target.Parts.Count() == 1);
                Assert.IsTrue(target.Parts.First().Identifiers.OfType <IpIdentifier>().Count() == 3);
                Assert.IsTrue(target.Parts.First().Identifiers.OfType <DnsIdentifier>().Count() == 2);
                Assert.IsTrue(target.Parts.First().Identifiers.OfType <EmailIdentifier>().Count() == 1);
                Assert.IsTrue(target.Parts.First().Identifiers.OfType <IpIdentifier>().Any(x => x.Value == "1.1.1.1"));
                Assert.IsTrue(target.Parts.First().Identifiers.OfType <DnsIdentifier>().Any(x => x.Value == "www.win-acme.com"));
                Assert.IsTrue(target.Parts.First().Identifiers.OfType <EmailIdentifier>().Any(x => x.Value == "*****@*****.**"));
            }
            finally
            {
                File.Delete(tempFile);
            }
        }
        public ScriptPluginTests()
        {
            log = new Mock.Services.LogService(true);
            iis = new Mock.Clients.MockIISClient();
            cs  = new Mock.Services.CertificateService();
            var tempPath = new DirectoryInfo(Environment.ExpandEnvironmentVariables("%TEMP%\\wacs"));

            if (!tempPath.Exists)
            {
                tempPath.Create();
            }
            batchPath = new FileInfo(tempPath.FullName + "\\create.bat");
            File.WriteAllText(batchPath.FullName, "echo hello %1");

            psPath = new FileInfo(tempPath.FullName + "\\create.ps1");
            File.WriteAllText(psPath.FullName,
                              $"$arg = $($args[0])\n" +
                              $"if ($arg -ne $null -and $arg -ne \"world\") {{ Write-Error \"Wrong\" }}\n" +
                              $"Write-Host \"Hello $arg\""
                              );

            psNamedPath = new FileInfo(tempPath.FullName + "\\createnamed.ps1");
            File.WriteAllText(psNamedPath.FullName,
                              $"param([Parameter(Mandatory)][string]$What)\n" +
                              $"if ($What -ne \"world\") {{ Write-Error \"Wrong\" }} else {{\n" +
                              $"Write-Host \"Hello $arg\" + " +
                              $"}}"
                              );
        }
Пример #6
0
        public HostnameSorterTests()
        {
            var log      = new Mock.Services.LogService(true);
            var settings = new MockSettingsService();
            var proxy    = new Mock.Services.ProxyService();

            dp = new DomainParseService(log, proxy, settings);
        }
Пример #7
0
        private string TestScript(string parameters)
        {
            log = new Mock.Services.LogService(true);
            var argParser = new ArgumentsParser(log,
                                                new PluginService(log),
                                                $"--scriptparameters {parameters} --verbose".Split(' '));
            var argService = new ArgumentsService(log, argParser);
            var args       = argService.GetArguments <ScriptArguments>();

            return(args.ScriptParameters);
        }
Пример #8
0
        private void TestScript(string script, string parameters)
        {
            log = new Mock.Services.LogService(true);
            var renewal      = new Renewal();
            var storeOptions = new CertificateStoreOptions();
            var store        = new CertificateStore(log, iis, storeOptions);
            var oldCert      = cs.RequestCertificate(null, renewal, new Target()
            {
                CommonName = "test.local"
            }, null);
            var newCert = cs.RequestCertificate(null, renewal, new Target()
            {
                CommonName = "test.local"
            }, null);
            var options = new ScriptOptions
            {
                Script           = script,
                ScriptParameters = parameters
            };
            var installer = new Script(renewal, options, log);

            installer.Install(store, newCert, oldCert);
        }
Пример #9
0
 public ArgumentParserTests()
 {
     log = new Mock.Services.LogService(true);
 }
Пример #10
0
 public ArgumentParserTests()
 {
     log     = new Mock.Services.LogService(true);
     version = new VersionService(log);
 }