()
| 579 | } |
| 580 | |
| 581 | @Test |
| 582 | @SuppressWarnings("unchecked") |
| 583 | public void testAPI() throws Exception { |
| 584 | String errPath = "/details[0]/errorMessages[0]"; |
| 585 | String FILE1 = "/mypkg/v.0.12/jar_a.jar"; |
| 586 | String FILE2 = "/mypkg/v.0.12/jar_b.jar"; |
| 587 | String FILE3 = "/mypkg/v.0.13/jar_a.jar"; |
| 588 | |
| 589 | PackagePayload.AddVersion add = new PackagePayload.AddVersion(); |
| 590 | add.version = "0.12"; |
| 591 | add.pkg = "test_pkg"; |
| 592 | add.files = List.of(FILE1, FILE2); |
| 593 | V2Request req = |
| 594 | new V2Request.Builder("/cluster/package") |
| 595 | .forceV2(true) |
| 596 | .withMethod(SolrRequest.METHOD.POST) |
| 597 | .withPayload(Map.of("add", add)) |
| 598 | .build(); |
| 599 | |
| 600 | // the files are not yet there. The command should fail with error saying "No such file" |
| 601 | expectError(req, cluster.getSolrClient(), errPath, "No such file:"); |
| 602 | |
| 603 | // post the jar file. No signature is sent |
| 604 | postFileAndWait(cluster, "runtimecode/runtimelibs.jar.bin", FILE1, null); |
| 605 | |
| 606 | add.files = List.of(FILE1); |
| 607 | expectError(req, cluster.getSolrClient(), errPath, FILE1 + " has no signature"); |
| 608 | // now we upload the keys |
| 609 | byte[] derFile = readFile("cryptokeys/pub_key512.der"); |
| 610 | uploadKey(derFile, ClusterFileStore.KEYS_DIR + "/pub_key512.der", cluster); |
| 611 | // and upload the same file with a different name, but it has proper signature |
| 612 | postFileAndWait( |
| 613 | cluster, |
| 614 | "runtimecode/runtimelibs.jar.bin", |
| 615 | FILE2, |
| 616 | "L3q/qIGs4NaF6JiO0ZkMUFa88j0OmYc+I6O7BOdNuMct/xoZ4h73aZHZGc0+nmI1f/U3bOlMPINlSOM6LK3JpQ=="); |
| 617 | // with correct signature |
| 618 | // after uploading the file, let's delete the keys to see if we get proper error message |
| 619 | add.files = List.of(FILE2); |
| 620 | /*expectError(req, cluster.getSolrClient(), errPath, |
| 621 | "ZooKeeper does not have any public keys");*/ |
| 622 | |
| 623 | // Now lets' put the keys back |
| 624 | |
| 625 | // this time we have a file with proper signature, public keys are in ZK |
| 626 | // so the add {} command should succeed |
| 627 | req.process(cluster.getSolrClient()); |
| 628 | |
| 629 | // Now verify the data in ZK |
| 630 | TestDistribFileStore.assertResponseValues( |
| 631 | 1, |
| 632 | () -> |
| 633 | NavigableObject.wrap( |
| 634 | Utils.fromJSON(cluster.getZkClient().getData(SOLR_PKGS_PATH, null, new Stat()))), |
| 635 | Map.of(":packages:test_pkg[0]:version", "0.12", ":packages:test_pkg[0]:files[0]", FILE2)); |
| 636 | |
| 637 | // post a new jar with a proper signature |
| 638 | postFileAndWait( |
nothing calls this directly
no test coverage detected