Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bloomberg tornado set cookie #55743

Merged
merged 3 commits into from Dec 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -26,6 +26,8 @@ Versions are `MAJOR.PATCH`.

### Changed

- [#54013](https://github.com/saltstack/salt/pull/54103) - Set `session_id`
cookie in the rest_tornado backend.
- [SEP 14](https://github.com/saltstack/salt-enhancement-proposals/pull/20) - Changed to numeric versions.
- [SEP 1](https://github.com/saltstack/salt-enhancement-proposals/blob/master/accepted/0001-changelog-format.md), [SEP 14](https://github.com/saltstack/salt-enhancement-proposals/pull/20) - Adopted keepachangelog format.

Expand Down
1 change: 1 addition & 0 deletions salt/netapi/rest_tornado/saltnado.py
Expand Up @@ -740,6 +740,7 @@ def post(self):
self.send_error(401)
# return since we don't want to execute any more
return
self.set_cookie(AUTH_COOKIE_NAME, token['token'])

# Grab eauth config for the current backend for the current user
try:
Expand Down
10 changes: 9 additions & 1 deletion tests/unit/netapi/test_rest_tornado.py
Expand Up @@ -526,15 +526,17 @@ def test_login(self):
'''
Test valid logins
'''

# Test in form encoded
response = self.fetch('/login',
method='POST',
body=urlencode(self.auth_creds),
headers={'Content-Type': self.content_type_map['form']})

cookies = response.headers['Set-Cookie']
self.assertEqual(response.code, 200)
response_obj = salt.utils.json.loads(response.body)['return'][0]
token = response_obj['token']
self.assertIn('session_id={0}'.format(token), cookies)
self.assertEqual(sorted(response_obj['perms']), sorted(self.opts['external_auth']['auto'][self.auth_creds_dict['username']]))
self.assertIn('token', response_obj) # TODO: verify that its valid?
self.assertEqual(response_obj['user'], self.auth_creds_dict['username'])
Expand All @@ -546,8 +548,11 @@ def test_login(self):
body=salt.utils.json.dumps(self.auth_creds_dict),
headers={'Content-Type': self.content_type_map['json']})

cookies = response.headers['Set-Cookie']
self.assertEqual(response.code, 200)
response_obj = salt.utils.json.loads(response.body)['return'][0]
token = response_obj['token']
self.assertIn('session_id={0}'.format(token), cookies)
self.assertEqual(sorted(response_obj['perms']), sorted(self.opts['external_auth']['auto'][self.auth_creds_dict['username']]))
self.assertIn('token', response_obj) # TODO: verify that its valid?
self.assertEqual(response_obj['user'], self.auth_creds_dict['username'])
Expand All @@ -559,8 +564,11 @@ def test_login(self):
body=salt.utils.yaml.safe_dump(self.auth_creds_dict),
headers={'Content-Type': self.content_type_map['yaml']})

cookies = response.headers['Set-Cookie']
self.assertEqual(response.code, 200)
response_obj = salt.utils.json.loads(response.body)['return'][0]
token = response_obj['token']
self.assertIn('session_id={0}'.format(token), cookies)
self.assertEqual(sorted(response_obj['perms']), sorted(self.opts['external_auth']['auto'][self.auth_creds_dict['username']]))
self.assertIn('token', response_obj) # TODO: verify that its valid?
self.assertEqual(response_obj['user'], self.auth_creds_dict['username'])
Expand Down