Skip to content
Snippets Groups Projects
Commit 65b87a39 authored by Timm Fitschen's avatar Timm Fitschen Committed by Henrik tom Wörden
Browse files

TST: fix for anonymous user in pylib

parent f76dbb29
No related branches found
No related tags found
No related merge requests found
......@@ -27,14 +27,28 @@
"""
import os
from sys import hexversion
from urllib.parse import urlparse
from http.client import HTTPSConnection
import ssl
from subprocess import call, check_output
from lxml import etree
from pytest import skip
from caosdb.exceptions import LoginFailedException
import caosdb as h
from nose.tools import assert_false, assert_true, assert_is_none, assert_raises, assert_equal, assert_is_not_none, nottest # @UnresolvedImport
from nose.tools import (assert_false, assert_true, assert_is_none,
assert_raises, assert_equal, assert_is_not_none,
nottest, with_setup)
from caosdb.connection.connection import _Connection
def setup():
try:
h.execute_query("FIND Test*").delete()
except Exception as e:
print(e)
def test_pass():
if not h.get_config().has_option("Connection", "password_method") or not h.get_config().get("Connection", "password_method") == "pass":
skip()
......@@ -43,22 +57,10 @@ def test_pass():
def test_https_support():
from sys import hexversion
if hexversion < 0x02070900:
raise Exception("version " + str(hex(hexversion)))
elif 0x02999999 < hexversion < 0x03020000:
if 0x02999999 < hexversion < 0x03020000:
raise Exception("version " + str(hex(hexversion)))
try:
# python2
from httplib import HTTPSConnection
from urlparse import urlparse
except:
# python 3
from urllib.parse import urlparse
from http.client import HTTPSConnection
import ssl
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2) # @UndefinedVariable
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
context.verify_mode = ssl.CERT_REQUIRED
if hasattr(context, "check_hostname"):
context.check_hostname = True
......@@ -82,3 +84,47 @@ def test_login_via_post_form_data_failure():
"username": h.get_config().get("Connection", "username"),
"password": "wrongpassphrase"
})
def test_anonymous_setter():
""" this test verifies that the "test_login_while_anonymous_is_active" is
effective."""
# activate anonymous user
h.administration.set_server_property("AUTH_OPTIONAL", "TRUE")
# connect without auth-token
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
context.verify_mode = ssl.CERT_REQUIRED
context.load_verify_locations(h.get_config().get("Connection", "cacert"))
url = h.get_config().get("Connection", "url")
fullurl = urlparse(url)
http_con = HTTPSConnection(
str(fullurl.netloc), timeout=200, context=context)
http_con.request(method="GET", headers={}, url=str(fullurl.path) + "Info")
body = http_con.getresponse().read()
xml = etree.fromstring(body)
# verify unauthenticated
assert xml.xpath("/Response/UserInfo/Roles/Role")[0].text == "anonymous"
@with_setup(setup, setup)
def test_login_while_anonymous_is_active():
# activate anonymous user
h.administration.set_server_property("AUTH_OPTIONAL", "TRUE")
# logout
h.get_connection()._logout()
body = h.get_connection().retrieve(
entity_uri_segments=["Entity"],
reconnect=True).read()
xml = etree.fromstring(body)
# pylib did the login even though the anonymous user is active
assert xml.xpath(
"/Response/UserInfo/Roles/Role")[0].text == "administration"
......@@ -151,11 +151,7 @@ def test_deletion():
assert_is_not_none(cr2.id)
c.extend([cr1, sr, d])
try:
assert_raises(h.TransactionError, c.delete)
except:
import time
time.sleep(120)
assert_raises(h.TransactionError, c.delete)
assert_true(c.has_errors())
assert_equal(int(c.get_errors()[0].code), 12)
......
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