mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-05-16 09:47:21 +02:00
Removed unnecessary function
This commit is contained in:
parent
ec5dbc7e80
commit
02d773b6e1
@ -5,34 +5,6 @@ def is_feature_enabled(applications, feature: str, application_id: str) -> bool:
|
||||
app = applications.get(application_id, {})
|
||||
return bool(app.get('features', {}).get(feature, False))
|
||||
|
||||
|
||||
def get_csp_whitelist(applications, application_id: str, directive: str) -> list:
|
||||
"""
|
||||
Return the list of extra hosts/URLs to whitelist for a given CSP directive.
|
||||
"""
|
||||
app = applications.get(application_id, {})
|
||||
wl = app.get('csp', {}).get('whitelist', {}).get(directive, [])
|
||||
if isinstance(wl, list):
|
||||
return wl
|
||||
if wl:
|
||||
return [wl]
|
||||
return []
|
||||
|
||||
|
||||
def get_csp_flags(applications, application_id: str, directive: str) -> list:
|
||||
"""
|
||||
Read 'unsafe_eval' and 'unsafe_inline' flags from csp.flags.<directive>.
|
||||
Returns a list of string tokens, e.g. ["'unsafe-eval'", "'unsafe-inline'"].
|
||||
"""
|
||||
app = applications.get(application_id, {})
|
||||
flags_config = app.get('csp', {}).get('flags', {}).get(directive, {})
|
||||
tokens = []
|
||||
if flags_config.get('unsafe_eval', False):
|
||||
tokens.append("'unsafe-eval'")
|
||||
if flags_config.get('unsafe_inline', False):
|
||||
tokens.append("'unsafe-inline'")
|
||||
return tokens
|
||||
|
||||
def get_docker_compose(path_docker_compose_instances: str, application_id: str) -> dict:
|
||||
"""
|
||||
Build the docker_compose dict based on
|
||||
|
@ -3,8 +3,6 @@
|
||||
import unittest
|
||||
from filter_plugins.configuration_filters import (
|
||||
is_feature_enabled,
|
||||
get_csp_whitelist,
|
||||
get_csp_flags,
|
||||
)
|
||||
|
||||
|
||||
@ -16,25 +14,6 @@ class TestConfigurationFilters(unittest.TestCase):
|
||||
'features': {
|
||||
'oauth2': True,
|
||||
},
|
||||
'csp': {
|
||||
'whitelist': {
|
||||
# directive with a list
|
||||
'script-src': ['https://example.com'],
|
||||
# directive with a single string
|
||||
'connect-src': 'https://api.example.com',
|
||||
},
|
||||
'flags': {
|
||||
# both flags for script-src
|
||||
'script-src': {
|
||||
'unsafe_eval': True,
|
||||
'unsafe_inline': False,
|
||||
},
|
||||
# only unsafe_inline for style-src
|
||||
'style-src': {
|
||||
'unsafe_inline': True,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
'app2': {
|
||||
# no features or csp defined
|
||||
@ -51,42 +30,5 @@ class TestConfigurationFilters(unittest.TestCase):
|
||||
def test_is_feature_enabled_false_missing_app(self):
|
||||
self.assertFalse(is_feature_enabled(self.applications, 'oauth2', 'unknown_app'))
|
||||
|
||||
# Tests for get_csp_whitelist
|
||||
def test_get_csp_whitelist_returns_list_as_is(self):
|
||||
result = get_csp_whitelist(self.applications, 'app1', 'script-src')
|
||||
self.assertEqual(result, ['https://example.com'])
|
||||
|
||||
def test_get_csp_whitelist_wraps_string_in_list(self):
|
||||
result = get_csp_whitelist(self.applications, 'app1', 'connect-src')
|
||||
self.assertEqual(result, ['https://api.example.com'])
|
||||
|
||||
def test_get_csp_whitelist_empty_when_not_defined(self):
|
||||
result = get_csp_whitelist(self.applications, 'app1', 'frame-src')
|
||||
self.assertEqual(result, [])
|
||||
|
||||
def test_get_csp_whitelist_empty_when_app_missing(self):
|
||||
result = get_csp_whitelist(self.applications, 'nonexistent_app', 'script-src')
|
||||
self.assertEqual(result, [])
|
||||
|
||||
# Tests for get_csp_flags
|
||||
def test_get_csp_flags_includes_unsafe_eval(self):
|
||||
result = get_csp_flags(self.applications, 'app1', 'script-src')
|
||||
self.assertIn("'unsafe-eval'", result)
|
||||
self.assertNotIn("'unsafe-inline'", result)
|
||||
|
||||
def test_get_csp_flags_includes_unsafe_inline(self):
|
||||
result = get_csp_flags(self.applications, 'app1', 'style-src')
|
||||
self.assertIn("'unsafe-inline'", result)
|
||||
self.assertNotIn("'unsafe-eval'", result)
|
||||
|
||||
def test_get_csp_flags_empty_when_none_configured(self):
|
||||
result = get_csp_flags(self.applications, 'app1', 'connect-src')
|
||||
self.assertEqual(result, [])
|
||||
|
||||
def test_get_csp_flags_empty_when_app_missing(self):
|
||||
result = get_csp_flags(self.applications, 'nonexistent_app', 'script-src')
|
||||
self.assertEqual(result, [])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
Loading…
x
Reference in New Issue
Block a user