moo.core.tests.test_security_imports

Security tests: import blocking and allowed-module return-value surfaces.

Covers: ContextManager, _publish_to_player, string module, moo.core submodules, SDK internal names, module attribute traversal, django_celery_beat import block, and re/hashlib/datetime/time return objects.

Functions

test_auth_not_in_sdk()

from moo.sdk import auth must raise ImportError.

test_code_not_in_sdk()

from moo.sdk import code must raise ImportError.

test_context_manager_not_importable()

ContextManager is in BLOCKED_IMPORTS for moo.sdk.

test_datetime_instances_are_safe()

datetime.datetime.now() returns a datetime instance.

test_datetime_timedelta_is_safe()

datetime.timedelta arithmetic returns timedelta instances — safe.

test_django_celery_beat_not_importable_by_non_wizards()

Non-wizards cannot import django_celery_beat either.

test_django_celery_beat_not_importable_by_wizards()

django_celery_beat is not in WIZARD_ALLOWED_MODULES or ALLOWED_MODULES.

test_hashlib_hash_object_attributes_are_safe()

hashlib.md5(b'data') returns a HASH object.

test_models_not_in_sdk()

from moo.sdk import models must raise ImportError.

test_publish_to_player_not_importable()

_publish_to_player must not be accessible from verb code.

test_re_match_object_attributes_are_safe()

re.compile(pattern).match(s) returns a Match object.

test_re_pattern_object_attributes_are_safe()

re.compile() returns a Pattern whose public attributes are strings/integers.

test_sdk_contextmanager_blocked_via_module_attribute()

ContextManager is imported as _ContextManager (underscore alias) in moo/sdk.py.

test_sdk_contextmanager_function_blocked()

contextmanager is imported at module level in moo/sdk.py from contextlib.

test_sdk_log_blocked()

log is the module-level logging.Logger in moo/sdk.py.

test_sdk_module_traversal_to_core_blocked()

import moo.sdk (bare, no 'as') binds the top-level moo package.

test_sdk_submodule_import_blocked()

Now that moo.sdk is a package, verb code must not be able to reach its submodules directly.

test_string_module_not_importable()

'string' was removed from ALLOWED_MODULES because string.Formatter.get_field calls CPython's real getattr internally, bypassing safe_getattr and allowing dunder attribute access (e.g. __class__) to reach the Django ORM.

test_tasks_not_in_sdk()

from moo.sdk import tasks must raise ImportError.

test_time_struct_time_is_safe()

time.gmtime() returns a struct_time — a named-tuple-like object.