Skip to content

Commit 46a9c45

Browse files
committed
#19 Enabled CORS
1 parent 3663b5d commit 46a9c45

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package au.org.ala.logger
2+
3+
/**
4+
* Interceptor for web service calls to logger
5+
*/
6+
class RestInterceptor {
7+
8+
RestInterceptor() {
9+
match(controller: "logger")
10+
}
11+
12+
boolean before() {
13+
header("Access-Control-Allow-Origin", "*")
14+
header("Access-Control-Allow-Credentials", "true")
15+
header("Access-Control-Allow-Methods", "POST, GET, OPTIONS")
16+
header("Access-Control-Max-Age", "3600")
17+
true
18+
}
19+
20+
boolean after() { true }
21+
22+
void afterView() {
23+
// no-op
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package au.org.ala.logger
2+
3+
import grails.testing.web.interceptor.InterceptorUnitTest
4+
import spock.lang.Specification
5+
6+
class RestInterceptorSpec extends Specification implements InterceptorUnitTest<RestInterceptor> {
7+
8+
def setup() {
9+
}
10+
11+
def cleanup() {
12+
13+
}
14+
15+
void "Test rest interceptor matching"() {
16+
when:"A request matches the interceptor"
17+
withRequest(controller:"logger")
18+
19+
then:"The interceptor does match"
20+
interceptor.doesMatch()
21+
}
22+
23+
void "Test unreadValidatedTasks interceptor matching"() {
24+
when: "A request does not matche the interceptor"
25+
withRequest(controller: "public", action: 'unreadValidatedTasks')
26+
27+
then: "The interceptor does match"
28+
interceptor.doesMatch() == false
29+
}
30+
}

0 commit comments

Comments
 (0)