Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
CaosDB Python Integration Tests
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
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
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
caosdb
Software
CaosDB Python Integration Tests
Commits
18a5d200
Commit
18a5d200
authored
3 years ago
by
Henrik tom Wörden
Browse files
Options
Downloads
Patches
Plain Diff
STY: cosmetic changes
parent
45d118c2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_server_side_scripting.py
+19
-10
19 additions, 10 deletions
tests/test_server_side_scripting.py
with
19 additions
and
10 deletions
tests/test_server_side_scripting.py
+
19
−
10
View file @
18a5d200
...
...
@@ -26,20 +26,22 @@
Integration tests for the implementation of the server-side-scripting api.
"""
from
__future__
import
print_function
,
unicode_literals
import
json
import
os
import
ssl
import
tempfile
from
pytest
import
raises
,
mark
import
json
from
lxml
import
etree
from
http.client
import
HTTPSConnection
import
ssl
from
caosdb
import
get_connection
,
get_config
,
Info
,
execute_query
,
RecordType
from
caosdb
.exceptions
import
(
HTTPClientError
,
HTTPResourceNotFoundError
)
from
caosdb
import
Info
,
RecordType
from
caosdb
import
administration
as
admin
from
caosdb
import
execute_query
,
get_config
,
get_connection
from
caosdb.connection.encode
import
MultipartParam
,
multipart_encode
from
caosdb.connection.utils
import
urlencode
,
urlparse
from
caosdb
import
administration
as
admin
from
caosdb
.exceptions
import
HTTPClientError
,
HTTPResourceNotFoundError
from
caosdb.utils.server_side_scripting
import
run_server_side_script
from
lxml
import
etree
from
pytest
import
mark
,
raises
_TEST_SCRIPTS
=
[
"
not_executable
"
,
"
ok
"
,
"
err
"
,
"
ok_anonymous
"
]
...
...
@@ -63,6 +65,7 @@ _ORIGINAL_SERVER_SCRIPTING_BIN_DIR = ""
def
clean_database
():
admin
.
_set_permissions
(
"
anonymous
"
,
[])
d
=
execute_query
(
"
FIND ENTITY WITH ID > 99
"
)
if
len
(
d
)
>
0
:
d
.
delete
()
...
...
@@ -84,15 +87,17 @@ def setup_module():
clean_database
()
from
os
import
makedirs
from
os.path
import
join
,
isdir
,
exists
from
os.path
import
exists
,
isdir
,
join
from
shutil
import
copyfile
,
copymode
print
(
"
bin dir (local):
"
+
str
(
_SERVER_SIDE_SCRIPTING_BIN_DIR_LOCAL
))
print
(
"
bin dir (server):
"
+
str
(
_SERVER_SIDE_SCRIPTING_BIN_DIR_SERVER
))
print
(
"
tests scripts:
"
+
str
(
_TEST_SCRIPTS
))
if
not
exists
(
_SERVER_SIDE_SCRIPTING_BIN_DIR_LOCAL
):
makedirs
(
_SERVER_SIDE_SCRIPTING_BIN_DIR_LOCAL
)
_REMOVE_FILES_AFTERWARDS
.
append
(
_SERVER_SIDE_SCRIPTING_BIN_DIR_LOCAL
)
assert
isdir
(
_SERVER_SIDE_SCRIPTING_BIN_DIR_LOCAL
)
for
script_file
in
_TEST_SCRIPTS
:
target
=
join
(
_SERVER_SIDE_SCRIPTING_BIN_DIR_LOCAL
,
script_file
)
src
=
join
(
_TEST_SCRIPTS_DIR
,
script_file
)
...
...
@@ -105,6 +110,7 @@ def teardown_module():
from
os
import
remove
from
os.path
import
exists
,
isdir
from
shutil
import
rmtree
for
obsolete
in
_REMOVE_FILES_AFTERWARDS
:
if
exists
(
obsolete
):
if
isdir
(
obsolete
):
...
...
@@ -330,6 +336,7 @@ def request(method, headers, path, body=None):
"""
context
=
ssl
.
SSLContext
(
ssl
.
PROTOCOL_TLSv1_2
)
context
.
verify_mode
=
ssl
.
CERT_REQUIRED
if
hasattr
(
context
,
"
check_hostname
"
):
context
.
check_hostname
=
True
context
.
load_verify_locations
(
get_config
().
get
(
"
Connection
"
,
"
cacert
"
))
...
...
@@ -341,6 +348,7 @@ def request(method, headers, path, body=None):
str
(
fullurl
.
netloc
),
timeout
=
200
,
context
=
context
)
http_con
.
request
(
method
=
method
,
headers
=
headers
,
url
=
str
(
fullurl
.
path
)
+
path
,
body
=
body
)
return
http_con
.
getresponse
()
...
...
@@ -364,7 +372,7 @@ def test_anonymous_script_calling_not_permitted():
assert
response
.
getheader
(
"
Set-Cookie
"
)
is
None
# no auth token returned
@mark.local_server
@
mark
.
local_server
def
test_anonymous_script_calling_success
():
admin
.
set_server_property
(
"
SERVER_SIDE_SCRIPTING_BIN_DIRS
"
,
_SERVER_SIDE_SCRIPTING_BIN_DIR_SERVER
)
...
...
@@ -398,6 +406,7 @@ def test_anonymous_script_calling_success():
@mark.local_server
def
test_evil_path
():
subdir
=
os
.
path
.
join
(
_SERVER_SIDE_SCRIPTING_BIN_DIR_LOCAL
,
"
subdir
"
)
if
not
os
.
path
.
exists
(
subdir
):
os
.
makedirs
(
subdir
)
_REMOVE_FILES_AFTERWARDS
.
append
(
subdir
)
...
...
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