Пример #1
0
def test_search_none_existing_entry(mocker, settings, base_dn, search_filter, attributes, msg_ids):
    page_ctrl = MagicMock()
    mocker.patch('flask_multipass.providers.ldap.operations.SimplePagedResultsControl', return_value=page_ctrl)
    ldap_connection = MagicMock(result3=MagicMock(side_effect=NO_SUCH_OBJECT),
                                search_ext=MagicMock(side_effect=msg_ids))
    mocker.patch('flask_multipass.providers.ldap.util.ReconnectLDAPObject', return_value=ldap_connection)

    with ldap_context(settings):
        for result in search(base_dn, search_filter, attributes):
            pytest.fail('search should not yield any result')
Пример #2
0
def test_search(mocker, settings, base_dn, search_filter, attributes, mock_data, expected):
    mock_data['cookies'].append('')  # last search operation should not return a cookie
    page_ctrl = MagicMock()
    mocker.patch('flask_multipass.providers.ldap.operations.SimplePagedResultsControl', return_value=page_ctrl)
    ldap_connection = MagicMock(result3=MagicMock(side_effect=((None, entries, None, [page_ctrl])
                                                               for entries in mock_data['results'])),
                                search_ext=MagicMock(side_effect=mock_data['msg_ids']))
    mocker.patch('flask_multipass.providers.ldap.util.ReconnectLDAPObject', return_value=ldap_connection)
    mocker.patch('flask_multipass.providers.ldap.operations.get_page_cookie', side_effect=mock_data['cookies'])

    with ldap_context(settings):
        for i, result in enumerate(search(base_dn, search_filter, attributes)):
            assert result == expected[i]
Пример #3
0
def test_search_none_existing_entry(mocker, settings, base_dn, search_filter,
                                    attributes, msg_ids):
    page_ctrl = MagicMock()
    mocker.patch(
        'flask_multipass.providers.ldap.operations.SimplePagedResultsControl',
        return_value=page_ctrl)
    ldap_connection = MagicMock(result3=MagicMock(side_effect=NO_SUCH_OBJECT),
                                search_ext=MagicMock(side_effect=msg_ids))
    mocker.patch('flask_multipass.providers.ldap.util.ReconnectLDAPObject',
                 return_value=ldap_connection)

    with ldap_context(settings):
        for result in search(base_dn, search_filter, attributes):
            pytest.fail('search should not yield any result')
Пример #4
0
def test_search(mocker, settings, base_dn, search_filter, attributes,
                mock_data, expected):
    mock_data['cookies'].append(
        '')  # last search operation should not return a cookie
    page_ctrl = MagicMock()
    mocker.patch(
        'flask_multipass.providers.ldap.operations.SimplePagedResultsControl',
        return_value=page_ctrl)
    ldap_connection = MagicMock(
        result3=MagicMock(side_effect=((None, entries, None, [page_ctrl])
                                       for entries in mock_data['results'])),
        search_ext=MagicMock(side_effect=mock_data['msg_ids']))
    mocker.patch('flask_multipass.providers.ldap.util.ReconnectLDAPObject',
                 return_value=ldap_connection)
    mocker.patch('flask_multipass.providers.ldap.operations.get_page_cookie',
                 side_effect=mock_data['cookies'])

    with ldap_context(settings):
        for i, result in enumerate(search(base_dn, search_filter, attributes)):
            assert result == expected[i]
Пример #5
0
 def _search_groups(self, search_filter):  # pragma: no cover
     return search(self.ldap_settings['group_base'],
                   search_filter,
                   attributes=[self.ldap_settings['gid']])
Пример #6
0
 def _search_users(self, search_filter):  # pragma: no cover
     return search(self.ldap_settings['user_base'], search_filter,
                   self._attributes)
Пример #7
0
 def _search_groups(self, search_filter):  # pragma: no cover
     return search(self.ldap_settings['group_base'], search_filter, attributes=[self.ldap_settings['gid']])
Пример #8
0
 def _search_users(self, search_filter):  # pragma: no cover
     return search(self.ldap_settings['user_base'], search_filter, self._attributes)