island: Add tests for ssl_certificate_file

This commit is contained in:
Mike Salvatore 2021-06-07 12:41:11 -04:00
parent f2a2efc2a7
commit 4231f316db
1 changed files with 42 additions and 0 deletions

View File

@ -1,6 +1,7 @@
import os
from monkey_island.cc.server_utils.consts import (
DEFAULT_CRT_PATH,
DEFAULT_DATA_DIR,
DEFAULT_LOG_LEVEL,
DEFAULT_START_MONGO_DB,
@ -11,6 +12,10 @@ TEST_CONFIG_FILE_CONTENTS_SPECIFIED = {
"data_dir": "/tmp",
"log_level": "test",
"mongodb": {"start_mongodb": False},
"ssl_certificate": {
"ssl_certificate_file": "/tmp/test.crt",
"ssl_certificate_key_file": "/tmp/test.key",
},
}
TEST_CONFIG_FILE_CONTENTS_UNSPECIFIED = {}
@ -68,6 +73,43 @@ def test_mongodb():
assert options.start_mongodb == DEFAULT_START_MONGO_DB
def test_crt_path_uses_default():
assert_ssl_certificate_file_equals(TEST_CONFIG_FILE_CONTENTS_UNSPECIFIED, DEFAULT_CRT_PATH)
def test_crt_path_specified():
assert_ssl_certificate_file_equals(
TEST_CONFIG_FILE_CONTENTS_SPECIFIED,
TEST_CONFIG_FILE_CONTENTS_SPECIFIED["ssl_certificate"]["ssl_certificate_file"],
)
def test_crt_path_expanduser(monkeypatch, tmpdir):
set_home_env(monkeypatch, tmpdir)
FILE_NAME = "test.crt"
assert_ssl_certificate_file_equals(
{"ssl_certificate": {"ssl_certificate_file": os.path.join("~", FILE_NAME)}},
os.path.join(tmpdir, FILE_NAME),
)
def test_crt_path_expandvars(monkeypatch, tmpdir):
set_home_env(monkeypatch, tmpdir)
FILE_NAME = "test.crt"
assert_ssl_certificate_file_equals(
{"ssl_certificate": {"ssl_certificate_file": os.path.join("$HOME", FILE_NAME)}},
os.path.join(tmpdir, FILE_NAME),
)
def assert_ssl_certificate_file_equals(config_file_contents, expected_ssl_certificate_file):
assert_island_config_option_equals(
config_file_contents, "crt_path", expected_ssl_certificate_file
)
def assert_island_config_option_equals(config_file_contents, option_name, expected_value):
options = IslandConfigOptions(config_file_contents)
assert getattr(options, option_name) == expected_value