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
4f0cf1f9
Commit
4f0cf1f9
authored
3 years ago
by
Florian Spreckelsen
Browse files
Options
Downloads
Plain Diff
Merge branch 'f-220' into 'dev'
Tests for
caosdb-server#223
See merge request
!31
parents
dd05c68e
6505d304
No related branches found
No related tags found
1 merge request
!31
Tests for caosdb-server#223
Pipeline
#21008
passed
3 years ago
Stage: info
Stage: setup
Stage: cert
Stage: style
Stage: test
Stage: deploy
Changes
1
Pipelines
52
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_state.py
+58
-1
58 additions, 1 deletion
tests/test_state.py
with
58 additions
and
1 deletion
tests/test_state.py
+
58
−
1
View file @
4f0cf1f9
# encoding: utf-8
#
# This file is a part of the CaosDB Project.
#
# Copyright (C) 2020-2022 IndiScale GmbH <info@indiscale.com>
# Copyright (C) 2020-2022 Timm Fitschen <t.fitschen@indiscale.com>
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <https://www.gnu.org/licenses/>.
#
# ** end header
#
import
pytest
import
pytest
import
caosdb
as
db
import
caosdb
as
db
from
caosdb
import
administration
as
admin
from
caosdb
import
administration
as
admin
...
@@ -111,6 +133,7 @@ def setup_module():
...
@@ -111,6 +133,7 @@ def setup_module():
"
ACL
"
:
None
})
"
ACL
"
:
None
})
state_acl
=
db
.
ACL
()
state_acl
=
db
.
ACL
()
state_acl
.
grant
(
role
=
"
role1
"
,
permission
=
"
UPDATE:DESCRIPTION
"
)
state_acl
.
grant
(
role
=
"
role1
"
,
permission
=
"
UPDATE:DESCRIPTION
"
)
state_acl
.
deny
(
role
=
"
anonymous
"
,
permission
=
"
RETRIEVE:ENTITY
"
)
state_acl
=
db
.
State
.
create_state_acl
(
state_acl
)
state_acl
=
db
.
State
.
create_state_acl
(
state_acl
)
st1
.
acl
=
state_acl
.
combine
(
st1
.
acl
)
st1
.
acl
=
state_acl
.
combine
(
st1
.
acl
)
st1
.
update_acl
()
st1
.
update_acl
()
...
@@ -146,6 +169,8 @@ def setup_module():
...
@@ -146,6 +169,8 @@ def setup_module():
def
teardown_function
(
function
):
def
teardown_function
(
function
):
switch_to_admin_user
()
switch_to_admin_user
()
# deactivate anonymous user
db
.
administration
.
set_server_property
(
"
AUTH_OPTIONAL
"
,
"
FALSE
"
)
d
=
db
.
execute_query
(
"
FIND TestRT
"
)
d
=
db
.
execute_query
(
"
FIND TestRT
"
)
if
len
(
d
)
>
0
:
if
len
(
d
)
>
0
:
d
.
delete
(
flags
=
{
"
forceFinalState
"
:
"
true
"
})
d
.
delete
(
flags
=
{
"
forceFinalState
"
:
"
true
"
})
...
@@ -480,10 +505,16 @@ def test_transfer_state_acl():
...
@@ -480,10 +505,16 @@ def test_transfer_state_acl():
rec
.
state
=
db
.
State
(
model
=
"
Model1
"
,
name
=
"
State1
"
)
rec
.
state
=
db
.
State
(
model
=
"
Model1
"
,
name
=
"
State1
"
)
insert_rec
=
rec
.
insert
(
flags
=
{
"
ACL
"
:
None
})
insert_rec
=
rec
.
insert
(
flags
=
{
"
ACL
"
:
None
})
state_acl
=
db
.
ACL
()
.
combine
(
db
.
get_global_acl
())
state_acl
=
db
.
ACL
()
state_acl
.
grant
(
role
=
"
role1
"
,
permission
=
"
UPDATE:DESCRIPTION
"
)
state_acl
.
grant
(
role
=
"
role1
"
,
permission
=
"
UPDATE:DESCRIPTION
"
)
state_acl
.
deny
(
role
=
"
anonymous
"
,
permission
=
"
RETRIEVE:ENTITY
"
)
state_acl
=
state_acl
.
combine
(
db
.
get_global_acl
())
# the acl has been transfered from the state record
# the acl has been transfered from the state record
assert
insert_rec
.
acl
.
get_permissions_for_role
(
"
role1
"
)
==
{
"
UPDATE:DESCRIPTION
"
}
assert
"
RETRIEVE:ENTITY
"
not
in
insert_rec
.
acl
.
get_permissions_for_role
(
"
anonymous
"
)
assert
insert_rec
.
acl
==
state_acl
assert
insert_rec
.
acl
==
state_acl
...
@@ -806,3 +837,29 @@ def test_transitions_included_after_empty_update():
...
@@ -806,3 +837,29 @@ def test_transitions_included_after_empty_update():
db
.
Transition
(
name
=
"
Transition4
"
,
db
.
Transition
(
name
=
"
Transition4
"
,
from_state
=
"
State2
"
,
from_state
=
"
State2
"
,
to_state
=
"
State2
"
)}
to_state
=
"
State2
"
)}
def
test_missing_retrieve_permission
():
"""
When the retrieve permission is missing, the state must not be leaked.
"""
# @review Florian Spreckelsen 2022-03-22
rec
=
db
.
Record
()
rec
.
description
=
"
old description
"
rec
.
add_parent
(
"
TestRT
"
)
rec
.
state
=
db
.
State
(
model
=
"
Model1
"
,
name
=
"
State1
"
)
rec
.
insert
(
flags
=
{
"
ACL
"
:
None
})
print
(
rec
)
# switch to anonymous
db
.
administration
.
set_server_property
(
"
AUTH_OPTIONAL
"
,
"
TRUE
"
)
db
.
configure_connection
(
password_method
=
"
unauthenticated
"
)
assert
db
.
Info
().
user_info
.
roles
==
[
"
anonymous
"
]
rec2
=
db
.
Record
(
id
=
rec
.
id
)
with
pytest
.
raises
(
db
.
TransactionError
)
as
te
:
rec2
.
retrieve
()
assert
te
.
value
.
has_error
(
db
.
AuthorizationError
)
rec2
=
db
.
Record
(
id
=
rec
.
id
)
rec2
.
retrieve
(
raise_exception_on_error
=
False
)
assert
len
(
rec2
.
get_errors
())
>
0
assert
rec2
.
state
is
None
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