示例#1
0
 @Test
 public void test7() {
   UrlRenderer r1 =
       new UrlRenderer(
           new MockWebRequest(
               Url.parse("MyTestPage/indexed1/indexed2/indexed3?10-27.ILinkListener-l2&p1=v1")));
   assertEquals("../../../MyTestPage?10", r1.renderUrl(Url.parse("MyTestPage?10")));
 }
示例#2
0
 @Test
 public void test8() {
   UrlRenderer r1 =
       new UrlRenderer(new MockWebRequest(Url.parse("en/first-test-page?16-1.ILinkListener-l1")));
   assertEquals(
       "./first-test-page/indexed1/indexed2/indexed3?p1=v1",
       r1.renderUrl(Url.parse("en/first-test-page/indexed1/indexed2/indexed3?p1=v1")));
 }
示例#3
0
 /**
  * Verify that absolute urls are rendered as is, ignoring the current client url and base url
  * completely.
  *
  * <p>https://issues.apache.org/jira/browse/WICKET-4466
  */
 @Test
 public void renderAbsoluteUrl() {
   String absoluteUrl = "http://www.example.com/some/path.ext";
   Url url = Url.parse(absoluteUrl);
   UrlRenderer renderer = new UrlRenderer(new MockWebRequest(Url.parse("foo/bar")));
   String renderedUrl = renderer.renderUrl(url);
   assertEquals(absoluteUrl, renderedUrl);
 }
示例#4
0
  /** WICKET-4935 prevent another double slash */
  @Test
  public void test15() {
    UrlRenderer r1 = new UrlRenderer(new MockWebRequest(Url.parse("private/AdminPage")));

    assertEquals(
        "../signIn;jsessionid=16k3wqa9c4sgq1cnp7fisa20u",
        r1.renderRelativeUrl(Url.parse("/signIn;jsessionid=16k3wqa9c4sgq1cnp7fisa20u")));
  }
示例#5
0
 @Test
 public void test1() {
   UrlRenderer r1 = new UrlRenderer(new MockWebRequest(Url.parse("foo/bar/baz?a=b")));
   assertEquals("./xyz?x=y", r1.renderUrl(Url.parse("foo/bar/xyz?x=y")));
   assertEquals("./baz/xyz?x=y", r1.renderUrl(Url.parse("foo/bar/baz/xyz?x=y")));
   assertEquals("../aaa/xyz?x=y", r1.renderUrl(Url.parse("foo/aaa/xyz?x=y")));
   assertEquals("../../bbb/aaa/xyz?x=y", r1.renderUrl(Url.parse("bbb/aaa/xyz?x=y")));
 }
示例#6
0
  @Test
  public void renderFullUrlAsRelativeToBaseUrlWithoutSchemeHostnameAndPort() {
    Url baseUrl = Url.parse("/contextPath/filterPath/a/b/c/d");
    Url encodedFullUrl = Url.parse("http://host:8080/contextPath/filterPath/a/b;jsessionid=123456");

    UrlRenderer renderer = new UrlRenderer(new MockWebRequest(baseUrl));
    String encodedRelativeUrl = renderer.renderRelativeUrl(encodedFullUrl);

    assertEquals("../../b;jsessionid=123456", encodedRelativeUrl);
  }
示例#7
0
  /** WICKET-4920 prevent double slash */
  @Test
  public void test14() {
    UrlRenderer r1 = new UrlRenderer(new MockWebRequest(new Url()));

    assertEquals(
        "./;jsessionid=1p87c5424zjuvd57kljcu2bwa?0-1.IBehaviorListener.1-component",
        r1.renderRelativeUrl(
            Url.parse(
                "http://localhost:8080/;jsessionid=1p87c5424zjuvd57kljcu2bwa?0-1.IBehaviorListener.1-component")));
  }
示例#8
0
 @Test
 public void renderFullUrlWithRelativeArgument() {
   Url baseUrl = Url.parse("one/two/three");
   baseUrl.setProtocol("http");
   baseUrl.setHost("www.example.com");
   baseUrl.setPort(8888);
   UrlRenderer renderer = new UrlRenderer(new MockWebRequest(baseUrl));
   renderer.setBaseUrl(baseUrl); // this is needed because MockWebRequest cuts data
   String fullUrl = renderer.renderFullUrl(Url.parse("../four"));
   assertEquals("http://www.example.com:8888/one/four", fullUrl);
 }
示例#9
0
  @Test
  public void renderFullUrlAsRelativeToBaseUrlWithoutComposedFilterPath() {
    Url baseUrl = Url.parse("a/b/c/d"); // base url without context path and filter path
    Url encodedFullUrl = Url.parse("http://host:8080/context/path/a/b;jsessionid=123456");

    MockWebRequest request = new MockWebRequest(baseUrl);
    request.setContextPath("context/path");
    UrlRenderer renderer = new UrlRenderer(request);
    String encodedRelativeUrl = renderer.renderRelativeUrl(encodedFullUrl);

    assertEquals("../../b;jsessionid=123456", encodedRelativeUrl);
  }
示例#10
0
 /** https://issues.apache.org/jira/browse/WICKET-4514 */
 @Test
 public void renderFullUrlWithAbsoluteArgument() {
   Url baseUrl = Url.parse("one/two/three");
   baseUrl.setProtocol("http");
   baseUrl.setHost("www.example.com");
   baseUrl.setPort(8888);
   UrlRenderer renderer = new UrlRenderer(new MockWebRequest(baseUrl));
   renderer.setBaseUrl(baseUrl); // this is needed because MockWebRequest cuts data
   String fullUrl = renderer.renderFullUrl(Url.parse("/four")); // url starting with slash is
   // considered absolute
   assertEquals("http://www.example.com:8888/four", fullUrl);
 }
示例#11
0
  @Test
  public void renderFullUrlAsRelativeToBaseUrlWithFirstSegmentsEqualToTheFilterPath() {
    // base url without context path and filter path
    // 'filterPath' here is a normal segment with the same value
    Url baseUrl = Url.parse("filterPath/a/b/c/d");

    // here 'filterPath' is the actual filter path and should be ignored
    Url encodedFullUrl = Url.parse("http://host:8080/filterPath/a/b;jsessionid=123456");

    MockWebRequest request = new MockWebRequest(baseUrl);
    request.setFilterPath("filterPath");
    UrlRenderer renderer = new UrlRenderer(request);
    String encodedRelativeUrl = renderer.renderRelativeUrl(encodedFullUrl);

    assertEquals("../../../../a/b;jsessionid=123456", encodedRelativeUrl);
  }
示例#12
0
  /**
   * https://issues.apache.org/jira/browse/WICKET-4561
   * https://issues.apache.org/jira/browse/WICKET-4562
   */
  @Test
  public void renderUrlWithRelativeArgument() {
    Url baseUrl = Url.parse("one/two/three");
    UrlRenderer renderer = new UrlRenderer(new MockWebRequest(baseUrl));
    baseUrl.setProtocol("http");
    baseUrl.setHost("www.example.com");
    baseUrl.setPort(8888);
    renderer.setBaseUrl(baseUrl);

    Url newUrl = Url.parse("four");
    newUrl.setProtocol("https");
    String fullUrl = renderer.renderUrl(newUrl);
    assertEquals("https://www.example.com:8888/four", fullUrl);

    newUrl = Url.parse("./four");
    newUrl.setProtocol("https");
    fullUrl = renderer.renderUrl(newUrl);
    assertEquals("https://www.example.com:8888/four", fullUrl);

    newUrl = Url.parse("./././four");
    newUrl.setProtocol("https");
    fullUrl = renderer.renderUrl(newUrl);
    assertEquals("https://www.example.com:8888/four", fullUrl);

    newUrl = Url.parse("../four");
    newUrl.setProtocol("https");
    fullUrl = renderer.renderUrl(newUrl);
    assertEquals("https://www.example.com:8888/four", fullUrl);

    newUrl = Url.parse(".././four");
    newUrl.setProtocol("https");
    fullUrl = renderer.renderUrl(newUrl);
    assertEquals("https://www.example.com:8888/four", fullUrl);

    newUrl = Url.parse("../../../../four");
    newUrl.setProtocol("https");
    fullUrl = renderer.renderUrl(newUrl);
    assertEquals("https://www.example.com:8888/four", fullUrl);
  }
示例#13
0
  @Test
  public void test10() {
    MockWebRequest request =
        new MockWebRequest(Url.parse("a/b/q/d/e"), "/contextPath", "/filterPath", "../");

    UrlRenderer r = new UrlRenderer(request);
    assertEquals("../../../../../", r.renderContextRelativeUrl(""));
    assertEquals("../../../../../", r.renderContextRelativeUrl("/"));
    assertEquals("../../../../../f", r.renderContextRelativeUrl("/f"));
    assertEquals("../../../../../../f", r.renderContextRelativeUrl("../f"));

    try {
      r.renderContextRelativeUrl(null);
      fail("Null 'url' is not allowed!");
    } catch (IllegalArgumentException iax) {
      assertTrue(true);
    }
  }
示例#14
0
 /** <a href="https://issues.apache.org/jira/browse/WICKET-3337">WICKET-3337</a> */
 @Test
 public void test11() {
   UrlRenderer r1 = new UrlRenderer(new MockWebRequest(Url.parse("a")));
   assertEquals("./.", r1.renderUrl(Url.parse("")));
 }
示例#15
0
 @Test
 public void test9() {
   UrlRenderer r1 = new UrlRenderer(new MockWebRequest(Url.parse("a/b/q/d/e")));
   assertEquals("../../../q/c/d/e", r1.renderUrl(Url.parse("a/q/c/d/e")));
 }
示例#16
0
 /**
  * https://issues.apache.org/jira/browse/WICKET-4401
  *
  * <p>A Url should not ends with '..' because some web containers do not handle it properly. Using
  * '../' works better.
  */
 @Test
 public void test13() {
   UrlRenderer r1 = new UrlRenderer(new MockWebRequest(Url.parse("foo/bar")));
   assertEquals("../", r1.renderUrl(Url.parse("")));
 }
示例#17
0
 @Test
 public void test2() {
   UrlRenderer r1 = new UrlRenderer(new MockWebRequest(Url.parse("foo/bar/baz?a=b")));
   assertEquals("../../foo?x=y", r1.renderUrl(Url.parse("foo?x=y")));
   assertEquals("../../aaa?x=y", r1.renderUrl(Url.parse("aaa?x=y")));
 }
示例#18
0
 @Test
 public void test6() {
   UrlRenderer r1 = new UrlRenderer(new MockWebRequest(Url.parse("url/")));
   assertEquals("./x?1", r1.renderUrl(Url.parse("url/x?1")));
 }
示例#19
0
 @Test
 public void test3() {
   UrlRenderer r1 = new UrlRenderer(new MockWebRequest(Url.parse("?a=b")));
   assertEquals("./a/b/c?x=y", r1.renderUrl(Url.parse("a/b/c?x=y")));
 }