Skip to content
This repository has been archived by the owner on May 31, 2019. It is now read-only.

Commit

Permalink
Use config secret key by default
Browse files Browse the repository at this point in the history
  • Loading branch information
c-bata committed Jan 1, 2017
1 parent 959a02d commit 40a9a92
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions kobin/environs.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,9 @@ def headerlist(self):

def set_cookie(self, key, value, expires=None, max_age=None, path='/',
secret=None, digestmod=hashlib.sha256):
from kobin.app import current_config
if secret is None:
secret = current_config().get('SECRET_KEY')
if secret:
if isinstance(secret, str):
secret = secret.encode('utf-8')
Expand Down
9 changes: 9 additions & 0 deletions tests/test_environs.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,15 @@ def test_get_cookie_with_secret(self):
expected = 'bar'
self.assertEqual(actual, expected)

@patch('kobin.app.current_config')
def test_set_cookie_with_secret_in_config(self, mock_current_config):
mock_current_config.return_value = Config(SECRET_KEY="secretkey")
response = BaseResponse()
response.set_cookie('foo', 'bar', path=None)
expected_set_cookie = ('Set-Cookie', 'foo="!VzhGFLGcW+5OMs1s4beLXaqFxAUwgHdWkH5fgapghoI='
'?gASVDwAAAAAAAACMA2Zvb5SMA2JhcpSGlC4="')
self.assertIn(expected_set_cookie, response.headerlist)


class BaseResponseTests(TestCase):
def test_constructor_body(self):
Expand Down

0 comments on commit 40a9a92

Please sign in to comment.