[1.7.x] Adapted invalid cookie test to all Python versions

Refs #23638. Older Python versions are less strict when parsing
invalid cookie content. The test just has to ensure Django doesn't
crash.