Skip to content

Commit

Permalink
test default adhoc.includes and excludes settings
Browse files Browse the repository at this point in the history
  • Loading branch information
lhotari committed Feb 25, 2014
1 parent 30842e4 commit ad1471c
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions test/unit/org/grails/plugin/resource/ResourceProcessorSpec.groovy
@@ -0,0 +1,78 @@
package org.grails.plugin.resource

import org.junit.Rule
import org.junit.rules.TemporaryFolder
import org.springframework.mock.web.MockHttpServletRequest
import org.springframework.mock.web.MockHttpServletResponse

import spock.lang.Specification
import spock.lang.Unroll

class ResourceProcessorSpec extends Specification {
@Rule public TemporaryFolder temporaryFolder = new TemporaryFolder()
ResourceProcessor resourceProcessor
MockHttpServletRequest request
MockHttpServletResponse response
ConfigObject config

def setup() {
resourceProcessor = new ResourceProcessor()
resourceProcessor.staticUrlPrefix = 'static'
config = new ConfigObject()
File temporarySubfolder = temporaryFolder.newFolder('test-tmp')
config.grails.resources.work.dir = temporarySubfolder.getAbsolutePath()
resourceProcessor.grailsApplication = [
config : config,
mainContext : [servletContext:[
getResource: { uri ->
null
},
getMimeType: { uri ->
null
}
]]
]
resourceProcessor.afterPropertiesSet()
request = new MockHttpServletRequest()
request.contextPath = '/'
response = new MockHttpServletResponse()
}

@Unroll
def "check default adhoc.includes/excludes settings - access to url #url should be #accepted"() {
given:
request.requestURI = url
when: 'default adhoc.includes and adhoc.excludes are used'
def uri = null
def exception=null
def result=false
try {
uri=resourceProcessor.removeQueryParams(resourceProcessor.extractURI(request, false))
result=resourceProcessor.canProcessLegacyResource(uri)
} catch (Exception e) {
result=false
exception=e
}
then:
result == accepted
when: 'adhoc.includes setting is accepting all resources'
resourceProcessor.adHocIncludes = ['/**/*']
try {
result=resourceProcessor.canProcessLegacyResource(uri)
} catch (Exception e) {
result=false
exception=e
}
then:
result == accepted
where:
url | accepted
'/static/images/image.png' | true
'/static/js/file.js' | true
'/static/WEB-INF/web.xml' | false
'/static/wEb-iNf/web.xml' | false
'/static/web-inf/web.xml' | false
'/static/META-INF/MANIFEST.MF' | false
'/static/meta-inf/MANIFEST.MF' | false
}
}

0 comments on commit ad1471c

Please sign in to comment.