示例#1
0
 def test_rejects_bad_group(self):
     conn = Mock()
     config = MagicMock()
     test_group = {'type':"DEADBEEF",
                   'ldap_id': "cn=test,dn=testdomain,dn=com",
                   'group_id': sentinel.group_id}
     with self.assertRaises(ldap_reader.InvalidGroupConfiguration):
         ldap_reader.get_group(conn, config, test_group)
示例#2
0
 def test_uses_base_dn(self):
     conn = Mock()
     conn.search_s.return_value = []
     config = MagicMock()
     test_group = {'type':"dn",
                   'ldap_id': "cn=test,dn=testdomain,dn=com",
                   'group_id': sentinel.group_id}
     ldap_reader.get_group((conn, sentinel.base_dn,), config, test_group)
     args, _ = conn.search_s.call_args
     self.assertIs(args[0], sentinel.base_dn)
示例#3
0
 def test_returns_empty_group(self):
     conn = Mock()
     conn.search_s.return_value = []
     test_group = {'type':"dn",
                   'ldap_id': "cn=test,dn=testdomain,dn=com",
                   'group_id': sentinel.group_id}
     self.assertEqual(
         len(ldap_reader.get_group((conn, Mock(),), MagicMock(), test_group)),
         0)
示例#4
0
    def test_returns_group_users(self):
        conn = Mock()
        config = {
            'dir_guid_source': 'user_guid_source',
            'dir_username_source': 'user_source',
            'dir_fname_source': 'fname_source',
            'dir_lname_source': 'lname_source',
            }
        ldap_results = [(Mock(), {config['dir_guid_source']    : [sentinel.guid1],
                                  config['dir_username_source']: [sentinel.testuser1],
                                  config['dir_fname_source']   : [sentinel.testfname1],
                                  config['dir_lname_source']   : [sentinel.testlname1],
                                  }
                         ),
                        (Mock(), {config['dir_guid_source']    : [sentinel.guid2],
                                  config['dir_username_source']: [sentinel.testuser2],
                                  config['dir_fname_source']   : [sentinel.testfname2],
                                  config['dir_lname_source']   : [sentinel.testlname2],
                                  }
                         ),
                        (None, [Mock()]),
                        (None, [Mock()]),
                        ]

        test_group = {'type':"dn",
                      'ldap_id': "cn=test,dn=testdomain,dn=com",
                      'group_id': sentinel.group_id}
        
        conn.search_s.return_value = ldap_results
        self.assertEqual(ldap_reader.get_group((conn, Mock(),),
                                               config,
                                               test_group),
                         [{'email'     : sentinel.testuser1,
                           'firstname' : sentinel.testfname1,
                           'lastname'  : sentinel.testlname1,
                           'uniqueid'  : sentinel.guid1,
                           'group_id'  : sentinel.group_id,
                           },
                          {'email'     : sentinel.testuser2,
                           'firstname' : sentinel.testfname2,
                           'lastname'  : sentinel.testlname2,
                           'uniqueid'  : sentinel.guid2,
                           'group_id'  : sentinel.group_id,
                           }
                          ])