Browse files

Several test updates:

1) Updated HttpClientHelper to expose statics for creating an HttpClient and an HttpClientHandler which is correctly set up to handle authentication. It uses a CredentialsCache along with preauthentication which handles authentication across redirects.

2) Updated KuduRemoteClientBase to make not force a teminating "/" on the base URI. This makes it possible to VFS to use the client base. Also cleaned up the class so that it is easier to use,

3) Added RemoteVfsManager to ApplicationManager which correct base URI and credentials.

4) Updated places which created an HttpClientHandler manually to instead use HttpClientHelper.CreateClientHandler
  • Loading branch information...
1 parent 438260c commit d269c81f59049b864ec994a9639d1d664be1c6c6 @HenrikFrystykNielsen HenrikFrystykNielsen committed Nov 30, 2012
View
24 Kudu.Client/Deployment/RemoteDeploymentManager.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Kudu.Client.Infrastructure;
@@ -9,13 +10,8 @@ namespace Kudu.Client.Deployment
{
public class RemoteDeploymentManager : KuduRemoteClientBase
{
- public RemoteDeploymentManager(string serviceUrl)
- : base(serviceUrl)
- {
- }
-
- public RemoteDeploymentManager(string serviceUrl, HttpMessageHandler handler)
- : base(serviceUrl, handler)
+ public RemoteDeploymentManager(string serviceUrl, ICredentials credentials = null, HttpMessageHandler handler = null)
+ : base(UrlUtility.EnsureTrailingSlash(serviceUrl), credentials, handler)
{
}
@@ -31,38 +27,38 @@ public Task<IEnumerable<DeployResult>> GetResultsAsync(int? maxItems = null, boo
url += "&$filter=LastSuccessEndTime ne null";
}
- return _client.GetJsonAsync<IEnumerable<DeployResult>>(url);
+ return Client.GetJsonAsync<IEnumerable<DeployResult>>(url);
}
public Task<DeployResult> GetResultAsync(string id)
{
- return _client.GetJsonAsync<DeployResult>(id);
+ return Client.GetJsonAsync<DeployResult>(id);
}
public Task<IEnumerable<LogEntry>> GetLogEntriesAsync(string id)
{
- return _client.GetJsonAsync<IEnumerable<LogEntry>>(id + "/log");
+ return Client.GetJsonAsync<IEnumerable<LogEntry>>(id + "/log");
}
public Task<IEnumerable<LogEntry>> GetLogEntryDetailsAsync(string id, string logId)
{
- return _client.GetJsonAsync<IEnumerable<LogEntry>>(id + "/log/" + logId);
+ return Client.GetJsonAsync<IEnumerable<LogEntry>>(id + "/log/" + logId);
}
public Task DeleteAsync(string id)
{
- return _client.DeleteSafeAsync(id);
+ return Client.DeleteSafeAsync(id);
}
public Task DeployAsync(string id)
{
- return _client.PutAsync(id);
+ return Client.PutAsync(id);
}
public Task DeployAsync(string id, bool clean)
{
var param = new KeyValuePair<string, string>("clean", clean.ToString());
- return _client.PutAsync(id, param);
+ return Client.PutAsync(id, param);
}
}
}
View
21 Kudu.Client/Editor/RemoteProjectSystem.cs
@@ -1,22 +1,23 @@
using System;
using System.Collections.Generic;
+using System.Net;
using Kudu.Client.Infrastructure;
using Kudu.Core.Editor;
namespace Kudu.Client.Editor
{
public class RemoteProjectSystem : KuduRemoteClientBase, IProjectSystem
{
- public RemoteProjectSystem(string serviceUrl)
- :base(serviceUrl)
+ public RemoteProjectSystem(string serviceUrl, ICredentials credentials = null)
+ : base(UrlUtility.EnsureTrailingSlash(serviceUrl), credentials)
{
}
public string ReadAllText(string path)
{
// REVIEW: Do we need to url encode?
// REVIEW: this goes through the same client that set the Accept header to application/json, but we receive text/plain
- return _client.GetAsync(path)
+ return Client.GetAsync(path)
.Result
.EnsureSuccessful()
.Content
@@ -26,21 +27,21 @@ public string ReadAllText(string path)
public Project GetProject()
{
- return _client.GetJson<Project>(String.Empty);
+ return Client.GetJson<Project>(String.Empty);
}
public void WriteAllText(string path, string content)
{
- _client.PutAsync(path, HttpClientHelper.CreateJsonContent(new KeyValuePair<string, string>("content", content)))
- .Result
- .EnsureSuccessful();
+ Client.PutAsync(path, HttpClientHelper.CreateJsonContent(new KeyValuePair<string, string>("content", content)))
+ .Result
+ .EnsureSuccessful();
}
public void Delete(string path)
{
- _client.DeleteAsync(path)
- .Result
- .EnsureSuccessful();
+ Client.DeleteAsync(path)
+ .Result
+ .EnsureSuccessful();
}
}
}
View
14 Kudu.Client/Editor/RemoteVfsManager.cs
@@ -0,0 +1,14 @@
+using System.Net;
+using System.Net.Http;
+using Kudu.Client.Infrastructure;
+
+namespace Kudu.Client.Editor
+{
+ public class RemoteVfsManager : KuduRemoteClientBase
+ {
+ public RemoteVfsManager(string serviceUrl, ICredentials credentials = null, HttpMessageHandler handler = null)
+ : base(serviceUrl, credentials, handler)
+ {
+ }
+ }
+}
View
17 Kudu.Client/Infrastructure/HttpClientExtensions.cs
@@ -1,13 +1,8 @@
using System;
using System.Collections.Generic;
-using System.Net;
using System.Net.Http;
-using System.Net.Http.Headers;
-using System.Text;
using System.Threading.Tasks;
-using Kudu.Contracts.Infrastructure;
using Newtonsoft.Json;
-using Newtonsoft.Json.Linq;
namespace Kudu.Client.Infrastructure
{
@@ -21,18 +16,6 @@ public static T GetJson<T>(this HttpClient client, string url)
return JsonConvert.DeserializeObject<T>(content);
}
- public static void SetClientCredentials(this HttpClient client, ICredentials credentials)
- {
- if (credentials == null)
- {
- return;
- }
-
- NetworkCredential networkCred = credentials.GetCredential(client.BaseAddress, "Basic");
- string credParameter = Convert.ToBase64String(Encoding.ASCII.GetBytes(networkCred.UserName + ":" + networkCred.Password));
- client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", credParameter);
- }
-
public static Task<T> GetJsonAsync<T>(this HttpClient client, string url)
{
return client.GetAsync(url).Then(result =>
View
72 Kudu.Client/Infrastructure/HttpClientHelper.cs
@@ -1,29 +1,29 @@
using System;
using System.Collections.Generic;
+using System.Net;
using System.Net.Http;
using System.Net.Http.Formatting;
using System.Net.Http.Headers;
-using System.Threading;
-using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
namespace Kudu.Client.Infrastructure
{
- internal static class HttpClientHelper
+ public static class HttpClientHelper
{
- public static HttpClient Create(string url, HttpMessageHandler handler)
- {
- // The URL needs to end with a slash for HttpClient to do the right thing with relative paths
- url = UrlUtility.EnsureTrailingSlash(url);
+ private static readonly char[] uriPathSeparator = new char[] { '/' };
- var slashHandler = new TrailingSlashHandler()
+ public static HttpClient CreateClient(string serviceUrl, ICredentials credentials = null, HttpMessageHandler handler = null)
+ {
+ if (serviceUrl == null)
{
- InnerHandler = handler ?? new HttpClientHandler()
- };
+ throw new ArgumentNullException("serviceUrl");
+ }
- var client = new HttpClient(slashHandler)
+ HttpMessageHandler effectiveHandler = handler ?? CreateClientHandler(serviceUrl, credentials);
+ Uri serviceAddr = new Uri(serviceUrl);
+ HttpClient client = new HttpClient(effectiveHandler)
{
- BaseAddress = new Uri(url),
+ BaseAddress = serviceAddr,
MaxResponseContentBufferSize = 30 * 1024 * 1024
};
@@ -32,33 +32,43 @@ public static HttpClient Create(string url, HttpMessageHandler handler)
return client;
}
- public static HttpContent CreateJsonContent(params KeyValuePair<string, string>[] items)
+ public static HttpClientHandler CreateClientHandler(string serviceUrl, ICredentials credentials)
{
- var jsonObject = new JObject();
- foreach (KeyValuePair<string, string> kv in items)
+ if (serviceUrl == null)
{
- jsonObject.Add(kv.Key, kv.Value);
+ throw new ArgumentNullException("serviceUrl");
}
- return new ObjectContent(typeof(JObject), jsonObject, new JsonMediaTypeFormatter());
- }
- private class TrailingSlashHandler : DelegatingHandler
- {
- protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
+ // Set up our own HttpClientHandler and configure it
+ HttpClientHandler clientHandler = new HttpClientHandler();
+
+ if (credentials != null)
{
- // Remove trailing slash before any request is made (since credentials are lost when a 307 is returned when auth is enabled)
- string url = request.RequestUri.OriginalString;
- if (url.EndsWith("/"))
- {
- url = url.Substring(0, url.Length - 1);
- }
+ // Set up credentials cache which will handle basic authentication
+ CredentialCache credentialCache = new CredentialCache();
- // Handle query strings
- url = url.Replace("/?", "?");
+ // Get base address without terminating slash
+ string credentialAddress = new Uri(serviceUrl).GetLeftPart(UriPartial.Authority).TrimEnd(uriPathSeparator);
- request.RequestUri = new Uri(url);
- return base.SendAsync(request, cancellationToken);
+ // Add credentials to cache and associate with handler
+ NetworkCredential networkCredentials = credentials.GetCredential(new Uri(credentialAddress), "Basic");
+ credentialCache.Add(new Uri(credentialAddress), "Basic", networkCredentials);
+ clientHandler.Credentials = credentialCache;
+ clientHandler.PreAuthenticate = true;
}
+
+ // Our handler is ready
+ return clientHandler;
+ }
+
+ public static HttpContent CreateJsonContent(params KeyValuePair<string, string>[] items)
+ {
+ var jsonObject = new JObject();
+ foreach (KeyValuePair<string, string> kv in items)
+ {
+ jsonObject.Add(kv.Key, kv.Value);
+ }
+ return new ObjectContent(typeof(JObject), jsonObject, new JsonMediaTypeFormatter());
}
}
}
View
44 Kudu.Client/Infrastructure/KuduRemoteClientBase.cs
@@ -1,47 +1,27 @@
-using System.Net;
+using System;
+using System.Net;
using System.Net.Http;
-using System.Net.Http.Headers;
namespace Kudu.Client.Infrastructure
{
public abstract class KuduRemoteClientBase
{
- protected readonly HttpClient _client;
- private ICredentials _credentials;
-
- public KuduRemoteClientBase(string serviceUrl)
- : this(serviceUrl, null)
+ protected KuduRemoteClientBase(string serviceUrl, ICredentials credentials = null, HttpMessageHandler handler = null)
{
+ if (serviceUrl == null)
+ {
+ throw new ArgumentNullException("serviceUrl");
+ }
- }
-
- public KuduRemoteClientBase(string serviceUrl, HttpMessageHandler handler)
- {
- ServiceUrl = UrlUtility.EnsureTrailingSlash(serviceUrl);
- _client = HttpClientHelper.Create(ServiceUrl, handler);
+ ServiceUrl = serviceUrl;
+ Credentials = credentials;
+ Client = HttpClientHelper.CreateClient(ServiceUrl, credentials, handler);
}
public string ServiceUrl { get; private set; }
- public HttpRequestHeaders Headers
- {
- get
- {
- return _client.DefaultRequestHeaders;
- }
- }
+ public ICredentials Credentials { get; private set; }
- public ICredentials Credentials
- {
- get
- {
- return _credentials;
- }
- set
- {
- _credentials = value;
- _client.SetClientCredentials(_credentials);
- }
- }
+ public HttpClient Client { get; private set; }
}
}
View
15 Kudu.Client/Infrastructure/UrlUtility.cs
@@ -1,14 +1,17 @@
-namespace Kudu.Client.Infrastructure
+using System;
+
+namespace Kudu.Client.Infrastructure
{
- internal static class UrlUtility
+ public static class UrlUtility
{
- internal static string EnsureTrailingSlash(string url)
+ public static string EnsureTrailingSlash(string url)
{
- if (url.EndsWith("/"))
+ UriBuilder address = new UriBuilder(url);
+ if (!address.Path.EndsWith("/"))
{
- return url;
+ address.Path += "/";
}
- return url + "/";
+ return address.Uri.AbsoluteUri;
}
}
}
View
1 Kudu.Client/Kudu.Client.csproj
@@ -68,6 +68,7 @@
<Link>Properties\CommonAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Diagnostics\RemoteLogStreamManager.cs" />
+ <Compile Include="Editor\RemoteVfsManager.cs" />
<Compile Include="Infrastructure\BasicAuthCredentialProvider.cs" />
<Compile Include="Infrastructure\HttpResponseMessageExtensions.cs" />
<Compile Include="Infrastructure\HttpClientExtensions.cs" />
View
13 Kudu.Client/RemoteEnvironmentManager.cs
@@ -1,19 +1,12 @@
-using System;
-using System.Net.Http;
-using System.Threading.Tasks;
+using System.Net;
using Kudu.Client.Infrastructure;
namespace Kudu.Client
{
public class RemoteEnvironmentManager : KuduRemoteClientBase
{
- public RemoteEnvironmentManager(string serviceUrl)
- : base(serviceUrl)
- {
- }
-
- public RemoteEnvironmentManager(string serviceUrl, HttpMessageHandler handler)
- : base(serviceUrl, handler)
+ public RemoteEnvironmentManager(string serviceUrl, ICredentials credentials = null)
+ : base(UrlUtility.EnsureTrailingSlash(serviceUrl), credentials)
{
}
}
View
15 Kudu.Client/SSHKey/RemoteSSHKeyManager.cs
@@ -1,22 +1,15 @@
using System;
using System.Collections.Generic;
-using System.Net.Http;
+using System.Net;
using System.Threading.Tasks;
using Kudu.Client.Infrastructure;
-using Kudu.Contracts.Infrastructure;
-using Newtonsoft.Json;
namespace Kudu.Client.SSHKey
{
public class RemoteSSHKeyManager : KuduRemoteClientBase
{
- public RemoteSSHKeyManager(string serviceUrl)
- : base(serviceUrl)
- {
- }
-
- public RemoteSSHKeyManager(string serviceUrl, HttpMessageHandler handler)
- : base(serviceUrl, handler)
+ public RemoteSSHKeyManager(string serviceUrl, ICredentials credentials = null)
+ : base(UrlUtility.EnsureTrailingSlash(serviceUrl), credentials)
{
}
@@ -27,7 +20,7 @@ public Task SetPrivateKey(string key)
new KeyValuePair<string, string>("key", key)
};
- return _client.PutAsync(String.Empty, param).Then(response =>
+ return Client.PutAsync(String.Empty, param).Then(response =>
{
response.EnsureSuccessful();
return;
View
26 Kudu.Client/Settings/RemoteDeploymentSettingsManager.cs
@@ -1,47 +1,41 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
-using System.Net.Http;
+using System.Net;
using System.Threading.Tasks;
using Kudu.Client.Infrastructure;
-using Kudu.Contracts.Infrastructure;
using Newtonsoft.Json.Linq;
namespace Kudu.Client.Deployment
{
public class RemoteDeploymentSettingsManager : KuduRemoteClientBase
{
- public RemoteDeploymentSettingsManager(string serviceUrl)
- : base(serviceUrl)
- {
- }
-
- public RemoteDeploymentSettingsManager(string serviceUrl, HttpClientHandler handler)
- : base(serviceUrl, handler)
+ public RemoteDeploymentSettingsManager(string serviceUrl, ICredentials credentials = null)
+ : base(UrlUtility.EnsureTrailingSlash(serviceUrl), credentials)
{
}
public Task SetValueLegacy(string key, string value)
{
var values = HttpClientHelper.CreateJsonContent(new KeyValuePair<string, string>("key", key), new KeyValuePair<string, string>("value", value));
- return _client.PostAsync(String.Empty, values).Then(response => response.EnsureSuccessful());
+ return Client.PostAsync(String.Empty, values).Then(response => response.EnsureSuccessful());
}
public Task SetValue(string key, string value)
{
var values = HttpClientHelper.CreateJsonContent(new KeyValuePair<string, string>(key, value));
- return _client.PostAsync(String.Empty, values).Then(response => response.EnsureSuccessful());
+ return Client.PostAsync(String.Empty, values).Then(response => response.EnsureSuccessful());
}
public Task SetValues(params KeyValuePair<string, string>[] values)
{
var jsonvalues = HttpClientHelper.CreateJsonContent(values);
- return _client.PostAsync(String.Empty, jsonvalues).Then(response => response.EnsureSuccessful());
+ return Client.PostAsync(String.Empty, jsonvalues).Then(response => response.EnsureSuccessful());
}
public Task<NameValueCollection> GetValuesLegacy()
{
- return _client.GetJsonAsync<JArray>(String.Empty).Then(obj =>
+ return Client.GetJsonAsync<JArray>(String.Empty).Then(obj =>
{
var nvc = new NameValueCollection();
foreach (JObject value in obj)
@@ -55,7 +49,7 @@ public Task<NameValueCollection> GetValuesLegacy()
public Task<NameValueCollection> GetValues()
{
- return _client.GetJsonAsync<JObject>("?version=2").Then(obj =>
+ return Client.GetJsonAsync<JObject>("?version=2").Then(obj =>
{
var nvc = new NameValueCollection();
foreach (var pair in obj)
@@ -69,12 +63,12 @@ public Task<NameValueCollection> GetValues()
public Task<string> GetValue(string key)
{
- return _client.GetJsonAsync<string>(key);
+ return Client.GetJsonAsync<string>(key);
}
public Task Delete(string key)
{
- return _client.DeleteSafeAsync(key);
+ return Client.DeleteSafeAsync(key);
}
}
}
View
67 Kudu.Client/SourceControl/RemoteRepository.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Net;
using System.Net.Http;
using Kudu.Client.Infrastructure;
using Kudu.Core.SourceControl;
@@ -9,16 +10,16 @@ namespace Kudu.Client.SourceControl
{
public class RemoteRepository : KuduRemoteClientBase
{
- public RemoteRepository(string serviceUrl)
- :base(serviceUrl)
+ public RemoteRepository(string serviceUrl, ICredentials credentials = null)
+ : base(UrlUtility.EnsureTrailingSlash(serviceUrl), credentials)
{
}
public string CurrentId
{
get
{
- return _client.GetAsync("id")
+ return Client.GetAsync("id")
.Result
.EnsureSuccessful()
.Content
@@ -29,36 +30,36 @@ public string CurrentId
public void Initialize()
{
- _client.PostAsync("init", new StringContent(String.Empty))
- .Result
- .EnsureSuccessful();
+ Client.PostAsync("init", new StringContent(String.Empty))
+ .Result
+ .EnsureSuccessful();
}
public IEnumerable<Branch> GetBranches()
{
- return _client.GetJson<IEnumerable<Branch>>("branches");
+ return Client.GetJson<IEnumerable<Branch>>("branches");
}
public IEnumerable<FileStatus> GetStatus()
{
- return _client.GetJson<IEnumerable<FileStatus>>("status");
+ return Client.GetJson<IEnumerable<FileStatus>>("status");
}
public IEnumerable<ChangeSet> GetChanges()
{
- return _client.GetJson<IEnumerable<ChangeSet>>("log");
+ return Client.GetJson<IEnumerable<ChangeSet>>("log");
}
public IEnumerable<ChangeSet> GetChanges(int index, int limit)
{
- return _client.GetJson<IEnumerable<ChangeSet>>("log?index=" + index + "&limit=" + limit);
+ return Client.GetJson<IEnumerable<ChangeSet>>("log?index=" + index + "&limit=" + limit);
}
public ChangeSetDetail GetDetails(string id)
{
- return _client.GetJson<ChangeSetDetail>("details/" + id);
+ return Client.GetJson<ChangeSetDetail>("details/" + id);
}
-
+
public ChangeSet GetChangeSet(string id)
{
// Not used by client apis as yet
@@ -67,53 +68,53 @@ public ChangeSet GetChangeSet(string id)
public ChangeSetDetail GetWorkingChanges()
{
- return _client.GetJson<ChangeSetDetail>("working");
+ return Client.GetJson<ChangeSetDetail>("working");
}
public void AddFile(string path)
{
- _client.PostAsync("add", HttpClientHelper.CreateJsonContent(new KeyValuePair<string, string>("path", path)))
- .Result
- .EnsureSuccessful();
+ Client.PostAsync("add", HttpClientHelper.CreateJsonContent(new KeyValuePair<string, string>("path", path)))
+ .Result
+ .EnsureSuccessful();
}
public void RevertFile(string path)
{
- _client.PostAsync("remove", HttpClientHelper.CreateJsonContent(new KeyValuePair<string, string>("path", path)))
- .Result
- .EnsureSuccessful();
+ Client.PostAsync("remove", HttpClientHelper.CreateJsonContent(new KeyValuePair<string, string>("path", path)))
+ .Result
+ .EnsureSuccessful();
}
public ChangeSet Commit(string message, string authorName)
{
- string json = _client.PostAsync("commit", HttpClientHelper.CreateJsonContent(new KeyValuePair<string, string>("name", authorName), new KeyValuePair<string, string>("message", message)))
- .Result
- .EnsureSuccessful()
- .Content.ReadAsStringAsync()
- .Result;
+ string json = Client.PostAsync("commit", HttpClientHelper.CreateJsonContent(new KeyValuePair<string, string>("name", authorName), new KeyValuePair<string, string>("message", message)))
+ .Result
+ .EnsureSuccessful()
+ .Content.ReadAsStringAsync()
+ .Result;
return JsonConvert.DeserializeObject<ChangeSet>(json);
}
public void Push()
{
- _client.PostAsync("push", new StringContent(String.Empty))
- .Result
- .EnsureSuccessful();
+ Client.PostAsync("push", new StringContent(String.Empty))
+ .Result
+ .EnsureSuccessful();
}
public void Update(string id)
{
- _client.PostAsync("update", HttpClientHelper.CreateJsonContent(new KeyValuePair<string, string>("id", id)))
- .Result
- .EnsureSuccessful();
+ Client.PostAsync("update", HttpClientHelper.CreateJsonContent(new KeyValuePair<string, string>("id", id)))
+ .Result
+ .EnsureSuccessful();
}
public void Update()
{
- _client.PostAsync("update", new StringContent(String.Empty))
- .Result
- .EnsureSuccessful();
+ Client.PostAsync("update", new StringContent(String.Empty))
+ .Result
+ .EnsureSuccessful();
}
}
}
View
16 Kudu.Client/SourceControl/RemoteRepositoryManager.cs
@@ -1,4 +1,5 @@
using System;
+using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Kudu.Client.Infrastructure;
@@ -8,26 +9,19 @@ namespace Kudu.Client.SourceControl
{
public class RemoteRepositoryManager : KuduRemoteClientBase
{
- public RemoteRepositoryManager(string serviceUrl)
- :base(serviceUrl)
+ public RemoteRepositoryManager(string serviceUrl, ICredentials credentials = null)
+ : base(UrlUtility.EnsureTrailingSlash(serviceUrl), credentials)
{
-
- }
-
- public RemoteRepositoryManager(string serviceUrl, HttpMessageHandler handler)
- : base(serviceUrl, handler)
- {
-
}
public Task<RepositoryInfo> GetRepositoryInfo()
{
- return _client.GetJsonAsync<RepositoryInfo>("info");
+ return Client.GetJsonAsync<RepositoryInfo>("info");
}
public Task Delete()
{
- return _client.DeleteSafeAsync(String.Empty);
+ return Client.DeleteSafeAsync(String.Empty);
}
}
}
View
118 Kudu.FunctionalTests/DeploymentManagerTests.cs
@@ -6,6 +6,7 @@
using System.Threading;
using System.Threading.Tasks;
using Kudu.Client.Deployment;
+using Kudu.Client.Infrastructure;
using Kudu.Core.Deployment;
using Kudu.FunctionalTests.Infrastructure;
using Kudu.TestHarness;
@@ -140,11 +141,10 @@ public void DeploymentManagerExtensibility()
{
var handler = new FakeMessageHandler()
{
- InnerHandler = new HttpClientHandler()
+ InnerHandler = HttpClientHelper.CreateClientHandler(appManager.DeploymentManager.ServiceUrl, appManager.DeploymentManager.Credentials)
};
- var manager = new RemoteDeploymentManager(appManager.DeploymentManager.ServiceUrl, handler);
- manager.Credentials = appManager.DeploymentManager.Credentials;
+ var manager = new RemoteDeploymentManager(appManager.DeploymentManager.ServiceUrl, appManager.DeploymentManager.Credentials, handler);
var results = manager.GetResultsAsync().Result.ToList();
Assert.Equal(0, results.Count);
@@ -190,17 +190,7 @@ public void PullApiTestGitHubFormat()
ApplicationManager.Run(appName, appManager =>
{
- var handler = new HttpClientHandler
- {
- Credentials = appManager.DeploymentManager.Credentials
- };
-
- var client = new HttpClient(handler)
- {
- BaseAddress = new Uri(appManager.ServiceUrl),
- Timeout = TimeSpan.FromMinutes(5)
- };
-
+ var client = CreateClient(appManager);
client.DefaultRequestHeaders.Add("X-Github-Event", "push");
var post = new Dictionary<string, string>
@@ -226,17 +216,7 @@ public void PullApiTestBitbucketFormat()
ApplicationManager.Run(appName, appManager =>
{
- var handler = new HttpClientHandler
- {
- Credentials = appManager.DeploymentManager.Credentials
- };
-
- var client = new HttpClient(handler)
- {
- BaseAddress = new Uri(appManager.ServiceUrl),
- Timeout = TimeSpan.FromMinutes(5)
- };
-
+ var client = CreateClient(appManager);
client.DefaultRequestHeaders.Add("User-Agent", "Bitbucket.org");
var post = new Dictionary<string, string>
@@ -250,7 +230,7 @@ public void PullApiTestBitbucketFormat()
Assert.Equal(1, results.Count);
Assert.Equal(DeployStatus.Success, results[0].Status);
Assert.True(results[0].Deployer.StartsWith("Bitbucket"));
-
+
KuduAssert.VerifyUrl(appManager.SiteUrl, "Welcome to ASP.NET!");
});
}
@@ -263,17 +243,7 @@ public void PullApiTestGitlabHQFormat()
ApplicationManager.Run(appName, appManager =>
{
- var handler = new HttpClientHandler
- {
- Credentials = appManager.DeploymentManager.Credentials
- };
-
- var client = new HttpClient(handler)
- {
- BaseAddress = new Uri(appManager.ServiceUrl),
- Timeout = TimeSpan.FromMinutes(5)
- };
-
+ var client = CreateClient(appManager);
client.PostAsync("deploy", new StringContent(payload)).Wait();
var results = appManager.DeploymentManager.GetResultsAsync().Result.ToList();
@@ -292,19 +262,9 @@ public void PullApiTestCodebaseFormat()
ApplicationManager.Run(appName, appManager =>
{
- var handler = new HttpClientHandler
- {
- Credentials = appManager.DeploymentManager.Credentials
- };
-
- var client = new HttpClient(handler)
- {
- BaseAddress = new Uri(appManager.ServiceUrl),
- Timeout = TimeSpan.FromMinutes(5)
- };
-
+ var client = CreateClient(appManager);
client.DefaultRequestHeaders.Add("User-Agent", "Codebasehq.com");
-
+
var post = new Dictionary<string, string>
{
{ "payload", payload }
@@ -328,17 +288,7 @@ public void PullApiTestGenericFormat()
ApplicationManager.Run(appName, appManager =>
{
- var handler = new HttpClientHandler
- {
- Credentials = appManager.DeploymentManager.Credentials
- };
-
- var client = new HttpClient(handler)
- {
- BaseAddress = new Uri(appManager.ServiceUrl),
- Timeout = TimeSpan.FromMinutes(5)
- };
-
+ var client = CreateClient(appManager);
var post = new Dictionary<string, string>
{
{ "payload", payload }
@@ -362,17 +312,7 @@ public void PullApiTestGenericFormatCustomBranch()
ApplicationManager.Run(appName, appManager =>
{
- var handler = new HttpClientHandler
- {
- Credentials = appManager.DeploymentManager.Credentials
- };
-
- var client = new HttpClient(handler)
- {
- BaseAddress = new Uri(appManager.ServiceUrl),
- Timeout = TimeSpan.FromMinutes(5)
- };
-
+ var client = CreateClient(appManager);
var post = new Dictionary<string, string>
{
{ "payload", payload }
@@ -397,17 +337,7 @@ public void DeployingBranchThatExists()
ApplicationManager.Run(appName, appManager =>
{
- var handler = new HttpClientHandler
- {
- Credentials = appManager.DeploymentManager.Credentials
- };
-
- var client = new HttpClient(handler)
- {
- BaseAddress = new Uri(appManager.ServiceUrl),
- Timeout = TimeSpan.FromMinutes(5)
- };
-
+ var client = CreateClient(appManager);
var post = new Dictionary<string, string>
{
{ "payload", payload }
@@ -431,17 +361,7 @@ public void PullApiTestConsecutivePushesGetQueued()
ApplicationManager.Run(appName, appManager =>
{
- var handler = new HttpClientHandler
- {
- Credentials = appManager.DeploymentManager.Credentials
- };
-
- var client = new HttpClient(handler)
- {
- BaseAddress = new Uri(appManager.ServiceUrl),
- Timeout = TimeSpan.FromMinutes(5)
- };
-
+ var client = CreateClient(appManager);
var post = new Dictionary<string, string>
{
{ "payload", payload }
@@ -453,7 +373,7 @@ public void PullApiTestConsecutivePushesGetQueued()
new Thread(() =>
{
Thread.Sleep(1000);
-
+
// Ideally we'd push something else to github but at least this exercises the code path
responseTask = client.PostAsync("deploy", new FormUrlEncodedContent(post));
@@ -471,6 +391,16 @@ public void PullApiTestConsecutivePushesGetQueued()
});
}
+ private static HttpClient CreateClient(ApplicationManager appManager)
+ {
+ HttpClientHandler handler = HttpClientHelper.CreateClientHandler(appManager.ServiceUrl, appManager.DeploymentManager.Credentials);
+ return new HttpClient(handler)
+ {
+ BaseAddress = new Uri(appManager.ServiceUrl),
+ Timeout = TimeSpan.FromMinutes(5)
+ };
+ }
+
private class FakeMessageHandler : DelegatingHandler
{
public Uri Url { get; set; }
View
7 Kudu.FunctionalTests/DropboxTests.cs
@@ -44,13 +44,8 @@ public void TestDropboxBasic()
new KeyValuePair<string, string>("dropbox_email", account.email)
).Wait();
- HttpClient client = new HttpClient();
- client.BaseAddress = new Uri(appManager.ServiceUrl);
+ HttpClient client = HttpClientHelper.CreateClient(appManager.ServiceUrl, appManager.DeploymentManager.Credentials);
client.DefaultRequestHeaders.Add("user-agent", "dropbox");
- if (appManager.DeploymentManager.Credentials != null)
- {
- client.SetClientCredentials(appManager.DeploymentManager.Credentials);
- }
client.PostAsJsonAsync("deploy", deploy).Result.EnsureSuccessStatusCode();
KuduAssert.VerifyUrl(appManager.SiteUrl + "/default.html", "Hello Default!");
View
9 Kudu.FunctionalTests/Infrastructure/KuduAssert.cs
@@ -27,9 +27,8 @@ public static void VerifyUrl(Uri url, ICredentials cred, params string[] content
public static void VerifyUrl(string url, ICredentials cred, params string[] contents)
{
- var client = new HttpClient();
+ HttpClient client = HttpClientHelper.CreateClient(url, cred);
client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("Kudu-Test", "1.0"));
- client.SetClientCredentials(cred);
var response = client.GetAsync(url).Result.EnsureSuccessful();
if (contents.Length > 0)
@@ -48,10 +47,10 @@ public static void VerifyUrl(string url, string content = null, HttpStatusCode s
client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("Kudu-Test", "1.0"));
var response = client.GetAsync(url).Result;
string responseBody = response.Content.ReadAsStringAsync().Result;
-
- Assert.True(statusCode == response.StatusCode,
+
+ Assert.True(statusCode == response.StatusCode,
String.Format("For {0}, Expected Status Code: {1} Actual Status Code: {2}. \r\n Response: {3}", url, statusCode, response.StatusCode, responseBody));
-
+
if (content != null)
{
Assert.Contains(content, responseBody, StringComparison.Ordinal);
View
6 Kudu.FunctionalTests/Vfs/LiveScmEditorControllerTest.cs
@@ -1,5 +1,4 @@
-using System;
-using Kudu.TestHarness;
+using Kudu.TestHarness;
using Xunit;
namespace Kudu.FunctionalTests
@@ -14,8 +13,7 @@ public void VfsScmIntegrationTest()
ApplicationManager.Run(appName, appManager =>
{
- string vfsController = String.Format("{0}scmvfs", appManager.ServiceUrl);
- VfsControllerBaseTest suite = new VfsControllerBaseTest(vfsController, testConflictingUpdates: true);
+ VfsControllerBaseTest suite = new VfsControllerBaseTest(appManager.LiveScmVfsManager, testConflictingUpdates: true);
// Act + Assert
suite.RunIntegrationTest();
View
83 Kudu.FunctionalTests/Vfs/VfsControllerBaseTest.cs
@@ -3,14 +3,15 @@
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
+using Kudu.Client.Editor;
+using Kudu.Client.Infrastructure;
using Xunit;
namespace Kudu.FunctionalTests
{
public class VfsControllerBaseTest
{
private static readonly char _segmentDelimiter = '/';
- private static readonly char[] _segmentDelimiters = new char[] { _segmentDelimiter };
private static readonly byte[] _fileContent0 = Encoding.UTF8.GetBytes("aaa\r\nbbb\r\nccc\r\n");
private static readonly byte[] _fileContent1 = Encoding.UTF8.GetBytes("AAA\r\nbbb\r\nccc\r\n");
@@ -28,14 +29,20 @@ public class VfsControllerBaseTest
private bool _testConflictingUpdates;
- public VfsControllerBaseTest(string baseAddress, bool testConflictingUpdates)
+ public VfsControllerBaseTest(RemoteVfsManager client, bool testConflictingUpdates)
{
- BaseAddress = baseAddress.TrimEnd(_segmentDelimiters);
+ KuduClient = client;
+ Client = client.Client;
+ BaseAddress = Client.BaseAddress.AbsoluteUri;
_testConflictingUpdates = testConflictingUpdates;
}
protected string BaseAddress { get; private set; }
+ protected RemoteVfsManager KuduClient { get; private set; }
+
+ protected HttpClient Client { get; private set; }
+
public void RunIntegrationTest()
{
string dir = Guid.NewGuid().ToString("N");
@@ -46,30 +53,29 @@ public void RunIntegrationTest()
string fileAddress = dirAddressWithTerminatingSlash + file;
string fileAddressWithTerminatingSlash = fileAddress + _segmentDelimiter;
- HttpClient client = new HttpClient();
HttpResponseMessage response;
// Check not found file responses
- response = client.GetAsync(dirAddress).Result;
+ response = Client.GetAsync(dirAddress).Result;
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
- response = client.GetAsync(dirAddressWithTerminatingSlash).Result;
+ response = Client.GetAsync(dirAddressWithTerminatingSlash).Result;
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
- response = client.GetAsync(fileAddress).Result;
+ response = Client.GetAsync(fileAddress).Result;
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
- response = client.GetAsync(fileAddressWithTerminatingSlash).Result;
+ response = Client.GetAsync(fileAddressWithTerminatingSlash).Result;
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
// Check create file results in 201 response with etag
- response = client.PutAsync(fileAddress, CreateUploadContent(_fileContent0)).Result;
+ response = Client.PutAsync(fileAddress, CreateUploadContent(_fileContent0)).Result;
Assert.Equal(HttpStatusCode.Created, response.StatusCode);
EntityTagHeaderValue originalEtag = response.Headers.ETag;
Assert.NotNull(originalEtag);
// Check that we get a 200 (OK) on created file with the correct etag
- response = client.GetAsync(fileAddress).Result;
+ response = Client.GetAsync(fileAddress).Result;
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Equal(originalEtag, response.Headers.ETag);
Assert.Equal(_fileMediaType, response.Content.Headers.ContentType);
@@ -79,7 +85,7 @@ public void RunIntegrationTest()
{
headReq.Method = HttpMethod.Head;
headReq.RequestUri = new Uri(fileAddress);
- response = client.SendAsync(headReq).Result;
+ response = Client.SendAsync(headReq).Result;
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Equal(originalEtag, response.Headers.ETag);
Assert.Equal(_fileMediaType, response.Content.Headers.ContentType);
@@ -90,7 +96,7 @@ public void RunIntegrationTest()
{
ifNoneMatchReq.RequestUri = new Uri(fileAddress);
ifNoneMatchReq.Headers.IfNoneMatch.Add(originalEtag);
- response = client.SendAsync(ifNoneMatchReq).Result;
+ response = Client.SendAsync(ifNoneMatchReq).Result;
Assert.Equal(HttpStatusCode.NotModified, response.StatusCode);
Assert.Equal(originalEtag, response.Headers.ETag);
}
@@ -100,7 +106,7 @@ public void RunIntegrationTest()
{
ifNoneMatchReqBadEtag.RequestUri = new Uri(fileAddress);
ifNoneMatchReqBadEtag.Headers.IfNoneMatch.Add(new EntityTagHeaderValue("\"NotMatching\""));
- response = client.SendAsync(ifNoneMatchReqBadEtag).Result;
+ response = Client.SendAsync(ifNoneMatchReqBadEtag).Result;
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Equal(originalEtag, response.Headers.ETag);
}
@@ -111,7 +117,7 @@ public void RunIntegrationTest()
ifRangeReq.RequestUri = new Uri(fileAddress);
ifRangeReq.Headers.IfRange = new RangeConditionHeaderValue(originalEtag);
ifRangeReq.Headers.Range = new RangeHeaderValue(0, 0) { Unit = "bytes" };
- response = client.SendAsync(ifRangeReq).Result;
+ response = Client.SendAsync(ifRangeReq).Result;
Assert.Equal(HttpStatusCode.PartialContent, response.StatusCode);
Assert.Equal(originalEtag, response.Headers.ETag);
Assert.Equal(1, response.Content.Headers.ContentLength);
@@ -123,7 +129,7 @@ public void RunIntegrationTest()
{
ifRangeReqNoRange.RequestUri = new Uri(fileAddress);
ifRangeReqNoRange.Headers.IfRange = new RangeConditionHeaderValue(originalEtag);
- response = client.SendAsync(ifRangeReqNoRange).Result;
+ response = Client.SendAsync(ifRangeReqNoRange).Result;
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Equal(originalEtag, response.Headers.ETag);
}
@@ -135,22 +141,23 @@ public void RunIntegrationTest()
ifRangeReqBadRange.RequestUri = new Uri(fileAddress);
ifRangeReqBadRange.Headers.IfRange = new RangeConditionHeaderValue(originalEtag);
ifRangeReqBadRange.Headers.Range = new RangeHeaderValue(100, 100) { Unit = "bytes" };
- response = client.SendAsync(ifRangeReqBadRange).Result;
+ response = Client.SendAsync(ifRangeReqBadRange).Result;
Assert.Equal(HttpStatusCode.RequestedRangeNotSatisfiable, response.StatusCode);
Assert.Equal(_fileContentRange, response.Content.Headers.ContentRange);
}
// Check that we get a root directory view
- response = client.GetAsync(BaseAddress).Result;
+ response = Client.GetAsync(BaseAddress).Result;
Assert.Equal(_dirMediaType, response.Content.Headers.ContentType);
// Check that we get a directory view from folder
- response = client.GetAsync(dirAddress).Result;
+ response = Client.GetAsync(dirAddress).Result;
Assert.Equal(_dirMediaType, response.Content.Headers.ContentType);
// Check various redirects between files and folders
- HttpClientHandler redirectHandler = new HttpClientHandler { AllowAutoRedirect = false };
- using (HttpClient redirectClient = new HttpClient(redirectHandler))
+ HttpClientHandler redirectHandler = HttpClientHelper.CreateClientHandler(BaseAddress, KuduClient.Credentials);
+ redirectHandler.AllowAutoRedirect = false;
+ using (HttpClient redirectClient = HttpClientHelper.CreateClient(BaseAddress, KuduClient.Credentials, redirectHandler))
{
// Ensure that requests to root without slash is redirected to one with slash
response = redirectClient.GetAsync(BaseAddress).Result;
@@ -169,16 +176,16 @@ public void RunIntegrationTest()
}
// Check that 2nd create attempt fails
- response = client.PutAsync(fileAddress, CreateUploadContent(_fileContent0)).Result;
+ response = Client.PutAsync(fileAddress, CreateUploadContent(_fileContent0)).Result;
Assert.Equal(HttpStatusCode.PreconditionFailed, response.StatusCode);
Assert.Equal(originalEtag, response.Headers.ETag);
// Check that we can't update a directory
- response = client.PutAsync(dirAddress, CreateUploadContent(_fileContent0)).Result;
+ response = Client.PutAsync(dirAddress, CreateUploadContent(_fileContent0)).Result;
Assert.Equal(HttpStatusCode.Conflict, response.StatusCode);
// Check that we can't delete a directory
- response = client.DeleteAsync(dirAddress).Result;
+ response = Client.DeleteAsync(dirAddress).Result;
Assert.Equal(HttpStatusCode.Conflict, response.StatusCode);
EntityTagHeaderValue updatedEtag;
@@ -191,7 +198,7 @@ public void RunIntegrationTest()
update1.RequestUri = new Uri(fileAddress);
update1.Headers.IfMatch.Add(originalEtag);
update1.Content = CreateUploadContent(_fileContent1);
- response = client.SendAsync(update1).Result;
+ response = Client.SendAsync(update1).Result;
Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);
Assert.NotNull(response.Headers.ETag);
Assert.NotEqual(originalEtag, response.Headers.ETag);
@@ -205,7 +212,7 @@ public void RunIntegrationTest()
update2.RequestUri = new Uri(fileAddress);
update2.Headers.IfMatch.Add(originalEtag);
update2.Content = CreateUploadContent(_fileContent2);
- response = client.SendAsync(update2).Result;
+ response = Client.SendAsync(update2).Result;
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.NotNull(response.Headers.ETag);
Assert.NotEqual(updatedEtag, response.Headers.ETag);
@@ -220,7 +227,7 @@ public void RunIntegrationTest()
update3.RequestUri = new Uri(fileAddress);
update3.Headers.IfMatch.Add(originalEtag);
update3.Content = CreateUploadContent(_fileContent3);
- response = client.SendAsync(update3).Result;
+ response = Client.SendAsync(update3).Result;
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.NotNull(response.Headers.ETag);
Assert.Equal(updatedEtag, response.Headers.ETag);
@@ -235,7 +242,7 @@ public void RunIntegrationTest()
update4.RequestUri = new Uri(fileAddress);
update4.Headers.IfMatch.Add(originalEtag);
update4.Content = CreateUploadContent(_fileContent4);
- response = client.SendAsync(update4).Result;
+ response = Client.SendAsync(update4).Result;
Assert.Equal(HttpStatusCode.Conflict, response.StatusCode);
Assert.Equal(_conflictMediaType, response.Content.Headers.ContentType);
Assert.Null(response.Headers.ETag);
@@ -250,7 +257,7 @@ public void RunIntegrationTest()
update5.RequestUri = new Uri(fileAddress);
update5.Headers.IfMatch.Add(new EntityTagHeaderValue("\"invalidetag\""));
update5.Content = CreateUploadContent(_fileContent1);
- response = client.SendAsync(update5).Result;
+ response = Client.SendAsync(update5).Result;
Assert.Equal(HttpStatusCode.PreconditionFailed, response.StatusCode);
Assert.Equal(updatedEtag, response.Headers.ETag);
}
@@ -261,7 +268,7 @@ public void RunIntegrationTest()
deleteRequest.Method = HttpMethod.Delete;
deleteRequest.RequestUri = new Uri(fileAddress);
deleteRequest.Headers.IfMatch.Add(new EntityTagHeaderValue("\"invalidetag\""));
- response = client.SendAsync(deleteRequest).Result;
+ response = Client.SendAsync(deleteRequest).Result;
Assert.Equal(HttpStatusCode.PreconditionFailed, response.StatusCode);
Assert.Equal(updatedEtag, response.Headers.ETag);
}
@@ -272,7 +279,7 @@ public void RunIntegrationTest()
deleteRequest.Method = HttpMethod.Delete;
deleteRequest.RequestUri = new Uri(fileAddress);
deleteRequest.Headers.IfMatch.Add(originalEtag);
- response = client.SendAsync(deleteRequest).Result;
+ response = Client.SendAsync(deleteRequest).Result;
Assert.Equal(HttpStatusCode.Conflict, response.StatusCode);
}
@@ -282,7 +289,7 @@ public void RunIntegrationTest()
deleteRequest.Method = HttpMethod.Delete;
deleteRequest.RequestUri = new Uri(fileAddress);
deleteRequest.Headers.IfMatch.Add(updatedEtag);
- response = client.SendAsync(deleteRequest).Result;
+ response = Client.SendAsync(deleteRequest).Result;
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}
@@ -292,7 +299,7 @@ public void RunIntegrationTest()
deleteRequest.Method = HttpMethod.Delete;
deleteRequest.RequestUri = new Uri(fileAddress);
deleteRequest.Headers.IfMatch.Add(updatedEtag);
- response = client.SendAsync(deleteRequest).Result;
+ response = Client.SendAsync(deleteRequest).Result;
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
}
}
@@ -305,7 +312,7 @@ public void RunIntegrationTest()
updateRequest.RequestUri = new Uri(fileAddress);
updateRequest.Headers.IfMatch.Add(originalEtag);
updateRequest.Content = CreateUploadContent(_fileContent1);
- response = client.SendAsync(updateRequest).Result;
+ response = Client.SendAsync(updateRequest).Result;
Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);
Assert.NotNull(response.Headers.ETag);
Assert.NotEqual(originalEtag, response.Headers.ETag);
@@ -319,7 +326,7 @@ public void RunIntegrationTest()
updateRequest.RequestUri = new Uri(fileAddress);
updateRequest.Headers.IfMatch.Add(originalEtag);
updateRequest.Content = CreateUploadContent(_fileContent2);
- response = client.SendAsync(updateRequest).Result;
+ response = Client.SendAsync(updateRequest).Result;
Assert.Equal(HttpStatusCode.PreconditionFailed, response.StatusCode);
Assert.Equal(updatedEtag, response.Headers.ETag);
}
@@ -331,7 +338,7 @@ public void RunIntegrationTest()
updateRequest.RequestUri = new Uri(fileAddress);
updateRequest.Headers.IfMatch.Add(new EntityTagHeaderValue("\"invalidetag\""));
updateRequest.Content = CreateUploadContent(_fileContent1);
- response = client.SendAsync(updateRequest).Result;
+ response = Client.SendAsync(updateRequest).Result;
Assert.Equal(HttpStatusCode.PreconditionFailed, response.StatusCode);
Assert.Equal(updatedEtag, response.Headers.ETag);
}
@@ -342,7 +349,7 @@ public void RunIntegrationTest()
deleteRequest.Method = HttpMethod.Delete;
deleteRequest.RequestUri = new Uri(fileAddress);
deleteRequest.Headers.IfMatch.Add(new EntityTagHeaderValue("\"invalidetag\""));
- response = client.SendAsync(deleteRequest).Result;
+ response = Client.SendAsync(deleteRequest).Result;
Assert.Equal(HttpStatusCode.PreconditionFailed, response.StatusCode);
Assert.Equal(updatedEtag, response.Headers.ETag);
}
@@ -353,7 +360,7 @@ public void RunIntegrationTest()
deleteRequest.Method = HttpMethod.Delete;
deleteRequest.RequestUri = new Uri(fileAddress);
deleteRequest.Headers.IfMatch.Add(updatedEtag);
- response = client.SendAsync(deleteRequest).Result;
+ response = Client.SendAsync(deleteRequest).Result;
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}
@@ -363,7 +370,7 @@ public void RunIntegrationTest()
deleteRequest.Method = HttpMethod.Delete;
deleteRequest.RequestUri = new Uri(fileAddress);
deleteRequest.Headers.IfMatch.Add(updatedEtag);
- response = client.SendAsync(deleteRequest).Result;
+ response = Client.SendAsync(deleteRequest).Result;
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
}
}
View
6 Kudu.FunctionalTests/Vfs/VfsControllerTest.cs
@@ -1,5 +1,4 @@
-using System;
-using Kudu.TestHarness;
+using Kudu.TestHarness;
using Xunit;
namespace Kudu.FunctionalTests
@@ -14,8 +13,7 @@ public void VfsIntegrationTest()
ApplicationManager.Run(appName, appManager =>
{
- string vfsController = String.Format("{0}vfs", appManager.ServiceUrl);
- VfsControllerBaseTest suite = new VfsControllerBaseTest(vfsController, testConflictingUpdates: false);
+ VfsControllerBaseTest suite = new VfsControllerBaseTest(appManager.VfsManager, testConflictingUpdates: false);
// Act + Assert
suite.RunIntegrationTest();
View
18 Kudu.TestHarness/ApplicationManager.cs
@@ -74,6 +74,18 @@ public RemoteSSHKeyManager SSHKeyManager
private set;
}
+ public RemoteVfsManager VfsManager
+ {
+ get;
+ private set;
+ }
+
+ public RemoteVfsManager LiveScmVfsManager
+ {
+ get;
+ private set;
+ }
+
public string GitUrl
{
get;
@@ -145,7 +157,7 @@ public static ApplicationManager CreateApplication(string applicationName)
var siteManager = GetSiteManager(pathResolver, settingsResolver);
Site site;
-
+
if (KuduUtils.ReuseSameSiteForAllTests)
{
// In site reuse mode, try to get the existing site, and create it if needed
@@ -182,7 +194,9 @@ public static ApplicationManager CreateApplication(string applicationName)
SettingsManager = new RemoteDeploymentSettingsManager(site.ServiceUrl + "settings"),
LogStreamManager = new RemoteLogStreamManager(site.ServiceUrl + "logstream"),
SSHKeyManager = new RemoteSSHKeyManager(site.ServiceUrl + "sshkey"),
- RepositoryManager = repositoryManager
+ VfsManager = new RemoteVfsManager(site.ServiceUrl + "vfs"),
+ LiveScmVfsManager = new RemoteVfsManager(site.ServiceUrl + "scmvfs"),
+ RepositoryManager = repositoryManager,
};
}
View
13 Kudu.TestHarness/DeploymentManagerExtensions.cs
@@ -1,31 +1,26 @@
-using System;
-using System.Diagnostics;
+using System.Diagnostics;
using System.IO;
-using System.Threading;
using System.Threading.Tasks;
using System.Xml.Linq;
-using Kudu.Client.Deployment;
-using Kudu.Core.Deployment;
namespace Kudu.TestHarness
{
public static class DeploymentManagerExtensions
{
public static XDocument GetServerProfile(this ApplicationManager appManager, string applicationName)
- {
+ {
var zippedLogsPath = Path.Combine(PathHelper.TestResultsPath, applicationName + ".zip");
var unzippedLogsPath = Path.Combine(PathHelper.TestResultsPath, applicationName);
var profileLogPath = Path.Combine(unzippedLogsPath, "profiles", "profile.xml");
- return KuduUtils.GetServerProfile(appManager.ServiceUrl, zippedLogsPath, applicationName);
+ return KuduUtils.GetServerProfile(appManager.ServiceUrl, zippedLogsPath, applicationName);
}
private static void WaitForRepositorySite(ApplicationManager appManager)
{
- HttpUtils.WaitForSite(appManager.ServiceUrl);
+ HttpUtils.WaitForSite(appManager.ServiceUrl, appManager.DeploymentManager.Credentials);
}
-
private static void OnUnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
{
Debug.WriteLine(e.Exception.GetBaseException().ToString());
View
3 Kudu.TestHarness/Git.cs
@@ -135,8 +135,7 @@ private static string CreateCachedRepo(string repositoryName, string source, IDi
public static GitDeploymentResult GitDeploy(string kuduServiceUrl, string localRepoPath, string remoteRepoUrl, string localBranchName, string remoteBranchName)
{
- var deploymentManager = new RemoteDeploymentManager(kuduServiceUrl);
-
+ var deploymentManager = new RemoteDeploymentManager(kuduServiceUrl + "deployments");
return GitDeploy(deploymentManager, kuduServiceUrl, localRepoPath, remoteRepoUrl, localBranchName, remoteBranchName);
}
View
8 Kudu.TestHarness/HttpUtils.cs
@@ -1,14 +1,16 @@
using System.Net;
using System.Net.Http;
using System.Threading;
+using Kudu.Client.Infrastructure;
namespace Kudu.TestHarness
{
public class HttpUtils
{
- public static void WaitForSite(string siteUrl, int retries = 3, int delayBeforeRetry = 250)
+ public static void WaitForSite(string siteUrl, ICredentials credentials = null, int retries = 3, int delayBeforeRetry = 250)
{
- var client = new HttpClient();
+ var handler = HttpClientHelper.CreateClientHandler(siteUrl, credentials);
+ var client = new HttpClient(handler);
while (retries > 0)
{
@@ -30,6 +32,6 @@ public static void WaitForSite(string siteUrl, int retries = 3, int delayBeforeR
retries--;
Thread.Sleep(delayBeforeRetry);
}
- }
+ }
}
}
View
9 Kudu.TestHarness/KuduUtils.cs
@@ -5,6 +5,7 @@
using System.Net;
using System.Net.Http;
using System.Xml.Linq;
+using Kudu.Client.Infrastructure;
namespace Kudu.TestHarness
{
@@ -16,12 +17,8 @@ public static void DownloadDump(string serviceUrl, string zippedLogsPath, Networ
{
Directory.CreateDirectory(Path.GetDirectoryName(zippedLogsPath));
- var client = new HttpClient(new HttpClientHandler()
- {
- Credentials = credentials
- });
-
-
+ var clientHandler = HttpClientHelper.CreateClientHandler(serviceUrl, credentials);
+ var client = new HttpClient(clientHandler);
var result = client.GetAsync(serviceUrl + "dump").Result;
if (result.IsSuccessStatusCode)
{
View
9 Kudu.TestHarness/RemoteLogStreamManager.cs
@@ -9,8 +9,8 @@ namespace Kudu.TestHarness
// This is a test class current workaround Stream.Close hangs.
public class RemoteLogStreamManager : KuduRemoteClientBase
{
- public RemoteLogStreamManager(string serviceUrl)
- : base(serviceUrl)
+ public RemoteLogStreamManager(string serviceUrl, ICredentials credentials = null)
+ : base(UrlUtility.EnsureTrailingSlash(serviceUrl), credentials)
{
}
@@ -20,10 +20,9 @@ public Task<Stream> GetStream()
TaskCompletionSource<Stream> tcs = new TaskCompletionSource<Stream>();
RequestState state = new RequestState { Manager = this, TaskCompletionSource = tcs, Request = request };
- if (this._client.DefaultRequestHeaders.Authorization != null)
+ if (Client.DefaultRequestHeaders.Authorization != null)
{
-
- request.Headers["Authorization"] = this._client.DefaultRequestHeaders.Authorization.Scheme + " " + this._client.DefaultRequestHeaders.Authorization.Parameter;
+ request.Headers["Authorization"] = Client.DefaultRequestHeaders.Authorization.Scheme + " " + Client.DefaultRequestHeaders.Authorization.Parameter;
}
IAsyncResult result = request.BeginGetResponse(RemoteLogStreamManager.OnGetResponse, state);
View
18 Kudu.Web/Infrastructure/ApplicationExtensions.cs
@@ -3,8 +3,8 @@
using System.Threading.Tasks;
using System.Xml.Linq;
using Kudu.Client.Deployment;
+using Kudu.Client.Infrastructure;
using Kudu.Client.SourceControl;
-using Kudu.Contracts.Infrastructure;
using Kudu.Core.SourceControl;
using Kudu.Web.Models;
@@ -14,32 +14,26 @@ public static class ApplicationExtensions
{
public static Task<RepositoryInfo> GetRepositoryInfo(this IApplication application, ICredentials credentials)
{
- var repositoryManager = new RemoteRepositoryManager(application.ServiceUrl + "live/scm");
- repositoryManager.Credentials = credentials;
+ var repositoryManager = new RemoteRepositoryManager(application.ServiceUrl + "live/scm", credentials);
return repositoryManager.GetRepositoryInfo();
}
public static RemoteDeploymentManager GetDeploymentManager(this IApplication application, ICredentials credentials)
{
- var deploymentManager = new RemoteDeploymentManager(application.ServiceUrl + "/deployments");
- deploymentManager.Credentials = credentials;
+ var deploymentManager = new RemoteDeploymentManager(application.ServiceUrl + "/deployments", credentials);
return deploymentManager;
}
public static RemoteDeploymentSettingsManager GetSettingsManager(this IApplication application, ICredentials credentials)
{
- var deploymentSettingsManager = new RemoteDeploymentSettingsManager(application.ServiceUrl + "/settings");
- deploymentSettingsManager.Credentials = credentials;
+ var deploymentSettingsManager = new RemoteDeploymentSettingsManager(application.ServiceUrl + "/settings", credentials);
return deploymentSettingsManager;
}
public static Task<XDocument> DownloadTrace(this IApplication application, ICredentials credentials)
{
- var client = new HttpClient(new HttpClientHandler()
- {
- Credentials = credentials
- });
-
+ var clientHandler = HttpClientHelper.CreateClientHandler(application.ServiceUrl, credentials);
+ var client = new HttpClient(clientHandler);
return client.GetAsync(application.ServiceUrl + "dump").Then(response =>
{

0 comments on commit d269c81

Please sign in to comment.