Skip to content

Commit

Permalink
[requested-changes] Removed rsa_public_key_path from settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Aryamanz29 committed Aug 9, 2022
1 parent e0e23d9 commit 13b6416
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 27 deletions.
7 changes: 2 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1212,8 +1212,6 @@ in `openwisp settings <https://github.com/openwisp/openwisp-monitoring/blob/mast
BQIDAQAB
"""
),
# relative to /root directory
'rsa_public_key_path' : '/tmp/iperf-public-key.pem',
'client_options': {
'port': 5209,
'udp': {'bitrate': '20M'},
Expand Down Expand Up @@ -1364,9 +1362,8 @@ For example, if you want to change only the **port number** of
+--------------+-------------------------------+

This setting allows you to set whether
`iperf check RSA public key <#configure-iperf-check-for-authentication>`_ will be deleted from the path
defined in `OPENWISP_MONITORING_IPERF_CHECK_CONFIG <#OPENWISP_MONITORING_IPERF_CHECK_CONFIG>`_
after successful completion of the check or not.
`iperf check RSA public key <#configure-iperf-check-for-authentication>`_
will be deleted after successful completion of the check or not.

``OPENWISP_MONITORING_AUTO_CHARTS``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
8 changes: 1 addition & 7 deletions openwisp_monitoring/check/classes/iperf.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@
'type': 'string',
'default': '',
},
'rsa_public_key_path': {
'type': 'string',
'default': '/tmp/iperf-rsa-public.pem',
},
'client_options': {
'type': 'object',
'properties': {
Expand Down Expand Up @@ -156,9 +152,7 @@ def check(self, store=True):
password = self._get_param('password', 'password.default')
key = self._get_param('rsa_public_key', 'rsa_public_key.default')
rsa_public_key = self._get_compelete_rsa_key(key)
rsa_public_key_path = self._get_param(
'rsa_public_key_path', 'rsa_public_key_path.default'
)
rsa_public_key_path = '/tmp/iperf-public-key.pem'

command_tcp = f'echo "{rsa_public_key}" > {rsa_public_key_path} && \
IPERF3_PASSWORD="{password}" iperf3 -c {server} -p {port} -t {time} \
Expand Down
6 changes: 1 addition & 5 deletions openwisp_monitoring/check/tests/iperf_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -832,11 +832,7 @@
iperf3 homepage at: https://software.es.net/iperf/
Report bugs to: https://github.com/esnet/iperf
iperf3: parameter error - you must specify username (max 20 chars), password (max 20 chars) and a path to a valid public rsa client to be used
Keyword arguments:
argument -- description
Return: return_description"""
iperf3: parameter error - you must specify username (max 20 chars), password (max 20 chars) and a path to a valid public rsa client to be used"""

TEST_RSA_KEY = """MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwuEm+iYrfSWJOupy6X3N
dxZvUCxvmoL3uoGAs0O0Y32unUQrwcTIxudy38JSuCccD+k2Rf8S4WuZSiTxaoea
Expand Down
15 changes: 5 additions & 10 deletions openwisp_monitoring/check/tests/test_iperf.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def _set_auth_expected_calls(self, dc, org_id, config):
test_prefix = '-----BEGIN PUBLIC KEY-----\n'
test_suffix = '\n-----END PUBLIC KEY-----'
key = config[org_id]['rsa_public_key']
rsa_key_path = config[org_id]['rsa_public_key_path']
rsa_key_path = '/tmp/iperf-public-key.pem'

self._EXPECTED_COMMAND_CALLS = [
call(
Expand Down Expand Up @@ -172,7 +172,6 @@ def test_iperf_check_params(
'username': 'openwisp-test-user',
'password': 'openwisp_pass',
'rsa_public_key': TEST_RSA_KEY,
'rsa_public_key_path': rsa_key_path,
'client_options': {
'port': 6201,
'time': 20,
Expand All @@ -187,6 +186,7 @@ def test_iperf_check_params(
username = test_params['username']
password = test_params['password']
key = test_params['rsa_public_key']
rsa_key_path = '/tmp/iperf-public-key.pem'
check.params = test_params
check.save()
self._EXPECTED_COMMAND_CALLS = [
Expand Down Expand Up @@ -367,16 +367,14 @@ def test_iperf_check(self, mock_warn, mock_get_iperf_servers, mock_exec_command)
org_id: {
'username': 'test',
'password': 'testpass',
'rsa_public_key': TEST_RSA_KEY,
'rsa_public_key_path': '/invalid_path/iperf-rsa-public.pem',
'rsa_public_key': 'INVALID_RSA_KEY',
}
}
with patch.object(app_settings, 'IPERF_CHECK_CONFIG', iperf_config):
dir_error = "ash: can't create /invalid_path/iperf-rsa-public.pem: nonexistent directory"
mock_exec_command.side_effect = [(dir_error, 1), (PARAM_ERROR, 1)]
mock_exec_command.side_effect = [(PARAM_ERROR, 1), (PARAM_ERROR, 1)]
EXPECTED_WARN_CALLS = [
call(
f'Iperf check failed for "{self.device}", error - {dir_error}'
f'Iperf check failed for "{self.device}", error - {PARAM_ERROR}'
),
call(
f'Iperf check failed for "{self.device}", error - {PARAM_ERROR}'
Expand Down Expand Up @@ -538,23 +536,20 @@ def test_iperf_check_auth_config(
'username': 'test',
'password': 'testpass',
'rsa_public_key': TEST_RSA_KEY,
'rsa_public_key_path': '/tmp/test-rsa.pem',
}
}
iperf_conf_wrong_pass = {
org_id: {
'username': 'test',
'password': 'wrongpass',
'rsa_public_key': TEST_RSA_KEY,
'rsa_public_key_path': '/tmp/test-rsa.pem',
}
}
iperf_conf_wrong_user = {
org_id: {
'username': 'wronguser',
'password': 'testpass',
'rsa_public_key': TEST_RSA_KEY,
'rsa_public_key_path': '/tmp/test-rsa.pem',
}
}
auth_error = "test authorization failed"
Expand Down

0 comments on commit 13b6416

Please sign in to comment.