Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added validation for all types of cfbs.json files and all fields #167

Merged
merged 64 commits into from
Dec 13, 2023
Merged
Changes from 1 commit
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
ba903ee
Moved module validation function into separate function
olehermanse Dec 4, 2023
bed074d
Removed unused import
olehermanse Dec 4, 2023
1b91d1f
Renamed CFBSIndexError to CFBSValidationError
olehermanse Dec 5, 2023
c0e1eca
Changed to double quotes in validation errors to match JSON syntax
olehermanse Dec 5, 2023
58434eb
Refactored module alias validation to prepare for further changes
olehermanse Dec 5, 2023
2ded2a5
Added separate validation for required fields
olehermanse Dec 5, 2023
0032e32
Simplified validation functions now that required fields are handled …
olehermanse Dec 5, 2023
3a82a9d
Changed all validation functions which only care about a single modul…
olehermanse Dec 5, 2023
40d3b2f
Added basic validation of module names to shared validation function
olehermanse Dec 5, 2023
ba7f69d
cfbs validate now more thoroughly validates various cfbs.json files
olehermanse Dec 5, 2023
a8c1cc7
validate.py: Small formatting improvements
olehermanse Dec 5, 2023
045c906
Added warnings when cfbs.json files have unknown fields
olehermanse Dec 5, 2023
6addb4c
Removed assertions which are no longer valid
olehermanse Dec 5, 2023
f180fef
Fixed typo in required fields logic
olehermanse Dec 5, 2023
9d5a224
validate.py: Fixed typo in alias validation
olehermanse Dec 5, 2023
0f4649a
Added raw_data property for working with the actual JSON data of a CF…
olehermanse Dec 5, 2023
fa1a66b
Fixed issue with typechecking for index and provides fields
olehermanse Dec 5, 2023
ee8aac6
Fixed checking of aliases
olehermanse Dec 5, 2023
77a320a
Made it possible to only pass message to CFBSValidationError
olehermanse Dec 5, 2023
9deb960
Updated validation log messages for being used more generally
olehermanse Dec 5, 2023
f656cfe
Prepared CFBSValidationError to be used with an index instead of a name
olehermanse Dec 5, 2023
a36219c
Added validation for top level keys of cfbs.json
olehermanse Dec 5, 2023
fe5d7de
Removed a lot of the special handling for validation of index files
olehermanse Dec 5, 2023
eb19557
Added "alias" as a known module key so it's recognized in validation
olehermanse Dec 5, 2023
48218aa
Fixed the warning message for unknown keys
olehermanse Dec 5, 2023
7011dc3
Validation: Added checking to keep required_fields in sync with globa…
olehermanse Dec 5, 2023
d5e4659
Put the index in place of module name when module name is missing
olehermanse Dec 5, 2023
d532da9
Improved validation error messages by catching the exception
olehermanse Dec 5, 2023
165437c
Fixed validation error message for missing index
olehermanse Dec 7, 2023
02c0334
Fixed validation error message for a required field missing inside mo…
olehermanse Dec 7, 2023
4613db3
Added more thorough validation of build steps
olehermanse Dec 7, 2023
471ea24
Added more thorough validation of subdirectory
olehermanse Dec 7, 2023
6dd1cb3
Reformatted files with black
olehermanse Dec 7, 2023
447c478
Added a unit test for validating a simple index and catching many of …
olehermanse Dec 7, 2023
bfba0dc
Added validation for module input information in cfbs.json
olehermanse Dec 7, 2023
6906453
Added unit test for validation of module input inside cfbs.json
olehermanse Dec 7, 2023
0827f12
Fixed exception name for alias not supported error message
olehermanse Dec 7, 2023
991a33e
Prevented an exception when trying to look for unknown keys in non-ex…
olehermanse Dec 7, 2023
2cb7a86
Applied suggestions from @larsewi's code review
olehermanse Dec 8, 2023
c9c1c57
Made cfbs validate exit with non-zero exit code in case of errors
olehermanse Dec 8, 2023
df2e9c0
Added warning message about having to fix cfbs.json for future cfbs b…
olehermanse Dec 8, 2023
8ee8207
Removed special handling of validation in build / download commands
olehermanse Dec 8, 2023
69a6621
Reformatted @larsewi's addition with black
olehermanse Dec 8, 2023
86095e5
Added can_reach_dependency() helper to make the dependency logic more…
olehermanse Dec 8, 2023
abffd62
Added validation for the "provides" field
olehermanse Dec 8, 2023
2d8fd73
Removed leftover print statements used while debugging
olehermanse Dec 8, 2023
8d4fbbf
Added a shell test for cfbs validate
olehermanse Dec 8, 2023
1ed9aa4
Changed validation to look for dependencies in the appropriate field(s)
olehermanse Dec 8, 2023
46690fd
validate.py: Improved variable name mode to context
olehermanse Dec 8, 2023
29b99b2
Fixed issue with checking the target of an alias
olehermanse Dec 8, 2023
c2853b5
Fixed argument name for validate_dependencies
olehermanse Dec 8, 2023
5f576e3
Updated backwards compatibility tests to more strict validation
olehermanse Dec 12, 2023
c25dc57
Applied suggestion from @larsewi's code review
olehermanse Dec 12, 2023
83fb681
Fixed 2 issues with looking for alias targets / dependencies
olehermanse Dec 12, 2023
ee2de69
Added validation test for aliases
olehermanse Dec 12, 2023
6973e02
JSON.md: Removed trailing whitespace
olehermanse Dec 12, 2023
af9210a
Fixed validation for number of arguments for "run" build steps
olehermanse Dec 12, 2023
81c4877
Fixed validation for looking for dependencies of modules in "build" a…
olehermanse Dec 12, 2023
6d67490
Updated many "subdirectory" fields to conform with the new stricter v…
olehermanse Dec 12, 2023
d5656f7
A tribute to Python 3.5
olehermanse Dec 12, 2023
8a7ca28
Fixed validation for when "key" is not required in module input list …
olehermanse Dec 12, 2023
ba459ce
test_validate_index_alias.py: Fixed name of one of the tests / functions
olehermanse Dec 12, 2023
edd4a7b
Improved some validation warning messages
olehermanse Dec 12, 2023
0e23a7b
Fixed typo / spacing by @larsewi
olehermanse Dec 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions tests/test_validate_index_alias.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
from collections import OrderedDict
from copy import deepcopy
from pathlib import Path

from cfbs.pretty import pretty
from cfbs.validate import validate_config
from cfbs.cfbs_config import CFBSConfig

INDEX_ALIAS_VALID = {
"name": "index",
"description": "An example index of 1 module",
"type": "index",
"index": {
"test-alias": {
"alias": "test-target",
},
"test-target": {
"description": "Allows all hosts / IP addresses to connect and fetch policy.",
"tags": ["management", "experimental"],
"repo": "https://github.com/cfengine/modules",
"by": "https://github.com/olehermanse",
"version": "0.0.1",
"commit": "85f9aec38783b5a4dac4777ffa9d17fde5054d14",
"subdirectory": "management/allow-all-hosts",
"steps": ["json def.json def.json"],
},
},
}

INDEX_ALIAS_INVALID = {
"name": "index",
"description": "An example index of 1 module",
"type": "index",
"index": {
"test-alias": {
"alias": "test-target",
}
},
}


def test_valid_index_with_alias():
filename = Path("tmp-cfbs.json")
with open(filename, "w") as f:
f.write(pretty(INDEX_ALIAS_VALID))
config = CFBSConfig(filename)
r = validate_config(config)
del config
filename.unlink()
assert r == 0


def test_valid_index_with_alias():
olehermanse marked this conversation as resolved.
Show resolved Hide resolved
filename = Path("tmp-cfbs.json")
with open(filename, "w") as f:
f.write(pretty(INDEX_ALIAS_INVALID))
config = CFBSConfig(filename)
r = validate_config(config)
del config
filename.unlink()
assert r != 0
Loading