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
91630fbe
Commit
91630fbe
authored
8 years ago
by
Sebastian Lobinger
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' into 16-update-documentation
parents
67b9dd1b
a9f98fe3
No related branches found
No related tags found
1 merge request
!12
Resolve "Dokumentation aktualisieren"
Changes
2
Show 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 @
91630fbe
...
@@ -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,6 +51,12 @@ class SAMSProxy:
...
@@ -50,6 +51,12 @@ class SAMSProxy:
filteredSession
[
filteredParams
[
param
][
'
name
'
]]
=
str
(
session
.
get
(
param
))
filteredSession
[
filteredParams
[
param
][
'
name
'
]]
=
str
(
session
.
get
(
param
))
return
filteredSession
return
filteredSession
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
:
def
_get_first_dict
(
self
,
*
possibleDicts
)
->
dict
:
for
possibleDict
in
possibleDicts
:
for
possibleDict
in
possibleDicts
:
if
isinstance
(
possibleDict
,
dict
):
if
isinstance
(
possibleDict
,
dict
):
...
...
This diff is collapsed.
Click to expand it.
test/test_sams_proxy.py
+
61
−
25
View file @
91630fbe
...
@@ -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
'
}}}},
{
'
in
'
:
'
/foo/bar
'
,
'
out
'
:
'
http://baz.foo
'
,
'
session-passthrough
'
:
{
'
default
'
:
{
'
user
'
:
{
'
param_type
'
:
'
body
'
}}}}
]
for
method
in
(
'
get
'
,
'
post
'
,
'
delete
'
,
'
put
'
,
'
update
'
):
for
method
in
(
'
get
'
,
'
post
'
,
'
delete
'
,
'
put
'
,
'
update
'
):
SAMSProxy
(
proxySpec
=
{
'
in
'
:
'
/foo/bar
'
,
'
out
'
:
'
http://baz.foo
'
proxySpecs
.
append
(
{
'
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
'
:
{
'
param_type
'
:
'
body
'
}}}})
SAMSProxy
(
proxySpec
=
{
'
in
'
:
'
/foo/bar
'
,
'
out
'
:
'
http://baz.foo
'
proxySpecs
.
append
(
{
'
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
'
:
{
'
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
):
...
@@ -188,3 +195,32 @@ class TestSAMSHubWithThreadedAPI(unittest.TestCase):
...
@@ -188,3 +195,32 @@ class TestSAMSHubWithThreadedAPI(unittest.TestCase):
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
'
)
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