Exemple #1
0
            public async Task GivenNoLinkAndEmailClaim_ItDisplaysLogOnViewWithEmailPrefilled()
            {
                // Arrange
                var cred     = new CredentialBuilder().CreateExternalCredential("MicrosoftAccount", "blorg", "Bloog");
                var msAuther = new MicrosoftAccountAuthenticator();
                var msaUI    = msAuther.GetUI();

                GetMock <AuthenticationService>(); // Force a mock to be created

                var controller = GetController <AuthenticationController>();

                GetMock <AuthenticationService>()
                .Setup(x => x.AuthenticateExternalLogin(controller.OwinContext))
                .CompletesWith(new AuthenticateExternalLoginResult()
                {
                    ExternalIdentity = new ClaimsIdentity(new[] {
                        new Claim(ClaimTypes.Email, "*****@*****.**")
                    }),
                    Authenticator = msAuther
                });

                // Act
                var result = await controller.LinkExternalAccount("theReturnUrl");

                // Assert
                var model = ResultAssert.IsView <LogOnViewModel>(result, viewName: LinkExternalViewName);

                Assert.Equal(msaUI.AccountNoun, model.External.ProviderAccountNoun);
                Assert.Null(model.External.AccountName);
                Assert.False(model.External.FoundExistingUser);
                Assert.Equal("*****@*****.**", model.SignIn.UserNameOrEmail);
                Assert.Equal("*****@*****.**", model.Register.EmailAddress);
            }
Exemple #2
0
            public async Task GivenNoLinkButEmailMatchingLocalUser_ItDisplaysLogOnViewPresetForSignIn()
            {
                // Arrange
                var fakes        = Get <Fakes>();
                var existingUser = new User("existingUser")
                {
                    EmailAddress = "*****@*****.**"
                };
                var cred     = new CredentialBuilder().CreateExternalCredential("MicrosoftAccount", "blorg", "Bloog");
                var msAuther = new MicrosoftAccountAuthenticator();
                var msaUI    = msAuther.GetUI();
                var authUser = new AuthenticatedUser(
                    fakes.CreateUser("test", cred),
                    cred);

                GetMock <AuthenticationService>(); // Force a mock to be created
                GetMock <IUserService>()
                .Setup(u => u.FindByEmailAddress(existingUser.EmailAddress))
                .Returns(existingUser);

                var controller = GetController <AuthenticationController>();

                GetMock <AuthenticationService>()
                .Setup(x => x.AuthenticateExternalLogin(controller.OwinContext))
                .CompletesWith(new AuthenticateExternalLoginResult()
                {
                    ExternalIdentity = new ClaimsIdentity(new[] {
                        new Claim(ClaimTypes.Email, existingUser.EmailAddress)
                    }),
                    Authenticator = msAuther
                });

                // Act
                var result = await controller.LinkExternalAccount("theReturnUrl");

                // Assert
                var model = ResultAssert.IsView <LogOnViewModel>(result, viewName: LinkExternalViewName);

                Assert.Equal(msaUI.AccountNoun, model.External.ProviderAccountNoun);
                Assert.Null(model.External.AccountName);
                Assert.True(model.External.FoundExistingUser);
                Assert.Equal(existingUser.EmailAddress, model.SignIn.UserNameOrEmail);
                Assert.Equal(existingUser.EmailAddress, model.Register.EmailAddress);
            }
            public async Task GivenNoLinkButEmailMatchingLocalUser_ItDisplaysLogOnViewPresetForSignIn()
            {
                // Arrange
                var existingUser = new User("existingUser") { EmailAddress = "*****@*****.**" };
                var cred = CredentialBuilder.CreateExternalCredential("MicrosoftAccount", "blorg", "Bloog");
                var msAuther = new MicrosoftAccountAuthenticator();
                var msaUI = msAuther.GetUI();
                var authUser = new AuthenticatedUser(
                    Fakes.CreateUser("test", cred),
                    cred);

                GetMock<AuthenticationService>(); // Force a mock to be created
                GetMock<IUserService>()
                    .Setup(u => u.FindByEmailAddress(existingUser.EmailAddress))
                    .Returns(existingUser);

                var controller = GetController<AuthenticationController>();

                GetMock<AuthenticationService>()
                    .Setup(x => x.AuthenticateExternalLogin(controller.OwinContext))
                    .CompletesWith(new AuthenticateExternalLoginResult()
                    {
                        ExternalIdentity = new ClaimsIdentity(new [] {
                            new Claim(ClaimTypes.Email, existingUser.EmailAddress)
                        }),
                        Authenticator = msAuther
                    });

                // Act
                var result = await controller.LinkExternalAccount("theReturnUrl");

                // Assert
                var model = ResultAssert.IsView<LogOnViewModel>(result, viewName: "LogOn");
                Assert.Equal(msaUI.AccountNoun, model.External.ProviderAccountNoun);
                Assert.Null(model.External.AccountName);
                Assert.True(model.External.FoundExistingUser);
                Assert.Equal(existingUser.EmailAddress, model.SignIn.UserNameOrEmail);
                Assert.Equal(existingUser.EmailAddress, model.Register.EmailAddress);
            }
            public void GivenAnExternalCredential_ItDescribesItCorrectly()
            {
                // Arrange
                var cred = CredentialBuilder.CreateExternalCredential("MicrosoftAccount", "abc123", "Test User");
                var msftAuther = new MicrosoftAccountAuthenticator();
                var authService = Get<AuthenticationService>();

                // Act
                var description = authService.DescribeCredential(cred);

                // Assert
                Assert.Equal(cred.Type, description.Type);
                Assert.Equal(msftAuther.GetUI().Caption, description.TypeCaption);
                Assert.Equal(cred.Identity, description.Identity);
                Assert.True(String.IsNullOrEmpty(description.Value));
                Assert.Equal(CredentialKind.External, description.Kind);
                Assert.NotNull(description.AuthUI);
                Assert.Equal(msftAuther.GetUI().AccountNoun, description.AuthUI.AccountNoun);
            }
            public async Task GivenNoLinkAndEmailClaim_ItDisplaysLogOnViewWithEmailPrefilled()
            {
                // Arrange
                var cred = CredentialBuilder.CreateExternalCredential("MicrosoftAccount", "blorg", "Bloog");
                var msAuther = new MicrosoftAccountAuthenticator();
                var msaUI = msAuther.GetUI();

                GetMock<AuthenticationService>(); // Force a mock to be created

                var controller = GetController<AuthenticationController>();

                GetMock<AuthenticationService>()
                    .Setup(x => x.AuthenticateExternalLogin(controller.OwinContext))
                    .CompletesWith(new AuthenticateExternalLoginResult()
                    {
                        ExternalIdentity = new ClaimsIdentity(new[] {
                            new Claim(ClaimTypes.Email, "*****@*****.**")
                        }),
                        Authenticator = msAuther
                    });

                // Act
                var result = await controller.LinkExternalAccount("theReturnUrl");

                // Assert
                var model = ResultAssert.IsView<LogOnViewModel>(result, viewName: "LogOn");
                Assert.Equal(msaUI.AccountNoun, model.External.ProviderAccountNoun);
                Assert.Null(model.External.AccountName);
                Assert.False(model.External.FoundExistingUser);
                Assert.Equal("*****@*****.**", model.SignIn.UserNameOrEmail);
                Assert.Equal("*****@*****.**", model.Register.EmailAddress);
            }