Validators¶
Two RequestValidator subclasses that hook into viur-core's
Router.requestValidators chain. You rarely instantiate them yourself
— activate() installs TokenValidator,
protect() installs ProductionGuardValidator.
TokenValidator¶
TokenValidator
¶
Bases: RequestValidator
Reject every request that does not carry a matching test-token cookie.
Source code in src/viur/testing/validator.py
ProductionGuardValidator¶
ProductionGuardValidator
¶
Bases: RequestValidator
Reject any request that carries the test-token cookie outside dev.
Defense in depth: the full :class:TokenValidator is only installed
inside :func:viur.testing.activate, which itself refuses to run outside
a local dev server. A cloud deployment therefore normally has no
e2e validator at all — which means the viur-test-token cookie
would be ignored rather than rejected.
This validator closes that gap. The host installs it explicitly via
:func:viur.testing.protect in every environment. In a dev process
it is effectively a no-op (the full :class:TokenValidator owns the
cookie logic). In a cloud process it raises 403 the moment the
test-token cookie shows up at all, regardless of its value.