/**
  * Testing connection to server http interface with CLI using trusted certificate. Client has
  * server certificate in truststore, and also server has certificate from client, so client can
  * successfully connect.
  */
 @Test
 public void testTrustedCLICertificate() throws InterruptedException, IOException {
   String cliOutput =
       CustomCLIExecutor.execute(TRUSTED_JBOSS_CLI_FILE, TESTING_OPERATION, HTTPS_CONTROLLER);
   assertThat(
       "Client with valid certificate should be authenticated.",
       cliOutput,
       containsString("\"outcome\" => \"success\""));
 }
 /**
  * Testing connection to server http interface with default CLI settings. Client doesn't have
  * servers certificate in truststore and therefore it rejects connection.
  */
 @Test
 public void testDefaultCLIConfiguration() throws InterruptedException, IOException {
   String cliOutput =
       CustomCLIExecutor.execute(null, TESTING_OPERATION, HTTPS_CONTROLLER, true, "N");
   assertThat(
       "Untrusted client should not be authenticated.",
       cliOutput,
       not(containsString("\"outcome\" => \"success\"")));
 }
  /**
   * Testing connection to server http interface with CLI using wrong certificate. Server doesn't
   * have client certificate in truststore and therefore it rejects connection.
   */
  @Test
  @InSequence(2)
  public void testUntrustedCLICertificate() throws InterruptedException, IOException {

    String cliOutput =
        CustomCLIExecutor.execute(UNTRUSTED_JBOSS_CLI_FILE, TESTING_OPERATION, HTTPS_CONTROLLER);
    assertThat(
        "Untrusted client should not be authenticated.",
        cliOutput,
        not(containsString("\"outcome\" => \"success\"")));
  }
  @Test
  @InSequence(4)
  public void resetTestConfiguration() throws Exception {

    LOGGER.info("*** reseting test configuration");
    ModelControllerClient client = getNativeModelControllerClient();
    ManagementClient managementClient =
        new ManagementClient(
            client, TestSuiteEnvironment.getServerAddress(), MANAGEMENT_NATIVE_PORT, "remoting");

    resetHttpInterfaceConfiguration(client);

    // reload to apply changes
    CustomCLIExecutor.execute(null, RELOAD, NATIVE_CONTROLLER);
    CustomCLIExecutor.waitForServerToReload(MAX_RELOAD_TIME, NATIVE_CONTROLLER);

    keystoreFilesSetup.tearDown(managementClient, CONTAINER);
    managementNativeRealmSetup.tearDown(managementClient, CONTAINER);

    LOGGER.info("*** stopping container");
    containerController.stop(CONTAINER);
  }
  @Test
  @InSequence(-1)
  public void prepareServer() throws Exception {

    LOGGER.info("*** starting server");
    containerController.start(CONTAINER);
    final ModelControllerClient client = TestSuiteEnvironment.getModelControllerClient();
    ManagementClient mgmtClient =
        new ManagementClient(
            client,
            TestSuiteEnvironment.getServerAddress(),
            TestSuiteEnvironment.getServerPort(),
            "http-remoting");
    keystoreFilesSetup.setup(mgmtClient, CONTAINER);
    managementNativeRealmSetup.setup(mgmtClient, CONTAINER);

    mgmtClient.close();
    // To apply new security realm settings for http interface reload of
    // server is required
    LOGGER.info("*** restart server");
    CustomCLIExecutor.execute(null, RELOAD, NATIVE_CONTROLLER);
    CustomCLIExecutor.waitForServerToReload(MAX_RELOAD_TIME, NATIVE_CONTROLLER);
  }