-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib/pact/consumer/mock_service/app.rb lib/pact/mock_service/cli.rb pact-mock-service.gemspec spec/support/integration_spec_support.rb
- Loading branch information
Showing
22 changed files
with
456 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,4 @@ def matching_interactions actual_request | |
|
||
end | ||
end | ||
end | ||
end |
30 changes: 30 additions & 0 deletions
30
lib/pact/consumer/mock_service/cors_origin_header_middleware.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module Pact | ||
module Consumer | ||
class CorsOriginHeaderMiddleware | ||
|
||
def initialize app, cors_enabled | ||
@app = app | ||
@cors_enabled = cors_enabled | ||
end | ||
|
||
def call env | ||
response = @app.call env | ||
if env['HTTP_X_PACT_MOCK_SERVICE'] || @cors_enabled | ||
add_cors_header env, response | ||
else | ||
response | ||
end | ||
end | ||
|
||
def shutdown | ||
@app.shutdown | ||
end | ||
|
||
private | ||
|
||
def add_cors_header env, response | ||
[response[0], response[1].merge('Access-Control-Allow-Origin' => env.fetch('HTTP_ORIGIN','*')), response[2]] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require 'pact/consumer/mock_service/rack_request_helper' | ||
require 'pact/consumer/mock_service/mock_service_administration_endpoint' | ||
|
||
module Pact | ||
module Consumer | ||
|
||
class Options | ||
|
||
include RackRequestHelper | ||
|
||
attr_reader :name, :logger, :cors_enabled | ||
|
||
def initialize name, logger, cors_enabled | ||
@name = name | ||
@logger = logger | ||
@cors_enabled = cors_enabled | ||
end | ||
|
||
def match? env | ||
is_options_request?(env) && (cors_enabled || is_administration_request?(env)) | ||
end | ||
|
||
def respond env | ||
cors_headers = { | ||
'Access-Control-Allow-Origin' => env.fetch('HTTP_ORIGIN','*'), | ||
'Access-Control-Allow-Headers' => headers_from(env)["Access-Control-Request-Headers"], | ||
'Access-Control-Allow-Methods' => 'DELETE, POST, GET, HEAD, PUT, TRACE, CONNECT' | ||
} | ||
logger.info "Received OPTIONS request for mock service administration endpoint #{env['HTTP_ACCESS_CONTROL_REQUEST_METHOD']} #{env['PATH_INFO']}. Returning CORS headers: #{cors_headers.to_json}." | ||
[200, cors_headers, []] | ||
end | ||
|
||
def is_options_request? env | ||
env['REQUEST_METHOD'] == 'OPTIONS' | ||
end | ||
|
||
def is_administration_request? env | ||
env["HTTP_ACCESS_CONTROL_REQUEST_HEADERS"].match(/x-pact-mock-service/i) | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
require 'cgi/core' | ||
module Pact | ||
module Consumer | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module Pact | ||
module MockService | ||
VERSION = "0.2.3.pre.rc1" | ||
VERSION = "0.2.3" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.