moo.core.tests.test_security_context

Security tests: ContextManager state and invoke() guards.

Covers: caller_stack copy, context read-only descriptor, set_task_perms wizard check, invoke() periodic/cron/execute permission checks (passes 2, 3, 7).

Functions

test_caller_stack_previous_caller_reference_accessible()

Known gap (information disclosure): context.caller_stack returns a copy of the live stack (preventing mutation), but each frame dict contains 'previous_caller' — a live Object reference.

test_caller_stack_returns_copy()

ContextManager.get('caller_stack') must return a copy of the stack list.

test_context_caller_is_read_only_directly()

Directly assigning context.caller must raise AttributeError.

test_context_caller_shadowing_blocked_in_verb()

Verb code must not be able to shadow context.caller via _write_ assignment.

test_context_parser_is_none_outside_command_dispatch()

context.parser returns the Parser instance for the current command.

test_context_task_id_is_string_or_none()

context.task_id returns the Celery task ID string (or None outside a task).

test_context_writer_equivalent_to_print()

context.writer is the same callable that the sandbox's print() uses internally (_print_._call_print calls writer(s)).

test_invoke_checks_execute_permission()

invoke() must call can_caller("execute", verb) before dispatching.

test_invoke_cron_requires_wizard()

invoke(..., cron=...) raises UserError when called by a non-wizard.

test_invoke_kwargs_caller_id_cannot_be_forged()

invoke() unconditionally overwrites caller_id, player_id, this_id, and verb_name with values derived from the authenticated context after merging any verb-supplied kwargs.

test_invoke_oneshot_allowed_for_nonwizard()

invoke() without periodic/cron must not raise for non-wizards.

test_invoke_periodic_requires_wizard()

invoke(..., periodic=True) raises UserError when called by a non-wizard.

test_invoke_periodic_returns_task_with_registered_task_name()

invoke(verb, delay=60, periodic=True) is wizard-gated and returns a live PeriodicTask model instance.

test_set_task_perms_requires_wizard(t_init, ...)

set_task_perms() raises UserError when called by a non-wizard.