You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2011/03/01 20:29:26 UTC
svn commit: r1075992 - in /tapestry/tapestry5/trunk/tapestry-core/src/test:
groovy/org/apache/tapestry5/integration/app1/
groovy/org/apache/tapestry5/internal/services/assets/
java/org/apache/tapestry5/integration/app1/
java/org/apache/tapestry5/integr...
Author: hlship
Date: Tue Mar 1 19:29:26 2011
New Revision: 1075992
URL: http://svn.apache.org/viewvc?rev=1075992&view=rev
Log:
TAP5-73: Fill in some gaps in the unit and integration tests
Added:
tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/AssetDigestTests.groovy
tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/assets/
tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/assets/ContentTypeAnalyzerTests.groovy
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/nested/AssetDemo.properties
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/AssetTests.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/nested/AssetDemo.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/services/AppModule.java
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/nested/AssetDemo.tml
Added: tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/AssetDigestTests.groovy
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/AssetDigestTests.groovy?rev=1075992&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/AssetDigestTests.groovy (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/AssetDigestTests.groovy Tue Mar 1 19:29:26 2011
@@ -0,0 +1,75 @@
+// Copyright 2011 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry5.integration.app1
+
+import org.apache.tapestry5.integration.TapestryCoreTestCase
+import org.testng.annotations.Test
+
+/**
+ * Tests access to a "protected" asset, one that requires a digest in the URL in order to access. Ensures
+ * that such assets can only be accessed using a URL with the necessary digest.
+ */
+class AssetDigestTests extends TapestryCoreTestCase
+{
+ def tryBadPath(badPath) {
+ def url = new URL("${baseURL}${badPath}")
+
+ try {
+ url.getText()
+ unreachable()
+ }
+ catch (IOException ex) {
+ assert ex.getMessage().contains("403")
+ }
+ }
+
+ @Test
+ void protected_asset() {
+ clickThru "AssetDemo"
+
+ def path = getText("propurl").substring(1) // Strip leading slash
+
+ def url = new URL("${baseURL}${path}")
+
+ def p = new Properties();
+
+ p.load(url.newInputStream())
+
+ printf("URL: %s\nProperties: %s\n", url, p)
+
+ assert p.getProperty("note") == "Should be protected via a MD5 checksum"
+
+ assert path ==~ /.*\/AssetDemo\.\p{XDigit}+\.properties/
+ }
+
+ @Test
+ void invalid_digest() {
+ clickThru "AssetDemo"
+
+ def path = getText("propurl").substring(1)
+
+ tryBadPath ((path =~ /\.\p{XDigit}+\.properties/).replaceFirst(".abc.properties"))
+ }
+
+
+ @Test
+ void missing_digest() {
+ clickThru "AssetDemo"
+
+ def path = getText("propurl").substring(1)
+
+ tryBadPath( (path =~ /\.\p{XDigit}+\.properties/).replaceFirst(".properties"))
+ }
+}
Added: tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/assets/ContentTypeAnalyzerTests.groovy
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/assets/ContentTypeAnalyzerTests.groovy?rev=1075992&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/assets/ContentTypeAnalyzerTests.groovy (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/assets/ContentTypeAnalyzerTests.groovy Tue Mar 1 19:29:26 2011
@@ -0,0 +1,77 @@
+// Copyright 2011 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry5.internal.services.assets
+
+import org.apache.tapestry5.internal.test.InternalBaseTestCase
+import org.testng.annotations.Test
+
+class ContentTypeAnalyzerTests extends InternalBaseTestCase {
+
+ def configuration = [ "txt" : "application/text", "pdf" : "adobe/pdf" ]
+
+ def mockResource(String file) {
+ def r = mockResource()
+
+ expect (r.getFile()).andReturn(file).atLeastOnce()
+
+ return r
+ }
+
+ @Test
+ void file_type_in_configuration() {
+ def r = mockResource("foo.txt")
+
+ replay()
+
+ def cta = new ContentTypeAnalyzerImpl (null, configuration)
+
+ assert cta.getContentType(r) == "application/text"
+
+ verify()
+ }
+
+ @Test
+ void file_type_via_context() {
+
+ def r = mockResource("foo.png")
+ def context = mockContext()
+
+ expect(context.getMimeType("foo.png")).andReturn("image/png")
+
+ replay()
+
+ def cta = new ContentTypeAnalyzerImpl (context, configuration)
+
+ assert cta.getContentType(r) == "image/png"
+
+ verify()
+ }
+
+ @Test
+ void default_is_octect_stream() {
+ def r = mockResource("bar.unknown")
+ def context = mockContext()
+
+ expect(context.getMimeType("bar.unknown")).andReturn(null)
+
+ replay()
+
+ def cta = new ContentTypeAnalyzerImpl (context, configuration)
+
+ assert cta.getContentType(r) == "application/octet-stream"
+
+ verify()
+ }
+}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/AssetTests.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/AssetTests.java?rev=1075992&r1=1075991&r2=1075992&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/AssetTests.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/AssetTests.java Tue Mar 1 19:29:26 2011
@@ -1,10 +1,10 @@
-// Copyright 2009 The Apache Software Foundation
+// Copyright 2009, 2011 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
-// http://www.apache.org/licenses/LICENSE-2.0
+// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
@@ -33,10 +33,9 @@ public class AssetTests extends Tapestry
{
return new Object[][]
{
- { "icon", "src/test/app1/images/tapestry_banner.gif" },
- { "button",
- "src/test/resources/org/apache/tapestry5/integration/app1/pages/nested/tapestry-button.png" },
- { "viaContext", "src/test/app1/images/asf_logo_wide.gif" } };
+ { "icon", "src/test/app1/images/tapestry_banner.gif" },
+ { "button", "src/test/resources/org/apache/tapestry5/integration/app1/pages/nested/tapestry-button.png" },
+ { "viaContext", "src/test/app1/images/asf_logo_wide.gif" } };
}
@Test(dataProvider = "asset_data")
@@ -57,18 +56,14 @@ public class AssetTests extends Tapestry
private void compareDownloadedAsset(String assetURL, String localPath) throws Exception
{
- System.out.printf("compare %s to %s\n", assetURL, localPath);
-
// Strip off the leading slash
-
+
URL url = new URL(getBaseURL() + assetURL.substring(1));
byte[] downloaded = readContent(url);
File local = new File(TapestryTestConstants.MODULE_BASE_DIR, localPath);
- System.out.printf("Remote URL %s, Local file: %s\n", url, local);
-
byte[] actual = readContent(local.toURL());
assertEquals(downloaded, actual);
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/nested/AssetDemo.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/nested/AssetDemo.java?rev=1075992&r1=1075991&r2=1075992&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/nested/AssetDemo.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/nested/AssetDemo.java Tue Mar 1 19:29:26 2011
@@ -18,6 +18,7 @@ import org.apache.tapestry5.Asset;
import org.apache.tapestry5.annotations.Environmental;
import org.apache.tapestry5.annotations.Import;
import org.apache.tapestry5.annotations.Path;
+import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.javascript.JavaScriptSupport;
import org.apache.tapestry5.services.javascript.StylesheetLink;
@@ -29,14 +30,21 @@ import org.apache.tapestry5.services.jav
*/
public class AssetDemo
{
+ @Property
@Inject
@Path("context:images/tapestry_banner.gif")
private Asset icon;
+ @Property
@Inject
@Path("tapestry-button.png")
private Asset button;
+ @Property
+ @Inject
+ @Path("AssetDemo.properties")
+ private Asset properties;
+
@Inject
@Path("context:css/ie-only.css")
private Asset ieOnly;
@@ -49,14 +57,4 @@ public class AssetDemo
{
javascriptSupport.importStylesheet(new StylesheetLink(ieOnly, new StylesheetOptions(null, "IE")));
}
-
- public Asset getIcon()
- {
- return icon;
- }
-
- public Asset getButton()
- {
- return button;
- }
}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/services/AppModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/services/AppModule.java?rev=1075992&r1=1075991&r2=1075992&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/services/AppModule.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/services/AppModule.java Tue Mar 1 19:29:26 2011
@@ -47,6 +47,7 @@ import org.apache.tapestry5.services.Com
import org.apache.tapestry5.services.Request;
import org.apache.tapestry5.services.RequestFilter;
import org.apache.tapestry5.services.RequestHandler;
+import org.apache.tapestry5.services.ResourceDigestGenerator;
import org.apache.tapestry5.services.Response;
import org.apache.tapestry5.services.ValueEncoderFactory;
import org.slf4j.Logger;
@@ -289,4 +290,10 @@ public class AppModule
{
configuration.add("PreApp", preappResource, "before:AppCatalog");
}
+
+ @Contribute(ResourceDigestGenerator.class)
+ public static void protectPropertiesFiles(Configuration<String> configuration)
+ {
+ configuration.add("properties");
+ }
}
Added: tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/nested/AssetDemo.properties
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/nested/AssetDemo.properties?rev=1075992&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/nested/AssetDemo.properties (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/nested/AssetDemo.properties Tue Mar 1 19:29:26 2011
@@ -0,0 +1 @@
+note=Should be protected via a MD5 checksum
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/nested/AssetDemo.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/nested/AssetDemo.tml?rev=1075992&r1=1075991&r2=1075992&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/nested/AssetDemo.tml (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/nested/AssetDemo.tml Tue Mar 1 19:29:26 2011
@@ -22,7 +22,7 @@
Relative asset via asset: binding
</p>
- <img src="${asset:../smiley.png}"/>
+ <img id="relative" src="${asset:../smiley.png}"/>
<p>
@@ -46,4 +46,13 @@
<div class="via-import">
This text should be red.
</div>
+
+
+ <p>
+ Properties file URL:
+ <a id="propurl" href="${properties}">
+ ${properties}
+ </a>
+ </p>
+
</html>
\ No newline at end of file