Ejemplo n.º 1
0
    def test_errors(self):
        """Test various authorized key parsing errors"""

        tests = (('Bad key', 'xxx\n'), ('Unbalanced quote', 'xxx"\n'),
                 ('Unbalanced backslash', 'xxx\\\n'), ('Missing option name',
                                                       '=xxx\n'),
                 ('Environment missing equals', 'environment="FOO"\n'),
                 ('Environment missing variable name', 'environment="=xxx"\n'),
                 ('PermitOpen missing colon', 'permitopen="xxx"\n'),
                 ('PermitOpen non-integer port', 'permitopen="xxx:yyy"\n'))

        for msg, data in tests:
            with self.subTest(msg):
                with self.assertRaises(ValueError):
                    import_authorized_keys(data)
Ejemplo n.º 2
0
    def test_errors(self):
        """Test various authorized key parsing errors"""

        tests = (
            ('Bad key', 'xxx\n'),
            ('Unbalanced quote', 'xxx"\n'),
            ('Unbalanced backslash', 'xxx\\\n'),
            ('Missing option name', '=xxx\n'),
            ('Environment missing equals', 'environment="FOO"\n'),
            ('Environment missing variable name', 'environment="=xxx"\n'),
            ('PermitOpen missing colon', 'permitopen="xxx"\n'),
            ('PermitOpen non-integer port', 'permitopen="xxx:yyy"\n')
        )

        for msg, data in tests:
            with self.subTest(msg):
                with self.assertRaises(ValueError):
                    import_authorized_keys(data)
Ejemplo n.º 3
0
    def build_keys(self, keys, from_file=False):
        """Build and import a list of authorized keys"""

        auth_keys = '# Comment line\n   # Comment line with whitespace\n\n'

        for options in keys:
            options = options + ' ' if options else ''
            keynum = 1 if 'cert-authority' in options else 0

            auth_keys += '%s%s' % (options, self.keylist[keynum])

        if from_file:
            with open('authorized_keys', 'w') as f:
                f.write(auth_keys)

            return read_authorized_keys('authorized_keys')
        else:
            return import_authorized_keys(auth_keys)
Ejemplo n.º 4
0
    def build_keys(self, keys, from_file=False):
        """Build and import a list of authorized keys"""

        auth_keys = '# Comment line\n   # Comment line with whitespace\n\n'

        for options in keys:
            options = options + ' ' if options else ''
            keynum = 1 if 'cert-authority' in options else 0

            auth_keys += '%s%s' % (options, self.keylist[keynum])

        if from_file:
            with open('authorized_keys', 'w') as f:
                f.write(auth_keys)

            return read_authorized_keys('authorized_keys')
        else:
            return import_authorized_keys(auth_keys)