From b3d8aaf9e3f770267b4241bdee4e90368488e36a Mon Sep 17 00:00:00 2001 From: Daniel <d.hornung@indiscale.com> Date: Thu, 31 Mar 2022 14:04:35 +0200 Subject: [PATCH] FIX: JSON schema now is more permissive, and fixed if-conditions. For #75, #103. --- CHANGELOG.md | 3 ++ src/caosdb/schema-pycaosdb-ini.yml | 13 +++++++ .../pycaosdb-IntegrationTests.ini | 37 +++++++++++++++++++ .../test_configs/pycaosdb-real-world-1.ini | 17 +++++++++ .../test_configs/pycaosdb-real-world-2.ini | 15 ++++++++ .../pycaosdb-server-side-scripting.ini | 9 +++++ unittests/test_schema.py | 6 ++- 7 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 unittests/test_configs/pycaosdb-IntegrationTests.ini create mode 100644 unittests/test_configs/pycaosdb-real-world-1.ini create mode 100644 unittests/test_configs/pycaosdb-real-world-2.ini create mode 100644 unittests/test_configs/pycaosdb-server-side-scripting.ini diff --git a/CHANGELOG.md b/CHANGELOG.md index 061193ac..931653e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Security ### +* [#75](https://gitlab.indiscale.com/caosdb/src/caosdb-pylib/-/issues/75), [#103](https://gitlab.indiscale.com/caosdb/src/caosdb-pylib/-/issues/103) Fixed JSON schema to allow more sections, and correct requirements for + password method. + ### Documentation ### diff --git a/src/caosdb/schema-pycaosdb-ini.yml b/src/caosdb/schema-pycaosdb-ini.yml index bfe8fe7c..5dabdd89 100644 --- a/src/caosdb/schema-pycaosdb-ini.yml +++ b/src/caosdb/schema-pycaosdb-ini.yml @@ -65,26 +65,39 @@ schema-pycaosdb-ini: properties: password_method: const: input + required: [password_method] then: required: [url] - if: properties: password_method: const: plain + required: [password_method] then: required: [url, username, password] - if: properties: password_method: const: pass + required: [password_method] then: required: [url, username, password_identifier] - if: properties: password_method: const: keyring + required: [password_method] then: required: [url, username] IntegrationTests: description: "Used by the integration test suite from the caosdb-pyinttest repo." additionalProperties: true + Misc: + description: "Some additional configuration settings." + additionalProperties: true + advancedtools: + description: "Configuration settings for the caosadvancedtools." + additionalProperties: true + sss_helper: + description: "Configuration settings for server-side scripting." + additionalProperties: true diff --git a/unittests/test_configs/pycaosdb-IntegrationTests.ini b/unittests/test_configs/pycaosdb-IntegrationTests.ini new file mode 100644 index 00000000..cb987170 --- /dev/null +++ b/unittests/test_configs/pycaosdb-IntegrationTests.ini @@ -0,0 +1,37 @@ +# -*- mode:conf; -*- +## This sections needs to exist in addition to the usual section +[IntegrationTests] +# test_server_side_scripting.bin_dir.local=/path/to/scripting/bin +test_server_side_scripting.bin_dir.local=/home/myself/test/caosdb-server/scripting/bin +# test_server_side_scripting.bin_dir.server=/opt/caosdb/git/caosdb-server/scripting/bin + +# # location of the files from the pyinttest perspective +# test_files.test_insert_files_in_dir.local=/extroot/test_insert_files_in_dir/ +test_files.test_insert_files_in_dir.local=/home/myself/test/debug_advanced/paths/extroot/test_insert_files_in_dir +# # location of the files from the caosdb_servers perspective +test_files.test_insert_files_in_dir.server=/opt/caosdb/mnt/extroot/test_insert_files_in_dir/ + +########## Files ################## +## Used by tests of file handling. Specify the path to an existing +## directory in which file tests are performed, once as seen by the +## host and once as seen by the server. + +# location of the files from the pyinttest (i.e. host) perspective +#test_files.test_insert_files_in_dir.local=/extroot/test_insert_files_in_dir/ + +# location of the files from the caosdb server's perspective +#test_files.test_insert_files_in_dir.server=/opt/caosdb/mnt/extroot/test_insert_files_in_dir/ + +# # location of the one-time tokens from the pyinttest's perspective +# test_authentication.admin_token_crud = /authtoken/admin_token_crud.txt +# test_authentication.admin_token_expired = /authtoken/admin_token_expired.txt +# test_authentication.admin_token_3_attempts = /authtoken/admin_token_3_attempts.txt + + +## Insert your usual settings here +[Connection] +url=https://localhost:10443/ +username=admin +password_method=plain +password=caosdb + diff --git a/unittests/test_configs/pycaosdb-real-world-1.ini b/unittests/test_configs/pycaosdb-real-world-1.ini new file mode 100644 index 00000000..e524f1d3 --- /dev/null +++ b/unittests/test_configs/pycaosdb-real-world-1.ini @@ -0,0 +1,17 @@ +[Connection] +url = https://localhost:10443 +cacert = /opt/caosdb/cert/caosdb.cert.pem +debug = 0 +timeout = 5000 + +[Misc] +sendmail = /usr/local/bin/sendmail_to_file +entity_loan.curator_mail_from=crawler-test@example.com +entity_loan.curator_mail_to=crawler-test@example.com + +[sss_helper] +external_uri = https://caosdb.example.com:443 + +[advancedtools] +crawler.from_mail=admin@example.com +crawler.to_mail=admin@example.com diff --git a/unittests/test_configs/pycaosdb-real-world-2.ini b/unittests/test_configs/pycaosdb-real-world-2.ini new file mode 100644 index 00000000..5ebd115a --- /dev/null +++ b/unittests/test_configs/pycaosdb-real-world-2.ini @@ -0,0 +1,15 @@ +[Connection] +url = https://samplemanager.example.com:443 +cacert = /opt/caosdb/cert/caosdb.cert.pem +debug = 0 +timeout = 5000 +[Misc] +sendmail = /usr/local/bin/sendmail_to_file +entity_loan.curator_mail_from=crawler-test@example.com +entity_loan.curator_mail_to=crawler-test@example.com +[sss_helper] +external_uri = https://localhost:10443 +[advancedtools] +crawler.from_mail=crawler-test@example.com +crawler.to_mail=crawler-test@example.com + diff --git a/unittests/test_configs/pycaosdb-server-side-scripting.ini b/unittests/test_configs/pycaosdb-server-side-scripting.ini new file mode 100644 index 00000000..de2867f8 --- /dev/null +++ b/unittests/test_configs/pycaosdb-server-side-scripting.ini @@ -0,0 +1,9 @@ +; this is the pycaosdb.ini for the server-side-scripting home. +[Connection] +url = https://caosdb-server:10443 +cacert = /opt/caosdb/cert/caosdb.cert.pem +debug = 0 +timeout = 5000 + +[Misc] +sendmail = /usr/local/bin/sendmail_to_file diff --git a/unittests/test_schema.py b/unittests/test_schema.py index 50ff19d9..fc3f63a4 100644 --- a/unittests/test_schema.py +++ b/unittests/test_schema.py @@ -33,16 +33,18 @@ from configparser import ConfigParser def test_config_files(): for fn in glob(os.path.join(os.path.dirname(__file__), "test_configs", "*.ini")): + print(f"Testing {fn}.") c = ConfigParser() - print(f"Reading {fn}") c.read(fn) + print(config_to_yaml(c)) validate_yaml_schema(config_to_yaml(c)) def test_broken_config_files(): for fn in glob(os.path.join(os.path.dirname(__file__), "broken_configs", "*.ini")): - print(f"Reading {fn}") + print(f"Testing {fn}.") with raises(ValidationError): c = ConfigParser() c.read(fn) + print(config_to_yaml(c)) validate_yaml_schema(config_to_yaml(c)) -- GitLab