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

TST: update getCacheKey test

parent fd014207
No related branches found
No related tags found
1 merge request!65F permission checks
Pipeline #26230 failed
...@@ -26,7 +26,11 @@ import static org.junit.Assert.assertNull; ...@@ -26,7 +26,11 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import java.io.IOException; import java.io.IOException;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.caosdb.server.CaosDBServer; import org.caosdb.server.CaosDBServer;
import org.caosdb.server.ServerProperties;
import org.caosdb.server.accessControl.AnonymousAuthenticationToken;
import org.caosdb.server.database.access.InitAccess; import org.caosdb.server.database.access.InitAccess;
import org.caosdb.server.transaction.WriteTransaction; import org.caosdb.server.transaction.WriteTransaction;
import org.junit.BeforeClass; import org.junit.BeforeClass;
...@@ -37,6 +41,7 @@ public class QueryTest { ...@@ -37,6 +41,7 @@ public class QueryTest {
@BeforeClass @BeforeClass
public static void initServerProperties() throws IOException { public static void initServerProperties() throws IOException {
CaosDBServer.initServerProperties(); CaosDBServer.initServerProperties();
CaosDBServer.initShiro();
} }
String getCacheKey(String query) { String getCacheKey(String query) {
...@@ -45,6 +50,15 @@ public class QueryTest { ...@@ -45,6 +50,15 @@ public class QueryTest {
return q.getCacheKey(true); return q.getCacheKey(true);
} }
String getCacheKeyWithUser(String query) {
Subject anonymous = SecurityUtils.getSubject();
CaosDBServer.setProperty(ServerProperties.KEY_AUTH_OPTIONAL, "true");
anonymous.login(AnonymousAuthenticationToken.getInstance());
Query q = new Query(query, anonymous);
q.parse();
return q.getCacheKey(true);
}
@Test @Test
public void testGetKey() { public void testGetKey() {
assertEquals("enamePOV(pname,=,val1)", getCacheKey("FIND ename WITH pname = val1")); assertEquals("enamePOV(pname,=,val1)", getCacheKey("FIND ename WITH pname = val1"));
...@@ -72,6 +86,8 @@ public class QueryTest { ...@@ -72,6 +86,8 @@ public class QueryTest {
assertEquals( assertEquals(
"ename@(ref1,null)SUB(POV(pname,>,val1)", "ename@(ref1,null)SUB(POV(pname,>,val1)",
getCacheKey("FIND ename WHICH IS REFERENCED BY ref1 WITH pname > val1 ")); getCacheKey("FIND ename WHICH IS REFERENCED BY ref1 WITH pname > val1 "));
assertEquals("anonymous@anonymous@enamePOV(pname,=,val1)", getCacheKeyWithUser("FIND ename WITH pname = val1"));
} }
@Test @Test
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment