public void testIsAuthorizedForMirroring() throws Exception {
    MockMartusServer nobodyAuthorizedCore = new MockMartusServer(this);
    ServerForMirroring nobodyAuthorized = new ServerForMirroring(nobodyAuthorizedCore, logger);
    nobodyAuthorized.loadConfigurationFiles();
    assertFalse(
        "client already authorized?",
        nobodyAuthorized.isAuthorizedForMirroring(clientSecurity1.getPublicKeyString()));
    nobodyAuthorizedCore.deleteAllFiles();

    MockMartusServer twoAuthorizedCore = new MockMartusServer(this);
    twoAuthorizedCore.enterSecureMode();
    File mirrorsWhoCallUs =
        new File(twoAuthorizedCore.getStartupConfigDirectory(), "mirrorsWhoCallUs");
    mirrorsWhoCallUs.mkdirs();
    File pubKeyFile1 = new File(mirrorsWhoCallUs, "code=1.2.3.4.5-ip=1.2.3.4.txt");
    MartusUtilities.exportServerPublicKey(clientSecurity1, pubKeyFile1);
    File pubKeyFile2 = new File(mirrorsWhoCallUs, "code=2.3.4.5.6-ip=2.3.4.5.txt");
    MartusUtilities.exportServerPublicKey(clientSecurity2, pubKeyFile2);
    ServerForMirroring twoAuthorized = new ServerForMirroring(twoAuthorizedCore, logger);
    twoAuthorized.loadConfigurationFiles();
    assertTrue(
        "client1 not authorized?",
        twoAuthorized.isAuthorizedForMirroring(clientSecurity1.getPublicKeyString()));
    assertTrue(
        "client2 not authorized?",
        twoAuthorized.isAuthorizedForMirroring(clientSecurity2.getPublicKeyString()));
    assertFalse(
        "ourselves authorized?", twoAuthorized.isAuthorizedForMirroring(coreServer.getAccountId()));
    mirrorsWhoCallUs.delete();
    twoAuthorizedCore.deleteAllFiles();
  }
  public void testListAvailableIds() throws Exception {
    String authorAccountId = authorSecurity.getPublicKeyString();

    BulletinHeaderPacket bhp1 = new BulletinHeaderPacket(authorSecurity);
    bhp1.setStatus(BulletinConstants.STATUSSEALED);
    Vector result1 = writeSampleAvailableIDPacket(bhp1);

    BulletinHeaderPacket bhp2 = new BulletinHeaderPacket(authorSecurity);
    bhp2.setStatus(BulletinConstants.STATUSSEALED);
    Vector result2 = writeSampleAvailableIDPacket(bhp2);

    BulletinHeaderPacket bhpDraft = new BulletinHeaderPacket(authorSecurity);
    bhpDraft.setStatus(BulletinConstants.STATUSDRAFT);
    Vector resultDraft = writeSampleAvailableIDPacket(bhpDraft);

    supplier.authorizedCaller = callerAccountId;

    CallerSideMirroringInterface wrappedHandler = new PassThroughMirroringGateway(handler);

    Vector parameters = new Vector();
    parameters.add(MirroringInterface.CMD_MIRRORING_LIST_AVAILABLE_IDS);
    parameters.add(authorAccountId);
    String sig = callerSecurity.createSignatureOfVectorOfStrings(parameters);
    Vector result = wrappedHandler.request(callerAccountId, parameters, sig);
    assertEquals(NetworkInterfaceConstants.OK, result.get(0));
    Object[] infos = (Object[]) result.get(1);
    assertEquals(3, infos.length);
    boolean got1 = false;
    boolean got2 = false;
    boolean gotDraft = false;
    for (int i = 0; i < infos.length; ++i) {
      Object[] info = (Object[]) infos[i];
      String id = (String) info[0];
      String expectedId1 = (String) result1.get(0);
      if (id.equals(expectedId1)) got1 = true;
      String expectedId2 = (String) result2.get(0);
      if (id.equals(expectedId2)) got2 = true;
      String expectedIdDraft = (String) resultDraft.get(0);
      if (id.equals(expectedIdDraft)) gotDraft = true;
    }
    assertTrue("Didn't get bhp1?", got1);
    assertTrue("Didn't get bhp2?", got2);
    assertTrue("Didn't get bhpDraft?", gotDraft);
    Vector infosAsVector = new Vector(Arrays.asList(infos));

    CallerSideMirroringGateway gateway = new CallerSideMirroringGateway(wrappedHandler);
    LoggerToNull logger = new LoggerToNull();
    MockMartusServer server = new MockMartusServer();

    MirroringRetriever mirroringRetriever =
        new MirroringRetriever(server.getStore(), gateway, "Dummy IP", logger);
    Vector returnedListWeWantToMirror =
        mirroringRetriever.listOnlyPacketsThatWeWantUsingBulletinMirroringInformation(
            authorSecurity.getPublicKeyString(), infosAsVector);
    int bulletinsVerified = 0;
    for (int i = 0; i < returnedListWeWantToMirror.size(); i++) {
      BulletinMirroringInformation returnedInfo =
          (BulletinMirroringInformation) returnedListWeWantToMirror.get(i);
      bulletinsVerified = verifyStatus(bulletinsVerified, returnedInfo, bhp1, "BHP1");
      bulletinsVerified = verifyStatus(bulletinsVerified, returnedInfo, bhp2, "BHP2");
      bulletinsVerified = verifyStatus(bulletinsVerified, returnedInfo, bhpDraft, "BHPDRAFT");
    }
    assertEquals(3, bulletinsVerified);
    server.deleteAllFiles();
  }