Search in sources :

Example 1 with RemoteOnly

use of com.google.cloud.runtime.jetty.test.annotation.RemoteOnly in project jetty-runtime by GoogleCloudPlatform.

the class ConfigurationIntegrationTest method testNoDirectoryListing.

/**
   * Simple test validating no directory listing.
   *
   * @throws IOException test in error
   */
@Test
@RemoteOnly
public void testNoDirectoryListing() throws IOException {
    URI target = getUri().resolve("/directory/");
    assertThat(target.getPath(), containsString("/directory/"));
    HttpURLConnection http = HttpUrlUtil.openTo(target);
    assertThat(http.getResponseCode(), is(403));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) URI(java.net.URI) RemoteOnly(com.google.cloud.runtime.jetty.test.annotation.RemoteOnly) AbstractIntegrationTest(com.google.cloud.runtime.jetty.test.AbstractIntegrationTest) Test(org.junit.Test)

Example 2 with RemoteOnly

use of com.google.cloud.runtime.jetty.test.annotation.RemoteOnly in project jetty-runtime by GoogleCloudPlatform.

the class ForwardedIntegrationTest method testForwardedIgnored.

/**
   * Validate Forwarded header is ignored.
   *
   * @throws IOException test in error
   */
@Test
@RemoteOnly
public void testForwardedIgnored() throws IOException {
    URI target = getUri().resolve("/dump/info");
    assertThat(target.getPath(), containsString("/dump/info"));
    HttpURLConnection http = HttpUrlUtil.openTo(target);
    http.setRequestProperty("Forwarded", "for=1.2.3.4;by=1.1.1.1;proto=https;host=example.com");
    assertThat(http.getResponseCode(), is(200));
    String responseBody = HttpUrlUtil.getResponseBody(http);
    // Test forwarded header is ignored
    assertThat(responseBody, not(containsString("remoteHost/Addr:port=1.2.3.4")));
    assertThat(responseBody, containsString("scheme=http(secure=false)"));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) URI(java.net.URI) RemoteOnly(com.google.cloud.runtime.jetty.test.annotation.RemoteOnly) AbstractIntegrationTest(com.google.cloud.runtime.jetty.test.AbstractIntegrationTest) Test(org.junit.Test)

Example 3 with RemoteOnly

use of com.google.cloud.runtime.jetty.test.annotation.RemoteOnly in project jetty-runtime by GoogleCloudPlatform.

the class ForwardedIntegrationTest method testRemoteFor.

/**
   * Validate proxy for header is handled.
   *
   * @throws IOException test in error
   */
@Test
@RemoteOnly
public void testRemoteFor() throws IOException {
    URI target = getUri().resolve("/dump/info");
    assertThat(target.getPath(), containsString("/dump/info"));
    HttpURLConnection http = HttpUrlUtil.openTo(target);
    http.setRequestProperty("X-Forwarded-For", "1.2.3.4, 5.6.7.8");
    assertThat(http.getResponseCode(), is(200));
    String responseBody = HttpUrlUtil.getResponseBody(http);
    // Test that the client is trusted to say what their IP is 
    assertThat(responseBody, containsString("remoteHost/Addr:port=1.2.3.4"));
    // Test GFE IP is added to the forwarded list by looking for trailing comma
    assertThat(responseBody, containsString("X-Forwarded-For: 1.2.3.4, 5.6.7.8,"));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) URI(java.net.URI) RemoteOnly(com.google.cloud.runtime.jetty.test.annotation.RemoteOnly) AbstractIntegrationTest(com.google.cloud.runtime.jetty.test.AbstractIntegrationTest) Test(org.junit.Test)

Example 4 with RemoteOnly

use of com.google.cloud.runtime.jetty.test.annotation.RemoteOnly in project jetty-runtime by GoogleCloudPlatform.

the class LocalRemoteTestRunner method runChild.

@Override
protected void runChild(FrameworkMethod method, RunNotifier notifier) {
    Description description = describeChild(method);
    // check Ignore first
    if (method.getAnnotation(Ignore.class) != null) {
        notify("@Ignore", description);
        notifier.fireTestIgnored(description);
    } else if (localTestsEnabled && method.getAnnotation(RemoteOnly.class) != null) {
        // if running in local mode and @RemoteOnly annotation exists, ignore
        notify("Skip @RemoteOnly", description);
        notifier.fireTestIgnored(description);
    } else if (remoteTestsEnabled && method.getAnnotation(LocalOnly.class) != null) {
        // if running in remote mode and @LocalOnly annotation exists, ignore
        notify("Skip @LocalOnly", description);
        notifier.fireTestIgnored(description);
    } else {
        // default is run in either mode
        notify("Test[" + mode + "]", description);
        super.runChild(method, notifier);
    }
}
Also used : Ignore(org.junit.Ignore) RemoteOnly(com.google.cloud.runtime.jetty.test.annotation.RemoteOnly) Description(org.junit.runner.Description)

Example 5 with RemoteOnly

use of com.google.cloud.runtime.jetty.test.annotation.RemoteOnly in project jetty-runtime by GoogleCloudPlatform.

the class ForwardedIntegrationTest method testRemoteUserProto.

/**
   * Validate proxy proto header is handled.
   *
   * @throws IOException test in error
   */
@Test
@RemoteOnly
public void testRemoteUserProto() throws IOException {
    URI target = getUri().resolve("/dump/info");
    assertThat(target.getPath(), containsString("/dump/info"));
    // Check that user provided X-Forwarded-Proto is ignored
    HttpURLConnection http = HttpUrlUtil.openTo(target);
    http.setRequestProperty("X-Forwarded-Proto", "https");
    assertThat(http.getResponseCode(), is(200));
    String responseBody = HttpUrlUtil.getResponseBody(http);
    assertThat(responseBody, containsString("scheme=http(secure=false)"));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) URI(java.net.URI) RemoteOnly(com.google.cloud.runtime.jetty.test.annotation.RemoteOnly) AbstractIntegrationTest(com.google.cloud.runtime.jetty.test.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

RemoteOnly (com.google.cloud.runtime.jetty.test.annotation.RemoteOnly)7 AbstractIntegrationTest (com.google.cloud.runtime.jetty.test.AbstractIntegrationTest)6 HttpURLConnection (java.net.HttpURLConnection)6 URI (java.net.URI)6 Test (org.junit.Test)6 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)5 Page (com.google.api.gax.paging.Page)1 LogEntry (com.google.cloud.logging.LogEntry)1 Logging (com.google.cloud.logging.Logging)1 EntryListOption (com.google.cloud.logging.Logging.EntryListOption)1 LoggingOptions (com.google.cloud.logging.LoggingOptions)1 Severity (com.google.cloud.logging.Severity)1 HttpUrlUtil (com.google.cloud.runtime.jetty.util.HttpUrlUtil)1 BufferedReader (java.io.BufferedReader)1 StringReader (java.io.StringReader)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 CoreMatchers.is (org.hamcrest.CoreMatchers.is)1 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)1 Matchers (org.hamcrest.Matchers)1