Fixed availability regex for all access in the config.
This is an important change to correctly determine required access of
stored VC.
Change-Id: Id820a281dff6a036a4180376fb6362cddb2c1cab
diff --git a/src/test/java/de/ids_mannheim/korap/web/controller/AvailabilityTest.java b/src/test/java/de/ids_mannheim/korap/web/controller/AvailabilityTest.java
index 4cc98b0..8cf0b2b 100644
--- a/src/test/java/de/ids_mannheim/korap/web/controller/AvailabilityTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/controller/AvailabilityTest.java
@@ -5,6 +5,8 @@
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.net.HttpHeaders;
import jakarta.ws.rs.ProcessingException;
@@ -13,11 +15,15 @@
import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
import de.ids_mannheim.korap.config.Attributes;
+import de.ids_mannheim.korap.config.FullConfiguration;
import de.ids_mannheim.korap.config.SpringJerseyTest;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.utils.JsonUtils;
public class AvailabilityTest extends SpringJerseyTest {
+
+ @Autowired
+ public FullConfiguration config;
private void checkAndFree (String json) throws KustvaktException {
JsonNode node = JsonUtils.readTree(json);
@@ -100,37 +106,34 @@
private void checkAndAllWithACA (String json) throws KustvaktException {
JsonNode node = JsonUtils.readTree(json);
- assertNotNull(node);
- assertEquals(node.at("/collection/operation").asText(),
- "operation:and");
- assertEquals(node.at("/collection/rewrites/0/operation").asText(),
- "operation:injection");
- assertEquals(node.at("/collection/rewrites/0/scope").asText(),
- "availability(ALL)");
- assertEquals(node.at("/collection/operands/1/match").asText(),
- "match:eq");
- assertEquals(node.at("/collection/operands/1/type").asText(),
- "type:regex");
- assertEquals(node.at("/collection/operands/1/key").asText(),
- "availability");
- assertEquals(node.at("/collection/operands/1/value").asText(), "ACA.*");
+ System.out.println(node.toPrettyString());
+ assertEquals("operation:and",
+ node.at("/collection/operation").asText());
+ assertEquals("operation:injection",
+ node.at("/collection/rewrites/0/operation").asText());
+ assertEquals("availability(ALL)",
+ node.at("/collection/rewrites/0/scope").asText());
+ assertEquals("match:eq",
+ node.at("/collection/operands/1/match").asText());
+ assertEquals("type:regex",
+ node.at("/collection/operands/1/type").asText());
+ assertEquals("availability",
+ node.at("/collection/operands/1/key").asText());
+ assertEquals("ACA.*", node.at("/collection/operands/1/value").asText());
node = node.at("/collection/operands/0");
- assertEquals(node.at("/operands/0/match").asText(), "match:eq");
- assertEquals(node.at("/operands/0/type").asText(), "type:regex");
- assertEquals(node.at("/operands/0/key").asText(), "availability");
- assertEquals(node.at("/operands/0/value").asText(), "CC.*");
- assertEquals(
- node.at("/operands/1/operands/1/operands/0/match").asText(),
- "match:eq");
- assertEquals(
- node.at("/operands/1/operands/1/operands/0/value").asText(),
- "QAO-NC");
- assertEquals(
- node.at("/operands/1/operands/1/operands/1/match").asText(),
- "match:eq");
- assertEquals(
- node.at("/operands/1/operands/1/operands/1/value").asText(),
- "QAO.*");
+ assertEquals("match:eq", node.at("/operands/0/match").asText());
+ assertEquals("type:regex", node.at("/operands/0/type").asText());
+ assertEquals("availability", node.at("/operands/0/key").asText());
+ assertEquals(config.getFreeOnlyRegex(),
+ node.at("/operands/0/value").asText());
+ assertEquals("match:eq",
+ node.at("/operands/1/operands/1/operands/0/match").asText());
+ assertEquals("QAO-NC",
+ node.at("/operands/1/operands/1/operands/0/value").asText());
+ assertEquals("match:eq",
+ node.at("/operands/1/operands/1/operands/1/match").asText());
+ assertEquals(config.getAllOnlyRegex(),
+ node.at("/operands/1/operands/1/operands/1/value").asText());
}
private Response searchQuery (String collectionQuery) {
diff --git a/src/test/java/de/ids_mannheim/korap/web/controller/SearchControllerTest.java b/src/test/java/de/ids_mannheim/korap/web/controller/SearchControllerTest.java
index 132f6b0..796dc14 100644
--- a/src/test/java/de/ids_mannheim/korap/web/controller/SearchControllerTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/controller/SearchControllerTest.java
@@ -19,6 +19,7 @@
import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
import de.ids_mannheim.korap.config.Attributes;
+import de.ids_mannheim.korap.config.FullConfiguration;
import de.ids_mannheim.korap.config.SpringJerseyTest;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.exceptions.StatusCodes;
@@ -33,7 +34,7 @@
public class SearchControllerTest extends SpringJerseyTest {
@Autowired
- private KustvaktConfiguration config;
+ private FullConfiguration config;
private JsonNode requestSearchWithFields (String fields)
throws KustvaktException {
@@ -252,13 +253,14 @@
assertNotNull(node);
assertNotEquals(0, node.path("matches").size());
assertEquals("koral:docGroup", node.at("/collection/@type").asText());
- assertEquals("CC.*", node.at("/collection/operands/0/value").asText());
+ assertEquals(config.getFreeOnlyRegex(),
+ node.at("/collection/operands/0/value").asText());
assertEquals("ACA.*",
node.at("/collection/operands/1/operands/0/value").asText());
assertEquals("QAO-NC",
node.at("/collection/operands/1/operands/1/operands/0/value")
.asText());
- assertEquals("QAO.*",
+ assertEquals(config.getAllOnlyRegex(),
node.at("/collection/operands/1/operands/1/operands/1/value")
.asText());
assertEquals("operation:or", node.at("/collection/operation").asText());
diff --git a/src/test/java/de/ids_mannheim/korap/web/controller/vc/VirtualCorpusControllerTest.java b/src/test/java/de/ids_mannheim/korap/web/controller/vc/VirtualCorpusControllerTest.java
index b4c44d8..fad276a 100644
--- a/src/test/java/de/ids_mannheim/korap/web/controller/vc/VirtualCorpusControllerTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/controller/vc/VirtualCorpusControllerTest.java
@@ -322,6 +322,53 @@
}
@Test
+ public void testDetermineCorpusAccess () throws KustvaktException {
+ String vcName = "vc-all";
+ createPrivateVC(testUser, vcName);
+ JsonNode node = listVC(testUser);
+ assertEquals(2, node.size());
+
+ node = node.get(1);
+ assertEquals(vcName, node.get("name").asText());
+ assertEquals("ALL", node.get("requiredAccess").asText());
+ deleteVC(vcName, testUser, testUser);
+
+
+ vcName = "vc-pub-1";
+ String vcJson = "{\"type\": \"PRIVATE\""
+ + ",\"queryType\": \"VIRTUAL_CORPUS\""
+ + ",\"corpusQuery\": \"availability=/ACA.*/\"}";
+
+ createVC(authHeader, testUser, vcName, vcJson);
+ node = listVC(testUser).get(1);
+ assertEquals(vcName, node.get("name").asText());
+ assertEquals("PUB", node.get("requiredAccess").asText());
+ deleteVC(vcName, testUser, testUser);
+
+ vcName = "vc-pub-2";
+ vcJson = "{\"type\": \"PRIVATE\""
+ + ",\"queryType\": \"VIRTUAL_CORPUS\""
+ + ",\"corpusQuery\": \"availability=QAO-NC\"}";
+
+ createVC(authHeader, testUser, vcName, vcJson);
+ node = listVC(testUser).get(1);
+ assertEquals(vcName, node.get("name").asText());
+ assertEquals("PUB", node.get("requiredAccess").asText());
+ deleteVC(vcName, testUser, testUser);
+
+ vcName = "vc-free";
+ vcJson = "{\"type\": \"PRIVATE\""
+ + ",\"queryType\": \"VIRTUAL_CORPUS\""
+ + ",\"corpusQuery\": \"availability=/CC.*/\"}";
+
+ createVC(authHeader, testUser, vcName, vcJson);
+ node = listVC(testUser).get(1);
+ assertEquals(vcName, node.get("name").asText());
+ assertEquals("FREE", node.get("requiredAccess").asText());
+ deleteVC(vcName, testUser, testUser);
+ }
+
+ @Test
public void testMaxNumberOfVC () throws KustvaktException {
String json = "{\"type\": \"PRIVATE\""
+ ",\"queryType\": \"VIRTUAL_CORPUS\""
diff --git a/src/test/resources/kustvakt-test.conf b/src/test/resources/kustvakt-test.conf
index ddc8512..d40c39f 100644
--- a/src/test/resources/kustvakt-test.conf
+++ b/src/test/resources/kustvakt-test.conf
@@ -56,7 +56,9 @@
#
availability.regex.free = CC.*
availability.regex.public = ACA.*|QAO-NC
-availability.regex.all = QAO.*
+# The regex should be specific and make the access distinguishable
+# availability.regex.all = QAO.*
+availability.regex.all = QAO-NC-LOC:ids.*
# options referring to the security module!