Skip to content

Commit

Permalink
feat: add 'Access-Control-Allow-Headers' = true to cors response head…
Browse files Browse the repository at this point in the history
…ers (#121)
  • Loading branch information
vandemark authored Mar 14, 2020
1 parent 96e2604 commit 61bd9d1
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def shutdown
private

def add_cors_header env, response
[response[0], response[1].merge('Access-Control-Allow-Origin' => env.fetch('HTTP_ORIGIN','*')), response[2]]
cors_headers = { 'Access-Control-Allow-Origin' => env.fetch('HTTP_ORIGIN','*'), 'Access-Control-Allow-Credentials' => 'true'}
[response[0], response[1].merge(cors_headers), response[2]]
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions spec/features/administration_endpoints_cors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,25 @@
it "includes the CORS headers in the response to DELETE /interactions" do | example |
delete "/interactions", nil, admin_headers
expect(last_response.headers['Access-Control-Allow-Origin']).to eq '*'
expect(last_response.headers['Access-Control-Allow-Credentials']).to eq 'true'
end

it "includes the CORS headers in the response to POST /interactions" do | example |
post "/interactions", expected_interaction, admin_headers
expect(last_response.headers['Access-Control-Allow-Origin']).to eq '*'
expect(last_response.headers['Access-Control-Allow-Credentials']).to eq 'true'
end

it "includes the CORS headers in the response to POST /pact" do | example |
post "/pact", pact_details, admin_headers
expect(last_response.headers['Access-Control-Allow-Origin']).to eq '*'
expect(last_response.headers['Access-Control-Allow-Credentials']).to eq 'true'
end

it "includes the CORS headers in the response to GET /interactions/verification" do | example |
get "/interactions/verification", nil, admin_headers
expect(last_response.headers['Access-Control-Allow-Origin']).to eq '*'
expect(last_response.headers['Access-Control-Allow-Credentials']).to eq 'true'
end

context "when the Origin header is set" do
Expand Down
170 changes: 88 additions & 82 deletions spec/features/log/mock_multiple_responses_spec.log
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
INFO -- : Cleared interactions for example "Pact::Consumer::MockService when more than one response has been mocked when the actual request matches more than one expected request returns an error response"
INFO -- : Cleared interactions for example "Pact::Consumer::MockService when more than one response has been mocked when the actual request matches one expected request returns the expected response"
INFO -- : Registered expected interaction GET /alligators
DEBUG -- : {
"description": "a request for alligators",
Expand All @@ -20,15 +20,16 @@ DEBUG -- : {
"name": "Mary"
}
]
}
},
"metadata": null
}
INFO -- : Registered expected interaction GET /alligators
INFO -- : Registered expected interaction GET /zebras
DEBUG -- : {
"description": "a request for alligators",
"providerState": "there are no alligators",
"description": "a request for zebras",
"providerState": "there are zebras",
"request": {
"method": "get",
"path": "/alligators",
"path": "/zebras",
"headers": {
"Accept": "application/json"
}
Expand All @@ -39,9 +40,12 @@ DEBUG -- : {
"Content-Type": "application/json"
},
"body": [

{
"name": "Xena Zebra"
}
]
}
},
"metadata": null
}
INFO -- : Received request GET /alligators
DEBUG -- : {
Expand All @@ -56,7 +60,46 @@ DEBUG -- : {
"Cookie": ""
}
}
ERROR -- : Multiple interactions found for GET /alligators:
INFO -- : Found matching response for GET /alligators
DEBUG -- : {
"status": 200,
"headers": {
"Content-Type": "application/json"
},
"body": [
{
"name": "Mary"
}
]
}
INFO -- : Received request GET /zebras
DEBUG -- : {
"method": "get",
"query": "",
"path": "/zebras",
"headers": {
"Https": "off",
"Content-Length": "0",
"Accept": "application/json",
"Host": "example.org",
"Cookie": ""
}
}
INFO -- : Found matching response for GET /zebras
DEBUG -- : {
"status": 200,
"headers": {
"Content-Type": "application/json"
},
"body": [
{
"name": "Xena Zebra"
}
]
}
INFO -- : Verifying - interactions matched for example "Pact::Consumer::MockService when more than one response has been mocked when the actual request matches one expected request returns the expected response"
INFO -- : Cleared interactions for example "Pact::Consumer::MockService when more than one response has been mocked when the actual request matches more than one expected request returns an error response"
INFO -- : Registered expected interaction GET /alligators
DEBUG -- : {
"description": "a request for alligators",
"providerState": "alligators exist",
Expand All @@ -77,8 +120,10 @@ DEBUG -- : {
"name": "Mary"
}
]
}
},
"metadata": null
}
INFO -- : Registered expected interaction GET /alligators
DEBUG -- : {
"description": "a request for alligators",
"providerState": "there are no alligators",
Expand All @@ -97,21 +142,23 @@ DEBUG -- : {
"body": [

]
},
"metadata": null
}
INFO -- : Received request GET /alligators
DEBUG -- : {
"method": "get",
"query": "",
"path": "/alligators",
"headers": {
"Https": "off",
"Content-Length": "0",
"Accept": "application/json",
"Host": "example.org",
"Cookie": ""
}
}
WARN -- : Verifying - actual interactions do not match expected interactions for example "Pact::Consumer::MockService when more than one response has been mocked when the actual request matches more than one expected request returns an error response".
Missing requests:
GET /alligators
GET /alligators


WARN -- : Missing requests:
GET /alligators
GET /alligators


INFO -- : Cleared interactions for example "Pact::Consumer::MockService when more than one response has been mocked when the actual request matches one expected request returns the expected response"
INFO -- : Registered expected interaction GET /alligators
ERROR -- : Multiple interactions found for GET /alligators:
DEBUG -- : {
"description": "a request for alligators",
"providerState": "alligators exist",
Expand All @@ -132,15 +179,15 @@ DEBUG -- : {
"name": "Mary"
}
]
}
},
"metadata": null
}
INFO -- : Registered expected interaction GET /zebras
DEBUG -- : {
"description": "a request for zebras",
"providerState": "there are zebras",
"description": "a request for alligators",
"providerState": "there are no alligators",
"request": {
"method": "get",
"path": "/zebras",
"path": "/alligators",
"headers": {
"Accept": "application/json"
}
Expand All @@ -151,60 +198,19 @@ DEBUG -- : {
"Content-Type": "application/json"
},
"body": [
{
"name": "Xena Zebra"
}

]
}
}
INFO -- : Received request GET /alligators
DEBUG -- : {
"method": "get",
"query": "",
"path": "/alligators",
"headers": {
"Https": "off",
"Content-Length": "0",
"Accept": "application/json",
"Host": "example.org",
"Cookie": ""
}
}
INFO -- : Found matching response for GET /alligators
DEBUG -- : {
"status": 200,
"headers": {
"Content-Type": "application/json"
},
"body": [
{
"name": "Mary"
}
]
}
INFO -- : Received request GET /zebras
DEBUG -- : {
"method": "get",
"query": "",
"path": "/zebras",
"headers": {
"Https": "off",
"Content-Length": "0",
"Accept": "application/json",
"Host": "example.org",
"Cookie": ""
}
}
INFO -- : Found matching response for GET /zebras
DEBUG -- : {
"status": 200,
"headers": {
"Content-Type": "application/json"
},
"body": [
{
"name": "Xena Zebra"
}
]
"metadata": null
}
INFO -- : Verifying - interactions matched for example "Pact::Consumer::MockService when more than one response has been mocked when the actual request matches one expected request returns the expected response"
WARN -- : Verifying - actual interactions do not match expected interactions for example "Pact::Consumer::MockService when more than one response has been mocked when the actual request matches more than one expected request returns an error response".
Missing requests:
GET /alligators
GET /alligators


WARN -- : Missing requests:
GET /alligators
GET /alligators


Loading

0 comments on commit 61bd9d1

Please sign in to comment.