Fixed unknown authentication scheme, missing VC entity & parameter
checker
Change-Id: I2f0eb38e3dbe8105ccc42f7d386587a9be5504a1
diff --git a/full/Changes b/full/Changes
index 7703da9..7620c38 100644
--- a/full/Changes
+++ b/full/Changes
@@ -4,7 +4,9 @@
- Updated VC access controllers (margaretha)
19/03/2019
- Added close index controller (margaretha)
-
+11/04/2019
+ - Fixed unknown authentication scheme, missing VC entity, and parameter
+ checker (margaretha)
# version 0.61.6
04/02/2019
diff --git a/full/src/main/java/de/ids_mannheim/korap/service/VirtualCorpusService.java b/full/src/main/java/de/ids_mannheim/korap/service/VirtualCorpusService.java
index 556c2e4..c0ba90b 100644
--- a/full/src/main/java/de/ids_mannheim/korap/service/VirtualCorpusService.java
+++ b/full/src/main/java/de/ids_mannheim/korap/service/VirtualCorpusService.java
@@ -234,6 +234,7 @@
verifyUsername(username, vcCreator);
VirtualCorpus vc = vcDao.retrieveVCByName(vcName, vcCreator);
+ ParameterChecker.checkObjectValue(vcJson, "request entity");
if (vc == null) {
storeVC(vcJson, vcName, username);
}
@@ -305,7 +306,6 @@
public int storeVC (VirtualCorpusJson vc, String name, String createdBy)
throws KustvaktException {
-
ParameterChecker.checkStringValue(vc.getCorpusQuery(), "corpusQuery");
String koralQuery = serializeCorpusQuery(vc.getCorpusQuery());
diff --git a/full/src/test/java/de/ids_mannheim/korap/authentication/AuthenticationFilterTest.java b/full/src/test/java/de/ids_mannheim/korap/authentication/AuthenticationFilterTest.java
new file mode 100644
index 0000000..37db9b4
--- /dev/null
+++ b/full/src/test/java/de/ids_mannheim/korap/authentication/AuthenticationFilterTest.java
@@ -0,0 +1,33 @@
+package de.ids_mannheim.korap.authentication;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.sun.jersey.api.client.ClientResponse;
+
+import de.ids_mannheim.korap.config.Attributes;
+import de.ids_mannheim.korap.config.SpringJerseyTest;
+import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.utils.JsonUtils;
+
+public class AuthenticationFilterTest extends SpringJerseyTest {
+
+ @Test
+ public void testAuthenticationWithUnknownScheme ()
+ throws KustvaktException {
+ ClientResponse response = resource().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=die]").queryParam("ql", "poliqarp")
+ .header(Attributes.AUTHORIZATION, "Blah blah")
+ .get(ClientResponse.class);
+
+ String entity = response.getEntity(String.class);
+ JsonNode n = JsonUtils.readTree(entity);
+
+ assertEquals("2001", n.at("/errors/0/0").asText());
+ assertEquals("Authentication scheme is not supported.",
+ n.at("/errors/0/1").asText());
+ assertEquals("Blah", n.at("/errors/0/2").asText());
+ }
+}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/UserGroupControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/UserGroupControllerTest.java
index 60ffcf8..a0876ee 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/UserGroupControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/UserGroupControllerTest.java
@@ -687,8 +687,8 @@
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
assertEquals(StatusCodes.MISSING_PARAMETER,
node.at("/errors/0/0").asInt());
- assertEquals("groupId", node.at("/errors/0/1").asText());
- assertEquals("0", node.at("/errors/0/2").asText());
+ assertEquals("groupId is missing", node.at("/errors/0/1").asText());
+ assertEquals("groupId", node.at("/errors/0/2").asText());
}
@Test
@@ -871,8 +871,8 @@
assertEquals(StatusCodes.MISSING_PARAMETER,
node.at("/errors/0/0").asInt());
- assertEquals("groupId", node.at("/errors/0/1").asText());
- assertEquals("0", node.at("/errors/0/2").asText());
+ assertEquals("groupId is missing", node.at("/errors/0/1").asText());
+ assertEquals("groupId", node.at("/errors/0/2").asText());
}
@Test
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerTest.java
index 0cce338..ce5535a 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerTest.java
@@ -528,8 +528,28 @@
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.INVALID_ARGUMENT,
node.at("/errors/0/0").asInt());
- assertEquals("corpusQuery", node.at("/errors/0/1").asText());
- assertEquals("null", node.at("/errors/0/2").asText());
+ assertEquals("corpusQuery is null", node.at("/errors/0/1").asText());
+ assertEquals("corpusQuery", node.at("/errors/0/2").asText());
+ }
+
+ @Test
+ public void testCreateVCWithoutEntity() throws KustvaktException {
+ ClientResponse response = resource().path(API_VERSION).path("vc")
+ .path("VirtualCorpusControllerTest").path("new vc")
+ .header(Attributes.AUTHORIZATION,
+ HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(
+ "VirtualCorpusControllerTest", "pass"))
+ .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
+ .put(ClientResponse.class);
+ String entity = response.getEntity(String.class);
+ assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
+
+ JsonNode node = JsonUtils.readTree(entity);
+ assertEquals(StatusCodes.INVALID_ARGUMENT,
+ node.at("/errors/0/0").asInt());
+ assertEquals("request entity is null", node.at("/errors/0/1").asText());
+ assertEquals("request entity", node.at("/errors/0/2").asText());
}
@Test
@@ -552,8 +572,8 @@
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.INVALID_ARGUMENT,
node.at("/errors/0/0").asInt());
- assertEquals("type", node.at("/errors/0/1").asText());
- assertEquals("null", node.at("/errors/0/2").asText());
+ assertEquals("type is null", node.at("/errors/0/1").asText());
+ assertEquals("type", node.at("/errors/0/2").asText());
}
@Test