def setUp(self): app = flask.Flask(__name__) app.config.update(BASE_CONFIG) self.app = app ldap3_manager = ldap3_login.LDAP3LoginManager(app) self.manager = ldap3_manager
def test_server_added_when_unset(self): """ Ensures a default server is added when `LDAP_ADD_SERVER` is not set. """ config = dict(LDAPAddServerConfigTestCase.DEFAULT_CONFIG) ldap3_manager = ldap3_login.LDAP3LoginManager() ldap3_manager.init_config(config) self.assertEqual(len(list(ldap3_manager._server_pool)), 1)
def test_server_pool(self): manager = ldap3_login.LDAP3LoginManager() for _ in range(10): app = flask.Flask(__name__) app.config.update(BASE_CONFIG) manager.init_app(app) with app.test_request_context(): manager.connection self.assertEqual(len(list(app.ldap3_login_manager_server_pool)), 1)
def test_server_added_when_false(self): """ Ensures no server is added when `LDAP_ADD_SERVER` is False. """ config = dict(LDAPAddServerConfigTestCase.DEFAULT_CONFIG) config['LDAP_ADD_SERVER'] = False ldap3_manager = ldap3_login.LDAP3LoginManager() ldap3_manager.init_config(config) self.assertEqual(len(list(ldap3_manager._server_pool)), 0)
def test_server_added_when_true(self): """ Ensures a default server is added when `LDAP_ADD_SERVER` is True. """ self.app.config.update(LDAPAddServerConfigTestCase.DEFAULT_CONFIG) self.app.config['LDAP_ADD_SERVER'] = True ldap3_manager = ldap3_login.LDAP3LoginManager() ldap3_manager.init_app(self.app) self.assertEqual(len(list(ldap3_manager._server_pool)), 1)
def setUp(self): config = dict(LDAP_HOST='ad.mydomain.com', LDAP_BASE_DN='dc=mydomain,dc=com', LDAP_USER_DN='ou=users', LDAP_GROUP_DN='ou=groups', LDAP_BIND_USER_DN='cn=Bind,dc=mydomain,dc=com', LDAP_BIND_USER_PASSWORD='******', LDAP_USER_RDN_ATTR='cn', LDAP_USER_LOGIN_ATTR='cn') ldap3_manager = ldap3_login.LDAP3LoginManager() ldap3_manager.init_config(config) self.manager = ldap3_manager
def test_server_added_when_false(self): """ Ensures no server is added when `LDAP_ADD_SERVER` is False. """ self.app.config.update(LDAPAddServerConfigTestCase.DEFAULT_CONFIG) self.app.config["LDAP_ADD_SERVER"] = False ldap3_manager = ldap3_login.LDAP3LoginManager() ldap3_manager.init_app(self.app) self.assertEqual(len(list(self.app.ldap3_login_manager_server_pool)), 0)
def test_error_on_use_ssl_and_tls_ctx(self): """ Ensures a ValueError is thrown when use_ssl is False and a TLS context is passed together. """ ldap3_manager = ldap3_login.LDAP3LoginManager() self.app.config.update(AddServerTestCase.DEFAULT_CONFIG) ldap3_manager.init_app(self.app) def add_server(): return ldap3_manager.add_server("ad2.mydomain.com", 389, use_ssl=False, tls_ctx=object()) self.assertRaises(ValueError, add_server)
def test_server_with_no_tls_ctx(self): """ Ensures a server is created/added to the pool, however that the server was instantiated with `tls=None` and use_ssl=False """ ldap3_manager = ldap3_login.LDAP3LoginManager() self.app.config.update(AddServerTestCase.DEFAULT_CONFIG) ldap3_manager.init_app(self.app) ldap3_manager.add_server("ad2.mydomain.com", 389, use_ssl=False, tls_ctx=None) self.assertEqual(len(ldap3_manager._server_pool.servers), 1) server = ldap3_manager._server_pool.servers[-1] self.assertEqual(server.tls, None) self.assertFalse(server.use_ssl)
def setUp(self): app = flask.Flask(__name__) app.config['LDAP_HOST'] = 'ad.mydomain.com' app.config['LDAP_BASE_DN'] = 'dc=mydomain,dc=com' app.config['LDAP_USER_DN'] = 'ou=users' app.config['LDAP_GROUP_DN'] = 'ou=groups' app.config['LDAP_BIND_USER_DN'] = 'cn=Bind,dc=mydomain,dc=com' app.config['LDAP_BIND_USER_PASSWORD'] = '******' app.config['LDAP_USER_RDN_ATTR'] = 'uid' app.config['LDAP_USER_LOGIN_ATTR'] = 'mail' app.config['SECRET_KEY'] = 'secrets' app.config['WTF_CSRF_ENABLED'] = False self.app = app ldap3_manager = ldap3_login.LDAP3LoginManager(app) self.manager = ldap3_manager pass
def test_server_with_tls_with_ssl(self): """ Ensures a server is created/added to the pool, however that the server was instantiated with `tls=<TLS CTX OBJECT>` and use_ssl=True. """ fake_tls_ctx = Tls() ldap3_manager = ldap3_login.LDAP3LoginManager() self.app.config.update(AddServerTestCase.DEFAULT_CONFIG) ldap3_manager.init_app(self.app) ldap3_manager.add_server("ad2.mydomain.com", 389, use_ssl=True, tls_ctx=fake_tls_ctx) self.assertEqual(len(ldap3_manager._server_pool.servers), 1) server = ldap3_manager._server_pool.servers[-1] self.assertEqual(server.tls, fake_tls_ctx) self.assertTrue(server.use_ssl)
def setUp(self): app = flask.Flask(__name__) app.config["LDAP_HOST"] = "ad2.mydomain.com" app.config["LDAP_BASE_DN"] = "dc=mydomain,dc=com" app.config["LDAP_USER_DN"] = "ou=users" app.config["LDAP_GROUP_DN"] = "ou=groups" app.config["LDAP_BIND_USER_DN"] = "cn=Bind,dc=mydomain,dc=com" app.config["LDAP_BIND_USER_PASSWORD"] = "******" app.config["LDAP_USER_RDN_ATTR"] = "uid" app.config["LDAP_USER_LOGIN_ATTR"] = "mail" app.config["SECRET_KEY"] = "secrets" app.config["WTF_CSRF_ENABLED"] = False self.app = app ldap3_manager = ldap3_login.LDAP3LoginManager(app) self.manager = ldap3_manager self.app.config.update({ "LDAP_USER_RDN_ATTR": "cn", "LDAP_USER_LOGIN_ATTR": "cn" }) self.app.app_context().push()