Search in sources :

Example 1 with RestTestHarness

use of org.apache.solr.util.RestTestHarness in project lucene-solr by apache.

the class TestCryptoKeys method test.

@Test
public void test() throws Exception {
    System.setProperty("enable.runtime.lib", "true");
    setupHarnesses();
    String pk1sig = "G8LEW7uJ1is81Aqqfl3Sld3qDtOxPuVFeTLJHFJWecgDvUkmJNFXmf7nkHOVlXnDWahp1vqZf0W02VHXg37lBw==";
    String pk2sig = "pCyBQycB/0YvLVZfKLDIIqG1tFwM/awqzkp2QNpO7R3ThTqmmrj11wEJFDRLkY79efuFuQPHt40EE7jrOKoj9jLNELsfEqvU3jw9sZKiDONY+rV9Bj9QPeW8Pgt+F9Y1";
    String wrongKeySig = "xTk2hTipfpb+J5s4x3YZGOXkmHWtnJz05Vvd8RTm/Q1fbQVszR7vMk6dQ1URxX08fcg4HvxOo8g9bG2TSMOGjg==";
    String result = null;
    CryptoKeys cryptoKeys = null;
    SolrZkClient zk = getCommonCloudSolrClient().getZkStateReader().getZkClient();
    cryptoKeys = new CryptoKeys(CloudUtil.getTrustedKeys(zk, "exe"));
    ByteBuffer samplefile = ByteBuffer.wrap(readFile("cryptokeys/samplefile.bin"));
    //there are no keys yet created in ZK
    result = cryptoKeys.verify(pk1sig, samplefile);
    assertNull(result);
    zk.makePath("/keys/exe", true);
    zk.create("/keys/exe/pubk1.der", readFile("cryptokeys/pubk1.der"), CreateMode.PERSISTENT, true);
    zk.create("/keys/exe/pubk2.der", readFile("cryptokeys/pubk2.der"), CreateMode.PERSISTENT, true);
    Map<String, byte[]> trustedKeys = CloudUtil.getTrustedKeys(zk, "exe");
    cryptoKeys = new CryptoKeys(trustedKeys);
    result = cryptoKeys.verify(pk2sig, samplefile);
    assertEquals("pubk2.der", result);
    result = cryptoKeys.verify(pk1sig, samplefile);
    assertEquals("pubk1.der", result);
    try {
        result = cryptoKeys.verify(wrongKeySig, samplefile);
        assertNull(result);
    } catch (Exception e) {
    //pass
    }
    try {
        result = cryptoKeys.verify("SGVsbG8gV29ybGQhCg==", samplefile);
        assertNull(result);
    } catch (Exception e) {
    //pass
    }
    HttpSolrClient randomClient = (HttpSolrClient) clients.get(random().nextInt(clients.size()));
    String baseURL = randomClient.getBaseURL();
    baseURL = baseURL.substring(0, baseURL.lastIndexOf('/'));
    TestBlobHandler.createSystemCollection(getHttpSolrClient(baseURL, randomClient.getHttpClient()));
    waitForRecoveriesToFinish(".system", true);
    ByteBuffer jar = TestDynamicLoading.getFileContent("runtimecode/runtimelibs.jar.bin");
    String blobName = "signedjar";
    TestBlobHandler.postAndCheck(cloudClient, baseURL, blobName, jar, 1);
    String payload = "{\n" + "'create-requesthandler' : { 'name' : '/runtime', 'class': 'org.apache.solr.core.RuntimeLibReqHandler' , 'runtimeLib':true }" + "}";
    RestTestHarness client = restTestHarnesses.get(random().nextInt(restTestHarnesses.size()));
    TestSolrConfigHandler.runConfigCommand(client, "/config?wt=json", payload);
    TestSolrConfigHandler.testForResponseElement(client, null, "/config/overlay?wt=json", null, Arrays.asList("overlay", "requestHandler", "/runtime", "class"), "org.apache.solr.core.RuntimeLibReqHandler", 10);
    payload = "{\n" + "'add-runtimelib' : { 'name' : 'signedjar' ,'version':1}\n" + "}";
    client = restTestHarnesses.get(random().nextInt(restTestHarnesses.size()));
    TestSolrConfigHandler.runConfigCommand(client, "/config?wt=json", payload);
    TestSolrConfigHandler.testForResponseElement(client, null, "/config/overlay?wt=json", null, Arrays.asList("overlay", "runtimeLib", blobName, "version"), 1l, 10);
    Map map = TestSolrConfigHandler.getRespMap("/runtime?wt=json", client);
    String s = (String) Utils.getObjectByPath(map, false, Arrays.asList("error", "msg"));
    assertNotNull(TestBlobHandler.getAsString(map), s);
    assertTrue(TestBlobHandler.getAsString(map), s.contains("should be signed with one of the keys in ZK /keys/exe"));
    String wrongSig = "QKqHtd37QN02iMW9UEgvAO9g9qOOuG5vEBNkbUsN7noc2hhXKic/ABFIOYJA9PKw61mNX2EmNFXOcO3WClYdSw==";
    payload = "{\n" + "'update-runtimelib' : { 'name' : 'signedjar' ,'version':1, 'sig': 'QKqHtd37QN02iMW9UEgvAO9g9qOOuG5vEBNkbUsN7noc2hhXKic/ABFIOYJA9PKw61mNX2EmNFXOcO3WClYdSw=='}\n" + "}";
    client = restTestHarnesses.get(random().nextInt(restTestHarnesses.size()));
    TestSolrConfigHandler.runConfigCommand(client, "/config?wt=json", payload);
    TestSolrConfigHandler.testForResponseElement(client, null, "/config/overlay?wt=json", null, Arrays.asList("overlay", "runtimeLib", blobName, "sig"), wrongSig, 10);
    map = TestSolrConfigHandler.getRespMap("/runtime?wt=json", client);
    s = (String) Utils.getObjectByPath(map, false, Arrays.asList("error", "msg"));
    //No key matched signature for jar
    assertNotNull(TestBlobHandler.getAsString(map), s);
    assertTrue(TestBlobHandler.getAsString(map), s.contains("No key matched signature for jar"));
    String rightSig = "YkTQgOtvcM/H/5EQdABGl3wjjrPhonAGlouIx59vppBy2cZEofX3qX1yZu5sPNRmJisNXEuhHN2149dxeUmk2Q==";
    payload = "{\n" + "'update-runtimelib' : { 'name' : 'signedjar' ,'version':1, 'sig': 'YkTQgOtvcM/H/5EQdABGl3wjjrPhonAGlouIx59vppBy2cZEofX3qX1yZu5sPNRmJisNXEuhHN2149dxeUmk2Q=='}\n" + "}";
    client = restTestHarnesses.get(random().nextInt(restTestHarnesses.size()));
    TestSolrConfigHandler.runConfigCommand(client, "/config?wt=json", payload);
    TestSolrConfigHandler.testForResponseElement(client, null, "/config/overlay?wt=json", null, Arrays.asList("overlay", "runtimeLib", blobName, "sig"), rightSig, 10);
    map = TestSolrConfigHandler.testForResponseElement(client, null, "/runtime?wt=json", null, Arrays.asList("class"), "org.apache.solr.core.RuntimeLibReqHandler", 10);
    compareValues(map, MemClassLoader.class.getName(), asList("loader"));
    rightSig = "VJPMTxDf8Km3IBj2B5HWkIOqeM/o+HHNobOYCNA3WjrEVfOMZbMMqS1Lo7uLUUp//RZwOGkOhrUhuPNY1z2CGEIKX2/m8VGH64L14d52oSvFiwhoTDDuuyjW1TFGu35D";
    payload = "{\n" + "'update-runtimelib' : { 'name' : 'signedjar' ,'version':1, 'sig': 'VJPMTxDf8Km3IBj2B5HWkIOqeM/o+HHNobOYCNA3WjrEVfOMZbMMqS1Lo7uLUUp//RZwOGkOhrUhuPNY1z2CGEIKX2/m8VGH64L14d52oSvFiwhoTDDuuyjW1TFGu35D'}\n" + "}";
    client = restTestHarnesses.get(random().nextInt(restTestHarnesses.size()));
    TestSolrConfigHandler.runConfigCommand(client, "/config?wt=json", payload);
    TestSolrConfigHandler.testForResponseElement(client, null, "/config/overlay?wt=json", null, Arrays.asList("overlay", "runtimeLib", blobName, "sig"), rightSig, 10);
    map = TestSolrConfigHandler.testForResponseElement(client, null, "/runtime?wt=json", null, Arrays.asList("class"), "org.apache.solr.core.RuntimeLibReqHandler", 10);
    compareValues(map, MemClassLoader.class.getName(), asList("loader"));
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) RestTestHarness(org.apache.solr.util.RestTestHarness) CryptoKeys(org.apache.solr.util.CryptoKeys) MemClassLoader(org.apache.solr.core.MemClassLoader) SolrZkClient(org.apache.solr.common.cloud.SolrZkClient) ByteBuffer(java.nio.ByteBuffer) Map(java.util.Map) IOException(java.io.IOException) Test(org.junit.Test)

Example 2 with RestTestHarness

use of org.apache.solr.util.RestTestHarness in project lucene-solr by apache.

the class TestCustomStream method testDynamicLoadingCustomStream.

@Test
public void testDynamicLoadingCustomStream() throws Exception {
    System.setProperty("enable.runtime.lib", "true");
    setupHarnesses();
    String blobName = "colltest";
    HttpSolrClient randomClient = (HttpSolrClient) clients.get(random().nextInt(clients.size()));
    String baseURL = randomClient.getBaseURL();
    baseURL = baseURL.substring(0, baseURL.lastIndexOf('/'));
    TestBlobHandler.createSystemCollection(getHttpSolrClient(baseURL, randomClient.getHttpClient()));
    waitForRecoveriesToFinish(".system", true);
    String payload = "{\n" + "'create-expressible' : { 'name' : 'hello', 'class': 'org.apache.solr.core.HelloStream' }\n" + "}";
    RestTestHarness client = restTestHarnesses.get(random().nextInt(restTestHarnesses.size()));
    TestSolrConfigHandler.runConfigCommand(client, "/config?wt=json", payload);
    TestSolrConfigHandler.testForResponseElement(client, null, "/config/overlay?wt=json", null, Arrays.asList("overlay", "expressible", "hello", "class"), "org.apache.solr.core.HelloStream", 10);
    TestSolrConfigHandler.testForResponseElement(client, null, "/stream?expr=hello()", null, Arrays.asList("result-set", "docs[0]", "msg"), "Hello World!", 10);
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) RestTestHarness(org.apache.solr.util.RestTestHarness) Test(org.junit.Test)

Example 3 with RestTestHarness

use of org.apache.solr.util.RestTestHarness in project lucene-solr by apache.

the class TestDynamicLoading method testDynamicLoading.

@Test
public void testDynamicLoading() throws Exception {
    System.setProperty("enable.runtime.lib", "true");
    setupHarnesses();
    String blobName = "colltest";
    boolean success = false;
    HttpSolrClient randomClient = (HttpSolrClient) clients.get(random().nextInt(clients.size()));
    String baseURL = randomClient.getBaseURL();
    baseURL = baseURL.substring(0, baseURL.lastIndexOf('/'));
    String payload = "{\n" + "'add-runtimelib' : { 'name' : 'colltest' ,'version':1}\n" + "}";
    RestTestHarness client = restTestHarnesses.get(random().nextInt(restTestHarnesses.size()));
    TestSolrConfigHandler.runConfigCommand(client, "/config?wt=json", payload);
    TestSolrConfigHandler.testForResponseElement(client, null, "/config/overlay?wt=json", null, Arrays.asList("overlay", "runtimeLib", blobName, "version"), 1l, 10);
    payload = "{\n" + "'create-requesthandler' : { 'name' : '/test1', 'class': 'org.apache.solr.core.BlobStoreTestRequestHandler' ,registerPath: '/solr,/v2',  'runtimeLib' : true }\n" + "}";
    client = restTestHarnesses.get(random().nextInt(restTestHarnesses.size()));
    TestSolrConfigHandler.runConfigCommand(client, "/config?wt=json", payload);
    TestSolrConfigHandler.testForResponseElement(client, null, "/config/overlay?wt=json", null, Arrays.asList("overlay", "requestHandler", "/test1", "class"), "org.apache.solr.core.BlobStoreTestRequestHandler", 10);
    Map map = TestSolrConfigHandler.getRespMap("/test1?wt=json", client);
    assertNotNull(TestBlobHandler.getAsString(map), map = (Map) map.get("error"));
    assertTrue(TestBlobHandler.getAsString(map), map.get("msg").toString().contains(".system collection not available"));
    TestBlobHandler.createSystemCollection(getHttpSolrClient(baseURL, randomClient.getHttpClient()));
    waitForRecoveriesToFinish(".system", true);
    map = TestSolrConfigHandler.getRespMap("/test1?wt=json", client);
    assertNotNull(map = (Map) map.get("error"));
    assertTrue("full output " + TestBlobHandler.getAsString(map), map.get("msg").toString().contains("no such blob or version available: colltest/1"));
    payload = " {\n" + "  'set' : {'watched': {" + "                    'x':'X val',\n" + "                    'y': 'Y val'}\n" + "             }\n" + "  }";
    TestSolrConfigHandler.runConfigCommand(client, "/config/params?wt=json", payload);
    TestSolrConfigHandler.testForResponseElement(client, null, "/config/params?wt=json", cloudClient, Arrays.asList("response", "params", "watched", "x"), "X val", 10);
    for (int i = 0; i < 100; i++) {
        map = TestSolrConfigHandler.getRespMap("/test1?wt=json", client);
        if ("X val".equals(map.get("x"))) {
            success = true;
            break;
        }
        Thread.sleep(100);
    }
    ByteBuffer jar = null;
    //     jar = persistZip("/tmp/runtimelibs.jar.bin", TestDynamicLoading.class, RuntimeLibReqHandler.class, RuntimeLibResponseWriter.class, RuntimeLibSearchComponent.class);
    //    if(true) return;
    jar = getFileContent("runtimecode/runtimelibs.jar.bin");
    TestBlobHandler.postAndCheck(cloudClient, baseURL, blobName, jar, 1);
    payload = "{\n" + "'create-requesthandler' : { 'name' : '/runtime', 'class': 'org.apache.solr.core.RuntimeLibReqHandler' , 'runtimeLib':true }," + "'create-searchcomponent' : { 'name' : 'get', 'class': 'org.apache.solr.core.RuntimeLibSearchComponent' , 'runtimeLib':true }," + "'create-queryResponseWriter' : { 'name' : 'json1', 'class': 'org.apache.solr.core.RuntimeLibResponseWriter' , 'runtimeLib':true }" + "}";
    client = restTestHarnesses.get(random().nextInt(restTestHarnesses.size()));
    TestSolrConfigHandler.runConfigCommand(client, "/config?wt=json", payload);
    Map result = TestSolrConfigHandler.testForResponseElement(client, null, "/config/overlay?wt=json", null, Arrays.asList("overlay", "requestHandler", "/runtime", "class"), "org.apache.solr.core.RuntimeLibReqHandler", 10);
    compareValues(result, "org.apache.solr.core.RuntimeLibResponseWriter", asList("overlay", "queryResponseWriter", "json1", "class"));
    compareValues(result, "org.apache.solr.core.RuntimeLibSearchComponent", asList("overlay", "searchComponent", "get", "class"));
    result = TestSolrConfigHandler.testForResponseElement(client, null, "/runtime?wt=json", null, Arrays.asList("class"), "org.apache.solr.core.RuntimeLibReqHandler", 10);
    compareValues(result, MemClassLoader.class.getName(), asList("loader"));
    result = TestSolrConfigHandler.testForResponseElement(client, null, "/runtime?wt=json1", null, Arrays.asList("wt"), "org.apache.solr.core.RuntimeLibResponseWriter", 10);
    compareValues(result, MemClassLoader.class.getName(), asList("loader"));
    result = TestSolrConfigHandler.testForResponseElement(client, null, "/get?abc=xyz", null, Arrays.asList("get"), "org.apache.solr.core.RuntimeLibSearchComponent", 10);
    compareValues(result, MemClassLoader.class.getName(), asList("loader"));
    jar = getFileContent("runtimecode/runtimelibs_v2.jar.bin");
    TestBlobHandler.postAndCheck(cloudClient, baseURL, blobName, jar, 2);
    payload = "{\n" + "'update-runtimelib' : { 'name' : 'colltest' ,'version':2}\n" + "}";
    client = restTestHarnesses.get(random().nextInt(restTestHarnesses.size()));
    TestSolrConfigHandler.runConfigCommand(client, "/config?wt=json", payload);
    TestSolrConfigHandler.testForResponseElement(client, null, "/config/overlay?wt=json", null, Arrays.asList("overlay", "runtimeLib", blobName, "version"), 2l, 10);
    result = TestSolrConfigHandler.testForResponseElement(client, null, "/get?abc=xyz", null, Arrays.asList("Version"), "2", 10);
    payload = " {\n" + "  'set' : {'watched': {" + "                    'x':'X val',\n" + "                    'y': 'Y val'}\n" + "             }\n" + "  }";
    TestSolrConfigHandler.runConfigCommand(client, "/config/params?wt=json", payload);
    TestSolrConfigHandler.testForResponseElement(client, null, "/config/params?wt=json", cloudClient, Arrays.asList("response", "params", "watched", "x"), "X val", 10);
    result = TestSolrConfigHandler.testForResponseElement(client, null, "/test1?wt=json", cloudClient, Arrays.asList("x"), "X val", 10);
    payload = " {\n" + "  'set' : {'watched': {" + "                    'x':'X val changed',\n" + "                    'y': 'Y val'}\n" + "             }\n" + "  }";
    TestSolrConfigHandler.runConfigCommand(client, "/config/params?wt=json", payload);
    result = TestSolrConfigHandler.testForResponseElement(client, null, "/test1?wt=json", cloudClient, Arrays.asList("x"), "X val changed", 10);
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) RestTestHarness(org.apache.solr.util.RestTestHarness) Map(java.util.Map) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 4 with RestTestHarness

use of org.apache.solr.util.RestTestHarness in project lucene-solr by apache.

the class TestSolrConfigHandlerCloud method testReqHandlerAPIs.

private void testReqHandlerAPIs() throws Exception {
    String testServerBaseUrl = getRandomServer(cloudClient, "collection1");
    RestTestHarness writeHarness = restTestHarnesses.get(random().nextInt(restTestHarnesses.size()));
    TestSolrConfigHandler.reqhandlertests(writeHarness, testServerBaseUrl, cloudClient);
}
Also used : RestTestHarness(org.apache.solr.util.RestTestHarness) TestBlobHandler.getAsString(org.apache.solr.handler.TestBlobHandler.getAsString)

Example 5 with RestTestHarness

use of org.apache.solr.util.RestTestHarness in project lucene-solr by apache.

the class TestSolrConfigHandler method testProperty.

public void testProperty() throws Exception {
    RestTestHarness harness = restTestHarness;
    Map confMap = getRespMap("/config?wt=json", harness);
    assertNotNull(getObjectByPath(confMap, false, Arrays.asList("config", "requestHandler", "/admin/luke")));
    assertNotNull(getObjectByPath(confMap, false, Arrays.asList("config", "requestHandler", "/admin/system")));
    assertNotNull(getObjectByPath(confMap, false, Arrays.asList("config", "requestHandler", "/admin/mbeans")));
    assertNotNull(getObjectByPath(confMap, false, Arrays.asList("config", "requestHandler", "/admin/plugins")));
    assertNotNull(getObjectByPath(confMap, false, Arrays.asList("config", "requestHandler", "/admin/threads")));
    assertNotNull(getObjectByPath(confMap, false, Arrays.asList("config", "requestHandler", "/admin/properties")));
    assertNotNull(getObjectByPath(confMap, false, Arrays.asList("config", "requestHandler", "/admin/logging")));
    assertNotNull(getObjectByPath(confMap, false, Arrays.asList("config", "requestHandler", "/admin/file")));
    assertNotNull(getObjectByPath(confMap, false, Arrays.asList("config", "requestHandler", "/admin/ping")));
    String payload = "{\n" + " 'set-property' : { 'updateHandler.autoCommit.maxDocs':100, 'updateHandler.autoCommit.maxTime':10 , 'requestDispatcher.requestParsers.addHttpRequestToContext':true} \n" + " }";
    runConfigCommand(harness, "/config?wt=json", payload);
    Map m = (Map) getRespMap("/config/overlay?wt=json", harness).get("overlay");
    Map props = (Map) m.get("props");
    assertNotNull(props);
    assertEquals("100", String.valueOf(getObjectByPath(props, true, ImmutableList.of("updateHandler", "autoCommit", "maxDocs"))));
    assertEquals("10", String.valueOf(getObjectByPath(props, true, ImmutableList.of("updateHandler", "autoCommit", "maxTime"))));
    m = getRespMap("/config/updateHandler?wt=json", harness);
    assertNotNull(getObjectByPath(m, true, ImmutableList.of("config", "updateHandler", "commitWithin", "softCommit")));
    assertNotNull(getObjectByPath(m, true, ImmutableList.of("config", "updateHandler", "autoCommit", "maxDocs")));
    assertNotNull(getObjectByPath(m, true, ImmutableList.of("config", "updateHandler", "autoCommit", "maxTime")));
    m = (Map) getRespMap("/config?wt=json", harness).get("config");
    assertNotNull(m);
    assertEquals("100", String.valueOf(getObjectByPath(m, true, ImmutableList.of("updateHandler", "autoCommit", "maxDocs"))));
    assertEquals("10", String.valueOf(getObjectByPath(m, true, ImmutableList.of("updateHandler", "autoCommit", "maxTime"))));
    assertEquals("true", String.valueOf(getObjectByPath(m, true, ImmutableList.of("requestDispatcher", "requestParsers", "addHttpRequestToContext"))));
    payload = "{\n" + " 'unset-property' :  'updateHandler.autoCommit.maxDocs'} \n" + " }";
    runConfigCommand(harness, "/config?wt=json", payload);
    m = (Map) getRespMap("/config/overlay?wt=json", harness).get("overlay");
    props = (Map) m.get("props");
    assertNotNull(props);
    assertNull(getObjectByPath(props, true, ImmutableList.of("updateHandler", "autoCommit", "maxDocs")));
    assertEquals("10", String.valueOf(getObjectByPath(props, true, ImmutableList.of("updateHandler", "autoCommit", "maxTime"))));
}
Also used : RestTestHarness(org.apache.solr.util.RestTestHarness) TestBlobHandler.getAsString(org.apache.solr.handler.TestBlobHandler.getAsString) HashMap(java.util.HashMap) Map(java.util.Map) ValidatingJsonMap(org.apache.solr.common.util.ValidatingJsonMap) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap)

Aggregations

RestTestHarness (org.apache.solr.util.RestTestHarness)40 Map (java.util.Map)19 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)15 StringReader (java.io.StringReader)12 JSONParser (org.noggit.JSONParser)12 SolrClient (org.apache.solr.client.solrj.SolrClient)11 ArrayList (java.util.ArrayList)9 HashSet (java.util.HashSet)6 List (java.util.List)6 TestBlobHandler.getAsString (org.apache.solr.handler.TestBlobHandler.getAsString)6 Test (org.junit.Test)6 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)5 Replica (org.apache.solr.common.cloud.Replica)4 Slice (org.apache.solr.common.cloud.Slice)4 HashMap (java.util.HashMap)3 SortedMap (java.util.SortedMap)3 TreeMap (java.util.TreeMap)3 DocCollection (org.apache.solr.common.cloud.DocCollection)3 ValidatingJsonMap (org.apache.solr.common.util.ValidatingJsonMap)3 ByteBuffer (java.nio.ByteBuffer)2