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
65b87a39
Commit
65b87a39
authored
5 years ago
by
Timm Fitschen
Committed by
Henrik tom Wörden
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
TST: fix for anonymous user in pylib
parent
f76dbb29
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/test_authentication.py
+62
-16
62 additions, 16 deletions
tests/test_authentication.py
tests/test_deletion.py
+1
-5
1 addition, 5 deletions
tests/test_deletion.py
with
63 additions
and
21 deletions
tests/test_authentication.py
+
62
−
16
View file @
65b87a39
...
...
@@ -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
"
This diff is collapsed.
Click to expand it.
tests/test_deletion.py
+
1
−
5
View file @
65b87a39
...
...
@@ -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
)
...
...
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