Skip to content
Snippets Groups Projects

Resolve "SAMSProxy entwickeln"

Merged slobinger requested to merge 6-SAMSProxy_development into master
1 file
+ 29
1
Compare changes
  • Side-by-side
  • Inline
+ 29
1
@@ -187,4 +187,32 @@ class TestSAMSHubWithThreadedAPI(unittest.TestCase):
@@ -187,4 +187,32 @@ class TestSAMSHubWithThreadedAPI(unittest.TestCase):
resDict = json.loads(res.data.decode('utf-8'))
resDict = json.loads(res.data.decode('utf-8'))
self.assertEqual(resDict['url']['u'], 'foo')
self.assertEqual(resDict['url']['u'], 'foo')
self.assertEqual(resDict['body']['g'], 'bar')
self.assertEqual(resDict['body']['g'], 'bar')
self.assertEqual(resDict['header']['Lang'], 'klingon')
self.assertEqual(resDict['header']['Lang'], 'klingon')
\ No newline at end of file
 
def test_token_passthrough(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
 
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'])
 
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')
 
self.assertEquals(resDict[param_type]['api-token'], '53CUR34P170K3N')
 
\ No newline at end of file
Loading