Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-server
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-server
Commits
2edfcff6
Verified
Commit
2edfcff6
authored
3 years ago
by
Timm Fitschen
Browse files
Options
Downloads
Patches
Plain Diff
TST: more unit tests for Retrieve transactions
parent
efe146b3
No related branches found
No related tags found
2 merge requests
!58
REL: prepare release 0.7.2
,
!57
F 220
Pipeline
#20573
passed
3 years ago
Stage: info
Stage: test
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/org/caosdb/server/transaction/Retrieve.java
+1
-1
1 addition, 1 deletion
src/main/java/org/caosdb/server/transaction/Retrieve.java
src/test/java/org/caosdb/server/transaction/RetrieveTest.java
+78
-0
78 additions, 0 deletions
...test/java/org/caosdb/server/transaction/RetrieveTest.java
with
79 additions
and
1 deletion
src/main/java/org/caosdb/server/transaction/Retrieve.java
+
1
−
1
View file @
2edfcff6
...
@@ -79,7 +79,7 @@ public class Retrieve extends Transaction<RetrieveContainer> {
...
@@ -79,7 +79,7 @@ public class Retrieve extends Transaction<RetrieveContainer> {
protected
void
postTransaction
()
{
protected
void
postTransaction
()
{
// generate Error for missing RETRIEVE:ENTITY Permission.
// generate Error for missing RETRIEVE:ENTITY Permission.
for
(
final
EntityInterface
e
:
getContainer
())
{
for
(
final
EntityInterface
e
:
getContainer
())
{
if
(
e
.
getEntity
ACL
()
!=
null
)
{
if
(
e
.
getEntity
Status
()
!=
EntityStatus
.
NONEXISTENT
)
{
try
{
try
{
e
.
checkPermission
(
EntityPermission
.
RETRIEVE_ENTITY
);
e
.
checkPermission
(
EntityPermission
.
RETRIEVE_ENTITY
);
}
catch
(
final
AuthorizationException
exc
)
{
}
catch
(
final
AuthorizationException
exc
)
{
...
...
This diff is collapsed.
Click to expand it.
src/test/java/org/caosdb/server/transaction/RetrieveTest.java
0 → 100644
+
78
−
0
View file @
2edfcff6
package
org.caosdb.server.transaction
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
java.io.IOException
;
import
org.apache.shiro.SecurityUtils
;
import
org.apache.shiro.subject.Subject
;
import
org.caosdb.server.CaosDBServer
;
import
org.caosdb.server.ServerProperties
;
import
org.caosdb.server.accessControl.AnonymousAuthenticationToken
;
import
org.caosdb.server.accessControl.Role
;
import
org.caosdb.server.database.BackendTransaction
;
import
org.caosdb.server.database.access.Access
;
import
org.caosdb.server.database.backend.interfaces.RetrieveRoleImpl
;
import
org.caosdb.server.database.exceptions.TransactionException
;
import
org.caosdb.server.database.misc.TransactionBenchmark
;
import
org.caosdb.server.entity.EntityInterface
;
import
org.caosdb.server.entity.RetrieveEntity
;
import
org.caosdb.server.entity.container.RetrieveContainer
;
import
org.caosdb.server.entity.xml.IdAndServerMessagesOnlyStrategy
;
import
org.caosdb.server.permissions.EntityACLFactory
;
import
org.caosdb.server.utils.EntityStatus
;
import
org.caosdb.server.utils.ServerMessages
;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
public
class
RetrieveTest
{
@BeforeClass
public
static
void
setup
()
throws
IOException
{
CaosDBServer
.
initServerProperties
();
CaosDBServer
.
setProperty
(
ServerProperties
.
KEY_AUTH_OPTIONAL
,
"TRUE"
);
CaosDBServer
.
initShiro
();
BackendTransaction
.
setImpl
(
RetrieveRoleImpl
.
class
,
RetrieveRoleMockup
.
class
);
}
/** a mock-up which returns null */
public
static
class
RetrieveRoleMockup
implements
RetrieveRoleImpl
{
public
RetrieveRoleMockup
(
Access
a
)
{}
@Override
public
void
setTransactionBenchmark
(
TransactionBenchmark
b
)
{}
@Override
public
TransactionBenchmark
getBenchmark
()
{
return
null
;
}
@Override
public
Role
retrieve
(
String
role
)
throws
TransactionException
{
return
null
;
}
}
@Test
public
void
testMissingRetrievePermission
()
{
Subject
subject
=
SecurityUtils
.
getSubject
();
subject
.
login
(
AnonymousAuthenticationToken
.
getInstance
());
EntityInterface
entity
=
new
RetrieveEntity
(
1234
);
EntityACLFactory
fac
=
new
EntityACLFactory
();
fac
.
deny
(
AnonymousAuthenticationToken
.
PRINCIPAL
,
"RETRIEVE:ENTITY"
);
entity
.
setEntityACL
(
fac
.
create
());
RetrieveContainer
container
=
new
RetrieveContainer
(
null
,
null
,
null
,
null
);
assertTrue
(
entity
.
getMessages
().
isEmpty
());
assertEquals
(
entity
.
getEntityStatus
(),
EntityStatus
.
QUALIFIED
);
container
.
add
(
entity
);
Retrieve
retrieve
=
new
Retrieve
(
container
);
retrieve
.
postTransaction
();
assertFalse
(
entity
.
getMessages
().
isEmpty
());
assertEquals
(
entity
.
getMessages
(
"error"
).
get
(
0
),
ServerMessages
.
AUTHORIZATION_ERROR
);
assertEquals
(
entity
.
getEntityStatus
(),
EntityStatus
.
UNQUALIFIED
);
assertTrue
(
entity
.
getSerializeFieldStrategy
()
instanceof
IdAndServerMessagesOnlyStrategy
);
}
}
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