public void TestSendReport_BadDateFormat()
        {
            var report = new Model.SendReportBody
            {
                JobId               = Guid.NewGuid(),
                StartTime           = "NOW",
                EndTime             = "THEN",
                OperationType       = "FOO",
                ReportFormatVersion = "BAR",
            };

            var config = BuildConfig();

            using (var client = new DscPullClient(config))
            {
                client.DisableReportAdditionalData = _testConfig.adjust_for_wmf_50;
                TugAssert.ThrowsExceptionWhen <AggregateException>(
                    condition: (ex) =>
                    ex.InnerException is HttpRequestException &&
                    ex.InnerException.Message.Contains(
                        "Response status code does not indicate success: 500 (Internal Server Error)"),
                    action: () =>
                    client.SendReport(report).Wait(),
                    message:
                    "Throws HTTP exception for internal server error (500)");
            }
        }
コード例 #2
0
        public void TestGetConfiguration()
        {
            var config = BuildConfig();

            using (var client = new DscPullClient(config))
            {
                client.RegisterDscAgent().Wait();

                var actionResult = client.GetDscAction(new[]
                {
                    new Model.ClientStatusItem
                    {
                        ConfigurationName = "TestConfig1",
                        ChecksumAlgorithm = "SHA-256",
                        Checksum          = "",
                    }
                }).Result;
                Assert.IsNotNull(actionResult, "Action result is not null");

                var resultArr = actionResult.ToArray();
                Assert.AreEqual(1, resultArr.Length, "Number of action results");
                Assert.AreEqual("TestConfig1", resultArr[0]?.ConfigurationName,
                                "Action result config name");
                Assert.AreEqual(Model.DscActionStatus.GetConfiguration, resultArr[0].Status,
                                "Action result status");

                var configResult = client.GetConfiguration(resultArr[0]?.ConfigurationName).Result;
                Assert.IsNotNull(configResult?.Content, "Configuration content not null");
                Assert.AreNotEqual(0, configResult.Content.Length, "Configuration content length > 0");
            }
        }
        public void TestGetReports_Multi()
        {
            var strArr1 = new[] { "STATUS-1" };
            var strArr2 = new[] { "STATUS-2" };
            var strArr3 = new[] { "ERROR-1" };
            var strArr4 = new[] { "ERROR-2" };

            var config = BuildConfig(newAgentId: true);

            using (var client = new DscPullClient(config))
            {
                client.DisableReportAdditionalData = _testConfig.adjust_for_wmf_50;
                client.RegisterDscAgent().Wait();
                client.SendReport(operationType: "1", statusData: strArr1).Wait();
                client.SendReport(operationType: "2", statusData: strArr2).Wait();
                client.SendReport(operationType: "3", errors: strArr3).Wait();
                client.SendReport(operationType: "4", errors: strArr4).Wait();

                var sr = client.GetReports().Result;
                Assert.IsNotNull(sr, "All reports not null");
                var srArr = sr.ToArray();
                Assert.AreEqual(4, srArr.Length, "All reports length");

                var srArrOrd = srArr.OrderBy(x => x.OperationType).ToArray();
                CollectionAssert.AreEqual(strArr1, srArrOrd[0].StatusData);
                CollectionAssert.AreEqual(strArr2, srArrOrd[1].StatusData);
                CollectionAssert.AreEqual(strArr3, srArrOrd[2].Errors);
                CollectionAssert.AreEqual(strArr4, srArrOrd[3].Errors);
            }
        }
コード例 #4
0
        public void TestGetModule_Content()
        {
            var modName = "xPSDesiredStateConfiguration";
            var modVers = "5.1.0.0";

            // Get path and content of expected results
            var myPath   = typeof(ClassicPullServerProtocolCompatibilityTests).GetTypeInfo().Assembly.Location;
            var myDir    = Path.GetDirectoryName(myPath);
            var dscDir   = Path.Combine(myDir, "../../../../../../tools/ci/DSC");
            var modPath  = Path.Combine(dscDir, $"{modName}_{modVers}.zip");
            var csumPath = Path.Combine(dscDir, $"{modName}_{modVers}.zip.checksum");
            var modBody  = File.ReadAllBytes(modPath);
            var csumBody = File.ReadAllText(csumPath);

            var config = BuildConfig();

            using (var client = new DscPullClient(config))
            {
                client.RegisterDscAgent().Wait();

                var moduleResult = client.GetModule(modName, modVers).Result;
                Assert.IsNotNull(moduleResult?.Content, "Module content not null");
                Assert.AreNotEqual(0, moduleResult.Content.Length, "Module content length > 0");

                Assert.AreEqual(csumBody, moduleResult.Checksum, "Expected module checksum");

                Assert.AreEqual(modBody.Length, moduleResult.Content.Length, "Expected module content size");
                CollectionAssert.AreEqual(modBody, moduleResult.Content, "Expected module content");
            }
        }
コード例 #5
0
        public void TestGetDscAction_BadContent_StatusItem()
        {
            var config = BuildConfig();

            using (var client = new DscPullClient(config))
            {
                // Construct our own status item collection
                var statusItems = new[] { new Model.ClientStatusItem() };
                statusItems[0].ChecksumAlgorithm = "SHA-256";
                statusItems[0].Checksum          = "";
                statusItems[0].ConfigurationName = config.ConfigurationNames.First();
                // Inject one unexpected property
                statusItems[0]["foo"] = "bar";

                client.RegisterDscAgent().Wait();

                Assert.That.ThrowsWhen <AggregateException>(
                    condition: (ex) =>
                    ex.InnerException is HttpRequestException &&
                    ex.InnerException.Message.Contains(
                        "Response status code does not indicate success: 400 (Bad Request)"),
                    action: () =>
                    client.GetDscAction(statusItems).Wait(),
                    message:
                    "Throws HTTP exception for bad request (400)");
            }
        }
コード例 #6
0
        public void TestRegisterDscAgent_BadCert_FieldOrder()
        {
            var config = BuildConfig(newAgentId: true);

            // Force bad/unexpected cert info
            var badCert = new BadFieldOrderCertInfo(config.CertificateInformation);

            config.CertificateInformation = badCert;

            using (var client = new DscPullClient(config))
            {
                Assert.That.ThrowsWhen <AggregateException>(
                    condition: (ex) =>
                    ex.InnerException is HttpRequestException
                    // We test for one of two possible error codes, either
                    // 401 which is returned from Classic DSC Pull Server or
                    // 400 which is returned from Tug Server which could not
                    // easily or practically reproduce the same error condition
                    && (ex.InnerException.Message.Contains(
                            "Response status code does not indicate success: 401 (Unauthorized)") ||
                        ex.InnerException.Message.Contains(
                            "Response status code does not indicate success: 400 (Bad Request)")),
                    action: () =>
                    client.RegisterDscAgent().Wait(),
                    message:
                    "Throws HTTP exception for unauthorized (401)");
            }
        }
コード例 #7
0
        public void TestRegisterDscAgent()
        {
            var config = BuildConfig();

            using (var client = new DscPullClient(config))
            {
                client.RegisterDscAgent().Wait();
            }
        }
コード例 #8
0
        public void TestGetConfiguration_Content()
        {
            // Get path and content of expected results
            var myPath   = typeof(ClassicPullServerProtocolCompatibilityTests).GetTypeInfo().Assembly.Location;
            var myDir    = Path.GetDirectoryName(myPath);
            var dscDir   = Path.Combine(myDir, "../../../../../../tools/ci/DSC");
            var mofPath  = Path.Combine(dscDir, "StaticTestConfig.mof");
            var csumPath = Path.Combine(dscDir, "StaticTestConfig.mof.checksum");
            var mofBody  = File.ReadAllText(mofPath);
            var csumBody = File.ReadAllText(csumPath);

            var config = BuildConfig(newAgentId: true);

            config.ConfigurationNames = new[] { "StaticTestConfig" };

            using (var client = new DscPullClient(config))
            {
                client.RegisterDscAgent().Wait();

                var actionResult = client.GetDscAction(new[]
                {
                    new Model.ClientStatusItem
                    {
                        ConfigurationName = "StaticTestConfig",
                        ChecksumAlgorithm = "SHA-256",
                        Checksum          = "",
                    }
                }).Result;
                Assert.IsNotNull(actionResult, "Action result is not null");

                var resultArr = actionResult.ToArray();
                Assert.AreEqual(1, resultArr.Length, "Number of action results");
                Assert.AreEqual("StaticTestConfig", resultArr[0]?.ConfigurationName,
                                "Action result config name");
                Assert.AreEqual(Model.DscActionStatus.GetConfiguration, resultArr[0].Status,
                                "Action result status");

                var configResult = client.GetConfiguration(resultArr[0]?.ConfigurationName).Result;
                Assert.IsNotNull(configResult?.Content, "Configuration content not null");
                Assert.AreNotEqual(0, configResult.Content.Length, "Configuration content length > 0");

                Assert.AreEqual(csumBody, configResult.Checksum, "Expected MOF config checksum");

                // The fixed content is expected to be in UTF-16 Little Endian (LE)
                var configBody = Encoding.Unicode.GetString(configResult.Content);

                // Skip the BOM
                configBody = configBody.Substring(1);

                Assert.AreEqual(mofBody, configBody, "Expected MOF config content");
            }
        }
コード例 #9
0
        public static void Init(TestContext ctx)
        {
            var myPath = typeof(ServerProtocolTests).GetTypeInfo().Assembly.Location;
            var myDir  = Path.GetDirectoryName(myPath);

            Directory.SetCurrentDirectory(myDir);

            var hostBuilder = new WebHostBuilder()
                              .UseLoggerFactory(AppLog.Factory)
                              .UseStartup <Startup>();

            _tugServer = new TestServer(hostBuilder);

            _defaultConfig = BuildConfig();
            _defaultClient = BuildClient();
        }
        public void TestSendReport_BadMissingJobId()
        {
            var config = BuildConfig();

            using (var client = new DscPullClient(config))
            {
                client.DisableReportAdditionalData = _testConfig.adjust_for_wmf_50;
                TugAssert.ThrowsExceptionWhen <AggregateException>(
                    condition: (ex) =>
                    ex.InnerException is HttpRequestException &&
                    ex.InnerException.Message.Contains(
                        "Response status code does not indicate success: 400 (Bad Request)"),
                    action: () =>
                    client.SendReport(new BadSendReportBody()).Wait(),
                    message:
                    "Throws HTTP exception for bad request (400)");
            }
        }
コード例 #11
0
        public void TestGetDscAction()
        {
            var config = BuildConfig();

            using (var client = new DscPullClient(config))
            {
                client.RegisterDscAgent().Wait();

                var actionResult = client.GetDscAction().Result;
                Assert.IsNotNull(actionResult, "Action result is not null");

                var resultArr = actionResult.ToArray();
                Assert.AreEqual(1, resultArr.Length, "Number of action results");
                Assert.AreEqual(config.ConfigurationNames.First(), resultArr[0]?.ConfigurationName,
                                "Action result config name");
                Assert.AreEqual(Model.DscActionStatus.GetConfiguration, resultArr[0].Status,
                                "Action result status");
            }
        }
コード例 #12
0
        public void TestRegisterDscAgent_NoRegKey()
        {
            var config = BuildConfig(newAgentId: true);

            // Remove the RegKey
            config.ConfigurationRepositoryServer.RegistrationKey = null;

            using (var client = new DscPullClient(config))
            {
                Assert.That.ThrowsWhen <AggregateException>(
                    condition: (ex) =>
                    ex.InnerException is HttpRequestException &&
                    ex.InnerException.Message.Contains(
                        "Response status code does not indicate success: 401 (Unauthorized)"),
                    action: () =>
                    client.RegisterDscAgent().Wait(),
                    message:
                    "Throws HTTP exception for unauthorized (401)");
            }
        }
コード例 #13
0
        public void TestRegisterDscAgent_BadContent_CertInfo()
        {
            var config = BuildConfig(newAgentId: true);

            // Add an unexpected property
            config.CertificateInformation["foo"] = "bar";

            using (var client = new DscPullClient(config))
            {
                Assert.That.ThrowsWhen <AggregateException>(
                    condition: (ex) =>
                    ex.InnerException is HttpRequestException &&
                    ex.InnerException.Message.Contains(
                        "Response status code does not indicate success: 400 (Bad Request)"),
                    action: () =>
                    client.RegisterDscAgent().Wait(),
                    message:
                    "Throws HTTP exception for bad request (400)");
            }
        }
        public void TestSendReport()
        {
            var config = BuildConfig(newAgentId: true);

            using (var client = new DscPullClient(config))
            {
                client.DisableReportAdditionalData = _testConfig.adjust_for_wmf_50;
                client.RegisterDscAgent().Wait();
                client.SendReport("SimpleInventoryDefaults",
                                  overrides: new Model.SendReportBody
                {
                    NodeName  = "MY_NAME",
                    IpAddress = "::1;127.0.01",
                }).Wait();
                client.SendReport("DetailedStatusDefaults",
                                  statusData: new[] { "STATUS" }).Wait();
                client.SendReport("ErrorDefaults",
                                  errors: new[] { "ERROR" }).Wait();
            }
        }
コード例 #15
0
        public void TestGetDscAction_NonExistentConfig()
        {
            var config = BuildConfig(newAgentId: true);

            config.ConfigurationNames = new[] { "NoSuchConfig" };

            using (var client = new DscPullClient(config))
            {
                try
                {
                    client.RegisterDscAgent().Wait();

                    var actionResult = client.GetDscAction(new[]
                    {
                        new Model.ClientStatusItem
                        {
                            ConfigurationName = "NoSuchConfig",
                            ChecksumAlgorithm = "SHA-256",
                            Checksum          = "",
                        }
                    }).Result;

                    Assert.IsNotNull(actionResult, "Action result is not null");

                    var resultArr = actionResult.ToArray();
                    Assert.AreEqual(1, resultArr.Length, "Number of action results");
                    Assert.AreEqual("NoSuchConfig", resultArr[0]?.ConfigurationName,
                                    "Action result config name");
                    Assert.AreEqual(Model.DscActionStatus.RETRY, resultArr[0].Status,
                                    "Action result status");
                }
                catch (AggregateException ex)
                    when(ex.InnerException.Message.Contains(
                             "Response status code does not indicate success: 404 (Not Found)"))
                    {
                        Assert.IsInstanceOfType(ex.InnerException,
                                                typeof(HttpRequestException),
                                                "Expected HTTP exception for missing config");
                    }
            }
        }
コード例 #16
0
        public void TestRegisterDscAgent_BadCert_NewField()
        {
            var config = BuildConfig(newAgentId: true);

            // Force bad/unexpected cert info
            var badCert = new BadNewFieldCertInfo(config.CertificateInformation);

            config.CertificateInformation = badCert;

            using (var client = new DscPullClient(config))
            {
                Assert.That.ThrowsWhen <AggregateException>(
                    condition: (ex) =>
                    ex.InnerException is HttpRequestException &&
                    ex.InnerException.Message.Contains(
                        "Response status code does not indicate success: 400 (Bad Request)"),
                    action: () =>
                    client.RegisterDscAgent().Wait(),
                    message:
                    "Throws HTTP exception for unauthorized (401)");
            }
        }
コード例 #17
0
ファイル: Program.cs プロジェクト: vDanielBolger/tug
        public void Execute(string[] args)
        {
            var run = new List <Action>();

            _commandLine = new CommandLine();
            _commandLine.OnRegisterAgent             = () => run.Add(DoRegisterAgent);
            _commandLine.OnGetAction                 = () => run.Add(DoGetAction);
            _commandLine.OnGetConfiguration          = () => run.Add(DoGetConfiguration);
            _commandLine.OnGetActionAndConfiguration = () => run.Add(DoGetActionAndConfiguration);
            _commandLine.OnGetModule                 = () => run.Add(DoGetModule);

            _commandLine.Init().Execute(args);

            _config = ResolveClientConfiguration();

            try
            {
                using (_client = new DscPullClient(_config))
                {
                    foreach (var r in run)
                    {
                        r();
                    }
                }
            }
            catch (AggregateException ex)
            {
                Console.Error.WriteLine("UNCAUGHT EXCEPTION:");
                Console.Error.WriteLine(ex.InnerException);
                Console.Error.WriteLine("INNER EXCEPTIONS ====================>");
                foreach (var iex in ex.InnerExceptions)
                {
                    Console.Error.WriteLine(iex);
                }
            }
        }
        public void TestGetReports_Single()
        {
            var reportDateFormat = CLASSIC_SERVER_REPORT_DATE_FORMAT;

            if (_testConfig.adjust_for_wmf_50)
            {
                reportDateFormat = CLASSIC_SERVER_REPORT_DATE_FORMAT_ALT;
            }

            var config = BuildConfig(newAgentId: true);
            var report = new Model.SendReportBody
            {
                JobId                = Guid.NewGuid(),
                OperationType        = "FOO",
                RefreshMode          = Model.DscRefreshMode.Pull,
                Status               = "BAR",
                ReportFormatVersion  = "Spooky",
                ConfigurationVersion = "Scary",
                //StartTime = DateTime.Now.ToString(Model.SendReportBody.REPORT_DATE_FORMAT),
                StartTime = DateTime.Now.ToString(reportDateFormat),
                //EndTime = DateTime.Now.ToString(Model.SendReportBody.REPORT_DATE_FORMAT),
                EndTime         = DateTime.Now.ToString(reportDateFormat),
                RebootRequested = Model.DscTrueFalse.False,
                StatusData      = new[] { "STATUS-DATA" },
                Errors          = new[] { "ERRORS" },
                AdditionalData  = new[]
                {
                    new Model.SendReportBody.AdditionalDataItem {
                        Key = "1", Value = "ONE",
                    },
                    new Model.SendReportBody.AdditionalDataItem {
                        Key = "2", Value = "TWO",
                    },
                },
            };

            using (var client = new DscPullClient(config))
            {
                client.DisableReportAdditionalData = _testConfig.adjust_for_wmf_50;
                client.RegisterDscAgent().Wait();
                client.SendReport(report).Wait();

                var sr = client.GetReports().Result;
                Assert.IsNotNull(sr, "Reports not null");
                var srArr = sr.ToArray();
                Assert.AreEqual(1, srArr.Length, "Reports length is exactly 1");

                // Unfortunate kludge to deal with broken DscService on WMF 5.1
                //    See https://github.com/PowerShell/PowerShell/issues/2921
                if (_testConfig.adjust_for_wmf_50)
                {
                    report.AdditionalData = Model.SendReportBody.AdditionalDataItem.EMPTY_ITEMS;
                }

                var ser1 = JsonConvert.SerializeObject(report);
                var ser2 = JsonConvert.SerializeObject(srArr[0]);
                Assert.AreEqual(ser1, ser2, "Submitted and retrieved reports are the same");

                sr = client.GetReports().Result;
                Assert.IsNotNull(sr, "All reports not null");
                srArr = sr.ToArray();
                Assert.AreEqual(1, srArr.Length, "All reports length is exactly 1");
            }
        }
コード例 #19
0
ファイル: Program.cs プロジェクト: vDanielBolger/tug
        public void DoSendReport(DscPullClient client)
        {
            Console.WriteLine("SEND-REPORT");

            throw new NotImplementedException();
        }