
This fix provides to Synergy a security mechanism highly configurable. The security policies are pluggable so that it is possible to define any kind of authorization checks. This commit includes a very simple authorization plugin (i.e. synergy.auth.plugin.LocalHostAuthorization) which denies any command coming from clients having IP address different from the Synergy's one. Bug: #1691352 Change-Id: I2535b2a3edeea5e56cd8918d01070a6f8a534c3e Sem-Ver: bugfix
52 lines
1.6 KiB
Python
52 lines
1.6 KiB
Python
# coding: utf-8
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
"""
|
|
Test the HTTPCommand class.
|
|
|
|
"""
|
|
|
|
import mock
|
|
import requests
|
|
|
|
from synergy.client.command import HTTPCommand
|
|
from synergy.tests import base
|
|
|
|
|
|
class TestHTTPCommand(base.TestCase):
|
|
|
|
def setUp(self):
|
|
super(TestHTTPCommand, self).setUp()
|
|
self.http_command = HTTPCommand(name="dummy_httpcmd")
|
|
|
|
def test_get_name(self):
|
|
self.assertEqual("dummy_httpcmd", self.http_command.getName())
|
|
|
|
def test_configure_parser(self):
|
|
"""This method should be implemented in sub-classes."""
|
|
self.assertRaises(
|
|
NotImplementedError,
|
|
self.http_command.configureParser,
|
|
"dummy_subparser")
|
|
|
|
def test_execute_success(self):
|
|
mock_response = mock.Mock()
|
|
mock_response.text = '{"test": true}' # mock a simple json response
|
|
|
|
with mock.patch.object(requests, "get", return_value=mock_response)\
|
|
as m:
|
|
result = self.http_command.execute("dummy_url")
|
|
|
|
m.assert_called_once_with("dummy_url", headers=None, params=None)
|
|
self.assertEqual({"test": True}, result)
|