Skip to content

Commit c5d3937

Browse files
committed
feat: respond correctly to OPTIONS requests
1 parent d6260c1 commit c5d3937

37 files changed

+60
-35
lines changed

lib/pact_broker/api/resources/all_webhooks.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def content_types_accepted
1818
end
1919

2020
def allowed_methods
21-
["GET", "POST"]
21+
["GET", "POST", "OPTIONS", "OPTIONS"]
2222
end
2323

2424
def create_path

lib/pact_broker/api/resources/badge.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module Resources
99
class Badge < BaseResource
1010

1111
def allowed_methods
12-
['GET']
12+
["GET", "OPTIONS", "OPTIONS"]
1313
end
1414

1515
def content_types_provided

lib/pact_broker/api/resources/base_resource.rb

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ def initialize
3030
PactBroker.configuration.before_resource.call(self)
3131
end
3232

33+
def options
34+
{ 'Access-Control-Allow-Methods' => allowed_methods.join(", ")}
35+
end
36+
3337
def update_matrix_after_request?
3438
false
3539
end

lib/pact_broker/api/resources/dashboard.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def content_types_provided
1616
end
1717

1818
def allowed_methods
19-
["GET"]
19+
["GET", "OPTIONS"]
2020
end
2121

2222
def to_json

lib/pact_broker/api/resources/error_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def content_types_accepted
2020
end
2121

2222
def allowed_methods
23-
["GET", "POST"]
23+
["GET", "POST", "OPTIONS"]
2424
end
2525

2626
def to_json

lib/pact_broker/api/resources/group.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def content_types_provided
1313
end
1414

1515
def allowed_methods
16-
["GET"]
16+
["GET", "OPTIONS"]
1717
end
1818

1919
def resource_exists?

lib/pact_broker/api/resources/index.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def content_types_provided
1212
end
1313

1414
def allowed_methods
15-
["GET"]
15+
["GET", "OPTIONS"]
1616
end
1717

1818
def to_json

lib/pact_broker/api/resources/label.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def content_types_accepted
1515
end
1616

1717
def allowed_methods
18-
["GET","PUT","DELETE"]
18+
["GET", "PUT", "DELETE", "OPTIONS"]
1919
end
2020

2121
def from_json

lib/pact_broker/api/resources/latest_pact.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def content_types_provided
1414
end
1515

1616
def allowed_methods
17-
["GET"]
17+
["GET", "OPTIONS"]
1818
end
1919

2020
def resource_exists?

lib/pact_broker/api/resources/latest_pacts.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def content_types_provided
1111
end
1212

1313
def allowed_methods
14-
["GET"]
14+
["GET", "OPTIONS"]
1515
end
1616

1717
def to_json

lib/pact_broker/api/resources/latest_verifications_for_consumer_version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module Resources
1111
class LatestVerificationsForConsumerVersion < BaseResource
1212

1313
def allowed_methods
14-
["GET"]
14+
["GET", "OPTIONS"]
1515
end
1616

1717
def content_types_provided

lib/pact_broker/api/resources/matrix.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def content_types_provided
2020
end
2121

2222
def allowed_methods
23-
["GET"]
23+
["GET", "OPTIONS"]
2424
end
2525

2626
def malformed_request?

lib/pact_broker/api/resources/matrix_for_consumer_and_provider.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def content_types_provided
1111
end
1212

1313
def allowed_methods
14-
["GET"]
14+
["GET", "OPTIONS"]
1515
end
1616

1717
def resource_exists?

lib/pact_broker/api/resources/pact.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def content_types_accepted
3434
end
3535

3636
def allowed_methods
37-
["GET", "PUT", "DELETE", "PATCH"]
37+
["GET", "PUT", "DELETE", "PATCH", "OPTIONS"]
3838
end
3939

4040
def known_methods

lib/pact_broker/api/resources/pact_content_diff.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def content_types_provided
1111
end
1212

1313
def allowed_methods
14-
["GET"]
14+
["GET", "OPTIONS"]
1515
end
1616

1717
def resource_exists?

lib/pact_broker/api/resources/pact_triggered_webhooks.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Api
55
module Resources
66
class PactTriggeredWebhooks < BaseResource
77
def allowed_methods
8-
["GET"]
8+
["GET", "OPTIONS"]
99
end
1010

1111
def content_types_provided

lib/pact_broker/api/resources/pact_version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Api
55
module Resources
66
class PactVersion < Pact
77
def allowed_methods
8-
["GET"]
8+
["GET", "OPTIONS"]
99
end
1010
end
1111
end

lib/pact_broker/api/resources/pact_versions.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def content_types_provided
1313
end
1414

1515
def allowed_methods
16-
["GET"]
16+
["GET", "OPTIONS"]
1717
end
1818

1919
def resource_exists?

lib/pact_broker/api/resources/pact_webhooks.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module Resources
1111
class PactWebhooks < BaseResource
1212

1313
def allowed_methods
14-
["POST", "GET"]
14+
["POST", "GET", "OPTIONS"]
1515
end
1616

1717
def content_types_provided

lib/pact_broker/api/resources/pact_webhooks_status.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module Resources
99
class PactWebhooksStatus < BaseResource
1010

1111
def allowed_methods
12-
["GET"]
12+
["GET", "OPTIONS"]
1313
end
1414

1515
def content_types_provided

lib/pact_broker/api/resources/pacticipant.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def content_types_accepted
2323
end
2424

2525
def allowed_methods
26-
["GET", "PATCH", "DELETE"]
26+
["GET", "PATCH", "DELETE", "OPTIONS"]
2727
end
2828

2929
def known_methods

lib/pact_broker/api/resources/pacticipants.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def content_types_accepted
1717
end
1818

1919
def allowed_methods
20-
["GET", "POST"]
20+
["GET", "POST", "OPTIONS"]
2121
end
2222

2323
def malformed_request?

lib/pact_broker/api/resources/pacticipants_for_label.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def content_types_provided
1111
end
1212

1313
def allowed_methods
14-
["GET"]
14+
["GET", "OPTIONS"]
1515
end
1616

1717
def to_json

lib/pact_broker/api/resources/previous_distinct_pact_version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def content_types_provided
1414
end
1515

1616
def allowed_methods
17-
["GET"]
17+
["GET", "OPTIONS"]
1818
end
1919

2020
def resource_exists?

lib/pact_broker/api/resources/provider_pacts.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def content_types_provided
1212
end
1313

1414
def allowed_methods
15-
["GET"]
15+
["GET", "OPTIONS"]
1616
end
1717

1818
def resource_exists?

lib/pact_broker/api/resources/relationships.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def content_types_provided
1212
end
1313

1414
def allowed_methods
15-
["GET"]
15+
["GET", "OPTIONS"]
1616
end
1717

1818
def to_csv

lib/pact_broker/api/resources/tag.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def content_types_accepted
1414
end
1515

1616
def allowed_methods
17-
["GET","PUT","DELETE"]
17+
["GET","PUT","DELETE", "OPTIONS"]
1818
end
1919

2020
def from_json

lib/pact_broker/api/resources/triggered_webhook_logs.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def content_types_provided
1212
end
1313

1414
def allowed_methods
15-
["GET"]
15+
["GET", "OPTIONS"]
1616
end
1717

1818
def resource_exists?

lib/pact_broker/api/resources/verification.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def content_types_provided
1515
end
1616

1717
def allowed_methods
18-
["GET"]
18+
["GET", "OPTIONS"]
1919
end
2020

2121
def resource_exists?

lib/pact_broker/api/resources/verification_triggered_webhooks.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Api
55
module Resources
66
class VerificationTriggeredWebhooks < BaseResource
77
def allowed_methods
8-
["GET"]
8+
["GET", "OPTIONS"]
99
end
1010

1111
def content_types_provided

lib/pact_broker/api/resources/verifications.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def content_types_provided
1919
end
2020

2121
def allowed_methods
22-
["POST"]
22+
["POST", "OPTIONS"]
2323
end
2424

2525
def post_is_create?

lib/pact_broker/api/resources/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def content_types_provided
1313
end
1414

1515
def allowed_methods
16-
["GET", "DELETE"]
16+
["GET", "DELETE", "OPTIONS"]
1717
end
1818

1919
def resource_exists?

lib/pact_broker/api/resources/versions.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def content_types_provided
1313
end
1414

1515
def allowed_methods
16-
["GET"]
16+
["GET", "OPTIONS"]
1717
end
1818

1919
def resource_exists?

lib/pact_broker/api/resources/webhook.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def content_types_provided
1717
end
1818

1919
def allowed_methods
20-
["GET", "PUT", "DELETE"]
20+
["GET", "PUT", "DELETE", "OPTIONS"]
2121
end
2222

2323
def resource_exists?

lib/pact_broker/api/resources/webhook_execution.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module Resources
1010
class WebhookExecution < BaseResource
1111

1212
def allowed_methods
13-
["POST"]
13+
["POST", "OPTIONS"]
1414
end
1515

1616
def process_post

lib/pact_broker/api/resources/webhooks.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module Resources
99
class Webhooks < BaseResource
1010

1111
def allowed_methods
12-
["POST", "GET"]
12+
["POST", "GET", "OPTIONS"]
1313
end
1414

1515
def content_types_provided

spec/lib/pact_broker/api/resources/base_resource_spec.rb

+21
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,27 @@ module Resources
1111
subject { BaseResource.new(request, response) }
1212

1313
its(:resource_url) { is_expected.to eq 'http://example.org/path' }
14+
15+
describe "options" do
16+
subject { options "/"; last_response }
17+
18+
it "returns a list of allowed methods" do
19+
expect(subject.headers['Access-Control-Allow-Methods']).to eq "GET, OPTIONS"
20+
end
21+
end
22+
end
23+
24+
ALL_RESOURCES = ObjectSpace.each_object(::Class).select {|klass| klass < BaseResource }
25+
26+
ALL_RESOURCES.each do | resource |
27+
describe resource do
28+
let(:request) { double('request', uri: URI("http://example.org")) }
29+
let(:response) { double('response') }
30+
31+
it "includes OPTIONS in the list of allowed_methods" do
32+
expect(resource.new(request, response).allowed_methods).to include "OPTIONS"
33+
end
34+
end
1435
end
1536
end
1637
end

0 commit comments

Comments
 (0)