summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2023-12-10 21:08:55 +0100
committerGitHub <noreply@github.com>2023-12-10 21:08:55 +0100
commit5b2ee47e85b536800897e4f4a475ca3167238254 (patch)
treed7ea162954b6493c03c539d80350e51a503f34bd
parente099dd70e874e64823d2b139e95178100da8e4d3 (diff)
parent02976d4f207c2c462a1cecacb92adbd98f24eb97 (diff)
downloadvyos-1x-5b2ee47e85b536800897e4f4a475ca3167238254.tar.gz
vyos-1x-5b2ee47e85b536800897e4f4a475ca3167238254.zip
Merge pull request #2604 from vyos/mergify/bp/sagitta/pr-2600
T5773: API add smoketest for load config via HTTP URL (backport #2600)
-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)