cpoerschke commented on code in PR #951:
URL: https://github.com/apache/solr/pull/951#discussion_r933286618


##########
solr/core/src/test/org/apache/solr/security/TestAuthorizationFramework.java:
##########
@@ -52,53 +55,45 @@ public void distribSetUp() throws Exception {
       zkStateReader
           .getZkClient()
           .create(
-              ZkStateReader.SOLR_SECURITY_CONF_PATH,
-              
"{\"authorization\":{\"class\":\"org.apache.solr.security.MockAuthorizationPlugin\"}}"
-                  .getBytes(StandardCharsets.UTF_8),
-              CreateMode.PERSISTENT,
-              true);
+              ZkStateReader.SOLR_SECURITY_CONF_PATH, SECURITY_JSON, 
CreateMode.PERSISTENT, true);
     }
   }
 
   @Test
   public void authorizationFrameworkTest() throws Exception {
     MockAuthorizationPlugin.denyUsers.add("user1");
-    MockAuthorizationPlugin.denyUsers.add("user1");
 
-    try {
-      waitForThingsToLevelOut(10, TimeUnit.SECONDS);
-      String baseUrl = jettys.get(0).getBaseUrl().toString();
-      verifySecurityStatus(
-          ((CloudLegacySolrClient) cloudClient).getHttpClient(),
-          baseUrl + "/admin/authorization",
-          "authorization/class",
-          MockAuthorizationPlugin.class.getName(),
-          20);
-      log.info("Starting test");
-      ModifiableSolrParams params = new ModifiableSolrParams();
-      params.add("q", "*:*");
-      // This should work fine.
-      cloudClient.query(params);
-      MockAuthorizationPlugin.protectedResources.add("/select");
+    waitForThingsToLevelOut(10, TimeUnit.SECONDS);
+    String baseUrl = jettys.get(0).getBaseUrl().toString();
+    verifySecurityStatus(
+        ((CloudLegacySolrClient) cloudClient).getHttpClient(),
+        baseUrl + "/admin/authorization",
+        "authorization/class",
+        s -> MockAuthorizationPlugin.class.getName().equals(s),
+        20);
+    log.info("Starting test");

Review Comment:
   removing logging here too or add back the "Ending test" logging
   ```suggestion
   ```



##########
solr/core/src/test/org/apache/solr/rest/TestManagedFileStorage.java:
##########
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.rest;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.common.util.NamedList;
+import org.apache.solr.core.SolrResourceLoader;
+import org.apache.solr.rest.ManagedResourceStorage.FileStorageIO;
+import org.apache.solr.rest.ManagedResourceStorage.JsonStorage;
+import org.apache.solr.rest.ManagedResourceStorage.StorageIO;
+import org.junit.Test;
+
+public class TestManagedFileStorage extends SolrTestCaseJ4 {
+
+  /** Runs persisted managed resource creation and update tests on JSON 
storage. */
+  @Test
+  public void testFileBasedJsonStorage() throws Exception {
+    File instanceDir = createTempDir("json-storage").toFile();
+    try (SolrResourceLoader loader = new 
SolrResourceLoader(instanceDir.toPath())) {
+      NamedList<String> initArgs = new NamedList<>();
+      String managedDir = instanceDir.getAbsolutePath() + File.separator + 
"managed";
+      initArgs.add(ManagedResourceStorage.STORAGE_DIR_INIT_ARG, managedDir);
+      FileStorageIO fileStorageIO = new FileStorageIO();
+      fileStorageIO.configure(loader, initArgs);
+      TestManagedFileStorage.doStorageTests(loader, fileStorageIO);
+    }
+  }
+
+  /**
+   * Called from tests for each storage type to run creation and update tests 
on a persisted managed
+   * resource.
+   */
+  @SuppressWarnings("unchecked")
+  public static void doStorageTests(SolrResourceLoader loader, StorageIO 
storageIO)
+      throws Exception {
+    String resourceId = "/test/foo";
+
+    JsonStorage jsonStorage = new JsonStorage(storageIO, loader);
+
+    Map<String, String> managedInitArgs = new HashMap<>();
+    managedInitArgs.put("ignoreCase", "true");
+    managedInitArgs.put("dontIgnoreCase", "false");
+
+    List<String> managedList = new ArrayList<>(); // we need a mutable List 
for this test
+    managedList.addAll(Arrays.asList("a", "b", "c", "d", "e"));
+
+    Map<String, Object> toStore = new HashMap<>();
+    toStore.put(ManagedResource.INIT_ARGS_JSON_FIELD, managedInitArgs);
+    toStore.put(ManagedResource.MANAGED_JSON_LIST_FIELD, managedList);
+
+    jsonStorage.store(resourceId, toStore);
+
+    String storedResourceId = jsonStorage.getStoredResourceId(resourceId);
+    assertTrue(storedResourceId + " file not found!", 
storageIO.exists(storedResourceId));
+
+    Object fromStorage = jsonStorage.load(resourceId);
+    assertNotNull(fromStorage);
+
+    Map<String, Object> storedMap = (Map<String, Object>) fromStorage;
+    Map<String, Object> storedArgs =
+        (Map<String, Object>) 
storedMap.get(ManagedResource.INIT_ARGS_JSON_FIELD);
+    assertNotNull(storedArgs);
+    assertEquals("true", storedArgs.get("ignoreCase"));
+    List<String> storedList = (List<String>) 
storedMap.get(ManagedResource.MANAGED_JSON_LIST_FIELD);
+    assertNotNull(storedList);
+    assertEquals(managedList.size(), storedList.size());
+    assertTrue(storedList.contains("a"));
+
+    // now verify you can update existing data
+    managedInitArgs.put("anotherArg", "someValue");
+    managedList.add("f");
+    jsonStorage.store(resourceId, toStore);
+    fromStorage = jsonStorage.load(resourceId);
+    assertNotNull(fromStorage);
+
+    storedMap = (Map<String, Object>) fromStorage;
+    storedArgs = (Map<String, Object>) 
storedMap.get(ManagedResource.INIT_ARGS_JSON_FIELD);
+    assertNotNull(storedArgs);
+    assertEquals("someValue", storedArgs.get("anotherArg"));
+    storedList = (List<String>) 
storedMap.get(ManagedResource.MANAGED_JSON_LIST_FIELD);
+    assertNotNull(storedList);
+    assertEquals(managedList.size(), storedList.size());
+    assertTrue(storedList.contains("e"));

Review Comment:
   minor/carry-over from existing code: `f` instead of `e` here since the 
latter was already previously there and only the former is newly added?
   ```suggestion
       assertTrue(storedList.contains("f"));
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to