Esempio n. 1
0
 def pubkeys(self):
     if self._cache['pubkeys'] is None:  # an empty list is allowed :)
         ps = self.rest_client.account[self.user_id].pubkey.get()[1]
         self._cache['pubkeys'] = [
             mkVscAccountPubkey(p) for p in ps if not p['deleted']
         ]
     return self._cache['pubkeys']
Esempio n. 2
0
    def test_pubkeys_instantiation(self):

        mock_client = mock.MagicMock()
        test_account = mkVscAccount(test_account_1)
        mock_client.account[test_account.vsc_id].pubkey.get.return_value = (200, test_pubkeys_1)

        accountpageuser = user.VscAccountPageUser(test_account.vsc_id, rest_client=mock_client)

        self.assertEqual(set(accountpageuser.pubkeys), set([mkVscAccountPubkey(p) for p in test_pubkeys_1]))
Esempio n. 3
0
    def test_sync_altered_accounts_unicode_pubkey(self, mock_add_or_update):
        """Test the sync_altered accounts function with a pubkey containing unicode"""
        mock_client = mock.MagicMock()
        test_account = mkVscAccount(test_account_1)
        mock_client.account[test_account.vsc_id] = mock.MagicMock()
        mock_client.account.modified[1].get.return_value = (200,
                                                            [test_account_1])
        mock_client.account[test_account.vsc_id].usergroup.get.return_value = (
            200, test_usergroup_1)
        mock_client.get_public_keys.return_value = [
            mkVscAccountPubkey(p) for p in test_unicode_pubkeys
        ]
        mock_client.account[test_account.vsc_id].quota.get.return_value = (
            200, test_quota)

        mock_add_or_update.return_value = UPDATED
        ldapsyncer = LdapSyncer(mock_client)
        accounts = ldapsyncer.sync_altered_accounts(1)
        self.assertEqual(
            accounts, {
                'error': set([]),
                'new': set([]),
                'updated': set([test_account.vsc_id])
            })
        if is_py2():
            expected_key = 'some pubkey \\[email protected]\\u201d'
        else:
            expected_key = 'some pubkey \\xe2\\x80\\[email protected]\\xe2\\x80\\x9d'
        ldap_attrs = {
            'status': ['active'],
            'scratchDirectory': ['/user/scratch/gent/vsc400/vsc40075'],
            'dataDirectory': ['/user/data/gent/vsc400/vsc40075'],
            'cn': 'vsc40075',
            'homeQuota': ['5242880'],
            'institute': ['gent'],
            'loginShell': ['/bin/bash'],
            'uidNumber': ['2540075'],
            'researchField': ['Bollocks'],
            'gidNumber': ['2540075'],
            'gecos': ['Foo Bar'],
            'dataQuota': ['1'],
            'homeDirectory': ['/user/home/gent/vsc400/vsc40075'],
            'mail': ['*****@*****.**'],
            'scratchQuota': ['1'],
            'pubkey': [expected_key],
            'instituteLogin': ['foobar'],
            'uid': ['vsc40075']
        }
        mock_add_or_update.assert_called_with(VscLdapUser, test_account.vsc_id,
                                              ldap_attrs, True)
Esempio n. 4
0
    def test_sync_forceinactive_account(self, mock_add_or_update):
        """Test the sync_altered accounts function"""
        mock_client = mock.MagicMock()
        test_account = mkVscAccount(test_account_4)
        mock_client.account[test_account.vsc_id] = mock.MagicMock()
        mock_client.account.modified[1].get.return_value = (200, [test_account_4])
        mock_client.account[test_account.vsc_id].usergroup.get.return_value = (200, test_usergroup_1)
        mock_client.get_public_keys.return_value = [mkVscAccountPubkey(p) for p in test_pubkeys_1]
        mock_client.account[test_account.vsc_id].quota.get.return_value = (200, test_quota)

        mock_add_or_update.return_value = UPDATED
        ldapsyncer = LdapSyncer(mock_client)
        accounts = ldapsyncer.sync_altered_accounts(1)
        self.assertEqual(accounts, {'error': set([]), 'new': set([]), 'updated': set([test_account.vsc_id])})
        ldap_attrs = {'status': ['inactive'], 'scratchDirectory': ['/scratch/brussel/vsc100/vsc10001'], 'dataDirectory': ['/data/brussel/vsc100/vsc10001'], 'cn': 'vsc10004', 'homeQuota': ['5242880'], 'institute': ['brussel'], 'loginShell': ['/bin/bash'], 'uidNumber': ['2510004'], 'researchField': ['Dinges'], 'gidNumber': ['2540075'], 'gecos': ['Foo Bar'], 'dataQuota': ['1'], 'homeDirectory': ['/user/brussel/vsc100/vsc10001'], 'mail': ['*****@*****.**'], 'scratchQuota': ['1'], 'pubkey': ['pubkey1', 'pubkey2'], 'instituteLogin': ['fooby'], 'uid': ['vsc10004']}
        mock_add_or_update.assert_called_with(VscLdapUser, test_account.vsc_id, ldap_attrs, True)