public void CredentialsMustBeValid() { RequireCcsTestInfrastructure(); Assert.True(Disable()); dynamic ccsInfo = new { path = FOLDER_PATH, identity = new { username = CcsTestUsername, password = "******" }, private_key_password = PVK_PASS }; using (var client = ApiHttpClient.Create()) { JObject webserver = client.Get($"{Configuration.Instance().TEST_SERVER_URL}/api/webserver/"); string ccsLink = Utils.GetLink(webserver, "central_certificates"); HttpResponseMessage res = client.PostRaw(ccsLink, (object)ccsInfo); Assert.True((int)res.StatusCode == 400); Assert.True(res.Content.Headers.ContentType.ToString().Contains("json")); JObject apiError = JsonConvert.DeserializeObject <JObject>(res.Content.ReadAsStringAsync().Result); Assert.True(apiError.Value <string>("name").Equals("identity")); } }
public void WebFileRange() { var physicalPath = Path.Combine(Configuration.TEST_ROOT_PATH, "web_file_range_test"); if (Directory.Exists(physicalPath)) { Directory.Delete(physicalPath, true); Directory.CreateDirectory(physicalPath); } JObject site = null; using (HttpClient client = ApiHttpClient.Create()) { try { var dirs = new List <string>() { "dir1", "dir2", "dir3", "dir4" }; var files = new List <string>() { "file1.txt", "file2.txt", "file3.txt", "file4.txt" }; Sites.EnsureNoSite(client, FILE_TEST_SITE_NAME); site = Sites.CreateSite(client, FILE_TEST_SITE_NAME, Utils.GetAvailablePort(), physicalPath); Assert.NotNull(site); foreach (var dir in dirs) { Directory.CreateDirectory(Path.Combine(physicalPath, dir)); } foreach (var file in files) { File.Create(Path.Combine(physicalPath, file)).Dispose(); } JObject folder = Utils.FollowLink(client, site, "files"); HttpRequestMessage req = new HttpRequestMessage(HttpMethod.Get, Utils.GetLink(folder, "files")); req.Headers.Add("Range", "files=2-5"); var res = client.SendAsync(req).Result; Assert.True(res.Content.Headers.Contains("Content-Range")); Assert.True(res.Content.Headers.GetValues("Content-Range").First().Equals("2-5/8")); var children = JObject.Parse(res.Content.ReadAsStringAsync().Result)["files"].ToObject <IEnumerable <JObject> >(); Assert.True(children.Count() == 4); } finally { Directory.Delete(physicalPath, true); if (site != null) { client.Delete(Utils.Self(site)); } } } }
public void CreateRemoveRule() { using (HttpClient client = ApiHttpClient.Create()) { JObject feature = GetIpRestrictionsFeature(client, null, null); string rulesLink = Utils.GetLink(feature, "entries"); var rule = new { allowed = false, ip_address = "127.255.255.254", ip_restriction = feature }; string result; Assert.True(client.Get(rulesLink, out result)); JObject rulesRep = JsonConvert.DeserializeObject <JObject>(result); JArray rules = rulesRep.Value <JArray>("entries"); foreach (JObject r in rules) { if (r.Value <string>("ip_address").Equals("127.255.255.254")) { Assert.True(client.Delete(Utils.Self(r))); } } Assert.True(client.Post(rulesLink, JsonConvert.SerializeObject(rule), out result)); JObject newObject = JsonConvert.DeserializeObject <JObject>(result); Assert.True(client.Delete(Utils.Self(newObject))); Assert.False(client.Get(Utils.Self(newObject), out result)); } }
public async Task PathMustBeAllowed() { RequireCcsTestInfrastructure(); const string path = @"C:\Not\Allowed\Path"; Assert.True(Disable()); CcsUser user = await CcsUser.Get(); dynamic ccsInfo = new { path = path, identity = new { username = user.Username, password = user.Password }, private_key_password = PVK_PASS }; using (var client = ApiHttpClient.Create()) { JObject webserver = client.Get($"{Configuration.Instance().TEST_SERVER_URL}/api/webserver/"); string ccsLink = Utils.GetLink(webserver, "central_certificates"); HttpResponseMessage res = client.PostRaw(ccsLink, (object)ccsInfo); Assert.True((int)res.StatusCode == 403); } }
private void CreateCheckConflictRemove(HttpClient client, string linkName, ExpandoObject obj, JObject requestFilteringFeature = null) { if (requestFilteringFeature == null) { requestFilteringFeature = GetRequestFilteringFeature(client, null, null); } string link = Utils.GetLink(requestFilteringFeature, linkName); dynamic dynamicObj = obj; dynamicObj.request_filtering = requestFilteringFeature; string result; Assert.True(client.Post(link, JsonConvert.SerializeObject(obj), out result)); JObject newObject = JsonConvert.DeserializeObject <JObject>(result); // Try to post same object again, ensuring we are returning conflict status code HttpContent content = new StringContent(JsonConvert.SerializeObject(obj), Encoding.UTF8, "application/json"); HttpResponseMessage response = client.PostAsync(link, content).Result; Assert.True(response.StatusCode == HttpStatusCode.Conflict); Assert.True(client.Delete(Utils.Self(newObject))); Assert.False(client.Get(Utils.Self(newObject), out result)); }
public void CreateEditDeleteFile() { using (HttpClient client = ApiHttpClient.Create()) using (TestSiteContainer container = new TestSiteContainer(client)) { JObject site = Sites.GetSite(client, container.SiteName); // Create web file var webFile = CreateWebFile(client, site, TEST_FILE_NAME); Assert.True(webFile != null); try { // // Get physical file info var fileInfo = Utils.FollowLink(client, webFile.Value <JObject>("file_info"), "self"); // Update content of file var testContent = "Microsoft.IIS.Administration.Test.Files"; var res = client.PutAsync(Utils.GetLink(fileInfo, "content"), new StringContent(testContent)).Result; Assert.True(res.StatusCode == HttpStatusCode.OK); // Get updated content of file string result = null; Assert.True(client.Get(Utils.GetLink(fileInfo, "content"), out result)); Assert.True(result == testContent); var downloadsHref = Utils.GetLink(fileInfo, "downloads"); var dl = new { file = fileInfo }; // Create download link for file res = client.PostAsync(downloadsHref, new StringContent(JsonConvert.SerializeObject(dl), Encoding.UTF8, "application/json")).Result; Assert.True(res.StatusCode == HttpStatusCode.Created); IEnumerable <string> locationHeader; Assert.True(res.Headers.TryGetValues("location", out locationHeader)); var location = locationHeader.First(); // Download file Assert.True(client.Get($"{Configuration.TEST_SERVER_URL}{location}", out result)); Assert.True(result == testContent); // Update file with empty content res = client.PutAsync(Utils.GetLink(fileInfo, "content"), new ByteArrayContent(new byte[] { })).Result; Assert.True(res.StatusCode == HttpStatusCode.OK); // Assert file truncated res = client.GetAsync(Utils.GetLink(fileInfo, "content")).Result; Assert.True(res.Content.ReadAsByteArrayAsync().Result.Length == 0); } finally { Assert.True(client.Delete(Utils.Self(webFile.Value <JObject>("file_info")))); } } }
public static void DeleteModule(HttpClient client, JObject modulesFeature, string name) { if (modulesFeature != null) { string modulesLink = Utils.GetLink(modulesFeature, "entries"); string result; if (!client.Get(modulesLink, out result)) { throw new Exception(); } JObject modulesRep = JsonConvert.DeserializeObject <JObject>(result); var entries = modulesRep.Value <JArray>("entries").ToObject <IEnumerable <JObject> >(); JObject targetModule = entries.FirstOrDefault(e => e.Value <string>("name").Equals(name, StringComparison.OrdinalIgnoreCase)); if (targetModule != null && !client.Delete(Utils.Self(targetModule))) { throw new Exception(); } } var globalModules = GetGlobalModulesFeature(client).Value <JArray>("global_modules").ToObject <IEnumerable <JObject> >();; JObject targetGlobalModule = globalModules.FirstOrDefault(e => e.Value <string>("name").Equals(name, StringComparison.OrdinalIgnoreCase)); if (targetGlobalModule != null && !client.Delete(Utils.Self(targetGlobalModule))) { throw new Exception(); } }
private async Task <bool> MockUploadFile(HttpClient client, JObject file, int fileSize) { const int chunkSize = 1024 * 1024 / 2; var initialSize = chunkSize < fileSize ? chunkSize : fileSize; return(await UploadFileChunked(client, Utils.GetLink(file, "content"), GetFileSlice(0, initialSize), 0, chunkSize, fileSize)); }
private bool Disable() { using (var client = ApiHttpClient.Create()) { JObject webserver = client.Get($"{Configuration.Instance().TEST_SERVER_URL}/api/webserver/"); string ccsLink = Utils.GetLink(webserver, "central_certificates"); return(client.Delete(ccsLink)); } }
public void CopyFile() { string copyName = "TEST_FILE_NAME_COPY.txt"; string testContent = "Test content for copying files."; JObject copyInfo = null; using (HttpClient client = ApiHttpClient.Create()) { JObject site = Sites.GetSite(client, "Default Web Site"); var webFile = CreateWebFile(client, site, TEST_FILE_NAME); var physicalPath = Environment.ExpandEnvironmentVariables(webFile["file_info"].Value <string>("physical_path")); File.WriteAllText(physicalPath, testContent); try { var fileInfo = Utils.FollowLink(client, webFile.Value <JObject>("file_info"), "self"); var parent = fileInfo.Value <JObject>("parent"); var copy = new { name = copyName, parent = parent, file = fileInfo }; copyInfo = client.Post(Utils.GetLink(fileInfo, "copy"), copy); Assert.NotNull(copyInfo); // // Wait for copy to finish HttpResponseMessage res = null; do { res = client.GetAsync(Utils.Self(copyInfo)).Result; } while (res.StatusCode == HttpStatusCode.OK); var copyParent = new DirectoryInfo(physicalPath).Parent.FullName; var copyPhysicalPath = Environment.ExpandEnvironmentVariables(copyInfo["file"].Value <string>("physical_path")); Assert.True(copyPhysicalPath.Equals(Path.Combine(copyParent, copyName), StringComparison.OrdinalIgnoreCase)); var copyContent = File.ReadAllText(copyPhysicalPath); Assert.Equal(copyContent, testContent); } finally { if (webFile != null && webFile["file_info"] != null) { Assert.True(client.Delete(Utils.Self(webFile.Value <JObject>("file_info")))); } if (copyInfo != null) { Assert.True(client.Delete(Utils.Self(copyInfo.Value <JObject>("file")))); } } } }
public async Task AppPool() { using (HttpClient client = ApiHttpClient.Create()) { Sites.EnsureNoSite(client, SiteName); int port = Utils.GetAvailablePort(); JObject site = Sites.CreateSite(client, SiteName, port, SitePath); try { JObject appPool = client.Get(Utils.Self((JObject)site["application_pool"])); using (var stresser = new SiteStresser($"http://localhost:{port}")) using (var serverMonitor = new ServerMonitor(Utils.GetLink(appPool, "monitoring"))) { await Task.Delay(2000); JObject snapshot = serverMonitor.Current; _output.WriteLine("Validing monitoring data for application pool"); _output.WriteLine(snapshot.ToString(Formatting.Indented)); Assert.True(snapshot["requests"].Value <long>("total") > 0); Assert.True(snapshot["memory"].Value <long>("private_working_set") > 0); Assert.True(snapshot["memory"].Value <long>("system_in_use") > 0); Assert.True(snapshot["memory"].Value <long>("installed") > 0); Assert.True(snapshot["cpu"].Value <long>("threads") > 0); Assert.True(snapshot["cpu"].Value <long>("processes") > 0); int tries = 0; while (tries < 5) { snapshot = serverMonitor.Current; if (serverMonitor.Current["requests"].Value <long>("per_sec") > 0) { break; } await Task.Delay(1000); tries++; } _output.WriteLine("Validing monitoring data for application pool"); _output.WriteLine(snapshot.ToString(Formatting.Indented)); Assert.True(snapshot["requests"].Value <long>("per_sec") > 0); Assert.True(serverMonitor.ErrorCount == 0); } } finally { client.Delete(Utils.Self(site)); } } }
public void CopyDirectory() { string startName = "copy_dir_test"; string destName = "copy_dir_dest"; var physicalPath = Path.Combine(Configuration.TEST_ROOT_PATH, startName); var destPhysicalPath = Path.Combine(Configuration.TEST_ROOT_PATH, destName); CreateTestDirectory(physicalPath); JObject site = null; using (HttpClient client = ApiHttpClient.Create()) { Sites.EnsureNoSite(client, FILE_TEST_SITE_NAME); site = Sites.CreateSite(client, FILE_TEST_SITE_NAME, Utils.GetAvailablePort(), physicalPath); try { var rootDir = Utils.FollowLink(client, site, "files"); var rootDirFileInfo = Utils.FollowLink(client, rootDir.Value <JObject>("file_info"), "self"); object copy = new { name = destName, parent = rootDirFileInfo.Value <JObject>("parent"), file = rootDirFileInfo }; var copyInfo = client.Post(Utils.GetLink(rootDirFileInfo, "copy"), copy); // // Wait for copy to finish HttpResponseMessage res = null; do { res = client.GetAsync(Utils.Self(copyInfo)).Result; } while (res.StatusCode == HttpStatusCode.OK); // Don't add code between copy end and verification so we can make sure files aren't being held Assert.True(VerifyTestDirectory(physicalPath)); Assert.True(VerifyTestDirectory(destPhysicalPath)); } finally { if (site != null) { Sites.DeleteSite(client, Utils.Self(site)); } if (Directory.Exists(physicalPath)) { Directory.Delete(physicalPath, true); } if (Directory.Exists(destPhysicalPath)) { Directory.Delete(destPhysicalPath, true); } } } }
public static void ClearRules(HttpClient client, JObject feature) { string result; Assert.True(client.Get(Utils.GetLink(feature, "rules"), out result)); JArray rules = JsonConvert.DeserializeObject <JObject>(result).Value <JArray>("rules"); foreach (JObject r in rules) { Assert.True(client.Delete(Utils.Self(r))); } }
public void MoveDirectory() { string startName = "move_dir_test"; string destName = "move_dir_dest"; var physicalPath = Path.Combine(Configuration.TEST_ROOT_PATH, startName); var destPhysicalPath = Path.Combine(Configuration.TEST_ROOT_PATH, destName); CreateTestDirectory(physicalPath); JObject site = null; using (HttpClient client = ApiHttpClient.Create()) { Sites.EnsureNoSite(client, FILE_TEST_SITE_NAME); site = Sites.CreateSite(client, FILE_TEST_SITE_NAME, Utils.GetAvailablePort(), physicalPath); try { var rootDir = Utils.FollowLink(client, site, "files"); var rootDirFileInfo = Utils.FollowLink(client, rootDir.Value <JObject>("file_info"), "self"); object move = new { name = destName, parent = rootDirFileInfo.Value <JObject>("parent"), file = rootDirFileInfo }; var moveInfo = client.Post(Utils.GetLink(rootDirFileInfo, "move"), move); // Wait for move to finish HttpResponseMessage res = null; while (res == null || res.StatusCode == HttpStatusCode.OK) { res = client.GetAsync(Utils.Self(moveInfo)).Result; Thread.Sleep(25); } Assert.True(!Directory.Exists(physicalPath)); Assert.True(VerifyTestDirectory(destPhysicalPath)); } finally { if (site != null) { Sites.DeleteSite(client, Utils.Self(site)); } if (Directory.Exists(destPhysicalPath)) { Directory.Delete(destPhysicalPath, true); } } } }
public void CoreFileRange() { var physicalPath = Path.Combine(Configuration.TEST_ROOT_PATH, "api_file_range_test"); if (Directory.Exists(physicalPath)) { Directory.Delete(physicalPath, true); } using (HttpClient client = ApiHttpClient.Create()) { try { var dirs = new List <string>() { "dir1", "dir2", "dir3" }; var files = new List <string>() { "file1.txt", "file2.txt", "file3.txt" }; foreach (var dir in dirs) { Directory.CreateDirectory(Path.Combine(physicalPath, dir)); } foreach (var file in files) { File.Create(Path.Combine(physicalPath, file)).Dispose(); } JObject folder = client.Get($"{Configuration.TEST_SERVER_URL}/api/files?physical_path={physicalPath}"); HttpRequestMessage req = new HttpRequestMessage(HttpMethod.Get, Utils.GetLink(folder, "files")); req.Headers.Add("Range", "files=1-3"); var res = client.SendAsync(req).Result; Assert.True(res.Content.Headers.Contains("Content-Range")); Assert.True(res.Content.Headers.GetValues("Content-Range").First().Equals("1-3/6")); var children = JObject.Parse(res.Content.ReadAsStringAsync().Result)["files"].ToObject <IEnumerable <JObject> >(); Assert.True(children.Count() == 3); } finally { Directory.Delete(physicalPath, true); } } }
public void AddRemoveNativedModuleEntry() { using (HttpClient client = ApiHttpClient.Create()) { string name = "test_native_module"; JObject modulesFeature = GetModulesFeature(client, null, null); DeleteModule(client, modulesFeature, name); var globalModulePayload = new { name = name, // Use a module that exists with IIS installations because the dll must exist to create Global Module image = "%windir%\\System32\\inetsrv\\cachuri.dll", }; string result; Assert.True(client.Post(GLOBAL_MODULES_URL, JsonConvert.SerializeObject(globalModulePayload), out result)); JObject globalModule = JsonConvert.DeserializeObject <JObject>(result); modulesFeature = GetModulesFeature(client, null, null); string modulesLink = Utils.GetLink(modulesFeature, "entries"); var nativeModulePayload = new { name = globalModule.Value <string>("name"), // Type must be empty for native module type = "", modules = modulesFeature }; Assert.True(client.Post(modulesLink, JsonConvert.SerializeObject(nativeModulePayload), out result)); JObject nativeModule = JsonConvert.DeserializeObject <JObject>(result); // Make sure we can successfully retrieve the new modules Assert.True(client.Get(Utils.Self(nativeModule), out result)); Assert.True(client.Get(Utils.Self(globalModule), out result)); // Delete the native module in module entries Assert.True(client.Delete(Utils.Self(nativeModule))); // Delete the global module Assert.True(client.Delete(Utils.Self(globalModule))); } }
private bool Enable(string physicalPath, string username, string password, string privateKeyPassword) { dynamic ccsInfo = new { path = physicalPath, identity = new { username = username, password = password }, private_key_password = privateKeyPassword }; using (var client = ApiHttpClient.Create()) { JObject webserver = client.Get($"{Configuration.Instance().TEST_SERVER_URL}/api/webserver/"); string ccsLink = Utils.GetLink(webserver, "central_certificates"); return(client.Post(ccsLink, (object)ccsInfo) != null); } }
private JObject Create(HttpClient client, string linkName, ExpandoObject obj, JObject requestFilteringFeature = null) { if (requestFilteringFeature == null) { requestFilteringFeature = GetRequestFilteringFeature(client, null, null); } string link = Utils.GetLink(requestFilteringFeature, linkName); dynamic dynamicObj = obj; dynamicObj.request_filtering = requestFilteringFeature; string result; Assert.True(client.Post(link, JsonConvert.SerializeObject(obj), out result)); return(JsonConvert.DeserializeObject <JObject>(result)); }
public void AddRemoveRule() { 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); ClearRules(client, feature); var rulePayload = new { users = "test_u", roles = "test_r", verbs = "test_v", access_type = "deny", authorization = feature }; string result; Assert.True(client.Post(Utils.GetLink(feature, "rules"), JsonConvert.SerializeObject(rulePayload), out result)); JObject rule = JsonConvert.DeserializeObject <JObject>(result); var conflictingRule = new { users = "test_u", roles = "test_r", verbs = "test_v", access_type = "allow", authorization = feature }; HttpContent content = new StringContent(JsonConvert.SerializeObject(conflictingRule), Encoding.UTF8, "application/json"); var res = client.PostAsync(Utils.GetLink(feature, "rules"), content).Result; Assert.True(res.StatusCode == HttpStatusCode.Conflict); Assert.True(client.Delete(Utils.Self(rule))); Sites.EnsureNoSite(client, TEST_SITE_NAME); } }
public void AddRemoveManagedModuleEntry() { using (HttpClient client = ApiHttpClient.Create()) { JObject feature = GetModulesFeature(client, null, null); string modulesLink = Utils.GetLink(feature, "entries"); var testManagedModule = new { name = "test_managed_module", type = "test.managed.module", modules = feature }; string result; Assert.True(client.Post(modulesLink, JsonConvert.SerializeObject(testManagedModule), out result)); JObject managedModule = JsonConvert.DeserializeObject <JObject>(result); Assert.True(client.Get(Utils.Self(managedModule), out result)); Assert.True(client.Delete(Utils.Self(managedModule))); } }
public void CreateRemoveMimeMap() { using (HttpClient client = ApiHttpClient.Create()) { JObject feature = GetStaticContentFeature(client, null, null); string link = Utils.GetLink(feature, "mime_maps"); var mimeMapPayload = new { // Want to avoid collisions with any default file extensions file_extension = "tst9", mime_type = "test/test", static_content = feature }; string result; Assert.True(client.Post(link, JsonConvert.SerializeObject(mimeMapPayload), out result)); JObject mimeMap = JsonConvert.DeserializeObject <JObject>(result); Assert.True(client.Delete(Utils.Self(mimeMap))); Assert.False(client.Get(Utils.Self(mimeMap), out result)); } }
public void RangeUploadDownload() { using (HttpClient client = ApiHttpClient.Create()) { JObject site = Sites.GetSite(client, "Default Web Site"); // Create web file var webFile = CreateWebFile(client, site, TEST_FILE_NAME); try { // // Get physical file info var fileInfo = Utils.FollowLink(client, webFile.Value <JObject>("file_info"), "self"); var chunkSize = 1024 * 1024; var totalFileSize = 1024 * 1024 * 10; HttpRequestMessage req; HttpResponseMessage res; for (var i = 0; i < totalFileSize; i += chunkSize) { req = new HttpRequestMessage(HttpMethod.Put, Utils.GetLink(fileInfo, "content")); var currentChunkSize = totalFileSize - i < chunkSize ? totalFileSize - i : chunkSize; var slice = GetFileSlice(i, currentChunkSize); req.Content = new ByteArrayContent(slice); req.Content.Headers.Add("Content-Range", $"bytes {i}-{i + currentChunkSize - 1}/{totalFileSize}"); res = client.SendAsync(req).Result; Assert.True(Globals.Success(res)); } req = new HttpRequestMessage(HttpMethod.Get, Utils.GetLink(fileInfo, "content")); res = client.SendAsync(req).Result; Assert.True(Globals.Success(res)); var resultBytes = res.Content.ReadAsByteArrayAsync().Result; Assert.True(resultBytes.SequenceEqual(GetFileSlice(0, totalFileSize))); var download = new byte[totalFileSize]; // // Range download for (var i = 0; i < totalFileSize; i += chunkSize) { req = new HttpRequestMessage(HttpMethod.Get, Utils.GetLink(fileInfo, "content")); var currentChunkSize = totalFileSize - i < chunkSize ? totalFileSize - i : chunkSize; req.Headers.Add("Range", $"bytes={i}-{i + currentChunkSize - 1}"); res = client.SendAsync(req).Result; Assert.True(Globals.Success(res)); resultBytes = res.Content.ReadAsByteArrayAsync().Result; resultBytes.CopyTo(download, i); } Assert.True(download.SequenceEqual(GetFileSlice(0, totalFileSize))); } finally { Assert.True(client.Delete(Utils.Self(webFile.Value <JObject>("file_info")))); } } }
public async Task WebSite() { const string name = SiteName + "z"; using (HttpClient client = ApiHttpClient.Create()) { JObject pool = ApplicationPools.GetAppPool(client, name); if (pool == null) { pool = ApplicationPools.CreateAppPool(client, name); } JObject site = Sites.GetSite(client, name); if (site == null) { site = Sites.CreateSite(client, name, Utils.GetAvailablePort(), SitePath, true, pool); } int port = site["bindings"].ToObject <IEnumerable <JObject> >().First().Value <int>("port"); try { using (var stresser = new SiteStresser($"http://localhost:{port}")) using (var serverMonitor = new ServerMonitor(Utils.GetLink(site, "monitoring"))) { int tries = 0; JObject snapshot = null; while (tries < 15) { snapshot = serverMonitor.Current; if (snapshot != null && serverMonitor.Current["requests"].Value <long>("per_sec") > 0 && snapshot["network"].Value <long>("total_bytes_sent") > 0) { break; } await Task.Delay(1000); tries++; } Assert.True(snapshot["requests"].Value <long>("per_sec") > 0); Assert.True(snapshot["network"].Value <long>("total_bytes_sent") > 0); Assert.True(snapshot["network"].Value <long>("total_bytes_recv") > 0); Assert.True(snapshot["network"].Value <long>("total_connection_attempts") > 0); Assert.True(snapshot["requests"].Value <long>("total") > 0); Assert.True(snapshot["memory"].Value <long>("private_working_set") > 0); Assert.True(snapshot["memory"].Value <long>("system_in_use") > 0); Assert.True(snapshot["memory"].Value <long>("installed") > 0); Assert.True(snapshot["cpu"].Value <long>("threads") > 0); Assert.True(snapshot["cpu"].Value <long>("processes") > 0); Assert.True(serverMonitor.ErrorCount == 0); } } finally { client.Delete(Utils.Self(site)); client.Delete(Utils.Self(pool)); } } }
public void CreatePatchRemoveProvider() { var TEST_PROVIDER_NAME = "Test Provider"; var TEST_PROVIDER_GUID = Guid.NewGuid().ToString("B"); var TEST_AREAS = new string[] { "test_area", "test_area2" }; var PATCH_PROVIDER_NAME = "Patch Provider"; var PATCH_PROVIDER_GUID = Guid.NewGuid().ToString("B"); var PATCH_AREAS = new string[] { "patch_area", "patch_area2" }; using (var client = ApiHttpClient.Create()) { var feature = GetFeature(client, null, null); var providersObj = Utils.FollowLink(client, feature, "providers"); var providers = providersObj.Value <JArray>("providers").ToObject <IEnumerable <JObject> >(); foreach (var p in providers) { if (p.Value <string>("name").Equals(TEST_PROVIDER_NAME, StringComparison.OrdinalIgnoreCase) || p.Value <string>("name").Equals(PATCH_PROVIDER_NAME, StringComparison.OrdinalIgnoreCase)) { Assert.True(client.Delete(Utils.Self(p))); break; } } var testProvider = new { name = TEST_PROVIDER_NAME, guid = TEST_PROVIDER_GUID, areas = TEST_AREAS, request_tracing = feature }; var patchProvider = new { name = PATCH_PROVIDER_NAME, guid = PATCH_PROVIDER_GUID, areas = PATCH_AREAS }; var jProvider = JObject.FromObject(testProvider); var pProvider = JObject.FromObject(patchProvider); string result; Assert.True(client.Post(Utils.GetLink(feature, "providers"), JsonConvert.SerializeObject(testProvider), out result)); JObject newProvider = null; try { newProvider = Utils.ToJ(result); CompareProviders(jProvider, newProvider); Assert.True(client.Patch(Utils.Self(newProvider), JsonConvert.SerializeObject(patchProvider), out result)); newProvider = Utils.ToJ(result); CompareProviders(pProvider, newProvider); } finally { Assert.True(client.Delete(Utils.Self(newProvider))); } } }
public void CreatePatchRemoveRule() { var TEST_RULE_PATH = "test_rule*.path"; var TEST_RULE_STATUS_CODES = new string[] { "101", "244-245", "280-301", "340" }; var TEST_RULE_MIN_TIME = 100; var TEST_RULE_EVENT_SEVERITY = "error"; var TEST_RULE_PROVIDER_NAME = "ASP"; var TEST_RULE_ALLOWED_AREAS = new Dictionary <string, bool>() { }; var PATCH_PATH = "test_patch*.path"; var PATCH_RULE_STATUS_CODES = new string[] { "104-181", "333" }; var PATCH_RULE_MIN_TIME = 103; var PATCH_RULE_EVENT_SEVERITY = "criticalerror"; var PATCH_RULE_PROVIDER_NAME = "WWW Server"; var PATCH_RULE_ALLOWED_AREAS = new Dictionary <string, bool>() { { "Security", true }, { "Compression", true }, { "Module", true } }; using (var client = ApiHttpClient.Create()) { var feature = GetFeature(client, null, null); var rulesObj = Utils.FollowLink(client, feature, "rules"); var rules = rulesObj.Value <JArray>("rules").ToObject <IEnumerable <JObject> >(); var providersObj = Utils.FollowLink(client, feature, "providers"); var providers = providersObj.Value <JArray>("providers").ToObject <IEnumerable <JObject> >(); // Ensure rule with test path doesn't already exist foreach (var r in rules) { if (r.Value <string>("path").Equals(TEST_RULE_PATH, StringComparison.OrdinalIgnoreCase) || r.Value <string>("path").Equals(PATCH_PATH, StringComparison.OrdinalIgnoreCase)) { Assert.True(client.Delete(Utils.Self(r))); break; } } var testRule = new { path = TEST_RULE_PATH, status_codes = TEST_RULE_STATUS_CODES, min_request_execution_time = TEST_RULE_MIN_TIME, event_severity = TEST_RULE_EVENT_SEVERITY, traces = new [] { new { allowed_areas = TEST_RULE_ALLOWED_AREAS, provider = providers.FirstOrDefault(p => p.Value <string>("name").Equals(TEST_RULE_PROVIDER_NAME)), verbosity = "verbose" } }, request_tracing = feature }; var patchRule = new { path = PATCH_PATH, status_codes = PATCH_RULE_STATUS_CODES, min_request_execution_time = PATCH_RULE_MIN_TIME, event_severity = PATCH_RULE_EVENT_SEVERITY, traces = new[] { new { allowed_areas = PATCH_RULE_ALLOWED_AREAS, provider = providers.FirstOrDefault(p => p.Value <string>("name").Equals(PATCH_RULE_PROVIDER_NAME)), verbosity = "verbose" } }, }; var jRule = JObject.FromObject(testRule); var pRule = JObject.FromObject(patchRule); string result; Assert.True(client.Post(Utils.GetLink(feature, "rules"), JsonConvert.SerializeObject(testRule), out result)); JObject newRule = null; try { newRule = Utils.ToJ(result); CompareRules(jRule, newRule); Assert.True(client.Patch(Utils.Self(newRule), JsonConvert.SerializeObject(patchRule), out result)); newRule = Utils.ToJ(result); CompareRules(pRule, newRule); } finally { Assert.True(client.Delete(Utils.Self(newRule))); } } }
private JObject CreateHandlerForFeature(HttpClient client, JObject feature, JObject handler) { handler.Add("handler", feature); return(client.Post(Utils.GetLink(feature, "entries"), handler)); }