Skip to content
Snippets Groups Projects
Commit a028d664 authored by Sebastian Lobinger's avatar Sebastian Lobinger
Browse files

add test_no_token_passthrough_without_session to test_sams_proxy.py #38

parent 5fe5dd11
No related branches found
No related tags found
1 merge request!24Resolve "API Token nur bei Einträgen in der Session zulassen"
......@@ -234,4 +234,38 @@ class TestSAMSHubWithThreadedAPI(unittest.TestCase):
self.assertEqual(resDict['body']['g'], 'bar')
self.assertEqual(resDict['header']['Lang'], 'klingon')
eprint(resDict[param_type])
self.assertEquals(resDict[param_type]['Api-Token'], '53CUR34P170K3N')
\ No newline at end of file
self.assertEquals(resDict[param_type]['Api-Token'], '53CUR34P170K3N')
def test_no_token_passthrough_without_session(self):
"""The proxy passes the specified token and the other params"""
for param_type in ('header', 'url', 'body'):
proxyApp = Flask('test')
proxyApp.config['TESTING'] = True
proxyApp.secret_key = 'A0Zr98j/3yX R~XHH!jmN]LWX/,?RT'
proxy = SAMSProxy(
proxySpec = {
'in': '/proxy', 'out': 'http://localhost:4711',
'token': {
'name': 'Api-Token', 'value': '53CUR34P170K3N',
'param-type': param_type
}
}
)
with self.subTest(param_type):
proxyApp.add_url_rule(rule = proxy.urlRule, endpoint = 'proxy',
view_func = proxy.proxy, methods=['GET', 'POST', 'PUT', 'UPDATE',
'PATCH', 'DELETE', 'OPTIONS'])
proxyApp.add_url_rule(rule = proxy.rootUrlRule, endpoint = 'proxy',
view_func = proxy.proxy, methods=['GET', 'POST', 'PUT', 'UPDATE',
'PATCH', 'DELETE', 'OPTIONS'])
with proxyApp.test_client(self) as client:
res = client.get(path='/proxy/passthrough',
query_string={'u':'foo'}, data={'g':'bar'},
headers={'lang': 'klingon'})
resDict = json.loads(res.data.decode('utf-8'))
self.assertEqual(resDict['url']['u'], 'foo')
self.assertEqual(resDict['body']['g'], 'bar')
self.assertEqual(resDict['header']['Lang'], 'klingon')
eprint(resDict[param_type])
self.assertNotEquals(
resDict.get(param_type, {}).get('Api-Token'), '53CUR34P170K3N')
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment