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

Add tests with filename in token data and catch TypeError #12

Merged
merged 1 commit into from
Aug 28, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion salt/netapi/rest_cherrypy/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1930,7 +1930,7 @@ def _is_valid_token(self, auth_token):
# than hex, this will raise a ValueError.
try:
int(auth_token, 16)
except ValueError:
except (TypeError, ValueError):
return False

# First check if the given token is in our session table; if so it's a
Expand Down
27 changes: 27 additions & 0 deletions tests/integration/netapi/rest_cherrypy/app_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# Import python libs
from __future__ import absolute_import
import os
import json

# Import salttesting libs
Expand Down Expand Up @@ -172,6 +173,32 @@ def test_run_wrong_token(self):
})
assert response.status == '401 Unauthorized'

def test_run_pathname_token(self):
'''
Test the run URL with path that exists in token
'''
cmd = dict(self.low, **{'token': os.path.join('etc', 'passwd')})
body = urlencode(cmd)

request, response = self.request('/run', method='POST', body=body,
headers={
'content-type': 'application/x-www-form-urlencoded'
})
assert response.status == '401 Unauthorized'

def test_run_pathname_not_exists_token(self):
'''
Test the run URL with path that does not exist in token
'''
cmd = dict(self.low, **{'token': os.path.join('tmp', 'doesnotexist')})
body = urlencode(cmd)

request, response = self.request('/run', method='POST', body=body,
headers={
'content-type': 'application/x-www-form-urlencoded'
})
assert response.status == '401 Unauthorized'


class TestWebhookDisableAuth(BaseRestCherryPyTest):
__opts__ = {
Expand Down