Exemple #1
0
        public void ChangeEmail()
        {
            var apiRepository = new ApiMongoRepository(CONNECTION);
            var repository    = new MongoRepository(CONNECTION, apiRepository);
            var manager       = repository.CreateManager("test", "test");

            var domain = repository.CreateDomain("test", manager);

            var user = apiRepository.CreateUser(domain.Key, "test", "test",
                                                "*****@*****.**");

            user = apiRepository.Authenticate(domain.Key, "test", "test");

            var result = apiRepository
                         .ChangeEmail(domain.Key, user.AuthToken,
                                      "*****@*****.**");

            Assert.True(result);

            user = apiRepository.Validate(user.AuthToken, domain.Key);

            Assert.AreEqual(user.Email, "*****@*****.**");

            repository.DeleteDomain(domain.Id);
            repository.DeleteManager(manager.Id, "test");
        }
Exemple #2
0
        public void AddAdministrator()
        {
            var apiRepository = new ApiMongoRepository(CONNECTION_STRING);
            var repository    = new MongoRepository(CONNECTION_STRING,
                                                    apiRepository);
            var userName = "******";
            var secret   = "test";
            var manager  = repository.CreateManager(userName, secret);
            var admin    = repository.CreateManager(userName + "2", secret);

            var domain = repository.CreateDomain("test", manager);

            admin = repository.AddAdministrator(domain.Id, userName + "2");

            Assert.AreEqual(userName + "2", admin.UserName);

            repository.DeleteManager(manager.Id, secret);
            repository.DeleteManager(admin.Id, secret);
        }
Exemple #3
0
        public void CreateManager()
        {
            var apiRepository = new ApiMongoRepository(CONNECTION_STRING);
            var repository    = new MongoRepository(CONNECTION_STRING,
                                                    apiRepository);
            var userName = "******";
            var secret   = "test";
            var manager  = repository.CreateManager(userName, secret);

            Assert.AreEqual(manager.UserName, userName);
            repository.DeleteManager(manager.Id, secret);
        }
Exemple #4
0
        public void DeleteManager()
        {
            var apiRepository = new ApiMongoRepository(CONNECTION_STRING);
            var repository    = new MongoRepository(CONNECTION_STRING,
                                                    apiRepository);
            var userName = "******";
            var secret   = "test";
            var manager  = repository.CreateManager(userName, secret);
            var id       = manager.Id;

            repository.DeleteManager(manager.Id, secret);
            manager = repository.GetManager(id);
            Assert.IsNull(manager);
        }
Exemple #5
0
        public void ForgotPassword()
        {
            var apiRepository = new ApiMongoRepository(CONNECTION_STRING);
            var repository    = new MongoRepository(CONNECTION_STRING,
                                                    apiRepository);
            var userName = "******";
            var secret   = "test";
            var manager  = repository.CreateManager(userName, secret);

            var newPassword = repository.ForgotPassword(userName);

            //implicit assert, would fail if password didn't change
            repository.DeleteManager(manager.Id, newPassword);
        }
Exemple #6
0
        public void ValidateDomainKey()
        {
            var apiRepository = new ApiMongoRepository(CONNECTION);
            var repository    = new MongoRepository(CONNECTION, apiRepository);
            var manager       = repository.CreateManager("test", "test");

            var domain = repository.CreateDomain("test", manager);

            var result = apiRepository.ValidateDomainKey("test", domain.Key);

            Assert.True(result);
            repository.DeleteDomain(domain.Id);
            repository.DeleteManager(manager.Id, "test");
        }
Exemple #7
0
        public void ChangeEmail()
        {
            var apiRepository = new ApiMongoRepository(CONNECTION_STRING);
            var repository    = new MongoRepository(CONNECTION_STRING,
                                                    apiRepository);
            var userName = "******";
            var secret   = "test";
            var manager  = repository.CreateManager(userName, secret);

            repository.ChangeEmail(manager.Id, secret, "*****@*****.**");
            manager = repository.GetManager(manager.Id);
            Assert.AreEqual(manager.UserName, "*****@*****.**");
            repository.DeleteManager(manager.Id, secret);
        }
Exemple #8
0
        public void IpAllowed()
        {
            var apiRepository = new ApiMongoRepository(CONNECTION);
            var repository    = new MongoRepository(CONNECTION, apiRepository);
            var manager       = repository.CreateManager("test", "test");

            var domain = repository.CreateDomain("test", manager);

            var result = apiRepository.IpAllowed(domain.Key, "127.0.0.1");

            Assert.True(result);

            repository.DeleteDomain(domain.Id);
            repository.DeleteManager(manager.Id, "test");
        }
Exemple #9
0
        public void CreateUser()
        {
            var apiRepository = new ApiMongoRepository(CONNECTION);
            var repository    = new MongoRepository(CONNECTION, apiRepository);
            var manager       = repository.CreateManager("test", "test");

            var domain = repository.CreateDomain("test", manager);

            var user = apiRepository.CreateUser(domain.Key, "test", "test",
                                                "*****@*****.**");

            Assert.AreEqual("*****@*****.**", user.Email);
            repository.DeleteDomain(domain.Id);
            repository.DeleteManager(manager.Id, "test");
        }
Exemple #10
0
        public void ChangePassword()
        {
            var apiRepository = new ApiMongoRepository(CONNECTION_STRING);
            var repository    = new MongoRepository(CONNECTION_STRING,
                                                    apiRepository);
            var userName = "******";
            var secret   = "test";
            var manager  = repository.CreateManager(userName, secret);
            var pass     = manager.Secret;

            repository.ChangePassword(manager.Id, secret, "password", "password");
            manager = repository.GetManager(manager.Id);
            //Assert.AreEqual(manager.Secret, pass);
            //implicit assert, would fail if password didn't change
            repository.DeleteManager(manager.Id, "password");
        }
Exemple #11
0
        public void CreateRole()
        {
            var apiRepository = new ApiMongoRepository(CONNECTION_STRING);
            var repository    = new MongoRepository(CONNECTION_STRING,
                                                    apiRepository);
            var userName = "******";
            var secret   = "test";
            var manager  = repository.CreateManager(userName, secret);

            var domain = repository.CreateDomain("test", manager);

            var role = repository.CreateRole(domain.Id, "test");

            Assert.AreEqual("test", role.Name);
            repository.DeleteManager(manager.Id, secret);
        }
Exemple #12
0
        public void UpdateDomain()
        {
            var apiRepository = new ApiMongoRepository(CONNECTION_STRING);
            var repository    = new MongoRepository(CONNECTION_STRING,
                                                    apiRepository);
            var userName = "******";
            var secret   = "test";
            var manager  = repository.CreateManager(userName, secret);

            var domain = repository.CreateDomain("test", manager);

            Assert.True(domain.Enabled);
            domain.Enabled = false;
            domain         = repository.UpdateDomain(domain);
            Assert.False(domain.Enabled);
            repository.DeleteManager(manager.Id, secret);
        }
Exemple #13
0
        public void GetDomainUsers()
        {
            var apiRepository = new ApiMongoRepository(CONNECTION_STRING);
            var repository    = new MongoRepository(CONNECTION_STRING,
                                                    apiRepository);
            var userName = "******";
            var secret   = "test";
            var manager  = repository.CreateManager(userName, secret);
            var domain   = repository.CreateDomain("test", manager);
            var user     = apiRepository.CreateUser(domain.Key, "user1", "test",
                                                    "*****@*****.**");

            var users = repository.GetDomainUsers(domain.Id);

            Assert.AreEqual(1, users.Length);
            repository.DeleteManager(manager.Id, secret);
        }
Exemple #14
0
        public void GetUserInDomain()
        {
            var apiRepository = new ApiMongoRepository(CONNECTION_STRING);
            var repository    = new MongoRepository(CONNECTION_STRING,
                                                    apiRepository);
            var userName = "******";
            var secret   = "test";
            var manager  = repository.CreateManager(userName, secret);
            var domain   = repository.CreateDomain("test", manager);
            var user     = apiRepository.CreateUser(domain.Key, "user1", "test",
                                                    "*****@*****.**");

            user = repository.GetUser(domain.Id, "user1");

            Assert.NotNull(user);
            repository.DeleteManager(manager.Id, secret);
        }
Exemple #15
0
        public void DeleteDomain()
        {
            var apiRepository = new ApiMongoRepository(CONNECTION_STRING);
            var repository    = new MongoRepository(CONNECTION_STRING,
                                                    apiRepository);
            var userName = "******";
            var secret   = "test";
            var manager  = repository.CreateManager(userName, secret);

            var domain = repository.CreateDomain("test", manager);

            repository.DeleteDomain(domain.Id);
            domain = repository.GetDomain(domain.Id);

            Assert.IsNull(domain);
            repository.DeleteManager(manager.Id, secret);
        }
Exemple #16
0
        public void GetOwnerName()
        {
            var apiRepository = new ApiMongoRepository(CONNECTION_STRING);
            var repository    = new MongoRepository(CONNECTION_STRING,
                                                    apiRepository);
            var userName = "******";
            var secret   = "test";
            var manager  = repository.CreateManager(userName, secret);

            var domain = repository.CreateDomain("test", manager);

            var result = repository.GetOwnerName(domain);

            Assert.AreEqual(result, manager.UserName);

            repository.DeleteManager(manager.Id, secret);
        }
Exemple #17
0
        public void HasAccess()
        {
            var apiRepository = new ApiMongoRepository(CONNECTION_STRING);
            var repository    = new MongoRepository(CONNECTION_STRING,
                                                    apiRepository);
            var userName = "******";
            var secret   = "test";
            var manager  = repository.CreateManager(userName, secret);

            var domain = repository.CreateDomain("test", manager);

            var result = repository.HasAccess(domain, manager);

            Assert.True(result);

            repository.DeleteManager(manager.Id, secret);
        }
Exemple #18
0
        public void GetDomains()
        {
            var apiRepository = new ApiMongoRepository(CONNECTION_STRING);
            var repository    = new MongoRepository(CONNECTION_STRING,
                                                    apiRepository);
            var userName = "******";
            var secret   = "test";
            var manager  = repository.CreateManager(userName, secret);


            repository.CreateDomain("test", manager);
            repository.CreateDomain("test2", manager);
            var domains = repository.GetDomains(manager.Id);

            Assert.AreEqual(2, domains.Length);
            repository.DeleteManager(manager.Id, secret);
        }
Exemple #19
0
        public void Forgot()
        {
            var apiRepository = new ApiMongoRepository(CONNECTION);
            var repository    = new MongoRepository(CONNECTION, apiRepository);
            var manager       = repository.CreateManager("test", "test");

            var domain = repository.CreateDomain("test", manager);

            apiRepository.CreateUser(domain.Key, "test", "test",
                                     "*****@*****.**");

            var result = apiRepository
                         .Forgot(domain.Key, "*****@*****.**");

            Assert.True(result.Length > 0);

            repository.DeleteDomain(domain.Id);
            repository.DeleteManager(manager.Id, "test");
        }
Exemple #20
0
        public void Disable()
        {
            var apiRepository = new ApiMongoRepository(CONNECTION);
            var repository    = new MongoRepository(CONNECTION, apiRepository);
            var manager       = repository.CreateManager("test", "test");

            var domain = repository.CreateDomain("test", manager);

            var user = apiRepository.CreateUser(domain.Key, "test", "test",
                                                "*****@*****.**");

            user = apiRepository.Authenticate(domain.Key, "test", "test");
            bool result = apiRepository.Disable(user.AuthToken, domain.Key);

            Assert.True(result);

            repository.DeleteDomain(domain.Id);
            repository.DeleteManager(manager.Id, "test");
        }
Exemple #21
0
        public void GetRolesWithClaim()
        {
            var apiRepository = new ApiMongoRepository(CONNECTION_STRING);
            var repository    = new MongoRepository(CONNECTION_STRING,
                                                    apiRepository);
            var userName = "******";
            var secret   = "test";
            var manager  = repository.CreateManager(userName, secret);

            var domain = repository.CreateDomain("test", manager);

            var role = repository.CreateRole(domain.Id, "test");

            role.Claims.Add("claim1");

            repository.UpdateRole(role);

            var roles = repository.GetRolesWithClaim(domain.Id, "claim1");

            Assert.AreEqual(1, roles.Length);
            repository.DeleteManager(manager.Id, secret);
        }