Пример #1
0
    def test_match_in_single_attribute_with_schema(self):
        self.delete_at_teardown.append(
            add_user(self.connection,
                     testcase_id,
                     'mat-1',
                     attributes={test_singlevalued_attribute: 'FALSE'}))
        self.delete_at_teardown.append(
            add_user(self.connection,
                     testcase_id,
                     'mat-2',
                     attributes={test_singlevalued_attribute: 'FALSE'}))
        self.delete_at_teardown.append(
            add_user(self.connection,
                     testcase_id,
                     'mat-3',
                     attributes={test_singlevalued_attribute: 'TRUE'}))
        r = Reader(self.connection, 'inetorgperson', test_base,
                   'cn:=' + testcase_id + 'mat-*')

        results = r.search()
        self.assertEqual(len(results), 3)

        e = r.match(test_singlevalued_attribute, 'FALSE')
        self.assertEqual(len(e), 2)
        e = r.match(test_singlevalued_attribute, 'fAlSe')
        self.assertEqual(len(e), 2)
Пример #2
0
    def test_match_in_single_attribute_with_schema(self):
        self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'mat-1', attributes={test_singlevalued_attribute: 'FALSE'}))
        self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'mat-2', attributes={test_singlevalued_attribute: 'FALSE'}))
        self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'mat-3', attributes={test_singlevalued_attribute: 'TRUE'}))
        r = Reader(self.connection, 'inetorgperson', test_base, 'cn:=' + testcase_id + 'mat-*')

        results = r.search()
        self.assertEqual(len(results), 3)

        e = r.match(test_singlevalued_attribute, 'FALSE')
        self.assertEqual(len(e), 2)
        e = r.match(test_singlevalued_attribute, 'fAlSe')
        self.assertEqual(len(e), 2)
Пример #3
0
    def test_match_in_multiple_attribute(self):
        self.delete_at_teardown.append(
            add_user(self.connection,
                     testcase_id,
                     'mat-1',
                     attributes={
                         test_multivalued_attribute:
                         ['givenname-1', 'givenname-1a'],
                         'street':
                         '1a'
                     }))
        self.delete_at_teardown.append(
            add_user(self.connection,
                     testcase_id,
                     'mat-2',
                     attributes={
                         test_multivalued_attribute:
                         ['givenname-2', 'givenname-2a'],
                         'street':
                         '3a'
                     }))
        self.delete_at_teardown.append(
            add_user(self.connection,
                     testcase_id,
                     'mat-3',
                     attributes={
                         test_multivalued_attribute:
                         ['givenname-3', 'givenname-3a'],
                         'street':
                         '4a'
                     }))
        o = ObjectDef('inetOrgPerson')
        o += AttrDef('cn', 'Common Name')
        o += AttrDef('sn', 'Surname')
        o += AttrDef(test_multivalued_attribute, 'Given Name')
        o += AttrDef('street', 'Street')

        query_text = 'Common Name:=' + testcase_id + 'mat-*'
        r = Reader(self.connection, o, test_base, query_text)

        results = r.search()
        self.assertEqual(len(results), 3)

        e = r.match(['Given Name', 'Street'], '3a')  # multiple matches
        self.assertEqual(len(e), 2)
        e = r.match(['Given Name', 'street'], '1a')  # single match
        self.assertEqual(len(e), 1)
        e = r.match(['Given Name', 'street'], 'no-match')  # no match
        self.assertEqual(len(e), 0)
Пример #4
0
def _match_groups(reader: Reader, groups: Optional[Union[Iterable[str], str]], attributes, default=False) -> bool:
    """
    Check if at least one of the provided groups exists in a LDAP Reader for Groups.
    :param reader: LDAP Reader for Groups
    :param groups: One or more group names
    :param attributes: List of attributes to check for comparing group's name
    :param default: Default value when no group is provided.
    :return: Boolean if exist
    """
    if not groups:
        return default
    elif isinstance(groups, str):
        return bool(reader.match(attributes, groups))
    else:
        return bool(any(reader.match(attributes, group) for group in groups))
Пример #5
0
    def test_match_in_single_attribute(self):
        self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'mat-1', attributes={test_multivalued_attribute: ['givenname-1', 'givenname-1a']}))
        self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'mat-2', attributes={test_multivalued_attribute: ['givenname-2', 'givenname-2a']}))
        self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'mat-3', attributes={test_multivalued_attribute: ['givenname-3', 'givenname-3a']}))
        o = ObjectDef('inetOrgPerson')
        o += AttrDef('cn', 'Common Name')
        o += AttrDef('sn', 'Surname')
        o += AttrDef(test_multivalued_attribute, 'Given Name')

        query_text = 'Common Name:=' + testcase_id + 'mat-*'
        r = Reader(self.connection, o, test_base, query_text)

        results = r.search()
        self.assertEqual(len(results), 3)

        e = r.match('Given Name', 'name')  # multiple matches
        self.assertEqual(len(e), 3)
        e = r.match('Given Name', '2a')  # single match
        self.assertEqual(len(e), 1)
        e = r.match('Given Name', 'no-match')  # no match
        self.assertEqual(len(e), 0)
Пример #6
0
    def test_match_in_single_attribute_with_schema(self):
        self.delete_at_teardown.append(
            add_user(self.connection,
                     testcase_id,
                     'match-1',
                     attributes={
                         'givenname': ['givenname-1', 'givenname-1a'],
                         'loginDisabled': 'FALSE'
                     }))
        self.delete_at_teardown.append(
            add_user(self.connection,
                     testcase_id,
                     'match-2',
                     attributes={
                         'givenname': ['givenname-2', 'givenname-2a'],
                         'loginDisabled': 'FALSE'
                     }))
        self.delete_at_teardown.append(
            add_user(self.connection,
                     testcase_id,
                     'match-3',
                     attributes={
                         'givenname': ['givenname-3', 'givenname-3a'],
                         'loginDisabled': 'TRUE'
                     }))
        r = Reader(self.connection, 'inetorgperson', test_base,
                   'cn:=' + testcase_id + 'match-*')

        results = r.search()
        self.assertEqual(len(results), 3)

        e = r.match('givenname', 'name')  # multiple matches
        self.assertEqual(len(e), 3)
        e = r.match('givenname', '2a')  # single match
        self.assertEqual(len(e), 1)
        e = r.match('givenname', 'no-match')  # no match
        self.assertEqual(len(e), 0)
        e = r.match('loginDisabled', False)
        self.assertEqual(len(e), 2)
        e = r.match('loginDisabled', 'FALSE')
        self.assertEqual(len(e), 2)
        e = r.match('loginDisabled', 'fAlSe')
        self.assertEqual(len(e), 2)