Added warnings when requesting non-public fields via the search API with
accessRewriteDisabled (resolved #43).

Change-Id: I917415f242c1adf884bacb832fd7644cddaa6973
diff --git a/full/Changes b/full/Changes
index c8eeab2..6a8b188 100644
--- a/full/Changes
+++ b/full/Changes
@@ -11,6 +11,8 @@
      services (margaretha)
    - Added prefixes to username and groupname parameters in service paths 
      (margaretha, resolved #35)  
+13/11/2019
+   - Added tests for issue #43 (margaretha)
      
 
 # version 0.62.1
diff --git a/full/pom.xml b/full/pom.xml
index 011c48a..564d3be 100644
--- a/full/pom.xml
+++ b/full/pom.xml
@@ -205,7 +205,7 @@
 		<dependency>
 			<groupId>de.ids_mannheim.korap</groupId>
 			<artifactId>Kustvakt-core</artifactId>
-			<version>[0.62.1,)</version>
+			<version>[0.62.2,)</version>
 		</dependency>
 		<!-- LDAP -->
 		<dependency>
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/PublicMetadataTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/PublicMetadataTest.java
index 5412949..6975d54 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/PublicMetadataTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/PublicMetadataTest.java
@@ -53,6 +53,48 @@
 
         assertTrue(node.at("/matches/0/snippet").isMissingNode());
     }
+    
+    @Test
+    public void testSearchPublicMetadataWithCustomFields () throws KustvaktException {
+        ClientResponse response = resource().path(API_VERSION).path("search")
+                .queryParam("q", "Sonne").queryParam("ql", "poliqarp")
+                .queryParam("fields", "author,title")
+                .queryParam("access-rewrite-disabled", "true")
+                .get(ClientResponse.class);
+        assertEquals(ClientResponse.Status.OK.getStatusCode(),
+                response.getStatus());
+        String entity = response.getEntity(String.class);
+        JsonNode node = JsonUtils.readTree(entity);
+        assertEquals("availability(ALL)",
+                node.at("/collection/rewrites/0/scope").asText());
+
+        assertTrue(node.at("/matches/0/snippet").isMissingNode());
+        assertEquals("Goethe, Johann Wolfgang von",
+                node.at("/matches/0/author").asText());
+        assertEquals("Italienische Reise",
+                node.at("/matches/0/title").asText());
+        assertEquals(3, node.at("/matches/0").size());
+    }
+    
+    @Test
+    public void testSearchPublicMetadataWithNonPublicField () throws KustvaktException {
+        ClientResponse response = resource().path(API_VERSION).path("search")
+                .queryParam("q", "Sonne").queryParam("ql", "poliqarp")
+                .queryParam("fields", "author,title,snippet")
+                .queryParam("access-rewrite-disabled", "true")
+                .get(ClientResponse.class);
+        assertEquals(ClientResponse.Status.OK.getStatusCode(),
+                response.getStatus());
+        String entity = response.getEntity(String.class);
+        JsonNode node = JsonUtils.readTree(entity);
+
+        assertEquals(StatusCodes.NON_PUBLIC_FIELD_IGNORED,
+                node.at("/warnings/0/0").asInt());
+        assertEquals("The requested non public fields are ignored",
+                node.at("/warnings/0/1").asText());
+        assertEquals("snippet",
+                node.at("/warnings/0/2").asText());
+    }
 
 //  EM: The API is disabled
     @Ignore