<commit_before>package e2e;

import com.danielflower.apprunner.router.App;
import com.danielflower.apprunner.router.Config;
import com.danielflower.apprunner.router.mgmt.SystemInfo;
import org.junit.After;
import org.junit.Assert;
import org.junit.Test;
import scaffolding.ContentResponseMatcher;
import scaffolding.RestClient;

import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;

import static com.danielflower.apprunner.router.Config.dirPath;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;

public class HttpsTest {
    private App router;
    private final int httpPort = 20080;
    private final int httpsPort = 20443;

    // by using hostname for router, and localhost for instances, we test instances where host names don't match which affects some SSL stuff
    private final String hostname = SystemInfo.create().hostName;
    private final RestClient httpClient = RestClient.create("http://" + hostname + ":" + httpPort);
    private final RestClient httpsClient = RestClient.create("https://" + hostname + ":" + httpsPort);

    @Test
    public void httpOnlyIsSupported() throws Exception {
        Map<String, String> env = env();
        env.put("appserver.port", String.valueOf(httpPort));
        router = new App(new Config(env));
        router.start();

        assertWorks(httpClient);
        assertDoesNotWork(httpsClient);
    }

    @Test
    public void httpsOnlyIsSupported() throws Exception {
        Map<String, String> env = env();
        env.put("appserver.https.port", String.valueOf(httpsPort));
        env.put("apprunner.keystore.path", dirPath(new File("local/test.keystore")));
        env.put("apprunner.keystore.password", "password");
        env.put("apprunner.keymanager.password", "password");
        router = new App(new Config(env));
        router.start();<commit_msg>Removed lie about how testing with hostname would effect some SSL stuff. Turns out it doesn't.<commit_after>package e2e;

import com.danielflower.apprunner.router.App;
import com.danielflower.apprunner.router.Config;
import org.junit.After;
import org.junit.Assert;
import org.junit.Test;
import scaffolding.ContentResponseMatcher;
import scaffolding.RestClient;

import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;

import static com.danielflower.apprunner.router.Config.dirPath;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;

public class HttpsTest {
    private App router;
    private final int httpPort = 20080;
    private final int httpsPort = 20443;

    private final RestClient httpClient = RestClient.create("http://" + "localhost" + ":" + httpPort);
    private final RestClient httpsClient = RestClient.create("https://" + "localhost" + ":" + httpsPort);

    @Test
    public void httpOnlyIsSupported() throws Exception {
        Map<String, String> env = env();
        env.put("appserver.port", String.valueOf(httpPort));
        router = new App(new Config(env));
        router.start();

        assertWorks(httpClient);
        assertDoesNotWork(httpsClient);
    }

    @Test
    public void httpsOnlyIsSupported() throws Exception {
        Map<String, String> env = env();
        env.put("appserver.https.port", String.valueOf(httpsPort));
        env.put("apprunner.keystore.path", dirPath(new File("local/test.keystore")));
        env.put("apprunner.keystore.password", "password");
        env.put("apprunner.keymanager.password", "password");
        router = new App(new Config(env));
        router.start();
{'fraction_non_alphanumeric': 0.11618481491488787, 'fraction_numerical': 0.005944339367738449, 'mean_word_length': 3.975806451612903, 'pattern_counts': {'":': 4, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2954738', 'n_tokens_mistral': 1083, 'n_tokens_neox': 1047, 'n_words': 255}