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. // 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 // 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); .ToString(CultureInfo.InvariantCulture);
} }

View File

@ -84,9 +84,9 @@ namespace Microsoft.AspNetCore.Authentication.OpenIdConnect
{ {
base.Validate(); 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)) 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 /// 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. /// re-authenticate. By default no max_age is specified.
/// </summary> /// </summary>
public TimeSpan? MaxAge { get; set; } = null; public TimeSpan? MaxAge { get; set; }
/// <summary> /// <summary>
/// Gets or sets the <see cref="OpenIdConnectProtocolValidator"/> that is used to ensure that the 'id_token' received /// 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() public async Task Challenge_WithDefaultMaxAge_HasExpectedMaxAgeParam()
{ {
var settings = new TestSettings( var settings = new TestSettings(
opt => opt =>
{ {
opt.ClientId = "Test Id"; opt.ClientId = "Test Id";
opt.Authority = TestServerBuilder.DefaultAuthority; opt.Authority = TestServerBuilder.DefaultAuthority;
}); });
@ -434,8 +434,8 @@ namespace Microsoft.AspNetCore.Authentication.Test.OpenIdConnect
public async Task Challenge_WithSpecificMaxAge_HasExpectedMaxAgeParam() public async Task Challenge_WithSpecificMaxAge_HasExpectedMaxAgeParam()
{ {
var settings = new TestSettings( var settings = new TestSettings(
opt => opt =>
{ {
opt.ClientId = "Test Id"; opt.ClientId = "Test Id";
opt.Authority = TestServerBuilder.DefaultAuthority; opt.Authority = TestServerBuilder.DefaultAuthority;
opt.MaxAge = TimeSpan.FromMinutes(20); opt.MaxAge = TimeSpan.FromMinutes(20);

View File

@ -118,7 +118,7 @@ namespace Microsoft.AspNetCore.Authentication.Test.OpenIdConnect
[Fact] [Fact]
public Task ThrowsWhenMaxAgeIsNegative() public Task ThrowsWhenMaxAgeIsNegative()
{ {
return TestConfigurationException<InvalidOperationException>( return TestConfigurationException<ArgumentOutOfRangeException>(
o => o =>
{ {
o.SignInScheme = "TestScheme"; o.SignInScheme = "TestScheme";
@ -126,7 +126,7 @@ namespace Microsoft.AspNetCore.Authentication.Test.OpenIdConnect
o.Authority = TestServerBuilder.DefaultAuthority; o.Authority = TestServerBuilder.DefaultAuthority;
o.MaxAge = TimeSpan.FromSeconds(-1); 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;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Globalization;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Text; using System.Text;
using System.Text.Encodings.Web; using System.Text.Encodings.Web;
using System.Xml.Linq; using System.Xml.Linq;
using Microsoft.AspNetCore.Authentication.OpenIdConnect; using Microsoft.AspNetCore.Authentication.OpenIdConnect;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.TestHost; using Microsoft.AspNetCore.TestHost;
using Microsoft.IdentityModel.Protocols.OpenIdConnect; using Microsoft.IdentityModel.Protocols.OpenIdConnect;
using Xunit; using Xunit;
@ -270,10 +268,10 @@ namespace Microsoft.AspNetCore.Authentication.Test.OpenIdConnect
private void ValidateMaxAge(IDictionary<string, string> actualQuery, ICollection<string> errors, bool htmlEncoded) 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)) Assert.Equal(TimeSpan.FromMinutes(20), _options.MaxAge.Value);
.ToString(CultureInfo.InvariantCulture); string expectedMaxAge = "1200";
ValidateParameter(OpenIdConnectParameterNames.MaxAge, expectedMaxAge, actualQuery, errors, htmlEncoded); ValidateParameter(OpenIdConnectParameterNames.MaxAge, expectedMaxAge, actualQuery, errors, htmlEncoded);
} }
else if(actualQuery.ContainsKey(OpenIdConnectParameterNames.MaxAge)) else if(actualQuery.ContainsKey(OpenIdConnectParameterNames.MaxAge))