From 46f1a7d6b51747419469735eb8a50493d45c658d Mon Sep 17 00:00:00 2001 From: Tim Clem Date: Fri, 27 Apr 2012 09:33:21 -0700 Subject: [PATCH] Fallback to anon with invalid auth data --- Burr.Tests/GitHubClientTests.cs | 34 +++++++++++++++++++++++++++++++++ Burr/GitHubClient.cs | 20 ++++++++++++++----- 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/Burr.Tests/GitHubClientTests.cs b/Burr.Tests/GitHubClientTests.cs index ae3fe4ff..81580a67 100644 --- a/Burr.Tests/GitHubClientTests.cs +++ b/Burr.Tests/GitHubClientTests.cs @@ -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); + } } } } diff --git a/Burr/GitHubClient.cs b/Burr/GitHubClient.cs index 6c46d264..cfcf806d 100644 --- a/Burr/GitHubClient.cs +++ b/Burr/GitHubClient.cs @@ -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; + } } } }