Exemplo n.º 1
0
    public async Task OnRemoteError_HandlesResponseWhenErrorIsUnknown()
    {
        // Arrange

        var handlers = new AzureADB2COpenIDConnectEventHandlers(
            AzureADB2CDefaults.AuthenticationScheme,
            new AzureADB2COptions()
        {
            SignUpSignInPolicyId = "B2C_1_SiUpIn"
        });

        var remoteFailureContext = new RemoteFailureContext(
            new DefaultHttpContext(),
            new AuthenticationScheme(
                AzureADB2CDefaults.AuthenticationScheme,
                displayName: null,
                handlerType: typeof(OpenIdConnectHandler)),
            new OpenIdConnectOptions(),
            new OpenIdConnectProtocolException("some_other_error"));

        // Act
        await handlers.OnRemoteFailure(remoteFailureContext);

        // Assert
        Assert.Equal(StatusCodes.Status302Found, remoteFailureContext.Response.StatusCode);
        Assert.Equal("/AzureADB2C/Account/Error", remoteFailureContext.Response.Headers.Location);
        Assert.True(remoteFailureContext.Result.Handled);
    }
Exemplo n.º 2
0
    public async Task OnRemoteError_HandlesResponseWhenUserCancelsFlowFromTheAzureADB2CUserInterface()
    {
        // Arrange

        var handlers = new AzureADB2COpenIDConnectEventHandlers(
            AzureADB2CDefaults.AuthenticationScheme,
            new AzureADB2COptions()
        {
            SignUpSignInPolicyId = "B2C_1_SiUpIn"
        });

        var remoteFailureContext = new RemoteFailureContext(
            new DefaultHttpContext(),
            new AuthenticationScheme(
                AzureADB2CDefaults.AuthenticationScheme,
                displayName: null,
                handlerType: typeof(OpenIdConnectHandler)),
            new OpenIdConnectOptions(),
            new OpenIdConnectProtocolException("access_denied"));

        // Act
        await handlers.OnRemoteFailure(remoteFailureContext);

        // Assert
        Assert.Equal(StatusCodes.Status302Found, remoteFailureContext.Response.StatusCode);
        Assert.Equal("/", remoteFailureContext.Response.Headers.Location);
        Assert.True(remoteFailureContext.Result.Handled);
    }
Exemplo n.º 3
0
        public async void OnRemoteFailure_OtherException_RedirectsSuccessfully()
        {
            var httpContext = Substitute.For <HttpContext>();

            httpContext.Request.PathBase = PathBase;
            var handler = new AzureADB2COpenIDConnectEventHandlers(OpenIdConnectDefaults.AuthenticationScheme, new MicrosoftIdentityOptions());

            var otherException = "Generic exception.";

            await handler.OnRemoteFailure(new RemoteFailureContext(httpContext, _authScheme, new OpenIdConnectOptions(), new OpenIdConnectProtocolException(otherException)));

            httpContext.Response.Received().Redirect($"{httpContext.Request.PathBase}/MicrosoftIdentity/Account/Error");
        }
Exemplo n.º 4
0
        public async void OnRemoteFailure_PasswordReset_RedirectsSuccessfully()
        {
            var httpContext = Substitute.For <HttpContext>();

            httpContext.Request.PathBase = PathBase;
            var handler = new AzureADB2COpenIDConnectEventHandlers(OpenIdConnectDefaults.AuthenticationScheme, new MicrosoftIdentityOptions());

            var passwordResetException = "'access_denied', error_description: 'AADB2C90118: The user has forgotten their password. Correlation ID: f99deff4-f43b-43cc-b4e7-36141dbaf0a0 Timestamp: 2018-03-05 02:49:35Z', error_uri: 'error_uri is null'";

            await handler.OnRemoteFailure(new RemoteFailureContext(httpContext, _authScheme, new OpenIdConnectOptions(), new OpenIdConnectProtocolException(passwordResetException))).ConfigureAwait(false);

            httpContext.Response.Received().Redirect($"{httpContext.Request.PathBase}/MicrosoftIdentity/Account/ResetPassword/{OpenIdConnectDefaults.AuthenticationScheme}");
        }
Exemplo n.º 5
0
        public async void OnRemoteFailure_Cancel_RedirectsSuccessfully()
        {
            var httpContext = Substitute.For <HttpContext>();

            httpContext.Request.PathBase = PathBase;
            var handler = new AzureADB2COpenIDConnectEventHandlers(OpenIdConnectDefaults.AuthenticationScheme, new MicrosoftIdentityOptions());

            var cancelException = "'access_denied', error_description: 'AADB2C90091: The user has canceled entering self-asserted information. Correlation ID: d01c8878-0732-4eb2-beb8-da82a57432e0 Timestamp: 2018-03-05 02:56:49Z ', error_uri: 'error_uri is null'";

            await handler.OnRemoteFailure(new RemoteFailureContext(httpContext, _authScheme, new OpenIdConnectOptions(), new OpenIdConnectProtocolException(cancelException)));

            httpContext.Response.Received().Redirect($"{httpContext.Request.PathBase}/");
        }