Skip to content
This repository was archived by the owner on Dec 24, 2020. It is now read-only.

Commit 9a6a0eb

Browse files
committed
Split the unit tests classes into separate handler/middleware tests classes
1 parent 0125c36 commit 9a6a0eb

11 files changed

Lines changed: 2098 additions & 1951 deletions

File tree

src/Owin.Security.OAuth.Introspection/OAuthIntrospectionExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public static IAppBuilder UseOAuthIntrospection(
5454
throw new ArgumentNullException(nameof(options));
5555
}
5656

57-
return app.Use<OAuthIntrospectionMiddleware>(app, options);
57+
return app.Use<OAuthIntrospectionMiddleware>(app.Properties, options);
5858
}
5959
}
6060
}

src/Owin.Security.OAuth.Introspection/OAuthIntrospectionMiddleware.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
using System;
8+
using System.Collections.Generic;
89
using System.Net.Http;
910
using JetBrains.Annotations;
1011
using Microsoft.AspNetCore.DataProtection;
@@ -20,7 +21,7 @@ namespace Owin.Security.OAuth.Introspection {
2021
public class OAuthIntrospectionMiddleware : AuthenticationMiddleware<OAuthIntrospectionOptions> {
2122
public OAuthIntrospectionMiddleware(
2223
[NotNull] OwinMiddleware next,
23-
[NotNull] IAppBuilder app,
24+
[NotNull] IDictionary<string, object> properties,
2425
[NotNull] OAuthIntrospectionOptions options)
2526
: base(next, options) {
2627
if (string.IsNullOrEmpty(options.Authority) &&
@@ -38,14 +39,13 @@ public OAuthIntrospectionMiddleware(
3839
}
3940

4041
if (options.DataProtectionProvider == null) {
41-
// Try to use the application name provided by
42-
// the OWIN host as the application discriminator.
43-
var discriminator = new AppProperties(app.Properties).AppName;
44-
45-
// When an application discriminator cannot be resolved from
46-
// the OWIN host properties, generate a temporary identifier.
42+
// Use the application name provided by the OWIN host as the Data Protection discriminator.
43+
// If the application name cannot be resolved, throw an invalid operation exception.
44+
var discriminator = new AppProperties(properties).AppName;
4745
if (string.IsNullOrEmpty(discriminator)) {
48-
discriminator = Guid.NewGuid().ToString();
46+
throw new InvalidOperationException("The application name cannot be resolved from the OWIN application builder. " +
47+
"Consider manually setting the 'DataProtectionProvider' property in the " +
48+
"options using 'DataProtectionProvider.Create([unique application name])'.");
4949
}
5050

5151
options.DataProtectionProvider = DataProtectionProvider.Create(discriminator);

src/Owin.Security.OAuth.Validation/OAuthValidationExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public static IAppBuilder UseOAuthValidation(
6767
throw new ArgumentNullException(nameof(options));
6868
}
6969

70-
return app.Use<OAuthValidationMiddleware>(app, options);
70+
return app.Use<OAuthValidationMiddleware>(app.Properties, options);
7171
}
7272
}
7373
}

src/Owin.Security.OAuth.Validation/OAuthValidationMiddleware.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
using System;
8+
using System.Collections.Generic;
89
using JetBrains.Annotations;
910
using Microsoft.AspNetCore.DataProtection;
1011
using Microsoft.Extensions.Logging;
@@ -17,22 +18,21 @@ namespace Owin.Security.OAuth.Validation {
1718
public class OAuthValidationMiddleware : AuthenticationMiddleware<OAuthValidationOptions> {
1819
public OAuthValidationMiddleware(
1920
[NotNull] OwinMiddleware next,
20-
[NotNull] IAppBuilder app,
21+
[NotNull] IDictionary<string, object> properties,
2122
[NotNull] OAuthValidationOptions options)
2223
: base(next, options) {
2324
if (Options.Events == null) {
2425
Options.Events = new OAuthValidationEvents();
2526
}
2627

2728
if (options.DataProtectionProvider == null) {
28-
// Try to use the application name provided by
29-
// the OWIN host as the application discriminator.
30-
var discriminator = new AppProperties(app.Properties).AppName;
31-
32-
// When an application discriminator cannot be resolved from
33-
// the OWIN host properties, generate a temporary identifier.
29+
// Use the application name provided by the OWIN host as the Data Protection discriminator.
30+
// If the application name cannot be resolved, throw an invalid operation exception.
31+
var discriminator = new AppProperties(properties).AppName;
3432
if (string.IsNullOrEmpty(discriminator)) {
35-
discriminator = Guid.NewGuid().ToString();
33+
throw new InvalidOperationException("The application name cannot be resolved from the OWIN application builder. " +
34+
"Consider manually setting the 'DataProtectionProvider' property in the " +
35+
"options using 'DataProtectionProvider.Create([unique application name])'.");
3636
}
3737

3838
options.DataProtectionProvider = DataProtectionProvider.Create(discriminator);

0 commit comments

Comments
 (0)