PR style cleanup

This commit is contained in:
Chris Ross (ASP.NET) 2017-10-09 09:53:21 -07:00
parent e34a5f8fb8
commit 0904af8ff3
5 changed files with 14 additions and 16 deletions

View File

@ -355,9 +355,9 @@ namespace Microsoft.AspNetCore.Authentication.OpenIdConnect
// Add the 'max_age' parameter to the authentication request if MaxAge is not null.
// See http://openid.net/specs/openid-connect-core-1_0.html#AuthRequest
if (Options.MaxAge != null)
if (Options.MaxAge.HasValue)
{
message.MaxAge = Convert.ToInt64(Math.Floor(((TimeSpan)Options.MaxAge).TotalSeconds))
message.MaxAge = Convert.ToInt64(Math.Floor((Options.MaxAge.Value).TotalSeconds))
.ToString(CultureInfo.InvariantCulture);
}

View File

@ -84,9 +84,9 @@ namespace Microsoft.AspNetCore.Authentication.OpenIdConnect
{
base.Validate();
if (MaxAge != null && MaxAge.Value < TimeSpan.Zero)
if (MaxAge.HasValue && MaxAge.Value < TimeSpan.Zero)
{
throw new InvalidOperationException("MaxAge must not be a negative TimeSpan.");
throw new ArgumentOutOfRangeException(nameof(MaxAge), MaxAge.Value, "The value must not be a negative TimeSpan.");
}
if (string.IsNullOrEmpty(ClientId))
@ -169,7 +169,7 @@ namespace Microsoft.AspNetCore.Authentication.OpenIdConnect
/// provider has not actively authenticated the user within the length of time specified, the user will be prompted to
/// re-authenticate. By default no max_age is specified.
/// </summary>
public TimeSpan? MaxAge { get; set; } = null;
public TimeSpan? MaxAge { get; set; }
/// <summary>
/// Gets or sets the <see cref="OpenIdConnectProtocolValidator"/> that is used to ensure that the 'id_token' received

View File

@ -414,8 +414,8 @@ namespace Microsoft.AspNetCore.Authentication.Test.OpenIdConnect
public async Task Challenge_WithDefaultMaxAge_HasExpectedMaxAgeParam()
{
var settings = new TestSettings(
opt =>
{
opt =>
{
opt.ClientId = "Test Id";
opt.Authority = TestServerBuilder.DefaultAuthority;
});
@ -434,8 +434,8 @@ namespace Microsoft.AspNetCore.Authentication.Test.OpenIdConnect
public async Task Challenge_WithSpecificMaxAge_HasExpectedMaxAgeParam()
{
var settings = new TestSettings(
opt =>
{
opt =>
{
opt.ClientId = "Test Id";
opt.Authority = TestServerBuilder.DefaultAuthority;
opt.MaxAge = TimeSpan.FromMinutes(20);

View File

@ -118,7 +118,7 @@ namespace Microsoft.AspNetCore.Authentication.Test.OpenIdConnect
[Fact]
public Task ThrowsWhenMaxAgeIsNegative()
{
return TestConfigurationException<InvalidOperationException>(
return TestConfigurationException<ArgumentOutOfRangeException>(
o =>
{
o.SignInScheme = "TestScheme";
@ -126,7 +126,7 @@ namespace Microsoft.AspNetCore.Authentication.Test.OpenIdConnect
o.Authority = TestServerBuilder.DefaultAuthority;
o.MaxAge = TimeSpan.FromSeconds(-1);
},
ex => Assert.Equal("MaxAge must not be a negative TimeSpan.", ex.Message)
ex => Assert.StartsWith("The value must not be a negative TimeSpan.", ex.Message)
);
}

View File

@ -4,14 +4,12 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.Encodings.Web;
using System.Xml.Linq;
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.TestHost;
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
using Xunit;
@ -270,10 +268,10 @@ namespace Microsoft.AspNetCore.Authentication.Test.OpenIdConnect
private void ValidateMaxAge(IDictionary<string, string> actualQuery, ICollection<string> errors, bool htmlEncoded)
{
if(_options.MaxAge != null)
if(_options.MaxAge.HasValue)
{
string expectedMaxAge = Convert.ToInt64(Math.Floor(((TimeSpan)_options.MaxAge).TotalSeconds))
.ToString(CultureInfo.InvariantCulture);
Assert.Equal(TimeSpan.FromMinutes(20), _options.MaxAge.Value);
string expectedMaxAge = "1200";
ValidateParameter(OpenIdConnectParameterNames.MaxAge, expectedMaxAge, actualQuery, errors, htmlEncoded);
}
else if(actualQuery.ContainsKey(OpenIdConnectParameterNames.MaxAge))