testing: Move unsign_subdomain_cookie to test_helpers.

We'll be using it in other files soon.
This commit is contained in:
Umair Khan
2017-04-19 13:04:23 +05:00
committed by Tim Abbott
parent 8fee31f7ff
commit 4ab783134e
2 changed files with 12 additions and 11 deletions

View File

@@ -4,6 +4,7 @@ from contextlib import contextmanager
from typing import (cast, Any, Callable, Dict, Generator, Iterable, Iterator, List, Mapping,
Optional, Set, Sized, Tuple, Union, IO)
from django.core import signing
from django.core.urlresolvers import LocaleRegexURLResolver
from django.conf import settings
from django.test import TestCase
@@ -457,3 +458,11 @@ def get_all_templates():
process(template_dir, dirpath, fnames)
return templates
def unsign_subdomain_cookie(result):
# type: (HttpResponse) -> Dict[str, Any]
key = 'subdomain.signature'
salt = key + 'zerver.views.auth'
cookie = result.cookies.get(key)
value = signing.get_cookie_signer(salt=salt).unsign(cookie.value, max_age=15)
return ujson.loads(value)