Skip to content

Commit

Permalink
Add unit tests and improve documentation
Browse files Browse the repository at this point in the history
Signed-off-by: jakub-nt <[email protected]>
  • Loading branch information
jakub-nt committed Oct 22, 2024
1 parent 6762299 commit 2768a80
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
6 changes: 5 additions & 1 deletion masterfiles/check_download_matches_git.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# check that the downloadable files match the git files, mitigating a build system supply-chain attack
"""Check that the downloadable files match the git files.
This can be used to monitor / detect if something has been changed, accidentally or maliciously.
"""

import os
import dictdiffer

Expand Down
35 changes: 28 additions & 7 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from cfbs.utils import canonify, deduplicate_def_json, merge_json, loads_bundlenames


def test_canonify():
assert canonify("Hello CFEngine!") == "Hello_CFEngine_"
assert canonify("/etc/os-release") == "_etc_os_release"
assert canonify("my-example-module") == "my_example_module"
from cfbs.utils import (
canonify,
deduplicate_def_json,
file_sha256,
merge_json,
loads_bundlenames,
string_sha256,
)


def test_merge_json():
Expand Down Expand Up @@ -140,6 +141,26 @@ def test_deduplicate_def_json():
assert deduplicated == expected


def test_string_sha256():
s = "cfbs/masterfiles/"
checksum = "9e63d3266f80328fb6547b3462e81ab55b13f689d6b0944e242e2b3a0f3a32a3"

assert string_sha256(s) == checksum


def test_file_sha256():
file_path = "tests/sample/foo/main.cf"
checksum = "da90bdfe7b5ee30e4d7871496e8434603315fb1b267660e2d49aee8ef47b246d"

assert file_sha256(file_path) == checksum


def test_canonify():
assert canonify("Hello CFEngine!") == "Hello_CFEngine_"
assert canonify("/etc/os-release") == "_etc_os_release"
assert canonify("my-example-module") == "my_example_module"


def test_loads_bundlenames_single_bundle():
policy = """bundle agent bogus
{
Expand Down

0 comments on commit 2768a80

Please sign in to comment.