Skip to content
Snippets Groups Projects
Commit 18a5d200 authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

STY: cosmetic changes

parent 45d118c2
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment