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 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)"); } }
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"); } }
public void TestGetDscAction() { var actions = _defaultClient.GetDscAction().Result; Assert.IsNotNull(actions, "Actions are not missing or null"); var actionsArr = actions.ToArray(); Assert.AreEqual(1, actionsArr.Length, "Exactly 1 action response"); Assert.AreEqual(_defaultConfig.ConfigurationNames.First(), actionsArr[0].ConfigurationName, "Expected configuration name"); }
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"); } }
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"); } } }
public void DoGetAction() { Console.WriteLine("GET-ACTION"); _client.GetDscAction().Result?.ToArray(); }