Skip to content

Commit

Permalink
Add tests with filname in token data
Browse files Browse the repository at this point in the history
  • Loading branch information
Ch3LL committed Sep 25, 2018
1 parent 9756f8f commit ad0d83c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion salt/netapi/rest_cherrypy/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2178,7 +2178,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/test_app.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 salt libs
import salt.utils.json
Expand Down Expand Up @@ -163,6 +164,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(cptc.BaseRestCherryPyTest):

Expand Down

0 comments on commit ad0d83c

Please sign in to comment.