summaryrefslogtreecommitdiff
path: root/smoketest/scripts/cli
diff options
context:
space:
mode:
authorViacheslav Hletenko <v.gletenko@vyos.io>2023-12-10 15:44:46 +0200
committerGitHub <noreply@github.com>2023-12-10 15:44:46 +0200
commit5f7e35e7a73b57e016082d7c1bf1f541c160b35b (patch)
tree1b98e2972bfcf3b21897f761e2c0ddab559c04d2 /smoketest/scripts/cli
parent7d536adeabb076793cd75e43f0bf168cfdf4c5f3 (diff)
parentdb0df8e75b85d39ab61bf900f211d589f6cb8506 (diff)
downloadvyos-1x-5f7e35e7a73b57e016082d7c1bf1f541c160b35b.tar.gz
vyos-1x-5f7e35e7a73b57e016082d7c1bf1f541c160b35b.zip
Merge pull request #2600 from sever-sever/T5773-smoketests
T5773: API add smoketest for load config via HTTP URL
Diffstat (limited to 'smoketest/scripts/cli')
-rwxr-xr-xsmoketest/scripts/cli/test_service_https.py69
1 files changed, 69 insertions, 0 deletions
diff --git a/smoketest/scripts/cli/test_service_https.py b/smoketest/scripts/cli/test_service_https.py
index 6cb91bcf1..703e3e8c4 100755
--- a/smoketest/scripts/cli/test_service_https.py
+++ b/smoketest/scripts/cli/test_service_https.py
@@ -23,6 +23,7 @@ from urllib3.exceptions import InsecureRequestWarning
from base_vyostest_shim import VyOSUnitTestSHIM
from base_vyostest_shim import ignore_warning
from vyos.utils.file import read_file
+from vyos.utils.process import call
from vyos.utils.process import process_named_running
from vyos.configsession import ConfigSessionError
@@ -51,6 +52,23 @@ MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgPLpD0Ohhoq0g4nhx
u8/3jHMM7sDwL3aWzW/zp54/LhCWUoLMjDdDEEigK4fal4ZF9aA9F0Ww
"""
+# to test load config via HTTP URL
+nginx_conf_smoketest = """
+server {
+ listen 8000;
+ server_name localhost;
+
+ root /tmp;
+
+ index index.html;
+
+ location / {
+ try_files $uri $uri/ =404;
+ autoindex on;
+ }
+}
+"""
+
PROCESS_NAME = 'nginx'
class TestHTTPSService(VyOSUnitTestSHIM.TestCase):
@@ -375,6 +393,57 @@ class TestHTTPSService(VyOSUnitTestSHIM.TestCase):
r = request('POST', url, verify=False, headers=headers, data=payload)
self.assertEqual(r.status_code, 200)
+ @ignore_warning(InsecureRequestWarning)
+ def test_api_config_file_load_http(self):
+ """Test load config from HTTP URL
+ """
+ address = '127.0.0.1'
+ key = 'VyOS-key'
+ url = f'https://{address}/config-file'
+ url_config = f'https://{address}/configure'
+ headers = {}
+ tmp_file = 'tmp-config.boot'
+ nginx_tmp_site = '/etc/nginx/sites-enabled/smoketest'
+
+ self.cli_set(base_path + ['api', 'keys', 'id', 'key-01', 'key', key])
+ self.cli_commit()
+
+ # load config via HTTP requires nginx config
+ call(f'sudo touch {nginx_tmp_site}')
+ call(f'sudo chown vyos:vyattacfg {nginx_tmp_site}')
+ call(f'sudo chmod +w {nginx_tmp_site}')
+
+ with open(nginx_tmp_site, 'w') as f:
+ f.write(nginx_conf_smoketest)
+ call('sudo nginx -s reload')
+
+ # save config
+ payload = {
+ 'data': '{"op": "save", "file": "/tmp/tmp-config.boot"}',
+ 'key': f'{key}',
+ }
+ r = request('POST', url, verify=False, headers=headers, data=payload)
+ self.assertEqual(r.status_code, 200)
+
+ # change config
+ payload = {
+ 'data': '{"op": "set", "path": ["interfaces", "dummy", "dum1", "address", "192.0.2.31/32"]}',
+ 'key': f'{key}',
+ }
+ r = request('POST', url_config, verify=False, headers=headers, data=payload)
+ self.assertEqual(r.status_code, 200)
+
+ # load config from URL
+ payload = {
+ 'data': '{"op": "load", "file": "http://localhost:8000/tmp-config.boot"}',
+ 'key': f'{key}',
+ }
+ r = request('POST', url, verify=False, headers=headers, data=payload)
+ self.assertEqual(r.status_code, 200)
+
+ # cleanup tmp nginx conf
+ call(f'sudo rm -rf {nginx_tmp_site}')
+ call('sudo nginx -s reload')
if __name__ == '__main__':
unittest.main(verbosity=5)