Uploaded image for project: 'Wicket'
  1. Wicket
  2. WICKET-5851

PackageResourceTest#packageResourceGuard test fails under Windows

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 6.19.0
    • 6.20.0, 7.0.0-M6
    • wicket
    • None
    • Windows 8.1 Pro, Oracle JDK 7u72 x64

    Description

      I'm emphasized assert statement which causes the issue

      	@Test
      	public void packageResourceGuard() throws Exception
      	{
      		PackageResourceGuard guard = new PackageResourceGuard();
      		assertTrue(guard.acceptExtension("txt"));
      		assertFalse(guard.acceptExtension("java"));
      		assertTrue(guard.acceptAbsolutePath("foo/Bar.txt"));
      		assertFalse(guard.acceptAbsolutePath("foo/Bar.java"));
      		assertTrue(guard.accept(PackageResourceTest.class,
      			Packages.absolutePath(PackageResourceTest.class, "Bar.txt")));
      		assertTrue(guard.accept(PackageResourceTest.class,
      			Packages.absolutePath(PackageResourceTest.class, "Bar.txt.")));
      		assertTrue(guard.accept(PackageResourceTest.class,
      			Packages.absolutePath(PackageResourceTest.class, ".Bar.txt")));
      		assertTrue(guard.accept(PackageResourceTest.class,
      			Packages.absolutePath(PackageResourceTest.class, ".Bar.txt.")));
      		assertTrue(guard.accept(PackageResourceTest.class,
      			Packages.absolutePath(PackageResourceTest.class, ".Bar")));
      >>>>	assertTrue(guard.accept(PackageResourceTest.class,
      			Packages.absolutePath(PackageResourceTest.class, ".java")));
      		assertFalse(guard.accept(PackageResourceTest.class,
      			Packages.absolutePath(PackageResourceTest.class, "Bar.java")));
      	}
      

      There is another issue in PackageResourceGuardTest

      	@Test
      	public void acceptAbsolutePath()
      	{
      		PackageResourceGuard guard = new PackageResourceGuard();
      		guard.setAllowAccessToRootResources(false);
      
      		assertTrue(guard.acceptAbsolutePath("/test/test.js"));
      		assertFalse(guard.acceptAbsolutePath("/test.js"));
      
      >>> File.pathSeparator must be replaced with File.separator
      >>>		if ("\\".equals(File.pathSeparator))
      		{
      			assertTrue(guard.acceptAbsolutePath("c:\\test\\org\\apache\\test.js"));
      			assertTrue(guard.acceptAbsolutePath("\\test\\org\\apache\\test.js"));
      			assertFalse(guard.acceptAbsolutePath("c:\\test.js"));
      			assertFalse(guard.acceptAbsolutePath("\\test.js"));
      
      			// java also generates file paths with '/' on windows
      			assertTrue(guard.acceptAbsolutePath("c:/test/org/apache/test.js"));
      			assertTrue(guard.acceptAbsolutePath("/test/org/apache/test.js"));
      			assertFalse(guard.acceptAbsolutePath("c:/test.js"));
      			assertFalse(guard.acceptAbsolutePath("/test.js"));
      		}
      	}
      

      Attachments

        Issue Links

          Activity

            People

              mgrigorov Martin Tzvetanov Grigorov
              amorozov Alexander Morozov
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: