private void AssertHandlersEquals(JObject a, JObject b) { var handler = new { name = "test_handler", path = "*.test", verbs = "*", type = "Microsoft.IIS.Administration.Test.Type", modules = "ManagedPipelineHandler", script_processor = "", resource_type = "unspecified", require_access = "script", allow_path_info = false, precondition = "integratedMode" }; Assert.True(Utils.JEquals <string>(a, b, "name")); Assert.True(Utils.JEquals <string>(a, b, "path")); Assert.True(Utils.JEquals <string>(a, b, "verbs")); Assert.True(Utils.JEquals <string>(a, b, "type")); Assert.True(Utils.JEquals <string>(a, b, "modules")); Assert.True(Utils.JEquals <string>(a, b, "script_processor")); Assert.True(Utils.JEquals <string>(a, b, "resource_type")); Assert.True(Utils.JEquals <string>(a, b, "require_access")); Assert.True(Utils.JEquals <bool>(a, b, "allow_path_info")); Assert.True(Utils.JEquals <string>(a, b, "precondition")); }
private static void ChangeAndRestoreProps(HttpClient client, JObject feature) { JObject cachedFeature = new JObject(feature); feature["directory"] = @"c:\sites\test_site"; feature["do_disk_space_limitting"] = !feature.Value <bool>("do_disk_space_limitting"); feature["max_disk_space_usage"] = feature.Value <long>("max_disk_space_usage") + 1; feature["min_file_size"] = feature.Value <long>("min_file_size") + 1; feature["do_dynamic_compression"] = !feature.Value <bool>("do_dynamic_compression"); feature["do_static_compression"] = !feature.Value <bool>("do_static_compression"); JObject metaData = (JObject)feature["metadata"]; metaData["override_mode"] = metaData.Value <string>("override_mode") == "allow" ? "deny" : "allow"; string result; Assert.True(client.Patch(Utils.Self(feature), JsonConvert.SerializeObject(feature), out result)); JObject newFeature = JsonConvert.DeserializeObject <JObject>(result); Assert.True(Utils.JEquals <string>(feature, newFeature, "directory")); Assert.True(Utils.JEquals <bool>(feature, newFeature, "do_disk_space_limitting")); Assert.True(Utils.JEquals <string>(feature, newFeature, "max_disk_space_usage")); Assert.True(Utils.JEquals <string>(feature, newFeature, "min_file_size")); Assert.True(Utils.JEquals <bool>(feature, newFeature, "do_dynamic_compression")); Assert.True(Utils.JEquals <bool>(feature, newFeature, "do_static_compression")); Assert.True(Utils.JEquals <string>(feature, newFeature, "metadata.override_mode")); Assert.True(client.Patch(Utils.Self(feature), JsonConvert.SerializeObject(cachedFeature), out result)); }
private static void CompareRules(JObject rule1, JObject rule2) { Assert.True(Utils.JEquals <string>(rule1, rule2, "path")); var statusCodes1 = rule1.Value <JArray>("status_codes").ToObject <string[]>(); var statusCodes2 = rule1.Value <JArray>("status_codes").ToObject <string[]>(); Assert.True(statusCodes1.Length == statusCodes2.Length); for (int i = 0; i < statusCodes1.Length; i++) { Assert.Equal(statusCodes1[i], statusCodes2[i]); } Assert.True(Utils.JEquals <long>(rule1, rule2, "min_request_execution_time")); Assert.True(Utils.JEquals <string>(rule1, rule2, "event_severity")); var traceArea1 = rule1.Value <JArray>("traces").ToObject <List <JObject> >()[0]; var traceArea2 = rule2.Value <JArray>("traces").ToObject <List <JObject> >()[0]; var provider1 = traceArea1.Value <JObject>("provider"); var provider2 = traceArea2.Value <JObject>("provider"); var allowedAreas1 = traceArea1["allowed_areas"].ToObject <Dictionary <string, bool> >(); var allowedAreas2 = traceArea2["allowed_areas"].ToObject <Dictionary <string, bool> >(); foreach (var key in allowedAreas1.Keys) { if (allowedAreas1[key]) { Assert.True(allowedAreas2[key]); } } Assert.True(Utils.JEquals <string>(provider1, provider2, "name")); Assert.True(Utils.JEquals <string>(traceArea1, traceArea2, "verbosity")); }
public void CreatePatchRemoveRule() { using (HttpClient client = ApiHttpClient.Create()) { dynamic rule = new ExpandoObject(); rule.name = "test_rule"; rule.scan_url = true; rule.scan_query_string = true; rule.headers = new string[] { "h1", "h2" }; rule.applies_to = new string[] { ".e1", ".e2" }; rule.deny_strings = new string[] { "rand", "str" }; JObject r = Create(client, "rules", rule); string result; r["name"] = "test_rule-new"; Assert.True(client.Patch(Utils.Self(r), JsonConvert.SerializeObject(r), out result)); JObject newRule = JsonConvert.DeserializeObject <JObject>(result); Assert.True(Utils.JEquals <string>(r, newRule, "name")); Assert.True(client.Delete(Utils.Self(newRule))); } }
public void ChangeAllProperties() { using (HttpClient client = ApiHttpClient.Create()) { JObject serverSettings = client.Get(ENDPOINT + "?scope="); JObject original = (JObject)serverSettings.DeepClone(); serverSettings["enabled"] = !serverSettings.Value <bool>("enabled"); serverSettings["preserve_filename"] = !serverSettings.Value <bool>("preserve_filename"); serverSettings["destination"] = "http://httpredirecttestdestination.test"; serverSettings["absolute"] = !serverSettings.Value <bool>("absolute"); serverSettings["status_code"] = serverSettings.Value <int>("status_code") == 302 ? 301 : 302; JObject newSettings = client.Patch(Utils.Self(serverSettings), serverSettings); Assert.NotNull(newSettings); try { Assert.True(Utils.JEquals <bool>(serverSettings, newSettings, "enabled")); Assert.True(Utils.JEquals <bool>(serverSettings, newSettings, "preserve_filename")); Assert.True(Utils.JEquals <string>(serverSettings, newSettings, "destination")); Assert.True(Utils.JEquals <bool>(serverSettings, newSettings, "absolute")); Assert.True(Utils.JEquals <int>(serverSettings, newSettings, "status_code")); } finally { newSettings = client.Patch(Utils.Self(newSettings), original); Assert.NotNull(newSettings); } } }
public void ChangeAllProperties() { using (HttpClient client = ApiHttpClient.Create()) { JObject reqFilt = GetRequestFilteringFeature(client, null, null); JObject cachedFeature = new JObject(reqFilt); reqFilt["allow_unlisted_file_extensions"] = !reqFilt.Value <bool>("allow_unlisted_file_extensions"); reqFilt["allow_unlisted_verbs"] = !reqFilt.Value <bool>("allow_unlisted_verbs"); reqFilt["allow_high_bit_characters"] = !reqFilt.Value <bool>("allow_high_bit_characters"); reqFilt["allow_double_escaping"] = !reqFilt.Value <bool>("allow_double_escaping"); reqFilt["max_content_length"] = reqFilt.Value <long>("max_content_length") - 1; reqFilt["max_url_length"] = reqFilt.Value <long>("max_url_length") - 1; reqFilt["max_query_string_length"] = reqFilt.Value <long>("max_query_string_length") - 1; JObject verb = JObject.FromObject(new { allowed = false, name = "test_verb" }); reqFilt.Value <JArray>("verbs").Add(verb); string result; string body = JsonConvert.SerializeObject(reqFilt); Assert.True(client.Patch(Utils.Self(reqFilt), body, out result)); JObject newReqFilt = JsonConvert.DeserializeObject <JObject>(result); Assert.True(Utils.JEquals <bool>(reqFilt, newReqFilt, "allow_unlisted_file_extensions")); Assert.True(Utils.JEquals <bool>(reqFilt, newReqFilt, "allow_unlisted_verbs")); Assert.True(Utils.JEquals <bool>(reqFilt, newReqFilt, "allow_high_bit_characters")); Assert.True(Utils.JEquals <bool>(reqFilt, newReqFilt, "allow_double_escaping")); Assert.True(Utils.JEquals <long>(reqFilt, newReqFilt, "max_content_length")); Assert.True(Utils.JEquals <long>(reqFilt, newReqFilt, "max_url_length")); Assert.True(Utils.JEquals <long>(reqFilt, newReqFilt, "max_query_string_length")); var verbs = newReqFilt.Value <JArray>("verbs"); JObject targetVerb = null; foreach (var v in verbs) { if (v.Value <string>("name").Equals(verb.Value <string>("name"))) { targetVerb = (JObject)v; } } Assert.NotNull(targetVerb); // Create json payload of original feature state body = JsonConvert.SerializeObject(cachedFeature); // Patch request filtering to original state Assert.True(client.Patch(Utils.Self(newReqFilt), body, out result)); } }
private void AssertFeaturesEqual(JObject a, JObject b) { Assert.True(Utils.JEquals <bool>(a, b, allowedAccessProperty + ".read")); Assert.True(Utils.JEquals <bool>(a, b, allowedAccessProperty + ".write")); Assert.True(Utils.JEquals <bool>(a, b, allowedAccessProperty + ".execute")); Assert.True(Utils.JEquals <bool>(a, b, allowedAccessProperty + ".source")); Assert.True(Utils.JEquals <bool>(a, b, allowedAccessProperty + ".script")); Assert.True(Utils.JEquals <bool>(a, b, removePreventionProperty + ".write")); Assert.True(Utils.JEquals <bool>(a, b, removePreventionProperty + ".read")); Assert.True(Utils.JEquals <bool>(a, b, removePreventionProperty + ".execute")); Assert.True(Utils.JEquals <bool>(a, b, removePreventionProperty + ".script")); }
private static void CompareProviders(JObject provider1, JObject provider2) { Assert.True(Utils.JEquals <string>(provider1, provider2, "name")); Assert.True(Utils.JEquals <string>(provider1, provider2, "guid")); var area1 = provider1.Value <JArray>("areas").ToObject <List <string> >(); var area2 = provider2.Value <JArray>("areas").ToObject <List <string> >(); for (int i = 0; i < area1.Count(); i++) { Assert.Equal <string>(area1[i], area2[i]); } }
public void ChangeAllProperties() { using (HttpClient client = ApiHttpClient.Create()) { JObject ipRes = GetIpRestrictionsFeature(client, null, null); ipRes.Remove("enabled"); JObject cachedFeature = new JObject(ipRes); ipRes["allow_unlisted"] = !ipRes.Value <bool>("allow_unlisted"); ipRes["enable_reverse_dns"] = !ipRes.Value <bool>("enable_reverse_dns"); ipRes["enable_proxy_mode"] = !ipRes.Value <bool>("enable_proxy_mode"); ipRes["logging_only_mode"] = !ipRes.Value <bool>("logging_only_mode"); ipRes["deny_action"] = "NotFound"; JObject denyByConcurrentRequests = ipRes.Value <JObject>("deny_by_concurrent_requests"); denyByConcurrentRequests["enabled"] = !ipRes.Value <bool>("enabled"); denyByConcurrentRequests["max_concurrent_requests"] = denyByConcurrentRequests.Value <long>("max_concurrent_requests") + 1; JObject denyByRequestRate = ipRes.Value <JObject>("deny_by_request_rate"); denyByRequestRate["enabled"] = !denyByRequestRate.Value <bool>("enabled"); denyByRequestRate["max_requests"] = denyByRequestRate.Value <long>("max_requests") + 1; denyByRequestRate["time_period"] = denyByRequestRate.Value <long>("time_period") + 1; string result; string body = JsonConvert.SerializeObject(ipRes); Assert.True(client.Patch(Utils.Self(ipRes), body, out result)); JObject newIpRes = JsonConvert.DeserializeObject <JObject>(result); Assert.True(Utils.JEquals <bool>(ipRes, newIpRes, "allow_unlisted")); Assert.True(Utils.JEquals <bool>(ipRes, newIpRes, "enable_reverse_dns")); Assert.True(Utils.JEquals <bool>(ipRes, newIpRes, "enable_proxy_mode")); Assert.True(Utils.JEquals <bool>(ipRes, newIpRes, "logging_only_mode")); Assert.True(Utils.JEquals <string>(ipRes, newIpRes, "deny_action", StringComparison.OrdinalIgnoreCase)); Assert.True(Utils.JEquals <bool>(ipRes, newIpRes, "deny_by_concurrent_requests.enabled")); Assert.True(Utils.JEquals <long>(ipRes, newIpRes, "deny_by_concurrent_requests.max_concurrent_requests")); Assert.True(Utils.JEquals <bool>(ipRes, newIpRes, "deny_by_request_rate.enabled")); Assert.True(Utils.JEquals <long>(ipRes, newIpRes, "deny_by_request_rate.max_requests")); Assert.True(Utils.JEquals <long>(ipRes, newIpRes, "deny_by_request_rate.time_period")); // Create json payload of original feature state body = JsonConvert.SerializeObject(cachedFeature); // Patch request filtering to original state Assert.True(client.Patch(Utils.Self(newIpRes), body, out result)); } }
private static void ChangeAndRestoreProps(HttpClient client, JObject feature) { feature.Remove("metadata"); bool isWebServer = string.IsNullOrEmpty(feature.Value <string>("scope")); if (isWebServer) { feature["directory"] = Sites.TEST_SITE_PATH; feature["do_disk_space_limitting"] = !feature.Value <bool>("do_disk_space_limitting"); feature["max_disk_space_usage"] = feature.Value <long>("max_disk_space_usage") + 1; feature["min_file_size"] = feature.Value <long>("min_file_size") + 1; } else { feature.Remove("directory"); feature.Remove("do_disk_space_limitting"); feature.Remove("max_disk_space_usage"); feature.Remove("min_file_size"); } JObject cachedFeature = new JObject(feature); feature["do_dynamic_compression"] = !feature.Value <bool>("do_dynamic_compression"); feature["do_static_compression"] = !feature.Value <bool>("do_static_compression"); string result; Assert.True(client.Patch(Utils.Self(feature), JsonConvert.SerializeObject(feature), out result)); JObject newFeature = JsonConvert.DeserializeObject <JObject>(result); if (isWebServer) { Assert.True(Utils.JEquals <string>(feature, newFeature, "directory")); Assert.True(Utils.JEquals <bool>(feature, newFeature, "do_disk_space_limitting")); Assert.True(Utils.JEquals <string>(feature, newFeature, "max_disk_space_usage")); Assert.True(Utils.JEquals <string>(feature, newFeature, "min_file_size")); } Assert.True(Utils.JEquals <bool>(feature, newFeature, "do_dynamic_compression")); Assert.True(Utils.JEquals <bool>(feature, newFeature, "do_static_compression")); Assert.True(client.Patch(Utils.Self(feature), JsonConvert.SerializeObject(cachedFeature), out result)); }
public void ChangeAllProperties() { string defaultDocFooterTestValue = "test_str"; string clientCacheControlModeTestValue = "use_max_age"; string clientCacheControlCustomTestValue = "test_str_control_cust"; using (HttpClient client = ApiHttpClient.Create()) { JObject staticContent = GetStaticContentFeature(client, null, null); JObject cachedFeature = new JObject(staticContent); staticContent["default_doc_footer"] = defaultDocFooterTestValue; staticContent["is_doc_footer_file_name"] = !staticContent.Value <bool>("is_doc_footer_file_name"); staticContent["enable_doc_footer"] = !staticContent.Value <bool>("enable_doc_footer"); JObject clientCache = staticContent.Value <JObject>("client_cache"); clientCache["max_age"] = clientCache.Value <long>("max_age") == 0 ? 1 : clientCache.Value <long>("max_age") - 1; clientCache["control_mode"] = clientCacheControlModeTestValue; clientCache["control_custom"] = clientCacheControlCustomTestValue; clientCache["set_e_tag"] = !clientCache.Value <bool>("set_e_tag"); string result; string body = JsonConvert.SerializeObject(staticContent); Assert.True(client.Patch(Utils.Self(staticContent), body, out result)); JObject newStaticContent = JsonConvert.DeserializeObject <JObject>(result); Assert.True(Utils.JEquals <string>(staticContent, newStaticContent, "default_doc_footer")); Assert.True(Utils.JEquals <bool>(staticContent, newStaticContent, "is_doc_footer_file_name")); Assert.True(Utils.JEquals <bool>(staticContent, newStaticContent, "enable_doc_footer")); Assert.True(Utils.JEquals <long>(staticContent, newStaticContent, "client_cache.max_age")); Assert.True(Utils.JEquals <string>(staticContent, newStaticContent, "client_cache.control_mode")); Assert.True(Utils.JEquals <string>(staticContent, newStaticContent, "client_cache.control_custom")); Assert.True(Utils.JEquals <bool>(staticContent, newStaticContent, "client_cache.set_e_tag")); // Create json payload of original feature state body = JsonConvert.SerializeObject(cachedFeature); // Patch request filtering to original state Assert.True(client.Patch(Utils.Self(newStaticContent), body, out result)); } }
public void CreatePatchRemoveFileNameExtension() { using (HttpClient client = ApiHttpClient.Create()) { dynamic fileExtension = new ExpandoObject(); fileExtension.extension = "test_ext"; fileExtension.allowed = false; JObject ext = Create(client, "file_extensions", fileExtension); string result; ext["extension"] = "test_ext-new"; Assert.True(client.Patch(Utils.Self(ext), JsonConvert.SerializeObject(ext), out result)); JObject newExt = JsonConvert.DeserializeObject <JObject>(result); Assert.True(Utils.JEquals <string>(ext, newExt, "extension")); Assert.True(client.Delete(Utils.Self(newExt))); } }
public void CreatePatchRemoveUrl() { using (HttpClient client = ApiHttpClient.Create()) { dynamic url = new ExpandoObject(); url.url = "test_url"; url.allow = false; JObject u = Create(client, "urls", url); string result; u["url"] = "test_url-new"; Assert.True(client.Patch(Utils.Self(u), JsonConvert.SerializeObject(u), out result)); JObject newUrl = JsonConvert.DeserializeObject <JObject>(result); Assert.True(Utils.JEquals <string>(u, newUrl, "url")); Assert.True(client.Delete(Utils.Self(newUrl))); } }
public void CreatePatchRemoveQueryString() { using (HttpClient client = ApiHttpClient.Create()) { dynamic queryString = new ExpandoObject(); queryString.query_string = "test_q_string"; queryString.allow = false; JObject qs = Create(client, "query_strings", queryString); string result; qs["query_string"] = "test_q_string-new"; Assert.True(client.Patch(Utils.Self(qs), JsonConvert.SerializeObject(qs), out result)); JObject newQs = JsonConvert.DeserializeObject <JObject>(result); Assert.True(Utils.JEquals <string>(qs, newQs, "query_string")); Assert.True(client.Delete(Utils.Self(newQs))); } }
public void CreatePatchRemoveHeaderLimit() { using (HttpClient client = ApiHttpClient.Create()) { dynamic headerLimit = new ExpandoObject(); headerLimit.header = "test_header"; headerLimit.size_limit = 64; JObject hl = Create(client, "header_limits", headerLimit); string result; hl["header"] = "test_header-new"; Assert.True(client.Patch(Utils.Self(hl), JsonConvert.SerializeObject(hl), out result)); JObject newHl = JsonConvert.DeserializeObject <JObject>(result); Assert.True(Utils.JEquals <string>(hl, newHl, "header")); Assert.True(client.Delete(Utils.Self(newHl))); } }
public void ChangeAllProperties() { using (HttpClient client = ApiHttpClient.Create()) { Sites.EnsureNoSite(client, TEST_SITE_NAME); JObject site = Sites.CreateSite(_output, client, TEST_SITE_NAME, 50310, Sites.TEST_SITE_PATH); JObject feature = GetDirectoryBrowsingFeatrue(client, site.Value <string>("name"), null); Assert.NotNull(feature); JObject cachedFeature = new JObject(feature); feature["enabled"] = !feature.Value <bool>("enabled"); var allowedAttributes = feature.Value <JObject>("allowed_attributes"); allowedAttributes["date"] = !allowedAttributes.Value <bool>("date"); allowedAttributes["time"] = !allowedAttributes.Value <bool>("time"); allowedAttributes["size"] = !allowedAttributes.Value <bool>("size"); allowedAttributes["extension"] = !allowedAttributes.Value <bool>("extension"); allowedAttributes["long_date"] = !allowedAttributes.Value <bool>("long_date"); string result; string body = JsonConvert.SerializeObject(feature); Assert.True(client.Patch(Utils.Self(feature), body, out result)); JObject newFeature = JsonConvert.DeserializeObject <JObject>(result); Assert.True(Utils.JEquals <bool>(feature, newFeature, "enabled")); Assert.True(Utils.JEquals <bool>(feature, newFeature, "allowed_attributes.date")); Assert.True(Utils.JEquals <bool>(feature, newFeature, "allowed_attributes.time")); Assert.True(Utils.JEquals <bool>(feature, newFeature, "allowed_attributes.size")); Assert.True(Utils.JEquals <bool>(feature, newFeature, "allowed_attributes.extension")); Assert.True(Utils.JEquals <bool>(feature, newFeature, "allowed_attributes.long_date")); body = JsonConvert.SerializeObject(cachedFeature); Assert.True(client.Patch(Utils.Self(newFeature), body, out result)); Sites.EnsureNoSite(client, TEST_SITE_NAME); } }
public void ChangeAllProperties() { using (HttpClient client = ApiHttpClient.Create()) { Sites.EnsureNoSite(client, TEST_SITE_NAME); JObject site = Sites.CreateSite(client, TEST_SITE_NAME, 50310, @"c:\sites\test_site"); JObject feature = GetAuthorizationFeature(client, site.Value <string>("name"), null); Assert.NotNull(feature); feature["bypass_login_pages"] = !feature.Value <bool>("bypass_login_pages"); string result; string body = JsonConvert.SerializeObject(feature); Assert.True(client.Patch(Utils.Self(feature), body, out result)); JObject newFeature = JsonConvert.DeserializeObject <JObject>(result); Assert.True(Utils.JEquals <bool>(feature, newFeature, "bypass_login_pages")); Sites.EnsureNoSite(client, TEST_SITE_NAME); } }
public void ChangeAllProperties() { using (HttpClient client = ApiHttpClient.Create()) { EnsureNoPool(client, TEST_APP_POOL_NAME); string id; Assert.True(CreateAppPool(client, TEST_APP_POOL, out id)); JObject pool = GetAppPool(client, TEST_APP_POOL_NAME); JObject cachedPool = new JObject(pool); WaitForStatus(client, pool); pool["auto_start"] = !pool.Value <bool>("auto_start"); pool["enable_32bit_win64"] = !pool.Value <bool>("enable_32bit_win64"); pool["queue_length"] = pool.Value <long>("queue_length") + 1; pool["managed_runtime_version"] = "v2.0"; pool["status"] = Enum.GetName(typeof(Status), DynamicHelper.To <Status>(pool["status"]) == Status.Stopped ? Status.Started : Status.Stopped); pool["pipeline_mode"] = Enum.GetName(typeof(ManagedPipelineMode), DynamicHelper.To <ManagedPipelineMode>(pool["pipeline_mode"]) == ManagedPipelineMode.Integrated ? ManagedPipelineMode.Classic : ManagedPipelineMode.Integrated); JObject cpu = pool.Value <JObject>("cpu"); cpu["limit"] = cpu.Value <long>("limit") + 1; cpu["limit_interval"] = cpu.Value <long>("limit_interval") + 1; cpu["action"] = Enum.GetName(typeof(ProcessorAction), DynamicHelper.To <ProcessorAction>(cpu["action"]) == ProcessorAction.NoAction ? ProcessorAction.KillW3wp : ProcessorAction.NoAction); JObject pModel = pool.Value <JObject>("process_model"); pModel["idle_timeout"] = pModel.Value <long>("idle_timeout") + 1; pModel["max_processes"] = pModel.Value <long>("max_processes") + 1; pModel["ping_interval"] = pModel.Value <long>("ping_interval") + 1; pModel["ping_response_time"] = pModel.Value <long>("ping_response_time") + 1; pModel["shutdown_time_limit"] = pModel.Value <long>("shutdown_time_limit") + 1; pModel["startup_time_limit"] = pModel.Value <long>("startup_time_limit") + 1; pModel["pinging_enabled"] = !pModel.Value <bool>("pinging_enabled"); pModel["idle_timeout_action"] = Enum.GetName(typeof(IdleTimeoutAction), DynamicHelper.To <IdleTimeoutAction>(pModel["idle_timeout_action"]) == IdleTimeoutAction.Terminate ? IdleTimeoutAction.Suspend : IdleTimeoutAction.Terminate); JObject recycling = (JObject)pool["recycling"]; recycling["disable_overlapped_recycle"] = !recycling.Value <bool>("disable_overlapped_recycle"); recycling["disable_recycle_on_config_change"] = !recycling.Value <bool>("disable_recycle_on_config_change"); JObject logEvents = (JObject)pool["recycling"]["log_events"]; logEvents["time"] = !logEvents.Value <bool>("time"); logEvents["requests"] = !logEvents.Value <bool>("requests"); logEvents["schedule"] = !logEvents.Value <bool>("schedule"); logEvents["memory"] = !logEvents.Value <bool>("memory"); logEvents["isapi_unhealthy"] = !logEvents.Value <bool>("isapi_unhealthy"); logEvents["on_demand"] = !logEvents.Value <bool>("on_demand"); logEvents["config_change"] = !logEvents.Value <bool>("config_change"); logEvents["private_memory"] = !logEvents.Value <bool>("private_memory"); JObject pRestart = (JObject)pool["recycling"]["periodic_restart"]; pRestart["time_interval"] = pRestart.Value <long>("time_interval") + 1; pRestart["private_memory"] = pRestart.Value <long>("private_memory") + 1; pRestart["request_limit"] = pRestart.Value <long>("request_limit") + 1; pRestart["virtual_memory"] = pRestart.Value <long>("virtual_memory") + 1; JArray schedule = (JArray)pRestart["schedule"]; schedule.Add(new JValue(TimeSpan.FromHours(20).ToString(@"hh\:mm"))); JObject rfp = pool.Value <JObject>("rapid_fail_protection"); rfp["interval"] = rfp.Value <long>("interval") + 1; rfp["max_crashes"] = rfp.Value <long>("max_crashes") + 1; rfp["enabled"] = !rfp.Value <bool>("enabled"); rfp["auto_shutdown_exe"] = "test.exe"; rfp["auto_shutdown_params"] = "testparams"; rfp["load_balancer_capabilities"] = Enum.GetName(typeof(LoadBalancerCapabilities), DynamicHelper.To <LoadBalancerCapabilities>(rfp["idle_timeout_action"]) == LoadBalancerCapabilities.HttpLevel ? LoadBalancerCapabilities.TcpLevel : LoadBalancerCapabilities.HttpLevel); JObject processOrphaning = pool.Value <JObject>("process_orphaning"); processOrphaning["enabled"] = !processOrphaning.Value <bool>("enabled"); processOrphaning["orphan_action_exe"] = "test.exe"; processOrphaning["orphan_action_params"] = "testparams"; string result; string body = JsonConvert.SerializeObject(pool); Assert.True(client.Patch(Utils.Self(pool), body, out result)); JObject newPool = JsonConvert.DeserializeObject <JObject>(result); Assert.True(Utils.JEquals <bool>(pool, newPool, "auto_start")); Assert.True(Utils.JEquals <bool>(pool, newPool, "enable_32bit_win64")); Assert.True(Utils.JEquals <long>(pool, newPool, "queue_length")); Assert.True(Utils.JEquals <string>(pool, newPool, "pipeline_mode", StringComparison.OrdinalIgnoreCase)); Assert.True(Utils.JEquals <string>(pool, newPool, "managed_runtime_version")); Assert.True(Utils.JEquals <long>(pool, newPool, "cpu.limit")); Assert.True(Utils.JEquals <long>(pool, newPool, "cpu.limit_interval")); Assert.True(Utils.JEquals <bool>(pool, newPool, "cpu.processor_affinity_enabled")); Assert.True(Utils.JEquals <string>(pool, newPool, "cpu.action", StringComparison.OrdinalIgnoreCase)); Assert.True(Utils.JEquals <long>(pool, newPool, "process_model.idle_timeout")); Assert.True(Utils.JEquals <long>(pool, newPool, "process_model.max_processes")); Assert.True(Utils.JEquals <long>(pool, newPool, "process_model.ping_interval")); Assert.True(Utils.JEquals <long>(pool, newPool, "process_model.ping_response_time")); Assert.True(Utils.JEquals <long>(pool, newPool, "process_model.shutdown_time_limit")); Assert.True(Utils.JEquals <long>(pool, newPool, "process_model.startup_time_limit")); Assert.True(Utils.JEquals <bool>(pool, newPool, "process_model.pinging_enabled")); Assert.True(Utils.JEquals <string>(pool, newPool, "process_model.idle_timeout_action", StringComparison.OrdinalIgnoreCase)); Assert.True(Utils.JEquals <bool>(pool, newPool, "recycling.disable_overlapped_recycle")); Assert.True(Utils.JEquals <bool>(pool, newPool, "recycling.disable_recycle_on_config_change")); Assert.True(Utils.JEquals <bool>(pool, newPool, "recycling.log_events.time")); Assert.True(Utils.JEquals <bool>(pool, newPool, "recycling.log_events.requests")); Assert.True(Utils.JEquals <bool>(pool, newPool, "recycling.log_events.schedule")); Assert.True(Utils.JEquals <bool>(pool, newPool, "recycling.log_events.memory")); Assert.True(Utils.JEquals <bool>(pool, newPool, "recycling.log_events.isapi_unhealthy")); Assert.True(Utils.JEquals <bool>(pool, newPool, "recycling.log_events.on_demand")); Assert.True(Utils.JEquals <bool>(pool, newPool, "recycling.log_events.config_change")); Assert.True(Utils.JEquals <bool>(pool, newPool, "recycling.log_events.private_memory")); Assert.True(Utils.JEquals <long>(pool, newPool, "recycling.periodic_restart.time_interval")); Assert.True(Utils.JEquals <long>(pool, newPool, "recycling.periodic_restart.private_memory")); Assert.True(Utils.JEquals <long>(pool, newPool, "recycling.periodic_restart.request_limit")); Assert.True(Utils.JEquals <long>(pool, newPool, "recycling.periodic_restart.virtual_memory")); JArray scheduleOld = pool["recycling"]["periodic_restart"].Value <JArray>("schedule"); JArray scheduleNew = newPool["recycling"]["periodic_restart"].Value <JArray>("schedule"); for (int i = 0; i < scheduleOld.Count; i++) { Assert.True(scheduleOld[i].ToObject <string>().Equals(scheduleNew[i].ToObject <string>())); } Assert.True(Utils.JEquals <long>(pool, newPool, "rapid_fail_protection.interval")); Assert.True(Utils.JEquals <long>(pool, newPool, "rapid_fail_protection.max_crashes")); Assert.True(Utils.JEquals <bool>(pool, newPool, "rapid_fail_protection.enabled")); Assert.True(Utils.JEquals <string>(pool, newPool, "rapid_fail_protection.auto_shutdown_exe")); Assert.True(Utils.JEquals <string>(pool, newPool, "rapid_fail_protection.auto_shutdown_params")); Assert.True(Utils.JEquals <string>(pool, newPool, "rapid_fail_protection.load_balancer_capabilities", StringComparison.OrdinalIgnoreCase)); Assert.True(Utils.JEquals <bool>(pool, newPool, "process_orphaning.enabled")); Assert.True(Utils.JEquals <string>(pool, newPool, "process_orphaning.orphan_action_exe")); Assert.True(Utils.JEquals <string>(pool, newPool, "process_orphaning.orphan_action_params")); EnsureNoPool(client, TEST_APP_POOL_NAME); } }
public void ChangeAllProperties() { using (HttpClient client = ApiHttpClient.Create()) { EnsureNoSite(client, TEST_SITE_NAME); JObject site = CreateSite(client, TEST_SITE_NAME, 50306, @"c:\sites\test_site"); JObject cachedSite = new JObject(site); WaitForStatus(client, site); Assert.True(site != null); site["server_auto_start"] = !site.Value <bool>("server_auto_start"); site["physical_path"] = @"c:\sites"; site["enabled_protocols"] = "test_protocol"; // If site status is unknown then we don't know if it will be started or stopped when it becomes available // Utilizing the defaults we assume it will go from unkown to started site["status"] = Enum.GetName(typeof(Status), DynamicHelper.To <Status>(site["status"]) == Status.Stopped ? Status.Started : Status.Stopped); JObject limits = (JObject)site["limits"]; limits["connection_timeout"] = limits.Value <long>("connection_timeout") - 1; limits["max_bandwidth"] = limits.Value <long>("max_bandwidth") - 1; limits["max_connections"] = limits.Value <long>("max_connections") - 1; limits["max_url_segments"] = limits.Value <long>("max_url_segments") - 1; JArray bindings = site.Value <JArray>("bindings"); JObject binding = (JObject)bindings.First; binding["port"] = 63014; binding["ip_address"] = "40.3.5.15"; binding["hostname"] = "testhostname"; bindings.Add(JObject.FromObject(new { port = 63015, ip_address = "*", hostname = "", is_https = true, certificate = GetCertificate(client) })); string result; string body = JsonConvert.SerializeObject(site); Assert.True(client.Patch(Utils.Self(site), body, out result)); JObject newSite = JsonConvert.DeserializeObject <JObject>(result); Assert.True(Utils.JEquals <bool>(site, newSite, "server_auto_start")); Assert.True(Utils.JEquals <string>(site, newSite, "physical_path")); Assert.True(Utils.JEquals <string>(site, newSite, "enabled_protocols")); Assert.True(Utils.JEquals <string>(site, newSite, "status", StringComparison.OrdinalIgnoreCase)); Assert.True(Utils.JEquals <long>(site, newSite, "limits.connection_timeout")); Assert.True(Utils.JEquals <long>(site, newSite, "limits.max_bandwidth")); Assert.True(Utils.JEquals <long>(site, newSite, "limits.max_connections")); Assert.True(Utils.JEquals <long>(site, newSite, "limits.max_url_segments")); JObject oldBinding = (JObject)site.Value <JArray>("bindings").First; JObject newBinding = (JObject)newSite.Value <JArray>("bindings").First; Assert.True(Utils.JEquals <string>(oldBinding, newBinding, "port")); Assert.True(Utils.JEquals <string>(oldBinding, newBinding, "ip_address")); Assert.True(Utils.JEquals <string>(oldBinding, newBinding, "hostname")); Assert.True(DeleteSite(client, Utils.Self(site))); } }
public void ChangeAllProperties() { using (HttpClient client = ApiHttpClient.Create()) { EnsureNoSite(client, TEST_SITE_NAME); JObject site = CreateSite(client, TEST_SITE_NAME, TEST_PORT, Configuration.TEST_ROOT_PATH); JObject cachedSite = new JObject(site); WaitForStatus(client, ref site); Assert.True(site != null); site["server_auto_start"] = !site.Value <bool>("server_auto_start"); site["physical_path"] = Configuration.TEST_ROOT_PATH; site["enabled_protocols"] = site.Value <string>("enabled_protocols").Equals("http", StringComparison.OrdinalIgnoreCase) ? "https" : "http"; // If site status is unknown then we don't know if it will be started or stopped when it becomes available // Utilizing the defaults we assume it will go from unkown to started site["status"] = Enum.GetName(typeof(Status), DynamicHelper.To <Status>(site["status"]) == Status.Stopped ? Status.Started : Status.Stopped); JObject limits = (JObject)site["limits"]; limits["connection_timeout"] = limits.Value <long>("connection_timeout") - 1; limits["max_bandwidth"] = limits.Value <long>("max_bandwidth") - 1; limits["max_connections"] = limits.Value <long>("max_connections") - 1; limits["max_url_segments"] = limits.Value <long>("max_url_segments") - 1; JArray bindings = site.Value <JArray>("bindings"); bindings.Clear(); bindings.Add(JObject.FromObject(new { port = 63014, ip_address = "40.3.5.15", hostname = "testhostname", protocol = "http" })); bindings.Add(JObject.FromObject(new { port = 63015, ip_address = "*", hostname = "", protocol = "https", certificate = GetCertificate(client) })); string result; string body = JsonConvert.SerializeObject(site); Assert.True(client.Patch(Utils.Self(site), body, out result)); JObject newSite = JsonConvert.DeserializeObject <JObject>(result); WaitForStatus(client, ref newSite); Assert.True(Utils.JEquals <bool>(site, newSite, "server_auto_start")); Assert.True(Utils.JEquals <string>(site, newSite, "physical_path")); Assert.True(Utils.JEquals <string>(site, newSite, "enabled_protocols")); Assert.True(Utils.JEquals <string>(site, newSite, "status", StringComparison.OrdinalIgnoreCase)); Assert.True(Utils.JEquals <long>(site, newSite, "limits.connection_timeout")); Assert.True(Utils.JEquals <long>(site, newSite, "limits.max_bandwidth")); Assert.True(Utils.JEquals <long>(site, newSite, "limits.max_connections")); Assert.True(Utils.JEquals <long>(site, newSite, "limits.max_url_segments")); for (var i = 0; i < bindings.Count; i++) { var oldBinding = (JObject)bindings[i]; var newBinding = (JObject)bindings[i]; Assert.True(Utils.JEquals <string>(oldBinding, newBinding, "protocol")); Assert.True(Utils.JEquals <string>(oldBinding, newBinding, "port")); Assert.True(Utils.JEquals <string>(oldBinding, newBinding, "ip_address")); Assert.True(Utils.JEquals <string>(oldBinding, newBinding, "hostname")); if (newBinding.Value <string>("protocol").Equals("https")) { Assert.True(JToken.DeepEquals(oldBinding["certificate"], newBinding["certificate"])); } } Assert.True(DeleteSite(client, Utils.Self(site))); } }
public void ChangeAllProperties() { var testLogDirectoryPath = Path.Combine(@"%systemdrive%\inetpub", "logstest"); if (!Directory.Exists(Environment.ExpandEnvironmentVariables(testLogDirectoryPath))) { Directory.CreateDirectory(Environment.ExpandEnvironmentVariables(testLogDirectoryPath)); } using (HttpClient client = ApiHttpClient.Create()) { // Web Server Scope JObject feature = GetLoggingFeature(client, null, null); JObject cachedFeature = new JObject(feature); string result; List <LogFormat> logFormats = new List <LogFormat>() { new LogFormat() { Name = "w3c", IsServerLevel = true }, new LogFormat() { Name = "binary", IsServerLevel = true }, new LogFormat() { Name = "w3c", IsServerLevel = false }, }; try { foreach (var target in logFormats) { JObject rollover = feature.Value <JObject>("rollover"); feature["log_per_site"] = !target.IsServerLevel; feature["log_file_format"] = target.Name; Assert.True(client.Patch(Utils.Self(feature), JsonConvert.SerializeObject(feature), out result)); JObject uFeature = JsonConvert.DeserializeObject <JObject>(result); JObject cachedSpecific = new JObject(uFeature); Assert.True(Utils.JEquals <bool>(feature, uFeature, "log_per_site")); Assert.True(Utils.JEquals <string>(feature, uFeature, "log_file_format")); feature = uFeature; try { feature["enabled"] = !feature.Value <bool>("enabled"); feature["log_file_encoding"] = feature.Value <string>("log_file_encoding") == "utf-8" ? "ansi" : "utf-8"; feature["directory"] = testLogDirectoryPath; rollover["period"] = rollover.Value <string>("period") == "daily" ? "weekly" : "daily"; rollover["truncate_size"] = rollover.Value <long>("truncate_size") - 1; rollover["local_time_rollover"] = !rollover.Value <bool>("local_time_rollover"); if (target.Name == "w3c" && !target.IsServerLevel) { JObject logTarget = feature.Value <JObject>("log_target"); logTarget["etw"] = !logTarget.Value <bool>("etw"); logTarget["file"] = !logTarget.Value <bool>("file"); } if (target.Name == "w3c") { JObject logFields = feature.Value <JObject>("log_fields"); IList <string> keys = logFields.Properties().Select(p => p.Name).ToList(); foreach (var key in keys) { logFields[key] = !logFields.Value <bool>(key); } } Assert.True(client.Patch(Utils.Self(feature), JsonConvert.SerializeObject(feature), out result)); uFeature = JsonConvert.DeserializeObject <JObject>(result); Assert.True(Utils.JEquals <bool>(feature, uFeature, "log_per_site")); Assert.True(Utils.JEquals <bool>(feature, uFeature, "enabled")); Assert.True(Utils.JEquals <string>(feature, uFeature, "log_file_encoding")); Assert.True(Utils.JEquals <string>(feature, uFeature, "rollover.period")); Assert.True(Utils.JEquals <long>(feature, uFeature, "rollover.truncate_size")); Assert.True(Utils.JEquals <bool>(feature, uFeature, "rollover.use_local_time")); Assert.True(JToken.DeepEquals(feature["log_target"], uFeature["log_target"])); Assert.True(JToken.DeepEquals(feature["log_fields"], uFeature["log_fields"])); feature = uFeature; } finally { Assert.True(client.Patch(Utils.Self(cachedSpecific), JsonConvert.SerializeObject(cachedSpecific), out result)); } } } finally { Assert.True(client.Patch(Utils.Self(cachedFeature), JsonConvert.SerializeObject(cachedFeature), out result)); } } }