Esempio n. 1
0
        public void ServerConnect()

        {
            try

            {
                Connection = new LdapConnectionService(Server, BindDN, Password);



                if (Connection.CreateConnection() == 1)
                {
                    if (string.IsNullOrWhiteSpace(BaseDN))
                    {
                        TextQueryDTO dto = new TextQueryDTO("", LdapScope.SCOPE_BASE, VMDirConstants.SEARCH_ALL_OC,
                                                            new string[] { VMDirConstants.ATTR_ROOT_DOMAIN_NAMING_CONTEXT }, 0, IntPtr.Zero, 0);
                        try
                        {
                            Connection.Search(dto,
                                              delegate(ILdapMessage searchRequest, List <ILdapEntry> entries)
                            {
                                BaseDN = GetRootDomainNamingContext(entries);
                            });
                        }
                        catch (Exception)
                        {
                            throw new Exception(VMDirConstants.ERR_DN_RETRIEVAL);
                        }
                    }
                    else
                    {
                        TextQueryDTO dto = new TextQueryDTO(BaseDN, LdapScope.SCOPE_BASE, VMDirConstants.SEARCH_ALL_OC,
                                                            new string[] { VMDirConstants.ATTR_DN }, 0, IntPtr.Zero, 0);
                        Connection.Search(dto, null);
                    }

                    IsLoggedIn = true;
                }

                else
                {
                    IsLoggedIn = false;
                }
            }

            catch (Exception)

            {
                IsLoggedIn = false;

                throw;
            }
        }
Esempio n. 2
0
        public async Task Login_GivenUserModelAndPassword_ReturnsFailedSignInResult()
        {
            // Arrange
            var ldapAuthenticationModeRepository = Substitute.For <ILdapAuthenticationModeRepository>();
            var userRepository = Substitute.For <IUserRepository>();

            var ldapConnectionService = new LdapConnectionService(ldapAuthenticationModeRepository, userRepository, mockedLdapConnectionClient, mockedLdapConnectionClient);

            // Act
            var signInResult = await ldapConnectionService.Login(mockUserModel, "Password1#");

            // Assert
            Assert.False(signInResult.Succeeded, "Testing an LDAP login for should return failed.");
        }
Esempio n. 3
0
        public async Task CheckIfUserExist_GivenUserModelAndLdapAuthMode_ReturnsFalse()
        {
            // Arrange
            var ldapAuthenticationModeRepository = Substitute.For <ILdapAuthenticationModeRepository>();
            var userRepository = Substitute.For <IUserRepository>();

            ldapAuthenticationModeRepository.GetByIdAsync(mockUserModel.LdapAuthenticationMode.Id, Arg.Any <bool>(), Arg.Any <bool>()).Returns(mockUserModel.LdapAuthenticationMode);
            var ldapConnectionService = new LdapConnectionService(ldapAuthenticationModeRepository, userRepository, mockedLdapConnectionClient, mockedLdapConnectionClient);

            // Act
            var checkResult = await ldapConnectionService.CheckIfUserExist(mockUserModel.UserName, mockUserModel.LdapAuthenticationMode.Id);

            // Assert
            Assert.False(checkResult, "Checking if an LDAP user exist should return false.");
        }
Esempio n. 4
0
        public void TestLdapSettings_GivenUserModelAndLdapAuthMode_ReturnsTrue()
        {
            // Arrange
            var ldapAuthenticationModeRepository = Substitute.For <ILdapAuthenticationModeRepository>();
            var userRepository = Substitute.For <IUserRepository>();

            ldapAuthenticationModeRepository.GetByIdAsync(mockUserModel.LdapAuthenticationMode.Id, Arg.Any <bool>(), Arg.Any <bool>()).Returns(mockUserModel.LdapAuthenticationMode);
            var ldapConnectionService = new LdapConnectionService(ldapAuthenticationModeRepository, userRepository, mockedLdapConnectionClient, mockedLdapConnectionClient);

            // Act
            List <string> returnMessages = new List <string>();
            var           testResult     = ldapConnectionService.TestLdapSettings(mockUserModel.LdapAuthenticationMode, ref returnMessages);

            // Assert
            Assert.True(testResult, "Testing LDAP settings should return true.");
        }
Esempio n. 5
0
        public async Task CheckIfUserExist_GivenUnfindableLdapAuthMode_ThrowsItemNotFoundException()
        {
            // Arrange
            var ldapAuthenticationModeRepository = Substitute.For <ILdapAuthenticationModeRepository>();
            var userRepository = Substitute.For <IUserRepository>();

            var ldapConnectionService = new LdapConnectionService(ldapAuthenticationModeRepository, userRepository, mockedLdapConnectionClient, mockedLdapConnectionClient);

            // Act
            Exception caughtEx = null;

            try
            {
                var checkResult = await ldapConnectionService.CheckIfUserExist(mockUserModel.UserName, mockUserModel.LdapAuthenticationMode.Id);
            }
            catch (Exception ex)
            {
                caughtEx = ex;
            }

            // Assert
            Assert.True(caughtEx is ItemNotFoundException, "Attempted user check with an unfindable LdapAuthMode must throw an ItemNotFoundException.");
        }
Esempio n. 6
0
 public SchemaManager(LdapConnectionService conn)
 {
     _conn = conn;
 }