Esempio n. 1
0
        public void Configure_ThrowsAnExceptionForNullOptions()
        {
            // Arrange
            var configuration = new OpenIddictValidationConfiguration(Mock.Of <IDataProtectionProvider>());

            // Act and assert
            var exception = Assert.Throws <ArgumentNullException>(() => configuration.Configure(null));

            Assert.Equal("options", exception.ParamName);
        }
Esempio n. 2
0
        public void Configure_ThrowsAnExceptionWhenSchemeIsAlreadyRegisteredWithDifferentHandlerType()
        {
            // Arrange
            var options = new AuthenticationOptions();

            options.AddScheme(OpenIddictValidationDefaults.AuthenticationScheme, builder =>
            {
                builder.HandlerType = typeof(OAuthValidationHandler);
            });

            var initializer = new OpenIddictValidationConfiguration(Mock.Of <IDataProtectionProvider>());

            // Act and assert
            var exception = Assert.Throws <InvalidOperationException>(() => initializer.Configure(options));

            Assert.Equal(new StringBuilder()
                         .AppendLine("The OpenIddict validation handler cannot be registered as an authentication scheme.")
                         .AppendLine("This may indicate that an instance of the OAuth validation or JWT bearer handler was registered.")
                         .Append("Make sure that neither 'services.AddAuthentication().AddOAuthValidation()' nor ")
                         .Append("'services.AddAuthentication().AddJwtBearer()' are called from 'ConfigureServices'.")
                         .ToString(), exception.Message);
        }
Esempio n. 3
0
        public void PostConfigure_ThrowsAnExceptionWhenDefaultSchemesPointToValidationHandler(string[] schemes)
        {
            // Arrange
            var options = new AuthenticationOptions
            {
                DefaultSignInScheme  = schemes[0],
                DefaultSignOutScheme = schemes[1]
            };

            options.AddScheme <OpenIddictValidationHandler>(OpenIddictValidationDefaults.AuthenticationScheme, displayName: null);

            var configuration = new OpenIddictValidationConfiguration(Mock.Of <IDataProtectionProvider>());

            // Act and assert
            var exception = Assert.Throws <InvalidOperationException>(() => configuration.PostConfigure(Options.DefaultName, options));

            // Assert
            Assert.Equal(new StringBuilder()
                         .AppendLine("The OpenIddict validation handler cannot be used as the default sign-in/out scheme handler.")
                         .Append("Make sure that neither DefaultSignInScheme nor DefaultSignOutScheme ")
                         .Append("point to an instance of the OpenIddict validation handler.")
                         .ToString(), exception.Message);
        }