Beispiel #1
0
 def test_no_keys_for_unauthorized_user(self):
     """
     If the user is not in the mapping provided to
     L{AuthorizedKeysFilesMapping}, an empty iterator is returned
     by L{AuthorizedKeysFilesMapping.getAuthorizedKeys}
     """
     keydb = AuthorizedKeysFilesMapping({'alice': self.authorized_paths},
                                        lambda x: x)
     self.assertEqual([], list(keydb.getAuthorizedKeys('bob')))
Beispiel #2
0
 def test_no_keys_for_unauthorized_user(self):
     """
     If the user is not in the mapping provided to
     L{AuthorizedKeysFilesMapping}, an empty iterator is returned
     by L{AuthorizedKeysFilesMapping.getAuthorizedKeys}
     """
     keydb = AuthorizedKeysFilesMapping({'alice': self.authorized_paths},
                                        lambda x: x)
     self.assertEqual([], list(keydb.getAuthorizedKeys('bob')))
Beispiel #3
0
 def test_all_keys_in_all_authorized_files_for_authorized_user(self):
     """
     If the user is in the mapping provided to
     L{AuthorizedKeysFilesMapping}, an iterator with all the keys in all
     the authorized files is returned by
     L{AuthorizedKeysFilesMapping.getAuthorizedKeys}
     """
     keydb = AuthorizedKeysFilesMapping({'alice': self.authorized_paths},
                                        lambda x: x)
     keys = ['file 0 key 1', 'file 0 key 2', 'file 1 key 1', 'file 1 key 2']
     self.assertEqual(keys, list(keydb.getAuthorizedKeys('alice')))
Beispiel #4
0
 def test_all_keys_in_all_authorized_files_for_authorized_user(self):
     """
     If the user is in the mapping provided to
     L{AuthorizedKeysFilesMapping}, an iterator with all the keys in all
     the authorized files is returned by
     L{AuthorizedKeysFilesMapping.getAuthorizedKeys}
     """
     keydb = AuthorizedKeysFilesMapping({'alice': self.authorized_paths},
                                        lambda x: x)
     keys = ['file 0 key 1', 'file 0 key 2',
             'file 1 key 1', 'file 1 key 2']
     self.assertEqual(keys, list(keydb.getAuthorizedKeys('alice')))
Beispiel #5
0
    def test_ignores_nonexistant_or_unreadable_file(self):
        """
        L{AuthorizedKeysFilesMapping.getAuthorizedKeys} returns only the
        keys in the authorized files named that exist and are readable
        """
        directory = self.root.child('key2')
        directory.makedirs()

        keydb = AuthorizedKeysFilesMapping(
            {'alice': [directory.path,
                       self.root.child('key3').path,
                       self.authorized_paths[0]]},
            lambda x: x)
        self.assertEqual(['file 0 key 1', 'file 0 key 2'],
                         list(keydb.getAuthorizedKeys('alice')))
Beispiel #6
0
    def test_ignores_nonexistant_or_unreadable_file(self):
        """
        L{AuthorizedKeysFilesMapping.getAuthorizedKeys} returns only the
        keys in the authorized files named that exist and are readable
        """
        directory = self.root.child('key2')
        directory.makedirs()

        keydb = AuthorizedKeysFilesMapping(
            {
                'alice': [
                    directory.path,
                    self.root.child('key3').path, self.authorized_paths[0]
                ]
            }, lambda x: x)
        self.assertEqual(['file 0 key 1', 'file 0 key 2'],
                         list(keydb.getAuthorizedKeys('alice')))