Fallback to anon with invalid auth data

This commit is contained in:
Tim Clem
2012-04-27 09:33:21 -07:00
parent 82ed920b34
commit 46f1a7d6b5
2 changed files with 49 additions and 5 deletions
+34
View File
@@ -5,6 +5,7 @@ using System.Text;
using System.Threading.Tasks;
using Xunit;
using FluentAssertions;
using Xunit.Extensions;
namespace Burr.Tests
{
@@ -35,6 +36,39 @@ namespace Burr.Tests
client.AuthenticationType.Should().Be(AuthenticationType.Oauth);
}
[InlineData("")]
[InlineData(" ")]
[InlineData(null)]
[Theory]
public void InvalidTokenFallsBackToAnon(string t)
{
var client = new GitHubClient { Token = t };
client.AuthenticationType.Should().Be(AuthenticationType.Anonymous);
}
[InlineData("")]
[InlineData(" ")]
[InlineData(null)]
[Theory]
public void InvalidUserNameFallsBackToAnon(string t)
{
var client = new GitHubClient { Username = t };
client.AuthenticationType.Should().Be(AuthenticationType.Anonymous);
}
[InlineData("")]
[InlineData(" ")]
[InlineData(null)]
[Theory]
public void InvalidPasswordFallsBackToAnon(string t)
{
var client = new GitHubClient { Password = t };
client.AuthenticationType.Should().Be(AuthenticationType.Anonymous);
}
}
}
}
+15 -5
View File
@@ -17,7 +17,7 @@ namespace Burr
{
public GitHubClient()
{
AuthenticationType = Burr.AuthenticationType.Anonymous;
AuthenticationType = AuthenticationType.Anonymous;
}
public AuthenticationType AuthenticationType { get; private set; }
@@ -26,13 +26,17 @@ namespace Burr
public string Username
{
get { return username; }
set {
set
{
if (value == username) return;
Token = null;
AuthenticationType = Burr.AuthenticationType.Basic;
username = value;
if (username.IsNotBlank())
{
AuthenticationType = AuthenticationType.Basic;
}
}
}
@@ -45,9 +49,12 @@ namespace Burr
if (value == password) return;
Token = null;
AuthenticationType = Burr.AuthenticationType.Basic;
password = value;
if (password.IsNotBlank())
{
AuthenticationType = AuthenticationType.Basic;
}
}
}
@@ -61,9 +68,12 @@ namespace Burr
Username = null;
Password = null;
AuthenticationType = Burr.AuthenticationType.Oauth;
token = value;
if (token.IsNotBlank())
{
AuthenticationType = AuthenticationType.Oauth;
}
}
}
}