public async Task should_signin_user_and_redirect_when_signin_with_valid_user()
        {
            // Arrange
            ClaimsPrincipal signedInClaimsPrincipal = null;
            var             authService             = MockAuthService(principal => signedInClaimsPrincipal = principal);

            const string password = "******";

            _app.CreateUser("jim", password, "Jim Green");
            var userModel = new UserViewModel
            {
                UserName = "******",
                Password = password
            };

            // Act
            var accountCtrl = _app.CreateController <AccountController>();

            accountCtrl.TryValidateModel(userModel);
            var signinResult = await accountCtrl.DoSignin(userModel, null);

            // Assert
            Assert.True(accountCtrl.ModelState.IsValid);
            signinResult.IsType <RedirectResult>();

            authService.Verify();
            var signedInUser = signedInClaimsPrincipal.ToDiscussionUser(_app.GetService <IRepository <User> >());

            _app.ReloadEntity(signedInUser);
            Assert.Equal("jim", signedInUser.UserName);
            Assert.NotNull(signedInUser.LastSeenAt);
        }
Esempio n. 2
0
 public TopicControllerSpecs(TestDiscussionWebApp app)
 {
     _app = app.Reset();
     _app.DeleteAll <Topic>();
     _app.DeleteAll <WeChatAccount>();
     _author = _app.CreateUser();
 }
Esempio n. 3
0
        public Topic Create()
        {
            var someUser = _app.CreateUser(StringUtility.Random());

            var topicRepo = _app.GetService <IRepository <Topic> >();

            if (_topic.Author == null)
            {
                _topic.Author = someUser;
            }

            if (_replies.Count > 0)
            {
                _topic.LastRepliedUser = _replies.LastOrDefault(r => r.Author != null)?.Author ?? someUser;
            }


            topicRepo.Save(_topic);

            var replyRepo = _app.GetService <IRepository <Reply> >();

            _replies.ForEach(reply =>
            {
                reply.TopicId = _topic.Id;
                reply.Author  = _topic.Author ?? someUser;
                replyRepo.Save(reply);
            });
            return(_topic);
        }
        void should_be_able_to_signin_new_user()
        {
            var username = StringUtility.Random();
            var password = "******";

            _app.CreateUser(username, password);

            _app.Path("/signin")
            .Post()
            .WithForm(new
            {
                UserName = username,
                Password = password
            })
            .ShouldSuccessWithRedirect(_app.NoUser())
            .WithResponse(response =>
            {
                var cookieHeaders = response.Headers.GetValues("Set-Cookie").ToList();
                cookieHeaders.ShouldContain(cookie => cookie.Contains(".AspNetCore.Identity.Application"));
            });
        }
Esempio n. 5
0
        async void should_signin_existing_user_without_latest_claims_using_external_idp_enabled()
        {
            var userId       = StringUtility.Random(5);
            var name         = StringUtility.Random();
            var emailAddress = $"{StringUtility.Random(5)}@someplace.com";

            var existingUser = _app.CreateUser(userId, displayName: name);

            existingUser.OpenId         = userId;
            existingUser.EmailAddress   = emailAddress;
            existingUser.OpenIdProvider = "external";
            var userRepo = _app.GetService <IRepository <User> >();

            userRepo.Update(existingUser);

            MockExternalSignin(false, out var httpContext);

            var importedPrincipal = await _app.GetService <ExternalSigninManager>()
                                    .TransformToDiscussionUser(httpContext,
                                                               ComposeJwtClaims(userId, name, emailAddress, Guid.NewGuid().ToString("D")));

            VerifyTransformedUser(existingUser, importedPrincipal, name, emailAddress, false);
        }