Beispiel #1
0
        public async void ITest_CanResetPassword()
        {
            string email;
            string id;
            // SETUP
            using (var uow = ObjectFactory.GetInstance<IUnitOfWork>())
            {
                var fixtureData = new FixtureData(uow);
                var userDO = fixtureData.TestUser1();
                uow.UserRepository.Add(userDO);
                uow.SaveChanges();
                id = userDO.Id;
                email = userDO.EmailAddress.Address;
            }

            // EXECUTE
            // generate a forgot password email
            var account = ObjectFactory.GetInstance<Account>();
            await account.ForgotPasswordAsync(email);
            // get callback url from generated email
            string callbackUrl;
            using (var uow = ObjectFactory.GetInstance<IUnitOfWork>())
            {
                var envelopeDO = uow.EnvelopeRepository.GetQuery().Single();
                callbackUrl = (String)envelopeDO.MergeData["-callback_url-"];
            }
            var userId = Regex.Match(callbackUrl,
                                     "userId=(?<userId>[-a-f\\d]+)",
                                     RegexOptions.IgnoreCase)
                .Groups["userId"].Value;
            var code = Regex.Match(callbackUrl,
                                     "code=(?<code>[\\d]+)",
                                     RegexOptions.IgnoreCase)
                .Groups["code"].Value;
            var result = await account.ResetPasswordAsync(userId, code, "123456");

            // VERIFY
            Assert.AreEqual(id, userId);
            Assert.IsTrue(result.Succeeded, string.Join(", ", result.Errors));
        }
Beispiel #2
0
        public void CanOAuthRedirectToCallbackUrl()
        {
            // SETUP
            UserDO user;
            using (var uow = ObjectFactory.GetInstance<IUnitOfWork>())
            {
                var fixtureData = new FixtureData(uow);
                user = fixtureData.TestUser1();
                uow.SaveChanges();
            }

            // EXECUTE
            using (var uow = ObjectFactory.GetInstance<IUnitOfWork>())
            {
                var oauthProviders = uow.RemoteCalendarProviderRepository.GetQuery().Where(p => p.AuthType == ServiceAuthorizationType.OAuth2).ToArray();
                Assert.That(oauthProviders.Length > 0, "No OAuth providers.");
                foreach (var provider in oauthProviders)
                {
                    var authorizer = ObjectFactory.GetNamedInstance<IOAuthAuthorizer>(provider.Name);
                    var result = authorizer.AuthorizeAsync(
                        user.Id,
                        user.EmailAddress.Address,
                        UserController.GetCallbackUrl(provider.Name, "https://www.kwasant.com/"),
                        "https://www.kwasant.com/",
                        CancellationToken.None).Result;

                    // VERIFY
                    Assert.IsFalse(result.IsAuthorized, "User should be unauthorized.");
                    using (var httpClient = new HttpClient())
                    {
                        using (var response = httpClient.GetAsync(result.RedirectUri).Result)
                        {
                            // now here we are getting "403 Unathorized" instead of expected "200 OK" or "400 Bad Request", have to deal with google authorization somehow
                            Assert.IsTrue(response.IsSuccessStatusCode, string.Format("Redirected URL returned: {0}", response.StatusCode));
                        }
                    }
                }
            }
        }
Beispiel #3
0
        public void Customer_Add_CanCreateUser()
        {
            using (var uow = ObjectFactory.GetInstance<IUnitOfWork>())
            {
                var fixture = new FixtureData(uow);
                //SETUP
                //create a customer from fixture data
                UserDO curUserDO = fixture.TestUser1();

                //EXECUTE
                uow.UserRepository.Add(curUserDO);
                uow.SaveChanges();

                //VERIFY
                //check that it was saved to the db
                UserDO savedUserDO = uow.UserRepository.GetQuery().FirstOrDefault(u => u.Id == curUserDO.Id);
                Assert.AreEqual(curUserDO.FirstName, savedUserDO.FirstName);
                Assert.AreEqual(curUserDO.EmailAddress, savedUserDO.EmailAddress);

            }

        }