Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
sams-classes
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
coding-at-fu
sams-classes
Commits
a9f98fe3
Commit
a9f98fe3
authored
8 years ago
by
slobinger
Browse files
Options
Downloads
Plain Diff
Merge branch '6-SAMSProxy_development' into 'master'
Resolve "SAMSProxy entwickeln" Closes
#6
See merge request
!11
parents
0cc2e906
83ff9aa4
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!11
Resolve "SAMSProxy entwickeln"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
sams_classes/sams_proxy.py
+8
-1
8 additions, 1 deletion
sams_classes/sams_proxy.py
test/test_sams_proxy.py
+61
-25
61 additions, 25 deletions
test/test_sams_proxy.py
with
69 additions
and
26 deletions
sams_classes/sams_proxy.py
+
8
−
1
View file @
a9f98fe3
...
@@ -38,6 +38,7 @@ class SAMSProxy:
...
@@ -38,6 +38,7 @@ class SAMSProxy:
def
_pass_param
(
self
,
method
,
paramType
,
paramDict
=
{}):
def
_pass_param
(
self
,
method
,
paramType
,
paramDict
=
{}):
paramDict
.
update
(
self
.
_filter_session
(
method
,
paramType
))
paramDict
.
update
(
self
.
_filter_session
(
method
,
paramType
))
paramDict
.
update
(
self
.
_filter_token
(
paramType
))
return
paramDict
return
paramDict
def
_filter_session
(
self
,
method
,
paramType
):
def
_filter_session
(
self
,
method
,
paramType
):
...
@@ -50,7 +51,13 @@ class SAMSProxy:
...
@@ -50,7 +51,13 @@ class SAMSProxy:
filteredSession
[
filteredParams
[
param
][
'
name
'
]]
=
str
(
session
.
get
(
param
))
filteredSession
[
filteredParams
[
param
][
'
name
'
]]
=
str
(
session
.
get
(
param
))
return
filteredSession
return
filteredSession
def
_get_first_dict
(
self
,
*
possibleDicts
)
->
dict
:
def
_filter_token
(
self
,
paramType
:
str
)
->
dict
:
if
paramType
==
self
.
_proxySpec
.
get
(
'
token
'
,
{}).
get
(
'
param-type
'
):
return
{
self
.
_proxySpec
[
'
token
'
][
'
name
'
]:
self
.
_proxySpec
[
'
token
'
][
'
value
'
]}
return
{}
def
_get_first_dict
(
self
,
*
possibleDicts
)
->
dict
:
for
possibleDict
in
possibleDicts
:
for
possibleDict
in
possibleDicts
:
if
isinstance
(
possibleDict
,
dict
):
if
isinstance
(
possibleDict
,
dict
):
return
possibleDict
return
possibleDict
...
...
This diff is collapsed.
Click to expand it.
test/test_sams_proxy.py
+
61
−
25
View file @
a9f98fe3
...
@@ -26,30 +26,37 @@ class TestSAMSHub(unittest.TestCase):
...
@@ -26,30 +26,37 @@ class TestSAMSHub(unittest.TestCase):
def
test_mandatory_keys_in_spec
(
self
):
def
test_mandatory_keys_in_spec
(
self
):
"""
ProxySpecKeyMissing is raised if something is mising in spec
"""
"""
ProxySpecKeyMissing is raised if something is mising in spec
"""
with
self
.
assertRaises
(
ProxySpecKeyMssing
):
proxySpecs
=
[
SAMSProxy
(
proxySpec
=
{
'
out
'
:
'
http://baz.foo
'
})
{
'
out
'
:
'
http://baz.foo
'
},
SAMSProxy
(
proxySpec
=
{
'
in
'
:
'
/foo/bar
'
})
{
'
in
'
:
'
/foo/bar
'
},
SAMSProxy
(
proxySpec
=
{
'
in
'
:
'
/foo/bar
'
,
'
out
'
:
'
http://baz.foo
'
{
'
in
'
:
'
/foo/bar
'
,
'
out
'
:
'
http://baz.foo
'
,
'
token
'
:
{
'
name
'
:
'
user
'
}})
,
'
token
'
:
{
'
name
'
:
'
user
'
}},
SAMSProxy
(
proxySpec
=
{
'
in
'
:
'
/foo/bar
'
,
'
out
'
:
'
http://baz.foo
'
{
'
in
'
:
'
/foo/bar
'
,
'
out
'
:
'
http://baz.foo
'
,
'
token
'
:
{
'
value
'
:
'
user
'
}})
,
'
token
'
:
{
'
value
'
:
'
user
'
}},
SAMSProxy
(
proxySpec
=
{
'
in
'
:
'
/foo/bar
'
,
'
out
'
:
'
http://baz.foo
'
{
'
in
'
:
'
/foo/bar
'
,
'
out
'
:
'
http://baz.foo
'
,
'
session_passthrough
'
:
{}})
,
'
token
'
:
{
'
name
'
:
'
user
'
,
'
value
'
:
'
user
'
}},
SAMSProxy
(
proxySpec
=
{
'
in
'
:
'
/foo/bar
'
,
'
out
'
:
'
http://baz.foo
'
{
'
in
'
:
'
/foo/bar
'
,
'
out
'
:
'
http://baz.foo
'
,
'
session_passthrough
'
:
{
'
default
'
:
{}}})
,
'
session-passthrough
'
:
{}},
SAMSProxy
(
proxySpec
=
{
'
in
'
:
'
/foo/bar
'
,
'
out
'
:
'
http://baz.foo
'
{
'
in
'
:
'
/foo/bar
'
,
'
out
'
:
'
http://baz.foo
'
,
'
session_passthrough
'
:
{
'
default
'
:
{
'
user
'
:
{
'
name
'
:
'
u
'
}}}})
,
'
session-passthrough
'
:
{
'
default
'
:
{}}},
SAMSProxy
(
proxySpec
=
{
'
in
'
:
'
/foo/bar
'
,
'
out
'
:
'
http://baz.foo
'
{
'
in
'
:
'
/foo/bar
'
,
'
out
'
:
'
http://baz.foo
'
,
'
session_passthrough
'
:
{
'
default
'
:
{
'
user
'
:
{
'
param_type
'
:
'
body
'
}}}})
,
'
session-passthrough
'
:
{
'
default
'
:
{
'
user
'
:
{
'
name
'
:
'
u
'
}}}},
for
method
in
(
'
get
'
,
'
post
'
,
'
delete
'
,
'
put
'
,
'
update
'
):
{
'
in
'
:
'
/foo/bar
'
,
'
out
'
:
'
http://baz.foo
'
SAMSProxy
(
proxySpec
=
{
'
in
'
:
'
/foo/bar
'
,
'
out
'
:
'
http://baz.foo
'
,
'
session-passthrough
'
:
{
'
default
'
:
{
'
user
'
:
{
'
param_type
'
:
'
body
'
}}}}
,
'
session_passthrough
'
:
{
'
default
'
:
{
]
'
user
'
:
{
'
param_type
'
:
'
body
'
,
'
name
'
:
'
u
'
}
for
method
in
(
'
get
'
,
'
post
'
,
'
delete
'
,
'
put
'
,
'
update
'
):
},
method
:
{
'
user
'
:
{
'
param_type
'
:
'
body
'
}}}})
proxySpecs
.
append
({
'
in
'
:
'
/foo/bar
'
,
'
out
'
:
'
http://baz.foo
'
,
SAMSProxy
(
proxySpec
=
{
'
in
'
:
'
/foo/bar
'
,
'
out
'
:
'
http://baz.foo
'
'
session-passthrough
'
:
{
'
default
'
:
{
,
'
session_passthrough
'
:
{
'
default
'
:
{
'
user
'
:
{
'
param_type
'
:
'
body
'
,
'
name
'
:
'
u
'
}
'
user
'
:
{
'
param_type
'
:
'
body
'
,
'
name
'
:
'
u
'
}
},
method
:
{
'
user
'
:
{
'
param_type
'
:
'
body
'
}}}})
},
method
:
{
'
user
'
:
{
'
name
'
:
'
u
'
}}}})
proxySpecs
.
append
({
'
in
'
:
'
/foo/bar
'
,
'
out
'
:
'
http://baz.foo
'
,
'
session-passthrough
'
:
{
'
default
'
:
{
'
user
'
:
{
'
param_type
'
:
'
body
'
,
'
name
'
:
'
u
'
}
},
method
:
{
'
user
'
:
{
'
name
'
:
'
u
'
}}}})
for
proxySpec
in
proxySpecs
:
with
self
.
subTest
(
proxySpec
):
with
self
.
assertRaises
(
ProxySpecKeyMssing
):
SAMSProxy
(
proxySpec
=
proxySpec
)
class
TestSAMSHubWithThreadedAPI
(
unittest
.
TestCase
):
class
TestSAMSHubWithThreadedAPI
(
unittest
.
TestCase
):
...
@@ -187,4 +194,33 @@ class TestSAMSHubWithThreadedAPI(unittest.TestCase):
...
@@ -187,4 +194,33 @@ 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
'
)
eprint
(
resDict
[
param_type
])
self
.
assertEquals
(
resDict
[
param_type
][
'
Api-Token
'
],
'
53CUR34P170K3N
'
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment