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); } } }
//[Theory] //[InlineData("/api/webserver/default-documents")] //[InlineData("/api/webserver/http-request-tracing")] //[InlineData("/api/webserver/authentication/basic-authentication")] //[InlineData("/api/webserver/authentication/digest-authentication")] //[InlineData("/api/webserver/authentication/windows-authentication")] //[InlineData("/api/webserver/authorization")] //[InlineData("/api/webserver/ip-restrictions")] //[InlineData("/api/webserver/logging")] //[InlineData("/api/webserver/http-request-tracing")] //[InlineData("/api/webserver/http-response-compression")] //[InlineData("/api/webserver/directory-browsing")] //[InlineData("/api/webserver/static-content")] //[InlineData("/api/webserver/http-request-filtering")] //[InlineData("/api/webserver/http-redirect")] public void InstallUninstallFeature(string feature) { _logger.WriteLine("Testing installation/uninstallation of " + feature); using (HttpClient client = ApiHttpClient.Create()) { string result; bool installed = IsInstalled(feature, client); _logger.WriteLine("Feature is initially " + (installed ? "installed" : "uninstalled")); if (!installed) { _logger.WriteLine("Installing " + feature); Assert.True(client.Post(Configuration.Instance().TEST_SERVER_URL + feature, "", out result)); Assert.True(IsInstalled(feature, client)); } _logger.WriteLine("retrieving settings for " + feature); var settings = client.Get(Configuration.Instance().TEST_SERVER_URL + feature + "?scope="); _logger.WriteLine("Uninstalling " + feature); Assert.True(client.Delete(Utils.Self(settings))); Assert.True(!IsInstalled(feature, client)); if (installed) { _logger.WriteLine("Reinstalling " + feature); Assert.True(client.Post(Configuration.Instance().TEST_SERVER_URL + feature, "", out result)); Assert.True(IsInstalled(feature, client)); } } }
public void CreateRenameDirectory() { using (HttpClient client = ApiHttpClient.Create()) using (TestSiteContainer container = new TestSiteContainer(client)) { JObject site = Sites.GetSite(client, container.SiteName); JObject target = null; string updatedName = "updated_test_folder_name"; try { var webFile = CreateWebFile(client, site, TEST_FILE_NAME, "directory"); var physicalPath = Path.Combine(Environment.ExpandEnvironmentVariables(site.Value <string>("physical_path")), updatedName); if (Directory.Exists(physicalPath)) { Directory.Delete(physicalPath); } target = RenameSitesFile(client, site, webFile, updatedName); } finally { Assert.True(client.Delete(Utils.Self(target.Value <JObject>("file_info")))); } } }
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 ChangeAllFeatureProperties() { using (HttpClient client = ApiHttpClient.Create()) { var webserverFeature = Utils.GetFeature(client, HANDLERS_URL, null, null); Assert.NotNull(webserverFeature); AllowOverride(client, webserverFeature); TestScopedFeature(client, webserverFeature); Sites.EnsureNoSite(client, TEST_SITE_NAME); var site = Sites.CreateSite(client, TEST_SITE_NAME, Utils.GetAvailablePort(), Sites.TEST_SITE_PATH); Assert.NotNull(site); try { var siteFeature = Utils.GetFeature(client, HANDLERS_URL, site.Value <string>("name"), "/"); Assert.NotNull(siteFeature); AllowOverride(client, siteFeature); TestScopedFeature(client, siteFeature); client.Delete(Utils.Self(siteFeature)); } finally { Sites.EnsureNoSite(client, site.Value <string>("name")); } } }
public void Scope() { using (HttpClient client = ApiHttpClient.Create()) { Sites.EnsureNoSite(client, TEST_SITE_NAME); JObject site = Sites.CreateSite(client, TEST_SITE_NAME, 50311, Sites.TEST_SITE_PATH); JObject serverDoc = GetDefaultDocumentFeature(client, null, null); JObject siteDoc = GetDefaultDocumentFeature(client, site.Value <string>("name"), null); bool prevServerState = serverDoc.Value <bool>("enabled"); bool testServerState = true; bool testSiteState = false; // Server level configuration change Assert.True(SetEnabled(client, serverDoc, testServerState, out serverDoc)); // Site level configuration change Assert.True(SetEnabled(client, siteDoc, testSiteState, out siteDoc)); // Make sure site change didn't affect server level serverDoc = GetDefaultDocumentFeature(client, null, null); Assert.True(serverDoc.Value <bool>("enabled") == testServerState); Assert.True(Sites.DeleteSite(client, Utils.Self(site))); Assert.True(SetEnabled(client, serverDoc, prevServerState, out serverDoc)); } }
public void CreateAndCleanup() { bool pass = false; using (HttpClient client = ApiHttpClient.Create()) { JObject site = null; Sites.EnsureNoSite(client, TEST_APPLICATION_SITE_NAME); site = Sites.CreateSite(_output, client, TEST_APPLICATION_SITE_NAME, 50307, Sites.TEST_SITE_PATH); if (site != null) { JObject testApp = CreateApplication(client, "/test_application", TEST_APPLICATION_PHYSICAL_PATH, site); if (testApp != null) { string testAppUri = Utils.Self(testApp); pass = TestApplicationExists(client, testAppUri); Assert.True(DeleteApplication(client, testAppUri)); } Assert.True(Sites.DeleteSite(client, $"{Sites.SITE_URL}/{site.Value<string>("id")}")); } Assert.True(pass); } }
public void CreateAndCleanup() { bool pass = false; using (HttpClient client = ApiHttpClient.Create()) { _output.WriteLine($"Running Application tests with application {TEST_APPLICATION}"); JObject site; Sites.EnsureNoSite(client, TEST_APPLICATION_SITE_NAME); if (Sites.CreateSite(client, TEST_APPLICATION_SITE, out site)) { // Set up the application json with the newly created site uuid string testApplication = TEST_APPLICATION.Replace("{site_id}", site.Value <string>("id")); JObject testApp; if (CreateApplication(client, testApplication, out testApp)) { string testAppUri = Utils.Self(testApp); pass = TestApplicationExists(client, testAppUri); Assert.True(DeleteApplication(client, testAppUri)); } Assert.True(Sites.DeleteSite(client, $"{Sites.SITE_URL}/{site.Value<string>("id")}")); } Assert.True(pass); } }
public void TruncateOnCompleteRange() { var size = 1024 * 1024 * 5; var truncateSize = size / 2; using (HttpClient client = ApiHttpClient.Create()) { JObject site = Sites.GetSite(client, "Default Web Site"); var webFile = CreateWebFile(client, site, TEST_FILE_NAME); var fileInfo = Utils.FollowLink(client, webFile.Value <JObject>("file_info"), "self"); try { Assert.True(MockUploadFile(client, fileInfo, size).Result); fileInfo = Utils.FollowLink(client, fileInfo, "self"); Assert.True(fileInfo.Value <int>("size") == size); Assert.True(MockUploadFile(client, fileInfo, truncateSize).Result); fileInfo = Utils.FollowLink(client, fileInfo, "self"); Assert.True(fileInfo.Value <int>("size") == truncateSize); } finally { if (webFile != null) { Assert.True(client.Delete(Utils.Self(webFile.Value <JObject>("file_info")))); } } } }
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 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")))); } } }
private JObject GetCcs() { using (var client = ApiHttpClient.Create()) { JObject webserver = client.Get($"{Configuration.Instance().TEST_SERVER_URL}/api/webserver/"); return(Utils.FollowLink(client, webserver, "central_certificates")); } }
private IEnumerable <JObject> GetCertificates() { using (var client = ApiHttpClient.Create()) { JObject containingObject = client.Get(CERTIFICATES_API_PATH + "?fields=*"); return(containingObject["certificates"].ToObject <IEnumerable <JObject> >()); } }
public void CreateAndCleanup() { bool pass = false; using (HttpClient client = ApiHttpClient.Create()) { Sites.EnsureNoSite(client, TEST_SITE_NAME); JObject site = Sites.CreateSite(client, TEST_SITE_NAME, 50308, Sites.TEST_SITE_PATH); if (site != null) { JObject testApp = Applications.CreateApplication(client, "/test_vdir_application", Applications.TEST_APPLICATION_PHYSICAL_PATH, site); if (testApp != null) { JObject vdir = CreateVdir(client, TEST_VDIR_PATH, TEST_VDIR_PHYSICAL_PATH, testApp, false); if (vdir != null) { string vdirUri = Utils.Self(vdir); pass = VdirExists(client, vdirUri); Assert.True(DeleteVdir(client, vdirUri)); } Assert.True(Applications.DeleteApplication(client, Utils.Self(testApp))); } Assert.True(Sites.DeleteSite(client, Utils.Self(site))); } Assert.True(pass); } }
public void CreateWithKey(int key) { using (HttpClient client = ApiHttpClient.Create()) { EnsureNoSite(client, TEST_SITE_NAME); var siteData = new { name = TEST_SITE_NAME, physical_path = TEST_SITE_PATH, key = key, bindings = new object[] { new { ip_address = "*", port = TEST_PORT, protocol = "http" } } }; JObject site = client.Post(SITE_URL, siteData); Assert.NotNull(site); Assert.Equal(key, site.Value <int>("key")); Assert.True(client.Delete(Utils.Self(site))); } }
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))); } }
private IEnumerable <JObject> GetStores() { using (var client = ApiHttpClient.Create()) { JObject containingObject = client.Get(STORES_API_PATH); return(containingObject["stores"].ToObject <IEnumerable <JObject> >()); } }
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 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 WebServer() { using (HttpClient client = ApiHttpClient.Create()) { Sites.EnsureNoSite(client, SiteName); int port = Utils.GetAvailablePort(); JObject site = Sites.CreateSite(client, SiteName, port, SitePath); try { using (var stresser = new SiteStresser($"http://localhost:{port}")) using (var serverMonitor = new ServerMonitor()) { int tries = 0; JObject snapshot = null; while (tries < 10) { snapshot = serverMonitor.Current; _output.WriteLine("Waiting for webserver to track requests per sec and processes"); _output.WriteLine(snapshot == null ? "Snapshot is null" : snapshot.ToString(Formatting.Indented)); if (snapshot != null && snapshot["requests"].Value <long>("per_sec") > 0 && snapshot["cpu"].Value <long>("threads") > 0) { break; } await Task.Delay(1000); tries++; } _output.WriteLine("Validating webserver monitoring data"); _output.WriteLine(snapshot.ToString(Formatting.Indented)); 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(snapshot["cpu"].Value <long>("percent_usage") >= 0); Assert.True(snapshot["cpu"].Value <long>("system_percent_usage") >= 0); Assert.True(serverMonitor.ErrorCount == 0); } } finally { client.Delete(Utils.Self(site)); } } }
public async Task CanCreateCcsBinding() { RequireCcsTestInfrastructure(); CcsUser user = await CcsUser.Get(); Assert.True(Enable(FOLDER_PATH, user.Username, user.Password, PVK_PASS)); JObject site; const string siteName = "CcsBindingTestSite"; using (var client = ApiHttpClient.Create()) { Sites.EnsureNoSite(client, siteName); site = Sites.CreateSite(_output, client, siteName, Utils.GetAvailablePort(), Sites.TEST_SITE_PATH); Assert.NotNull(site); try { JObject cert = GetCertificates().FirstOrDefault(c => { return(c.Value <string>("alias").Equals(CERT_NAME + ".pfx") && c.Value <JObject>("store").Value <string>("name").Equals(NAME, StringComparison.OrdinalIgnoreCase)); }); Assert.NotNull(cert); site["bindings"] = JToken.FromObject(new object[] { new { port = 443, protocol = "https", ip_address = "*", hostname = CERT_NAME, certificate = cert, require_sni = true } }); site = client.Patch(Utils.Self(site), site); Assert.NotNull(site); string index = Path.Combine(site.Value <string>("physical_path"), "index.html"); if (!File.Exists(index)) { File.WriteAllText(index, $"<h1>{siteName}</h1>"); } site = client.Get(Utils.Self(site)); JObject binding = site["bindings"].ToObject <IEnumerable <JObject> >().First(); Assert.NotNull(binding["certificate"]); Assert.True(binding.Value <bool>("require_sni")); JObject certificate = client.Get(Utils.Self(binding.Value <JObject>("certificate"))); Assert.NotNull(certificate); Assert.True(certificate["store"].Value <string>("name").Equals(NAME)); } finally { Sites.EnsureNoSite(client, siteName); } } }
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 void CreateRemoveHiddenSegment() { using (HttpClient client = ApiHttpClient.Create()) { dynamic hiddenSegment = new ExpandoObject(); hiddenSegment.segment = "test_h_segment"; CreateCheckConflictRemove(client, "hidden_segments", hiddenSegment); } }
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)); } }
public void CreateCheckConflictRemoveQueryString() { using (HttpClient client = ApiHttpClient.Create()) { dynamic queryString = new ExpandoObject(); queryString.query_string = "test_q_string"; queryString.allow = false; CreateCheckConflictRemove(client, "query_strings", queryString); } }
public void CreateCheckConflictRemoveUrl() { using (HttpClient client = ApiHttpClient.Create()) { dynamic url = new ExpandoObject(); url.url = "test_url"; url.allow = false; CreateCheckConflictRemove(client, "urls", url); } }
public void GetSites(int n) { using (HttpClient client = ApiHttpClient.Create()) { string result; for (int i = 0; i < n; i++) { Assert.True(client.Get(SITE_URL, out result)); } } }