public async Task WebsocketBasic(HostType hostType) { using (ApplicationDeployer deployer = new ApplicationDeployer()) { string applicationUrl = deployer.Deploy(hostType, WebsocketBasicConfiguration); using (var client = new ClientWebSocket()) { await client.ConnectAsync(new Uri(applicationUrl.Replace("http://", "ws://")), CancellationToken.None); var receiveBody = new byte[100]; for (int i = 0; i < 4; i++) { var message = "Message " + i.ToString(); byte[] sendBody = Encoding.UTF8.GetBytes(message); await client.SendAsync(new ArraySegment<byte>(sendBody), WebSocketMessageType.Text, true, CancellationToken.None); var receiveResult = await client.ReceiveAsync(new ArraySegment<byte>(receiveBody), CancellationToken.None); Assert.Equal(WebSocketMessageType.Text, receiveResult.MessageType); Assert.True(receiveResult.EndOfMessage); Assert.Equal(sendBody.Length, receiveResult.Count); Assert.Equal(message, Encoding.UTF8.GetString(receiveBody, 0, receiveResult.Count)); } } } }
public void Static_EmbeddedFileSystem(HostType hostType) { using (ApplicationDeployer deployer = new ApplicationDeployer()) { var applicationUrl = deployer.Deploy(hostType, EmbeddedFileSystemConfiguration); var httpClient = new HttpClient() { BaseAddress = new Uri(applicationUrl) }; DownloadAndCompareFiles(httpClient, "RequirementFiles.EmbeddedResources.SampleAVI.avi", "video/x-msvideo"); DownloadAndCompareFiles(httpClient, "RequirementFiles.EmbeddedResources.SampleC.c", "text/plain"); DownloadAndCompareFiles(httpClient, "RequirementFiles.EmbeddedResources.SampleCHM.CHM", "application/octet-stream"); DownloadAndCompareFiles(httpClient, "RequirementFiles.EmbeddedResources.SampleCPP.cpp", "text/plain"); DownloadAndCompareFiles(httpClient, "RequirementFiles.EmbeddedResources.SampleCSS.css", "text/css"); DownloadAndCompareFiles(httpClient, "RequirementFiles.EmbeddedResources.SampleCSV.csv", "application/octet-stream"); DownloadAndCompareFiles(httpClient, "RequirementFiles.EmbeddedResources.SampleCUR.cur", "application/octet-stream"); DownloadAndCompareFiles(httpClient, "RequirementFiles.EmbeddedResources.SampleDISCO.disco", "text/xml"); DownloadAndCompareFiles(httpClient, "RequirementFiles.EmbeddedResources.SampleDOC.DOC", "application/msword"); DownloadAndCompareFiles(httpClient, "RequirementFiles.EmbeddedResources.SampleDOCX.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"); DownloadAndCompareFiles(httpClient, "RequirementFiles.EmbeddedResources.SampleHTM.htm", "text/html"); DownloadAndCompareFiles(httpClient, "RequirementFiles.EmbeddedResources.SampleHTML.html", "text/html"); DownloadAndCompareFiles(httpClient, "RequirementFiles.EmbeddedResources.SampleICO.ico", "image/x-icon"); DownloadAndCompareFiles(httpClient, "RequirementFiles.EmbeddedResources.SampleJPEG.jpg", "image/jpeg"); DownloadAndCompareFiles(httpClient, "RequirementFiles.EmbeddedResources.SampleJPG.jpg", "image/jpeg"); DownloadAndCompareFiles(httpClient, "RequirementFiles.EmbeddedResources.SamplePNG.png", "image/png"); //Unknown MIME types should not be served by default var response = httpClient.GetAsync("RequirementFiles.EmbeddedResources.Unknown.Unknown").Result; Assert.Equal<HttpStatusCode>(HttpStatusCode.NotFound, response.StatusCode); } }
public void OwinCallCancelled(HostType hostType) { using (ApplicationDeployer deployer = new ApplicationDeployer()) { var serverInstance = new NotificationServer(); serverInstance.StartNotificationService(); string applicationUrl = deployer.Deploy(hostType, Configuration); try { Trace.WriteLine(string.Format("Making a request to url : ", applicationUrl)); HttpClient httpClient = new HttpClient(); Task<HttpResponseMessage> response = httpClient.GetAsync(applicationUrl); response.Wait(1 * 1000); httpClient.CancelPendingRequests(); bool receivedNotification = serverInstance.NotificationReceived.WaitOne(20 * 1000); Assert.True(receivedNotification, "CallCancelled CancellationToken was not issued on cancelling the call"); } finally { serverInstance.Dispose(); } } }
public void Static_ValidIfModifiedSince(HostType hostType) { using (ApplicationDeployer deployer = new ApplicationDeployer()) { var applicationUrl = deployer.Deploy(hostType, ValidModifiedSinceConfiguration); var httpClient = new HttpClient() { BaseAddress = new Uri(applicationUrl) }; var fileContent = File.ReadAllBytes(@"RequirementFiles/Dir1/RangeRequest.txt"); var response = httpClient.GetAsync(@"RequirementFiles/Dir1/RangeRequest.txt").Result; Assert.Equal<HttpStatusCode>(HttpStatusCode.OK, response.StatusCode); //Modified since = lastmodified. Expect a 304 httpClient.DefaultRequestHeaders.IfModifiedSince = response.Content.Headers.LastModified; response = httpClient.GetAsync(@"RequirementFiles/Dir1/RangeRequest.txt").Result; Assert.Equal<HttpStatusCode>(HttpStatusCode.NotModified, response.StatusCode); //Modified since > lastmodified. Expect a 304 httpClient.DefaultRequestHeaders.IfModifiedSince = response.Content.Headers.LastModified.Value.AddMinutes(12); response = httpClient.GetAsync(@"RequirementFiles/Dir1/RangeRequest.txt").Result; Assert.Equal<HttpStatusCode>(HttpStatusCode.NotModified, response.StatusCode); //Modified since < lastmodified. Expect an OK. httpClient.DefaultRequestHeaders.IfModifiedSince = response.Content.Headers.LastModified.Value.Subtract(new TimeSpan(10 * 1000)); response = httpClient.GetAsync(@"RequirementFiles/Dir1/RangeRequest.txt").Result; Assert.Equal<HttpStatusCode>(HttpStatusCode.OK, response.StatusCode); CompareBytes(fileContent, response.Content.ReadAsByteArrayAsync().Result, 0, fileContent.Length - 1); //Modified since is an invalid date string. Expect an OK. httpClient.DefaultRequestHeaders.TryAddWithoutValidation("If-Modified-Since", "InvalidDate"); response = httpClient.GetAsync(@"RequirementFiles/Dir1/RangeRequest.txt").Result; Assert.Equal<HttpStatusCode>(HttpStatusCode.OK, response.StatusCode); } }
public void ExplicitlyRegisterOwinHttpHandler() { using (ApplicationDeployer deployer = new ApplicationDeployer()) { deployer.AutomaticAppStartupInWebHost = false; string url = deployer.Deploy(HostType.IIS); var webConfigPath = deployer.GetWebConfigPath(); var addHandler = "<system.webServer>" + "<handlers>" + "<add name=\"Owin\" verb=\"*\" type=\"Microsoft.Owin.Host.SystemWeb.OwinHttpHandler, Microsoft.Owin.Host.SystemWeb\" path=\"*\" />" + "</handlers>" + "</system.webServer>"; var configuration = new XmlDocument() { InnerXml = File.ReadAllText(webConfigPath) }; var configurationNode = configuration.SelectSingleNode("/configuration"); configurationNode.InnerXml += addHandler; File.WriteAllText(webConfigPath, configuration.InnerXml); ((WebDeployer)deployer.Application).Application.Deploy("Default.aspx", File.ReadAllText("RequirementFiles\\Default.aspx")); Assert.Equal(Startup.RESULT, HttpClientUtility.GetResponseTextFromUrl(url + "/Default.aspx")); Assert.Equal(Startup.RESULT, HttpClientUtility.GetResponseTextFromUrl(url)); } }
public void Static_DirectoryBrowserDefaults(HostType hostType) { using (ApplicationDeployer deployer = new ApplicationDeployer()) { string applicationUrl = deployer.Deploy(hostType, DirectoryBrowserDefaultsConfiguration); HttpResponseMessage response = null; //1. Check directory browsing enabled at application level var responseText = HttpClientUtility.GetResponseTextFromUrl(applicationUrl, out response); Assert.True(!string.IsNullOrWhiteSpace(responseText), "Received empty response"); Assert.True((response.Content).Headers.ContentType.ToString() == "text/html; charset=utf-8"); Assert.True(responseText.Contains("RequirementFiles/")); //2. Check directory browsing @RequirementFiles with a ending '/' responseText = HttpClientUtility.GetResponseTextFromUrl(applicationUrl + "RequirementFiles/", out response); Assert.True(!string.IsNullOrWhiteSpace(responseText), "Received empty response"); Assert.True((response.Content).Headers.ContentType.ToString() == "text/html; charset=utf-8"); Assert.True(responseText.Contains("Dir1/") && responseText.Contains("Dir2/") && responseText.Contains("Dir3/"), "Directories Dir1, Dir2, Dir3 not found"); //2. Check directory browsing @RequirementFiles with request path not ending '/' responseText = HttpClientUtility.GetResponseTextFromUrl(applicationUrl + "RequirementFiles", out response); Assert.True(!string.IsNullOrWhiteSpace(responseText), "Received empty response"); Assert.True((response.Content).Headers.ContentType.ToString() == "text/html; charset=utf-8"); Assert.True(responseText.Contains("Dir1/") && responseText.Contains("Dir2/") && responseText.Contains("Dir3/"), "Directories Dir1, Dir2, Dir3 not found"); } }
public void ApplicationPoolStop(HostType hostType) { var serverInstance = new NotificationServer(); serverInstance.StartNotificationService(); try { using (ApplicationDeployer deployer = new ApplicationDeployer()) { string applicationUrl = deployer.Deploy(hostType, Configuration); Assert.True(HttpClientUtility.GetResponseTextFromUrl(applicationUrl) == "SUCCESS"); if (hostType == HostType.IIS) { string webConfig = deployer.GetWebConfigPath(); string webConfigContent = File.ReadAllText(webConfig); File.WriteAllText(webConfig, webConfigContent); } } bool receivedNotification = serverInstance.NotificationReceived.WaitOne(20 * 1000); Assert.True(receivedNotification, "Cancellation token was not issued on closing host"); } finally { serverInstance.Dispose(); } }
public void ReadAppSettings() { using (ApplicationDeployer deployer = new ApplicationDeployer()) { var applicationUrl = deployer.Deploy(HostType.IIS, Configuration); var vDirPath = Path.GetDirectoryName(deployer.GetWebConfigPath()); var options = new MyStartOptions(true) { DontPassStartupClassInCommandLine = true, TargetApplicationDirectory = vDirPath }; string webConfigPath = deployer.GetWebConfigPath(); XmlDocument configuration = new XmlDocument() { InnerXml = File.ReadAllText(webConfigPath) }; var appSettingsNode = configuration.SelectSingleNode("/configuration/appSettings"); appSettingsNode.InnerXml += "<add key=\"traceoutput\" value=\"MyLogTextThroughAppSetting.txt\" />"; File.WriteAllText(webConfigPath, configuration.InnerXml); using (new HostServer(options)) { var httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Add("outputFile", "Test logging"); string response = httpClient.GetAsync("http://localhost:5000/").Result.Content.ReadAsStringAsync().Result; Assert.Equal("SUCCESS", response); Assert.True(File.Exists("MyLogTextThroughAppSetting.txt"), "Log file MyLogTextThroughAppSetting.txt is not created on specifying through appSetting"); } } }
public void Security_ReturnUrlAndSecureCookie(HostType hostType) { using (ApplicationDeployer deployer = new ApplicationDeployer()) { string applicationUrl = deployer.Deploy(hostType, ReturnUrlAndSecureCookieConfiguration); string secureServerUri = new UriBuilder(applicationUrl) { Scheme = Uri.UriSchemeHttps }.Uri.AbsoluteUri; HttpClientHandler handler = new HttpClientHandler(); HttpClient httpClient = new HttpClient(handler); // Unauthenticated request - verify Redirect url HttpResponseMessage response = httpClient.GetAsync(applicationUrl).Result; CookiesCommon.IsRedirectedToCookiesLogin(response.RequestMessage.RequestUri, applicationUrl, "Unauthenticated requests not automatically redirected to login page", "MyRedirectUrl"); var validCookieCredentials = new FormUrlEncodedContent(new kvp[] { new kvp("username", "test"), new kvp("password", "test") }); response = httpClient.PostAsync(response.RequestMessage.RequestUri, validCookieCredentials).Result; response.EnsureSuccessStatusCode(); //Verify cookie sent Assert.False(handler.CookieContainer.Count != 1, "Forms auth cookie not received automatically after successful login"); Cookie loginCookie = handler.CookieContainer.GetCookies(new Uri(secureServerUri))[0]; Assert.Equal(loginCookie.Secure, true); } }
public void InstanceContext(HostType hostType) { using (ApplicationDeployer deployer = new ApplicationDeployer()) { string applicationUrl = deployer.Deploy<InstanceContextStartup>(hostType); string[] urls = new string[] { applicationUrl, applicationUrl + "/one", applicationUrl + "/two" }; bool failed = false; foreach (string url in urls) { string previousResponse = null; for (int count = 0; count < 3; count++) { string currentResponse = HttpClientUtility.GetResponseTextFromUrl(url); if (!currentResponse.Contains("SUCCESS") || (previousResponse != null && currentResponse != previousResponse)) { failed = true; } previousResponse = currentResponse; } } Assert.True(!failed, "At least one of the instance contexts is not correct"); } }
public void Static_ContentTypes(HostType hostType) { using (ApplicationDeployer deployer = new ApplicationDeployer()) { var applicationUrl = deployer.Deploy(hostType, ContentTypesConfiguration); var httpClient = new HttpClient() { BaseAddress = new Uri(applicationUrl) }; DownloadAndCompareFiles(httpClient, @"RequirementFiles\ContentTypes\SampleAVI.avi", "video/x-msvideo"); DownloadAndCompareFiles(httpClient, @"RequirementFiles\ContentTypes\SampleC.c", "text/plain"); DownloadAndCompareFiles(httpClient, @"RequirementFiles\ContentTypes\SampleCHM.chm", "application/octet-stream"); DownloadAndCompareFiles(httpClient, @"RequirementFiles\ContentTypes\SampleCpp.cpp", "text/plain"); DownloadAndCompareFiles(httpClient, @"RequirementFiles\ContentTypes\SampleCss.CSS", "text/css"); DownloadAndCompareFiles(httpClient, @"RequirementFiles\ContentTypes\SampleCSV.csV", "application/octet-stream"); DownloadAndCompareFiles(httpClient, @"RequirementFiles\ContentTypes\SampleCUR.cur", "application/octet-stream"); DownloadAndCompareFiles(httpClient, @"RequirementFiles\ContentTypes\SampleDisco.disco", "text/xml"); DownloadAndCompareFiles(httpClient, @"RequirementFiles\ContentTypes\Sampledoc.doc", "application/msword"); DownloadAndCompareFiles(httpClient, @"RequirementFiles\ContentTypes\Sampledocx.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"); DownloadAndCompareFiles(httpClient, @"RequirementFiles\ContentTypes\SampleHTM.htm", "text/html"); DownloadAndCompareFiles(httpClient, @"RequirementFiles\ContentTypes\Samplehtml.html", "text/html"); DownloadAndCompareFiles(httpClient, @"RequirementFiles\ContentTypes\Sampleico.ico", "image/x-icon"); DownloadAndCompareFiles(httpClient, @"RequirementFiles\ContentTypes\SampleJPEG.jpg", "image/jpeg"); DownloadAndCompareFiles(httpClient, @"RequirementFiles\ContentTypes\SampleJPG.jpg", "image/jpeg"); DownloadAndCompareFiles(httpClient, @"RequirementFiles\ContentTypes\SamplePNG.png", "image/png"); DownloadAndCompareFiles(httpClient, @"RequirementFiles\Dir1\EmptyFile.txt", "text/plain"); //Unknown MIME types should not be served by default var response = httpClient.GetAsync(@"RequirementFiles\ContentTypes\Unknown.Unknown").Result; Assert.Equal<HttpStatusCode>(HttpStatusCode.NotFound, response.StatusCode); } }
public void ConvertibleMiddlewareTest(HostType hostType) { using (ApplicationDeployer deployer = new ApplicationDeployer()) { string applicationUrl = deployer.Deploy<ConvertibleMiddleWarePatternStartup>(hostType); Assert.Equal("SUCCESS", HttpClientUtility.GetResponseTextFromUrl(applicationUrl)); } }
public void ConvertibleMiddlewareTest(HostType hostType) { using (ApplicationDeployer deployer = new ApplicationDeployer()) { string applicationUrl = deployer.Deploy <ConvertibleMiddleWarePatternStartup>(hostType); Assert.Equal("SUCCESS", HttpClientUtility.GetResponseTextFromUrl(applicationUrl)); } }
public void AllowedConfigurationSignature2(HostType hostType) { using (ApplicationDeployer deployer = new ApplicationDeployer()) { string applicationUrl = deployer.Deploy<AllowedNonDefaultConfigurationSignatures2>(hostType); Assert.Equal("SUCCESS", HttpClientUtility.GetResponseTextFromUrl(applicationUrl)); } }
public void InstanceBasedMiddlewareTest(HostType hostType) { using (ApplicationDeployer deployer = new ApplicationDeployer()) { string applicationUrl = deployer.Deploy(hostType, Configuration); Assert.Equal("SUCCESS", HttpClientUtility.GetResponseTextFromUrl(applicationUrl)); } }
public void AllowedConfigurationSignature2(HostType hostType) { using (ApplicationDeployer deployer = new ApplicationDeployer()) { string applicationUrl = deployer.Deploy <AllowedNonDefaultConfigurationSignatures2>(hostType); Assert.Equal("SUCCESS", HttpClientUtility.GetResponseTextFromUrl(applicationUrl)); } }
public void InstanceBasedMiddlewareTest(HostType hostType) { using (ApplicationDeployer deployer = new ApplicationDeployer()) { string applicationUrl = deployer.Deploy(hostType, Configuration); Assert.Equal("SUCCESS", HttpClientUtility.GetResponseTextFromUrl(applicationUrl)); } }
public void DefaultDiscoveryTest(HostType hostType) { using (ApplicationDeployer deployer = new ApplicationDeployer()) { string applicationUrl = deployer.Deploy(hostType); string responseText = HttpClientUtility.GetResponseTextFromUrl(applicationUrl); Assert.Equal(Startup.RESULT, responseText); } }
public void DefaultDiscoveryTest(HostType hostType) { using (ApplicationDeployer deployer = new ApplicationDeployer()) { string applicationUrl = deployer.Deploy(hostType); string responseText = HttpClientUtility.GetResponseTextFromUrl(applicationUrl); Assert.Equal(Startup.RESULT, responseText); } }
public void WelcomePage(HostType hostType) { using (ApplicationDeployer deployer = new ApplicationDeployer()) { string applicationUrl = deployer.Deploy(hostType, WelcomePageConfiguration); HttpResponseMessage response; Assert.True(HttpClientUtility.GetResponseTextFromUrl(applicationUrl, out response).ToLower().Contains("your owin application has been successfully started")); Assert.Equal("text/html", response.Content.Headers.ContentType.MediaType.ToLower()); } }
public void UseHandlerAndReadFormParametersAndQuery(HostType hostType) { using (ApplicationDeployer deployer = new ApplicationDeployer()) { string applicationUrl = deployer.Deploy(hostType, ReadFormParametersConfiguration) + "?QUERY%name1=QueryValue1&Query3=~!@$ % ^*()_+1Aa&QUEry2=QUERYVALUE2"; HttpClient client = new HttpClient(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/xml")); ; var response = client.PostAsync(applicationUrl, new FormUrlEncodedContent(new kvp[] { new kvp("input1", "~!@#$%^&*()_+1Aa"), new kvp("input2", "FormInput2") })).Result; Assert.Equal("ReadFormParameters", response.Content.ReadAsStringAsync().Result); } }
public void UseHandlerAndReadFormParametersAndQuery(HostType hostType) { using (ApplicationDeployer deployer = new ApplicationDeployer()) { string applicationUrl = deployer.Deploy(hostType, ReadFormParametersConfiguration) + "?QUERY%name1=QueryValue1&Query3=~!@$ % ^*()_+1Aa&QUEry2=QUERYVALUE2"; HttpClient client = new HttpClient(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/xml"));; var response = client.PostAsync(applicationUrl, new FormUrlEncodedContent(new kvp[] { new kvp("input1", "~!@#$%^&*()_+1Aa"), new kvp("input2", "FormInput2") })).Result; Assert.Equal("ReadFormParameters", response.Content.ReadAsStringAsync().Result); } }
public void Static_CustomSendFileFunc(HostType hostType) { using (ApplicationDeployer deployer = new ApplicationDeployer()) { var applicationUrl = deployer.Deploy(hostType, CustomSendFileFuncConfiguration); var httpClient = new HttpClient() { BaseAddress = new Uri(applicationUrl) }; var response = httpClient.GetAsync("RequirementFiles/Dir1/Default.html").Result; Assert.Equal<string>("MyCustomSendFileAsync", response.Content.ReadAsStringAsync().Result); } }
public SamplesDeploymentResult( ApplicationDeployer originDeployer, DeploymentResult originResult, ApplicationDeployer destinationDeployer, DeploymentResult destinationResult) { OriginDeployer = originDeployer; OriginResult = originResult; DestinationDeployer = destinationDeployer; DestinationResult = destinationResult; }
public void WelcomePage(HostType hostType) { using (ApplicationDeployer deployer = new ApplicationDeployer()) { string applicationUrl = deployer.Deploy(hostType, WelcomePageConfiguration); HttpResponseMessage response; Assert.Contains("your owin application has been successfully started", HttpClientUtility.GetResponseTextFromUrl(applicationUrl, out response).ToLower()); Assert.Equal("text/html", response.Content.Headers.ContentType.MediaType.ToLower()); } }
public void InvalidAppStartupInConfiguration(HostType hostType) { using (ApplicationDeployer deployer = new ApplicationDeployer()) { string applicationUrl = deployer.Deploy(hostType, ValidConfiguration); string webConfig = deployer.GetWebConfigPath(); string webConfigContent = File.ReadAllText(webConfig).Replace(typeof(NegativeScenarios).Name, "NotExistingStartupClass"); File.WriteAllText(webConfig, webConfigContent); Assert.True(HttpClientUtility.GetResponseTextFromUrl(applicationUrl).Contains(expectedExceptionType.Name), "Fatal error not thrown with invalid owin:AppStartup"); } }
public void InvalidAppStartupInConfiguration(HostType hostType) { using (ApplicationDeployer deployer = new ApplicationDeployer()) { string applicationUrl = deployer.Deploy(hostType, ValidConfiguration); string webConfig = deployer.GetWebConfigPath(); string webConfigContent = File.ReadAllText(webConfig).Replace(typeof(NegativeScenarios).Name, "NotExistingStartupClass"); File.WriteAllText(webConfig, webConfigContent); Assert.True(HttpClientUtility.GetResponseTextFromUrl(applicationUrl).Contains(expectedExceptionType.Name), "Fatal error not thrown with invalid owin:AppStartup"); } }
public void DefaultStageMarkersTest() { using (ApplicationDeployer deployer = new ApplicationDeployer()) { string applicationUrl = deployer.Deploy(HostType.IIS, DefaultStageMarkersTestConfiguration); ((WebDeployer)deployer.Application).Application.Deploy("IntegratedPipelineTest.aspx", File.ReadAllText("RequirementFiles\\IntegratedPipelineTest.aspx")); string responseText = HttpClientUtility.GetResponseTextFromUrl(applicationUrl + "/IntegratedPipelineTest.aspx"); Assert.True(responseText.Contains("IntegratedPipelineTest"), "IntegratedPipelineTest.aspx not returned"); Assert.True(responseText.Contains("0;1;2;3;4;5;6;7;8;9"), "Pipeline order incorrect"); } }
public void OnSendingHeaders(HostType hostType) { using (ApplicationDeployer deployer = new ApplicationDeployer()) { string applicationUrl = deployer.Deploy<OnSendingHeadersTest>(hostType); HttpResponseMessage httpResponseMessage = null; HttpClientUtility.GetResponseTextFromUrl(applicationUrl, out httpResponseMessage); string receivedHeaderValue = httpResponseMessage.Headers.GetValues("DummyHeader").First(); Assert.True(receivedHeaderValue == "DummyHeaderValue,DummyHeaderValue", string.Format("Expected header values : {0}. Received header values : {1}", "DummyHeaderValue,DummyHeaderValue", receivedHeaderValue)); } }
public void OnSendingHeaders(HostType hostType) { using (ApplicationDeployer deployer = new ApplicationDeployer()) { string applicationUrl = deployer.Deploy <OnSendingHeadersTest>(hostType); HttpResponseMessage httpResponseMessage = null; HttpClientUtility.GetResponseTextFromUrl(applicationUrl, out httpResponseMessage); string receivedHeaderValue = httpResponseMessage.Headers.GetValues("DummyHeader").First(); Assert.True(receivedHeaderValue == "DummyHeaderValue,DummyHeaderValue", string.Format("Expected header values : {0}. Received header values : {1}", "DummyHeaderValue,DummyHeaderValue", receivedHeaderValue)); } }
public void Security_CookiesAuthDefaults(HostType hostType) { using (ApplicationDeployer deployer = new ApplicationDeployer()) { string applicationUrl = deployer.Deploy(hostType, CookieApplyRedirectConfiguration); var httpClient = new HttpClient(); // Unauthenticated request var response = httpClient.GetAsync(applicationUrl).Result; Assert.Equal<string>("custom", response.RequestMessage.RequestUri.ParseQueryString()["custom_redirect_uri"]); } }
public void Security_CookiesAuthDefaults(HostType hostType) { using (ApplicationDeployer deployer = new ApplicationDeployer()) { string applicationUrl = deployer.Deploy(hostType, CookieApplyRedirectConfiguration); var httpClient = new HttpClient(); // Unauthenticated request var response = httpClient.GetAsync(applicationUrl).Result; Assert.Equal <string>("custom", response.RequestMessage.RequestUri.ParseQueryString()["custom_redirect_uri"]); } }
public void DefaultStageMarkersTest() { using (ApplicationDeployer deployer = new ApplicationDeployer()) { string applicationUrl = deployer.Deploy(HostType.IIS, DefaultStageMarkersTestConfiguration); ((WebDeployer)deployer.Application).Application.Deploy("IntegratedPipelineTest.aspx", File.ReadAllText("RequirementFiles\\IntegratedPipelineTest.aspx")); string responseText = HttpClientUtility.GetResponseTextFromUrl(applicationUrl + "/IntegratedPipelineTest.aspx"); Assert.True(responseText.Contains("IntegratedPipelineTest"), "IntegratedPipelineTest.aspx not returned"); Assert.True(responseText.Contains("0;1;2;3;4;5;6;7;8;9"), "Pipeline order incorrect"); } }
private void EnsureInitialized() { if (_deployer != null) { return; } _configure(DeploymentParameters); _deployer = IISApplicationDeployerFactory.Create(DeploymentParameters, _loggerFactory); _deploymentResult = (IISDeploymentResult)_deployer.DeployAsync().Result; }
public void OrderOfExecution() { using (ApplicationDeployer deployer = new ApplicationDeployer()) { string applicationUrl = deployer.Deploy(HostType.IIS, OrderOfExecutionConfiguration); WebDeployer webDeployer = (WebDeployer)deployer.Application; webDeployer.Application.Deploy("IntegratedPipelineTest.aspx", File.ReadAllText("RequirementFiles\\IntegratedPipelineTest.aspx")); string responseText = HttpClientUtility.GetResponseTextFromUrl(applicationUrl + "/IntegratedPipelineTest.aspx"); Assert.True(responseText.Contains("IntegratedPipelineTest"), "IntegratedPipelineTest.aspx not returned"); Assert.True(responseText.Contains("0;1;2;3"), "Pipeline order incorrect"); } }
public void MapOwinPath() { using (ApplicationDeployer deployer = new ApplicationDeployer()) { string url = deployer.Deploy(HostType.IIS, MapOwinPathConfiguration); ((WebDeployer)deployer.Application).Application.Deploy("Default.aspx", File.ReadAllText("RequirementFiles\\Default.aspx")); Assert.True(HttpClientUtility.GetResponseTextFromUrl(url + "/Default.aspx").Contains("Asp.net Test page"), "Default.aspx page not returned successfully in SxS mode"); Assert.Equal(HttpClientUtility.GetResponseTextFromUrl(url + "/prefix1"), "prefix1"); Assert.Equal(HttpClientUtility.GetResponseTextFromUrl(url + "/prefix1Append"), "prefix1Append"); Assert.Equal(HttpClientUtility.GetResponseTextFromUrl(url + "/prefix2"), "prefix2"); } }
public void MapOwinPath() { using (ApplicationDeployer deployer = new ApplicationDeployer()) { string url = deployer.Deploy(HostType.IIS, MapOwinPathConfiguration); ((WebDeployer)deployer.Application).Application.Deploy("Default.aspx", File.ReadAllText("RequirementFiles\\Default.aspx")); Assert.True(HttpClientUtility.GetResponseTextFromUrl(url + "/Default.aspx").Contains("Asp.net Test page"), "Default.aspx page not returned successfully in SxS mode"); Assert.Equal("prefix1", HttpClientUtility.GetResponseTextFromUrl(url + "/prefix1")); Assert.Equal("prefix1Append", HttpClientUtility.GetResponseTextFromUrl(url + "/prefix1Append")); Assert.Equal("prefix2", HttpClientUtility.GetResponseTextFromUrl(url + "/prefix2")); } }
public void OrderOfExecution() { using (ApplicationDeployer deployer = new ApplicationDeployer()) { string applicationUrl = deployer.Deploy(HostType.IIS, OrderOfExecutionConfiguration); WebDeployer webDeployer = (WebDeployer)deployer.Application; webDeployer.Application.Deploy("IntegratedPipelineTest.aspx", File.ReadAllText("RequirementFiles\\IntegratedPipelineTest.aspx")); string responseText = HttpClientUtility.GetResponseTextFromUrl(applicationUrl + "/IntegratedPipelineTest.aspx"); Assert.True(responseText.Contains("IntegratedPipelineTest"), "IntegratedPipelineTest.aspx not returned"); Assert.True(responseText.Contains("0;1;2;3"), "Pipeline order incorrect"); } }
private ApplicationDeployer GetDeployer(string appName, ServiceDeployer service, string testOutputPath) { ApplicationDeployer dep = new ApplicationDeployer() { Name = appName, }; service.ConfigPackageName = SanityTest.ConfigurationPackageName; dep.Services.Add(service); dep.Services[0].ConfigurationSettings.Add(Tuple.Create(SanityTest.ConfigurationSectionName, SanityTest.ConfigurationParameterName, testOutputPath)); return(dep); }
public void Static_BlockedFiles(HostType hostType) { using (ApplicationDeployer deployer = new ApplicationDeployer()) { var applicationUrl = deployer.Deploy(hostType, BlockedFiles_Configuration); var response = HttpClientUtility.GetResponseTextFromUrl(applicationUrl + "TextFile.txt"); Assert.Equal<string>(@"BlockedFiles\TextFile", response); //Clock$ should not be served. This is the only file among the list of blocked files, I can create on the disk. response = HttpClientUtility.GetResponseTextFromUrl(applicationUrl + "clock$.txt"); Assert.Equal<string>("FallThrough", response); } }
public void Static_BlockedFiles(HostType hostType) { using (ApplicationDeployer deployer = new ApplicationDeployer()) { var applicationUrl = deployer.Deploy(hostType, BlockedFiles_Configuration); var response = HttpClientUtility.GetResponseTextFromUrl(applicationUrl + "TextFile.txt"); Assert.Equal <string>(@"BlockedFiles\TextFile", response); //Clock$ should not be served. This is the only file among the list of blocked files, I can create on the disk. response = HttpClientUtility.GetResponseTextFromUrl(applicationUrl + "clock$.txt"); Assert.Equal <string>("FallThrough", response); } }
public void CreateLogger(HostType hostType) { using (ApplicationDeployer deployer = new ApplicationDeployer()) { var service = new NotificationServer(); service.StartNotificationService(); string applicationUrl = deployer.Deploy(hostType, CreateLoggerConfiguration); Assert.Equal("SUCCESS", HttpClientUtility.GetResponseTextFromUrl(applicationUrl)); Assert.True(service.NotificationReceived.WaitOne(1 * 2000), "Did not receive all expected traces within expected time"); service.Dispose(); } }
public void Static_EmbeddedDirectoryBrowserFileSystem(HostType hostType) { using (ApplicationDeployer deployer = new ApplicationDeployer()) { var applicationUrl = deployer.Deploy(hostType, EmbeddedDirectoryBrowserFileSystemConfiguration); HttpResponseMessage response = null; var responseText = HttpClientUtility.GetResponseTextFromUrl(applicationUrl, out response); Assert.True(!string.IsNullOrWhiteSpace(responseText), "Received empty response"); Assert.True((response.Content).Headers.ContentType.ToString() == "text/html; charset=utf-8"); Assert.True(responseText.Contains("RequirementFiles.EmbeddedResources.SampleAVI.avi")); } }
public void TestResponseStatusCode(HostType hostType) { using (ApplicationDeployer deployer = new ApplicationDeployer()) { string applicationUrl = deployer.Deploy(hostType, ConfigurationTest); HttpResponseMessage httpResponseMessage = null; HttpClientUtility.GetResponseTextFromUrl(applicationUrl + "/BadRequestPath", out httpResponseMessage); Assert.Equal(httpResponseMessage.StatusCode, HttpStatusCode.BadRequest); HttpClientUtility.GetResponseTextFromUrl(applicationUrl + "/GoodRequestPath", out httpResponseMessage); Assert.Equal(httpResponseMessage.StatusCode, HttpStatusCode.OK); } }
public void Static_CustomMimeType(HostType hostType) { using (ApplicationDeployer deployer = new ApplicationDeployer()) { var applicationUrl = deployer.Deploy(hostType, CustomMimeTypeConfiguration); var httpClient = new HttpClient() { BaseAddress = new Uri(applicationUrl) }; var response = httpClient.GetAsync(@"RequirementFiles\ContentTypes\Unknown.unknown").Result; Assert.Equal <string>("CustomUnknown", string.Join("", response.Content.Headers.GetValues("Content-Type"))); } }
public void Static_IfNoneMatch(HostType hostType) { using (ApplicationDeployer deployer = new ApplicationDeployer()) { var applicationUrl = deployer.Deploy(hostType, IfNoneMatchConfiguration); var httpClient = new HttpClient() { BaseAddress = new Uri(applicationUrl) }; //Initial request to get the E-tag var response = httpClient.GetAsync("RequirementFiles/Dir1/Default.html").Result; httpClient.DefaultRequestHeaders.IfNoneMatch.Add(response.Headers.ETag); //Add the E-tag to the successive request to the same entity. Expect a Not modified 304. for (int count = 0; count < 10; count++) { response = httpClient.GetAsync("RequirementFiles/Dir1/Default.html").Result; Assert.Equal <HttpStatusCode>(HttpStatusCode.NotModified, response.StatusCode); } //Modify the file to see if the body is fetched fully again string fileContent = File.ReadAllText(@"RequirementFiles/Dir1/Default.html"); File.WriteAllText(@"RequirementFiles/Dir1/Default.html", fileContent); //Verify if the fully body is sent after the file modification response = httpClient.GetAsync("RequirementFiles/Dir1/Default.html").Result; Assert.Equal <HttpStatusCode>(HttpStatusCode.OK, response.StatusCode); //Add a non-matching E-tag to see if the body is fetched again. httpClient.DefaultRequestHeaders.IfNoneMatch.Clear(); httpClient.DefaultRequestHeaders.IfNoneMatch.Add(new EntityTagHeaderValue("\"etag1\"")); response = httpClient.GetAsync("RequirementFiles/Dir1/Default.html").Result; Assert.Equal <HttpStatusCode>(HttpStatusCode.OK, response.StatusCode); //Duplicate 4x e-tags httpClient.DefaultRequestHeaders.IfNoneMatch.Add(response.Headers.ETag); httpClient.DefaultRequestHeaders.IfNoneMatch.Add(response.Headers.ETag); httpClient.DefaultRequestHeaders.IfNoneMatch.Add(response.Headers.ETag); httpClient.DefaultRequestHeaders.IfNoneMatch.Add(response.Headers.ETag); response = httpClient.GetAsync("RequirementFiles/Dir1/Default.html").Result; Assert.Equal <HttpStatusCode>(HttpStatusCode.NotModified, response.StatusCode); //Etag=* should always get a 304. httpClient.DefaultRequestHeaders.IfNoneMatch.Clear(); httpClient.DefaultRequestHeaders.TryAddWithoutValidation("If-None-Match", "*"); response = httpClient.GetAsync("RequirementFiles/Dir1/Default.html").Result; Assert.Equal <HttpStatusCode>(HttpStatusCode.NotModified, response.StatusCode); } }
public void Static_EmbeddedDirectoryBrowserFileSystem(HostType hostType) { using (ApplicationDeployer deployer = new ApplicationDeployer()) { var applicationUrl = deployer.Deploy(hostType, EmbeddedDirectoryBrowserFileSystemConfiguration); HttpResponseMessage response = null; var responseText = HttpClientUtility.GetResponseTextFromUrl(applicationUrl, out response); Assert.True(!string.IsNullOrWhiteSpace(responseText), "Received empty response"); Assert.True((response.Content).Headers.ContentType.ToString() == "text/html; charset=utf-8"); Assert.True(responseText.Contains("RequirementFiles.EmbeddedResources.SampleAVI.avi")); } }
public void Static_EmbeddedFileSystemDefaultFiles(HostType hostType) { using (ApplicationDeployer deployer = new ApplicationDeployer()) { var applicationUrl = deployer.Deploy(hostType, EmbeddedFileSystemDefaultFilesConfiguration); HttpResponseMessage response = null; var responseText = HttpClientUtility.GetResponseTextFromUrl(applicationUrl, out response); Assert.True(!string.IsNullOrWhiteSpace(responseText), "Received empty response"); Assert.True((response.Content).Headers.ContentType.ToString() == "text/html"); Assert.True(responseText.Contains("SampleHTM")); } }
public void CreateLogger(HostType hostType) { using (ApplicationDeployer deployer = new ApplicationDeployer()) { var service = new NotificationServer(); service.StartNotificationService(); string applicationUrl = deployer.Deploy(hostType, CreateLoggerConfiguration); Assert.Equal("SUCCESS", HttpClientUtility.GetResponseTextFromUrl(applicationUrl)); Assert.True(service.NotificationReceived.WaitOne(1 * 2000), "Did not receive all expected traces within expected time"); service.Dispose(); } }
public void Static_CacheHeadersDefault(HostType hostType) { using (ApplicationDeployer deployer = new ApplicationDeployer()) { var applicationUrl = deployer.Deploy(hostType, CacheHeadersDefaultConfiguration); var httpClient = new HttpClient() { BaseAddress = new Uri(applicationUrl) }; var response = httpClient.GetAsync("RequirementFiles/Dir1/Default.html").Result; Assert.True(!string.IsNullOrWhiteSpace(response.Headers.ETag.Tag), "E-Tag header missing"); Assert.True(response.Headers.ETag.Tag.StartsWith("\""), "E-Tag header does not start with a quote"); Assert.True(response.Headers.ETag.Tag.EndsWith("\""), "E-Tag header does not end with a quote"); Assert.True(response.Content.Headers.LastModified.HasValue, "Date-Modified header missing"); } }
public void Static_EmbeddedFileSystemDefaultFiles(HostType hostType) { using (ApplicationDeployer deployer = new ApplicationDeployer()) { var applicationUrl = deployer.Deploy(hostType, EmbeddedFileSystemDefaultFilesConfiguration); HttpResponseMessage response = null; var responseText = HttpClientUtility.GetResponseTextFromUrl(applicationUrl, out response); Assert.True(!string.IsNullOrWhiteSpace(responseText), "Received empty response"); Assert.True((response.Content).Headers.ContentType.ToString() == "text/html"); Assert.True(responseText.Contains("SampleHTM")); } }
public void Static_CustomSendFileFunc(HostType hostType) { using (ApplicationDeployer deployer = new ApplicationDeployer()) { var applicationUrl = deployer.Deploy(hostType, CustomSendFileFuncConfiguration); var httpClient = new HttpClient() { BaseAddress = new Uri(applicationUrl) }; var response = httpClient.GetAsync("RequirementFiles/Dir1/Default.html").Result; Assert.Equal <string>("MyCustomSendFileAsync", response.Content.ReadAsStringAsync().Result); } }
public void TestResponseStatusCode(HostType hostType) { using (ApplicationDeployer deployer = new ApplicationDeployer()) { string applicationUrl = deployer.Deploy(hostType, ConfigurationTest); HttpResponseMessage httpResponseMessage = null; HttpClientUtility.GetResponseTextFromUrl(applicationUrl + "/BadRequestPath", out httpResponseMessage); Assert.Equal(httpResponseMessage.StatusCode, HttpStatusCode.BadRequest); HttpClientUtility.GetResponseTextFromUrl(applicationUrl + "/GoodRequestPath", out httpResponseMessage); Assert.Equal(httpResponseMessage.StatusCode, HttpStatusCode.OK); } }
public CorsDeploymentResult( ApplicationDeployer originDeployer, DeploymentResult originResult, ApplicationDeployer secondOriginDeployer, DeploymentResult secondOriginResult, ApplicationDeployer destinationDeployer, DeploymentResult destinationResult) { OriginDeployer = originDeployer; OriginResult = originResult; SecondOriginDeployer = secondOriginDeployer; SecondOriginResult = secondOriginResult; DestinationDeployer = destinationDeployer; DestinationResult = destinationResult; }
public void Static_OnPrepareResponseTest(HostType hostType) { using (ApplicationDeployer deployer = new ApplicationDeployer()) { var applicationUrl = deployer.Deploy(hostType, OnPrepareResponseTestConfiguration); var httpClient = new HttpClient() { BaseAddress = new Uri(applicationUrl) }; var response = httpClient.GetAsync(@"RequirementFiles\Dir1\Default.html").Result; Assert.Equal <string>("true", string.Join("", response.Headers.GetValues("CallBackInvoked"))); Assert.Equal <bool>(true, response.Content.ReadAsStringAsync().Result.Contains(@"Dir1\Default.html")); } }
public void InvalidAssemblyNameInConfiguration(HostType hostType) { using (ApplicationDeployer deployer = new ApplicationDeployer()) { string applicationUrl = deployer.Deploy(hostType, ValidConfiguration); string webConfig = deployer.GetWebConfigPath(); string fullyQualifiedConfigurationMethodName = ((Action <IAppBuilder>)ValidConfiguration).GetFullyQualifiedConfigurationMethodName(); string webConfigContent = File.ReadAllText(webConfig). Replace(fullyQualifiedConfigurationMethodName, fullyQualifiedConfigurationMethodName + ", NotExistingAssembly"); File.WriteAllText(webConfig, webConfigContent); Assert.True(HttpClientUtility.GetResponseTextFromUrl(applicationUrl).Contains(expectedExceptionType.Name), "Fatal error not thrown with invalid assembly name"); } }
public void Static_IfMatch(HostType hostType) { using (ApplicationDeployer deployer = new ApplicationDeployer()) { var applicationUrl = deployer.Deploy(hostType, IfMatchConfiguration); var httpClient = new HttpClient() { BaseAddress = new Uri(applicationUrl) }; //Initial request to get the E-tag var response = httpClient.GetAsync("RequirementFiles/Dir1/Default.html").Result; httpClient.DefaultRequestHeaders.IfMatch.Add(response.Headers.ETag); //Add the E-tag to the successive request to the same entity. Expect the body is fully fetched again. for (int count = 0; count < 10; count++) { response = httpClient.GetAsync("RequirementFiles/Dir1/Default.html").Result; Assert.Equal <HttpStatusCode>(HttpStatusCode.OK, response.StatusCode); } //Modify the file to see if the body is fetched fully again string fileContent = File.ReadAllText(@"RequirementFiles/Dir1/Default.html"); File.WriteAllText(@"RequirementFiles/Dir1/Default.html", fileContent); //Sometimes the test is flaky returning OK status code as the file change is not immediately recognized by the server. So give it a while. Thread.Sleep(500); //If the E-tag sent failed to match the entity's etag, then expect a Precondition failed 412. response = httpClient.GetAsync("RequirementFiles/Dir1/Default.html").Result; Assert.Equal <HttpStatusCode>(HttpStatusCode.PreconditionFailed, response.StatusCode); //Duplicate 4x e-tags httpClient.DefaultRequestHeaders.IfMatch.Clear(); response = httpClient.GetAsync("RequirementFiles/Dir1/Default.html").Result; httpClient.DefaultRequestHeaders.IfMatch.Add(response.Headers.ETag); httpClient.DefaultRequestHeaders.IfMatch.Add(response.Headers.ETag); httpClient.DefaultRequestHeaders.IfMatch.Add(response.Headers.ETag); httpClient.DefaultRequestHeaders.IfMatch.Add(response.Headers.ETag); response = httpClient.GetAsync("RequirementFiles/Dir1/Default.html").Result; Assert.Equal <HttpStatusCode>(HttpStatusCode.OK, response.StatusCode); //Etag=* should always get a 304. httpClient.DefaultRequestHeaders.IfMatch.Clear(); httpClient.DefaultRequestHeaders.TryAddWithoutValidation("If-Match", "*"); response = httpClient.GetAsync("RequirementFiles/Dir1/Default.html").Result; Assert.Equal <HttpStatusCode>(HttpStatusCode.OK, response.StatusCode); } }
public void ConfigurationMethodNotFound(HostType hostType) { using (ApplicationDeployer deployer = new ApplicationDeployer()) { var expectedExceptionType = typeof(EntryPointNotFoundException); if (hostType != HostType.IIS) { Assert.Throws(expectedExceptionType, () => deployer.Deploy <ConfigurationMethodNotFoundTest>(hostType)); } else { string applicationUrl = deployer.Deploy <ConfigurationMethodNotFoundTest>(hostType); Assert.True(HttpClientUtility.GetResponseTextFromUrl(applicationUrl).Contains(expectedExceptionType.Name), "Fatal error not thrown without Configuration method"); } } }
public void Static_DirectoryMiddlewareMappedToDifferentDirectory(HostType hostType) { using (ApplicationDeployer deployer = new ApplicationDeployer()) { string applicationUrl = deployer.Deploy(hostType, DirectoryMiddlewareMappedToDifferentDirectoryConfiguration); HttpResponseMessage response = null; //1. Check directory browsing enabled at application level var responseText = HttpClientUtility.GetResponseTextFromUrl(applicationUrl, out response); Assert.True(!string.IsNullOrWhiteSpace(responseText), "Received empty response"); Assert.True((response.Content).Headers.ContentType.ToString() == "text/html; charset=utf-8"); Assert.Contains("Default.html", responseText); Assert.Contains("EmptyFile.txt", responseText); } }
public void MappingMiddleware(HostType hostType) { using (ApplicationDeployer deployer = new ApplicationDeployer()) { string applicationUrl = deployer.Deploy(hostType, MappingMiddlewareConfiguration); //Anonymous Auth routes test Assert.Equal(HttpClientUtility.GetResponseTextFromUrl(applicationUrl + "anonymous1"), "Anonymous1"); Assert.Equal(HttpClientUtility.GetResponseTextFromUrl(applicationUrl + "anonymous2"), "Anonymous2"); Assert.Equal(HttpClientUtility.GetResponseTextFromUrl(applicationUrl + "a"), "/a"); Assert.Equal(HttpClientUtility.GetResponseTextFromUrl(applicationUrl + "a/b"), "/a/b"); //Default application Assert.Equal(HttpClientUtility.GetResponseTextFromUrl(applicationUrl), "Default"); } }