|
| 1 | +Feature: Server must implement the CORS protocol for preflight requests |
| 2 | + |
| 3 | + Background: Set up test container and resource |
| 4 | + * def testContainer = rootTestContainer.createContainer() |
| 5 | + * def resource = testContainer.createResource('.txt', 'Hello', 'text/plain') |
| 6 | + |
| 7 | + Scenario Outline: Pre-flight CORS request for <method> request |
| 8 | + Given url testContainer.url |
| 9 | + And header Origin = 'https://tester' |
| 10 | + And header Access-Control-Request-Method = '<method>' |
| 11 | + And header Access-Control-Request-Headers = 'X-CUSTOM, Content-Type, Accept' |
| 12 | + When method OPTIONS |
| 13 | + Then match [200, 204] contains responseStatus |
| 14 | + And match header Access-Control-Allow-Origin == 'https://tester' |
| 15 | + And match header Access-Control-Allow-Methods contains '<method>' |
| 16 | + And match header Access-Control-Allow-Headers contains 'X-CUSTOM' |
| 17 | + And match header Access-Control-Allow-Headers contains 'Content-Type' |
| 18 | + And match header Access-Control-Allow-Headers contains 'Accept' |
| 19 | + And match header Access-Control-Allow-Credentials == 'true' |
| 20 | + And match header Access-Control-Expose-Headers != null |
| 21 | + And match response == '' |
| 22 | + |
| 23 | + Given url testContainer.url |
| 24 | + And header Origin = 'https://tester' |
| 25 | + And headers clients.alice.getAuthHeaders('<method>', testContainer.url) |
| 26 | + # Demonstrates the case where a long Accept header is allowed |
| 27 | + And header Accept = 'text/turtle;q=0.9, application/rdf+xml;q=0.8, application/n-triples;q=0.8, application/n-quads;q=0.8, text/x-nquads;q=0.8, application/trig;q=0.8, text/n3;q=0.8, application/ld+json;q=0.8, application/x-binary-rdf;q=0.8, text/plain;q=0.7' |
| 28 | + * <body> |
| 29 | + When method <method> |
| 30 | + Then match <statuses> contains responseStatus |
| 31 | + And match header Access-Control-Allow-Origin == 'https://tester' |
| 32 | + And match header Access-Control-Allow-Credentials == 'true' |
| 33 | + And match header Access-Control-Expose-Headers != null |
| 34 | + And match header Access-Control-Expose-Headers != '*' |
| 35 | + # Check Content-Type on GET request only |
| 36 | + And <check> |
| 37 | + And match header Vary contains 'Origin' |
| 38 | + Examples: |
| 39 | + | method | body | statuses | check | |
| 40 | + | GET | def ignore = 1 | [200] | match header Content-Type contains 'text/turtle' | |
| 41 | + | HEAD | def ignore = 1 | [200] | def ignore = 1 | |
| 42 | + | POST | request "Hello" | [200, 201, 204, 205] | def ignore = 1 | |
| 43 | + |
| 44 | + @http-redirect |
| 45 | + Scenario: OPTIONS request returns headers for pre-flight check after redirect from http |
| 46 | + * configure followRedirects = false |
| 47 | + Given url testContainer.url.replace(/^https:/, 'http:') |
| 48 | + And header Origin = 'https://tester' |
| 49 | + And header Access-Control-Request-Method = 'POST' |
| 50 | + And header Access-Control-Request-Headers = 'X-CUSTOM, Content-Type' |
| 51 | + When method OPTIONS |
| 52 | + Then match [301, 308] contains responseStatus |
| 53 | + * def location = responseHeaders['Location'][0] |
| 54 | + |
| 55 | + Given url location |
| 56 | + And header Origin = 'https://tester' |
| 57 | + And header Access-Control-Request-Method = 'POST' |
| 58 | + And header Access-Control-Request-Headers = 'X-CUSTOM, Content-Type' |
| 59 | + When method OPTIONS |
| 60 | + Then match [200, 204] contains responseStatus |
| 61 | + And match header Access-Control-Allow-Origin == 'https://tester' |
| 62 | + And match header Access-Control-Allow-Methods contains 'POST' |
| 63 | + And match header Access-Control-Allow-Headers contains 'X-CUSTOM' |
| 64 | + And match header Access-Control-Allow-Headers contains 'Content-Type' |
| 65 | + And match header Access-Control-Allow-Credentials == 'true' |
| 66 | + And match header Access-Control-Expose-Headers != null |
| 67 | + And match response == '' |
0 commit comments