Skip to content

Commit

Permalink
removal of IsAuthenticated for now and replaces with a call to Authen…
Browse files Browse the repository at this point in the history
…ticate if required
  • Loading branch information
stack72 committed Apr 12, 2012
1 parent ab3eef2 commit 6ff1350
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
16 changes: 4 additions & 12 deletions src/TeamCitySharp/Connection/TeamCityCaller.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Dynamic;
using System.Net;
using System.Security.Authentication;
using EasyHttp.Http;
Expand Down Expand Up @@ -76,7 +75,6 @@ HttpClient CreateHttpRequest(string userName, string password)
{
var httpClient = new HttpClient(new TeamcityJsonEncoderDecoderConfiguration());
httpClient.Request.Accept = HttpContentTypes.ApplicationJson;
httpClient.ThrowExceptionOnHttpError = true;
if (!_configuration.ActAsGuest)
{
httpClient.Request.SetBasicAuthentication(userName, password);
Expand All @@ -90,19 +88,13 @@ public bool Authenticate(string urlPart)
{
try
{
var httpClient = new HttpClient{};
httpClient.ThrowExceptionOnHttpError = true;
var httpClient = CreateHttpRequest(_configuration.UserName, _configuration.Password);
httpClient.Request.Accept = HttpContentTypes.TextPlain;
if (!_configuration.ActAsGuest)
{
httpClient.Request.SetBasicAuthentication(_configuration.UserName, _configuration.Password);
httpClient.Request.ForceBasicAuth = true;
}

httpClient.ThrowExceptionOnHttpError = true;
httpClient.Get(CreateUrl(urlPart));
var response = httpClient.Response;

return (response.StatusCode == HttpStatusCode.OK);
var response = httpClient.Response;
return response.StatusCode == HttpStatusCode.OK;
}
catch (HttpException exception)
{
Expand Down
2 changes: 1 addition & 1 deletion src/TeamCitySharp/ITeamCityClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace TeamCitySharp
public interface ITeamCityClient
{
void Connect(string userName, string password, bool actAsGuest = false);
bool IsAuthenticated { get; }
bool Authenticate();
List<Project> AllProjects();
Project ProjectByName(string projectLocatorName);
Project ProjectById(string projectLocatorId);
Expand Down
7 changes: 5 additions & 2 deletions src/TeamCitySharp/TeamCityClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ namespace TeamCitySharp
public class TeamCityClient : IClientConnection, ITeamCityClient
{
private readonly TeamCityCaller _caller;
public bool IsAuthenticated { get; private set; }

public TeamCityClient(string hostName, bool useSsl = false)
{
Expand All @@ -20,7 +19,11 @@ public TeamCityClient(string hostName, bool useSsl = false)
public void Connect(string userName, string password, bool actAsGuest = false)
{
_caller.Connect(userName, password, actAsGuest);
IsAuthenticated = _caller.Authenticate("/app/rest");
}

public bool Authenticate()
{
return _caller.Authenticate("/app/rest");
}

public List<Project> AllProjects()
Expand Down
6 changes: 4 additions & 2 deletions src/Tests/IntegrationTests/SampleConnectionUsage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@ public void SetUp()
public void it_will_authenticate_a_known_user()
{
_client.Connect("admin", "qwerty");
Assert.That(_client.IsAuthenticated);

Assert.That(_client.Authenticate());
}

[Test]
[ExpectedException(typeof(AuthenticationException))]
public void it_will_throw_an_exception_for_an_unknown_user()
{
_client.Connect("smithy", "smithy");

_client.Authenticate();

//Assert.Throws Exception
}

Expand Down

0 comments on commit 6ff1350

Please sign in to comment.