def test_security(): from ldap2pg.config import Configuration config = Configuration() minimal_config = dict(sync_map=[]) with pytest.raises(ValueError): config.merge(environ=dict(), file_config=dict( minimal_config, ldap=dict(password='******'), )) with pytest.raises(ValueError): # Refuse world readable postgres URI with password config.merge(environ=dict(), file_config=dict( minimal_config, postgres=dict(dsn='password=unsecure'), )) with pytest.raises(ValueError): # Refuse world readable postgres URI with password config.merge(environ=dict(), file_config=dict( minimal_config, postgres=dict(dsn='postgres://*****:*****@h'), )) config.merge(environ=dict(), file_config=dict( minimal_config, postgres=dict(dsn='postgres://u@h'), ))
def test_merge(): from ldap2pg.config import Configuration # Noop config = Configuration() config.merge(file_config={}, environ={}) minimal_config = dict(verbose=True, sync_map=[]) config.merge( file_config=minimal_config, environ=dict(), ) config.merge( file_config=minimal_config, environ=dict(LDAPPASSWORD=b'envpass', PGDSN=b'envdsn'), ) assert 'envpass' == config['ldap']['password'] assert 'envdsn' == config['postgres']['dsn']
def test_merge_and_mappings(): from ldap2pg.config import Configuration # Noop config = Configuration() with pytest.raises(ValueError): config.merge(file_config={}, environ={}) # Minimal configuration minimal_config = dict( ldap=dict(host='confighost'), sync_map=dict(ldap=dict(), role=dict()), ) config.merge( file_config=minimal_config, environ=dict(), ) config.merge( file_config=minimal_config, environ=dict(LDAP_PASSWORD='******', PGDSN='envdsn'), ) assert 'confighost' == config['ldap']['host'] assert 'envpass' == config['ldap']['password'] assert 'envdsn' == config['postgres']['dsn']