def test_rsa_parser_algorithm_mismatch(self, mock_decode): public_key_text = 'ssh-rsa key' parser = rsa_parser.RSAParser() with mock.patch.object(parser, '_get_fields') as mock_get_fields: mock_get_fields.return_value = [b'otheralgo', b'exp', b'mod'] self.assertRaises(ValueError, parser.parse, public_key_text) mock_decode.assert_called_once_with('key') mock_get_fields.assert_called_once_with(mock_decode.return_value)
def test_rsa_parser_success(self): public_key_text = 'ssh-rsa ' + self._get_good_key() parser = rsa_parser.RSAParser() parser.parse(public_key_text) print(parser.modulus) self.assertEqual('ssh-rsa', parser.algorithm) self.assertEqual(self._get_good_modulus(), parser.modulus) self.assertEqual(self._get_good_exponent(), parser.exponent)
def test_rsa_parser_too_few_encoded_fields(self, mock_decode): public_key_text = 'ssh-rsa key' mock_decode.return_value = b'decodedkey' parser = rsa_parser.RSAParser() with mock.patch.object(parser, '_get_fields') as mock_get_fields: mock_get_fields.return_value = [b'ssh-rsa', b'exp'] self.assertRaises(ValueError, parser.parse, public_key_text) mock_decode.assert_called_once_with('key') mock_get_fields.assert_called_once_with(mock_decode.return_value)
def test_rsa_parser_wrong_algorithm(self): public_key_text = 'wrongalgo key' parser = rsa_parser.RSAParser() self.assertRaises(ValueError, parser.parse, public_key_text)
def test_rsa_parser_too_few_public_key_text_fields(self): public_key_text = 'algo' parser = rsa_parser.RSAParser() self.assertRaises(ValueError, parser.parse, public_key_text)