Example #1
0
        public void CreateAccountTest()
        {
            //signup
            string email = GetNewEmailAddress();

            WebAccountService.TransitAccount t_instance = new WebAccountService.TransitAccount();
            t_instance.Birthday = DateTime.UtcNow.AddYears(-10);
            t_instance.Name     = GetNewString();
            t_instance.Password = GetNewString();
            t_instance.Id       = EndPoint.CreateAccount(string.Empty, email, t_instance);
            Console.WriteLine("Created account: {0}", t_instance.Id);
            Assert.IsTrue(t_instance.Id > 0);
            // login
            string ticket = EndPoint.Login(email, t_instance.Password);

            Assert.IsFalse(string.IsNullOrEmpty(ticket));
            // retreive
            WebAccountService.TransitAccount t_instance2 = EndPoint.GetAccountById(ticket, t_instance.Id);
            Console.WriteLine("Retreived account: {0}", t_instance2.Id);
            Assert.AreEqual(t_instance.Id, t_instance2.Id);
            // update
            t_instance2.Name = GetNewString();
            EndPoint.CreateOrUpdateAccount(ticket, t_instance2);
            // object may be cached, use admin ticket
            string ticket2 = EndPoint.Login("*****@*****.**", "password");

            // check that the name was updated
            WebAccountService.TransitAccount t_instance3 = EndPoint.GetAccountById(ticket2, t_instance.Id);
            Console.WriteLine("Retreived account: {0}", t_instance3.Id);
            Assert.AreEqual(t_instance.Id, t_instance3.Id);
            Assert.AreEqual(t_instance2.Name, t_instance3.Name);
            // delete
            EndPoint.DeleteAccount(ticket, t_instance.Id);
            Console.WriteLine("Deleted account: {0}", t_instance.Id);
        }
        public void CreateAccountGroupInvitationTest()
        {
            WebGroupService.TransitAccountGroup t_group = new WebGroupService.TransitAccountGroup();
            t_group.Description = GetNewString();
            t_group.Name        = GetNewString();
            t_group.IsPrivate   = false;
            WebGroupService.WebGroupService groupService = new WebGroupService.WebGroupService();
            t_group.Id = groupService.CreateOrUpdateAccountGroup(GetAdminTicket(), t_group);
            // create an invitation from admin to a new user with a group
            WebAccountService.TransitAccountInvitation t_instance = GetTransitInstance();
            t_instance.AccountGroupId = t_group.Id;
            t_instance.Id             = Create(GetAdminTicket(), t_instance);
            // sign-up with this invitation
            WebAccountService.TransitAccount t_account = new WebAccountService.TransitAccount();
            t_account.Name     = GetNewString();
            t_account.Password = GetNewString();
            t_account.Birthday = DateTime.UtcNow.AddYears(-10);
            string ticket = EndPoint.CreateAccountWithInvitationAndLogin(t_instance.Id, t_instance.Code, t_account);

            Assert.IsFalse(string.IsNullOrEmpty(ticket));
            int id = EndPoint.GetAccountId(ticket);

            Assert.IsTrue(id > 0);
            Console.WriteLine("New account: {0}", id);
            // account must also be a member of the group
            WebGroupService.TransitAccountGroupAccount[] groupAccounts = groupService.GetAccountGroupAccountsByAccountId(
                ticket, id, null);
            Assert.IsNotEmpty(groupAccounts);
            Assert.AreEqual(1, groupAccounts.Length);
            Assert.AreEqual(t_group.Id, groupAccounts[0].AccountGroupId);
            Assert.AreEqual(id, groupAccounts[0].AccountId);
            EndPoint.DeleteAccount(ticket, id);
            groupService.DeleteAccountGroup(GetAdminTicket(), t_group.Id);
        }
Example #3
0
        protected int CreateUser(string email, string password, DateTime dateofbirth)
        {
            WebAccountService.TransitAccount t_instance = new WebAccountService.TransitAccount();
            t_instance.Name     = GetNewString();
            t_instance.Password = password;
            t_instance.Birthday = dateofbirth;
            WebAccountService.WebAccountService account_endpoint = new WebAccountService.WebAccountService();
            int id = account_endpoint.CreateAccount(string.Empty, email, t_instance);

            Console.WriteLine("Created user: {0}", id);
            Assert.IsTrue(id > 0);
            return(id);
        }
        public void PromoteAdministratorTest()
        {
            UserInfo user = CreateUserWithVerifiedEmailAddress();

            WebAccountService.TransitAccount t_user = EndPoint.GetAccountById(GetAdminTicket(), user.id);
            Assert.IsFalse(t_user.IsAdministrator);
            EndPoint.PromoteAdministrator(GetAdminTicket(), t_user.Id);
            WebAccountService.TransitAccount t_user_admin = EndPoint.GetAccountById(GetAdminTicket(), user.id);
            Assert.IsTrue(t_user_admin.IsAdministrator);
            EndPoint.DemoteAdministrator(GetAdminTicket(), t_user.Id);
            WebAccountService.TransitAccount t_user_nonadmin = EndPoint.GetAccountById(GetAdminTicket(), user.id);
            Assert.IsFalse(t_user_nonadmin.IsAdministrator);
            EndPoint.DeleteAccount(GetAdminTicket(), user.id);
        }
        public void CreateAccountInvitationTest()
        {
            // create an invitation from admin to a new user
            WebAccountService.TransitAccountInvitation t_instance = GetTransitInstance();
            t_instance.Id = Create(GetAdminTicket(), t_instance);
            // sign-up with this invitation
            WebAccountService.TransitAccount t_account = new WebAccountService.TransitAccount();
            t_account.Name     = GetNewString();
            t_account.Password = GetNewString();
            t_account.Birthday = DateTime.UtcNow.AddYears(-10);

            try
            {
                int impossible_id = EndPoint.CreateAccountWithInvitation(t_instance.Id, GetNewString(), t_account);
                Assert.IsTrue(false, "Invalid code should have thrown an exception.");
            }
            catch (Exception)
            {
            }

            try
            {
                int impossible_id = EndPoint.CreateAccountWithInvitation(-1, t_instance.Code, t_account);
                Assert.IsTrue(false, "Invalid id should have thrown an exception.");
            }
            catch (Exception)
            {
            }

            string ticket = EndPoint.CreateAccountWithInvitationAndLogin(t_instance.Id, t_instance.Code, t_account);

            Assert.IsFalse(string.IsNullOrEmpty(ticket));
            int id = EndPoint.GetAccountId(ticket);

            Assert.IsTrue(id > 0);
            Console.WriteLine("New account: {0}", id);

            WebAccountService.TransitAccountInvitation t_instance_deleted = EndPoint.GetAccountInvitationById(GetAdminTicket(), t_instance.Id);
            Assert.IsNull(t_instance_deleted, "Invitation hasn't been deleted after the account was created.");

            EndPoint.DeleteAccount(ticket, id);
        }
Example #6
0
        public void CreateOrUpdateAccountGroupAccountInvitationTest()
        {
            string      email    = GetNewEmailAddress();
            AccountTest _account = new AccountTest();

            WebAccountService.TransitAccount t_user = _account.GetTransitInstance();
            t_user.Id = _account.EndPoint.CreateAccount(string.Empty, email, t_user);
            Assert.AreNotEqual(0, t_user.Id);
            Console.WriteLine("Created account: {0}", t_user.Id);
            // only members can create invitations
            WebGroupService.TransitAccountGroupAccountInvitation t_instance = GetTransitInstance();
            t_instance.AccountId   = t_user.Id;
            t_instance.RequesterId = _user.id;
            try
            {
                // make sure the user is not a member of the group
                Assert.IsNull(EndPoint.GetAccountGroupAccountByAccountGroupId(
                                  GetAdminTicket(), _user.id, _group_id));
                // create the account group invitation
                EndPoint.CreateOrUpdateAccountGroupAccountInvitation(_user.ticket, t_instance);
                Assert.IsTrue(false, "Expected Access Denied exception.");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception: {0}", ex.Message);
                Assert.AreEqual("System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> SnCore.Services.ManagedAccount+AccessDeniedException: Access denied",
                                ex.Message.Split("\n".ToCharArray(), 2)[0],
                                string.Format("Unexpected exception: {0}", ex.Message));
            }
            // the user joins the group
            WebGroupService.TransitAccountGroupAccount t_accountinstance = new WebGroupService.TransitAccountGroupAccount();
            t_accountinstance.AccountGroupId  = _group_id;
            t_accountinstance.AccountId       = _user.id;
            t_accountinstance.IsAdministrator = false;
            t_accountinstance.Id = EndPoint.CreateOrUpdateAccountGroupAccount(GetAdminTicket(), t_accountinstance);
            // make sure the invitation can be now sent
            t_instance.Id = EndPoint.CreateOrUpdateAccountGroupAccountInvitation(_user.ticket, t_instance);
            Assert.AreNotEqual(0, t_instance.Id);

            // TODO: make sure another user can't see invitation
        }
        public void ChangePasswordAdminTest()
        {
            string   email       = GetNewEmailAddress();
            string   password    = GetNewString();
            DateTime dateofbirth = DateTime.UtcNow.AddYears(-10);
            int      user_id     = CreateUser(email, password, dateofbirth);

            Assert.IsTrue(user_id > 0);
            WebAccountService.TransitAccount ta1 = EndPoint.GetAccountById(GetAdminTicket(), user_id);
            Assert.IsFalse(ta1.IsPasswordExpired, "Password is not expired after admin password reset.");
            string newpassword = GetNewString();

            EndPoint.ChangePassword(GetAdminTicket(), user_id, string.Empty, newpassword);
            // get the user and check whether password is properly expired
            WebAccountService.TransitAccount ta2 = EndPoint.GetAccountById(GetAdminTicket(), user_id);
            Assert.IsTrue(ta2.IsPasswordExpired, "Password is not expired after admin password reset.");
            // check that it resets back when the user logs in
            string ticket = EndPoint.Login(email, newpassword);

            Assert.IsFalse(string.IsNullOrEmpty(ticket));
            EndPoint.ChangePassword(ticket, user_id, newpassword, GetNewString());
            WebAccountService.TransitAccount ta3 = EndPoint.GetAccountById(GetAdminTicket(), user_id);
            Assert.IsFalse(ta3.IsPasswordExpired, "Password is expired after user changes it.");
        }
Example #8
0
        public void AcceptAccountGroupAccountInvitationTest()
        {
            // login user
            string      email    = GetNewEmailAddress();
            AccountTest _account = new AccountTest();

            WebAccountService.TransitAccount t_user = _account.GetTransitInstance();
            t_user.Id = _account.EndPoint.CreateAccount(string.Empty, email, t_user);
            Assert.AreNotEqual(0, t_user.Id);
            Console.WriteLine("Created account: {0}", t_user.Id);
            string userticket = _account.Login(email, t_user.Password);

            // join user to group
            WebGroupService.TransitAccountGroupAccount t_account = new WebGroupService.TransitAccountGroupAccount();
            t_account.AccountGroupId  = _group_id;
            t_account.AccountId       = t_user.Id;
            t_account.IsAdministrator = false;
            t_account.Id = EndPoint.CreateOrUpdateAccountGroupAccount(userticket, t_account);
            Assert.AreNotEqual(0, t_account.Id);
            Console.WriteLine("Joined user: {0}", t_account.Id);
            // update the group to private
            WebGroupService.TransitAccountGroup t_group = EndPoint.GetAccountGroupById(GetAdminTicket(), _group_id);
            t_group.IsPrivate = true;
            EndPoint.CreateOrUpdateAccountGroup(GetAdminTicket(), t_group);
            Console.WriteLine("Updated group to private: {0}", _group_id);
            // create an invitatoin for user
            WebGroupService.TransitAccountGroupAccountInvitation t_instance = new WebGroupService.TransitAccountGroupAccountInvitation();
            t_instance.AccountGroupId = _group_id;
            t_instance.AccountId      = _user.id;
            t_instance.RequesterId    = t_account.AccountId;
            t_instance.Message        = GetNewString();
            t_instance.Id             = EndPoint.CreateOrUpdateAccountGroupAccountInvitation(GetAdminTicket(), t_instance);
            Console.WriteLine("Created invitation: {0}", t_instance.Id);
            // make sure the user isn't member of the group
            Assert.IsNull(EndPoint.GetAccountGroupAccountByAccountGroupId(GetAdminTicket(), _user.id, _group_id));
            // get the pending group membership requests
            WebGroupService.TransitAccountGroupAccountRequest[] requests1 = EndPoint.GetAccountGroupAccountRequests(
                GetAdminTicket(), _group_id, null);
            Console.WriteLine("Pending requests: {0}", requests1.Length);
            // accept invitation
            EndPoint.AcceptAccountGroupAccountInvitation(_user.ticket, t_instance.Id, GetNewString());
            // this has created a new request on the group, it should be +1
            WebGroupService.TransitAccountGroupAccountRequest[] requests2 = EndPoint.GetAccountGroupAccountRequests(
                GetAdminTicket(), _group_id, null);
            Console.WriteLine("Pending requests: {0}", requests2.Length);
            Assert.AreEqual(requests1.Length + 1, requests2.Length);
            // make sure there's an AccountId in the requests for the user
            WebGroupService.TransitAccountGroupAccountRequest request = null;
            Assert.IsTrue(new TransitServiceCollection <WebGroupService.TransitAccountGroupAccountRequest>(requests2).ContainsId(
                              _user.id, "AccountId", out request));
            Assert.IsNotNull(request);
            Console.WriteLine("New request: {0}", request.Id);
            // accept the request by admin
            EndPoint.AcceptAccountGroupAccountRequest(GetAdminTicket(), request.Id, GetNewString());
            // make sure the invitation was deleted
            Assert.IsNull(EndPoint.GetAccountGroupAccountInvitationById(_user.ticket, t_instance.Id));
            // make sure the request cannot be found any more
            WebGroupService.TransitAccountGroupAccountRequest[] requests3 = EndPoint.GetAccountGroupAccountRequests(
                GetAdminTicket(), _group_id, null);
            Console.WriteLine("Pending requests: {0}", requests3.Length);
            Assert.AreEqual(requests1.Length, requests3.Length);
            // make sure the user is member of the group
            WebGroupService.TransitAccountGroupAccount t_groupaccount = EndPoint.GetAccountGroupAccountByAccountGroupId(
                GetAdminTicket(), _user.id, _group_id);
            Assert.IsNotNull(t_groupaccount);
            Console.WriteLine("Account: {0}", t_groupaccount.Id);
            Assert.AreEqual(t_groupaccount.AccountId, _user.id);
            _account.Delete(GetAdminTicket(), t_user.Id);
        }