http_stub 0.24.1 → 0.24.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c9901731654d0eeda9511137a9f8a37af8b90d3d
4
- data.tar.gz: 15b7fd910cdba41e9c39d43b1856dbc224db93e1
3
+ metadata.gz: 19a6a02a024a22ad07ff458e4076ac6b3edae3c9
4
+ data.tar.gz: 2a8a5a9f5d0e4dd10e1e6e8471f7e263045b72d9
5
5
  SHA512:
6
- metadata.gz: f7ee3913ab3048dbe60b3d4f92ea573828011ca8496122a96c8533c92aa72ae8d1397f0739deb3b3eb4ba1bb5525a93d61a8e691578721394a46dc5e91c93290
7
- data.tar.gz: 90e55d873f32fede338a8eb54cbbc6345ddbe85d736919ebcae1d68e76499b46ebbb5844acb81a940922e4854110294a3b89a9cb78e057b0bab5d1b6529135c3
6
+ metadata.gz: 2c427195bbf661e6a9717658b1ca3a6f2b4cc286194fe3f2a8a677356da3f73bb187c336c14248ce4f37105ae3f78df2becc33dcb599b3854581f3008b6a7431
7
+ data.tar.gz: ddab90edb0e73220865ab2378295e90331d2e1692833c997380521e22217a817fc64ad6c4472563424f7fca79de85331e4795a097d0ad9892db51381221dae86
@@ -9,8 +9,8 @@ module HttpStub
9
9
  def add_headers_if_necessary
10
10
  response.headers.merge!(
11
11
  "Access-Control-Allow-Origin" => "*",
12
- "Access-Control-Allow-Methods" => @http_stub_request.method.upcase,
13
- "Access-Control-Allow-Headers" => @http_stub_request.headers.keys.join(",")
12
+ "Access-Control-Allow-Methods" => determine_allowed_methods,
13
+ "Access-Control-Allow-Headers" => determine_allowed_headers
14
14
  ) if settings.cross_origin_support?
15
15
  end
16
16
 
@@ -19,6 +19,16 @@ module HttpStub
19
19
  halt 200
20
20
  end
21
21
 
22
+ private
23
+
24
+ def determine_allowed_methods
25
+ @http_stub_request.headers["Access_Control_Request_Method"] || @http_stub_request.method.upcase
26
+ end
27
+
28
+ def determine_allowed_headers
29
+ @http_stub_request.headers["Access_Control_Request_Headers"] || @http_stub_request.headers.keys.join(",")
30
+ end
31
+
22
32
  end
23
33
 
24
34
  def self.registered(application)
@@ -1,3 +1,3 @@
1
1
  module HttpStub
2
- VERSION = "0.24.1".freeze
2
+ VERSION = "0.24.2".freeze
3
3
  end
@@ -4,8 +4,6 @@ describe "Cross origin support acceptance" do
4
4
 
5
5
  let(:cross_origin_page) { CrossOriginServer::IndexPage.new(browser) }
6
6
 
7
- let(:headers) { (1..3).each_with_object({}) { |i, result| result["HEADER_#{i}"] = "header value #{i}" } }
8
-
9
7
  context "when a stub server with cross origin support is initialized" do
10
8
  include_context "configurer integration"
11
9
 
@@ -34,7 +32,11 @@ describe "Cross origin support acceptance" do
34
32
 
35
33
  context "and a matching request is made" do
36
34
 
37
- let(:response) { HTTParty.get("#{server_uri}/some_path", headers: headers) }
35
+ let(:application_headers) do
36
+ (1..3).each_with_object({}) { |i, result| result["APPLICATION_HEADER_#{i}"] = "header value #{i}" }
37
+ end
38
+
39
+ let(:response) { HTTParty.get("#{server_uri}/some_path", headers: application_headers) }
38
40
 
39
41
  before(:example) { cross_origin_page.wait_for_response_indicator("Succeeded") }
40
42
 
@@ -43,7 +45,7 @@ describe "Cross origin support acceptance" do
43
45
  end
44
46
 
45
47
  it "responds with cross origin support headers" do
46
- expect_response_to_contain_cross_origin_headers("GET")
48
+ expect_response_to_contain_cross_origin_support(method: "GET", header_names: application_headers.keys)
47
49
  end
48
50
 
49
51
  end
@@ -54,13 +56,23 @@ describe "Cross origin support acceptance" do
54
56
 
55
57
  before(:example) { configurer.activate!("Options scenario") }
56
58
 
57
- context "and a matching request is made" do
59
+ context "and a matching pre-flight request is made" do
60
+
61
+ let(:access_control_request_method) { "PUT" }
62
+ let(:access_control_request_header_names) { (1..3).map { |i| "ACCESS_CONTROL_HEADER_#{i}" } }
63
+ let(:access_control_request_headers) do
64
+ {
65
+ "Access-Control-Request-Method" => access_control_request_method,
66
+ "Access-Control-Request-Headers" => access_control_request_header_names.join(",")
67
+ }
68
+ end
58
69
 
59
- let(:response) { HTTParty.options("#{server_uri}/some_path", headers: headers) }
70
+ let(:response) { HTTParty.options("#{server_uri}/some_path", headers: access_control_request_headers) }
60
71
 
61
- it "ignores the stub and replays a cross origin options response" do
72
+ it "ignores the stub and replays the cross origin response" do
62
73
  expect(response.code).to eql(200)
63
- expect_response_to_contain_cross_origin_headers("OPTIONS")
74
+ expect_response_to_contain_cross_origin_support(method: access_control_request_method,
75
+ header_names: access_control_request_header_names)
64
76
  end
65
77
 
66
78
  end
@@ -115,10 +127,10 @@ describe "Cross origin support acceptance" do
115
127
 
116
128
  end
117
129
 
118
- def expect_response_to_contain_cross_origin_headers(method_name)
130
+ def expect_response_to_contain_cross_origin_support(expectations)
119
131
  expect(response.headers["access-control-allow-origin"]).to eql("*")
120
- expect(response.headers["access-Control-allow-methods"]).to eql(method_name)
121
- headers.keys.each do |expected_header_name|
132
+ expect(response.headers["access-control-allow-methods"]).to eql(expectations[:method])
133
+ expectations[:header_names].each do |expected_header_name|
122
134
  expect(response.headers["access-control-allow-headers"]).to include(expected_header_name)
123
135
  end
124
136
 
@@ -79,6 +79,64 @@ describe HttpStub::Configurer::DSL::Server do
79
79
 
80
80
  end
81
81
 
82
+ describe "#enable" do
83
+
84
+ context "when a feature is provided" do
85
+
86
+ let(:feature) { :some_feature }
87
+
88
+ subject { server.enable(feature) }
89
+
90
+ it "enables the feature" do
91
+ subject
92
+
93
+ expect(server.enabled?(feature)).to be(true)
94
+ end
95
+
96
+ end
97
+
98
+ context "when features are provided" do
99
+
100
+ let(:features) { (1..3).map { |i| "feature_#{i}".to_sym } }
101
+
102
+ subject { server.enable(*features) }
103
+
104
+ it "enables the features" do
105
+ subject
106
+
107
+ features.each { |feature| expect(server.enabled?(feature)).to be(true) }
108
+ end
109
+
110
+ end
111
+
112
+ end
113
+
114
+ describe "#enabled?" do
115
+
116
+ let(:feature) { :some_feature }
117
+
118
+ subject { server.enabled?(feature) }
119
+
120
+ context "when a feature is enabled" do
121
+
122
+ before(:example) { server.enable(feature) }
123
+
124
+ it "returns false" do
125
+ expect(subject).to be(true)
126
+ end
127
+
128
+ end
129
+
130
+ context "when a feature is not enabled" do
131
+
132
+ it "returns false" do
133
+ expect(subject).to be(false)
134
+ end
135
+
136
+ end
137
+
138
+ end
139
+
82
140
  describe "#request_defaults=" do
83
141
 
84
142
  let(:args) { { request_rule_key: "request rule value" } }
@@ -1,9 +1,18 @@
1
1
  describe HttpStub::Server::Application::CrossOriginSupport do
2
2
  include Rack::Test::Methods
3
3
 
4
- let(:header_names) { (1..3).map { |i| "HEADER_#{i}" } }
5
- let(:request_headers) do
6
- header_names.each_with_object({}) { |name, result| result["HTTP_#{name}"] = "#{name} value" }
4
+ let(:application_header_names) { (1..3).map { |i| "APPLICATION_HEADER_#{i}" } }
5
+ let(:application_headers) do
6
+ application_header_names.each_with_object({}) { |name, result| result["HTTP_#{name}"] = "#{name} value" }
7
+ end
8
+
9
+ let(:access_control_request_method) { "PATCH" }
10
+ let(:access_control_request_header_names) { (1..3).map { |i| "ACCESS_CONTROL_HEADER_#{i}" } }
11
+ let(:access_control_request_headers) do
12
+ {
13
+ "ACCESS_CONTROL_REQUEST_METHOD" => access_control_request_method,
14
+ "ACCESS_CONTROL_REQUEST_HEADERS" => access_control_request_header_names.join(",")
15
+ }
7
16
  end
8
17
 
9
18
  let(:response) { last_response }
@@ -31,15 +40,13 @@ describe HttpStub::Server::Application::CrossOriginSupport do
31
40
  it "responds with an access control method header allowing the method of the current request" do
32
41
  subject
33
42
 
34
- expect(response.headers["Access-Control-Allow-Methods"]).to eql(request_method)
43
+ expect(response.headers["Access-Control-Allow-Methods"]).to eql(allowed_request_methods)
35
44
  end
36
45
 
37
46
  it "responds with an access control headers header allowing the headers of the current request" do
38
47
  subject
39
48
 
40
- header_names.each do |expected_header_name|
41
- expect(response.headers["Access-Control-Allow-Headers"]).to include(expected_header_name)
42
- end
49
+ expect(response.headers["Access-Control-Allow-Headers"]).to include(allowed_request_headers)
43
50
  end
44
51
 
45
52
  end
@@ -50,7 +57,10 @@ describe HttpStub::Server::Application::CrossOriginSupport do
50
57
 
51
58
  context "and a non-OPTIONS request is issued" do
52
59
 
53
- let(:request_method) { "GET" }
60
+ let(:request_headers) { application_headers }
61
+
62
+ let(:allowed_request_methods) { "GET" }
63
+ let(:allowed_request_headers) { application_header_names.join(",") }
54
64
 
55
65
  subject { get "/some_resource", {}, request_headers }
56
66
 
@@ -58,10 +68,12 @@ describe HttpStub::Server::Application::CrossOriginSupport do
58
68
 
59
69
  end
60
70
 
71
+ context "and a pre-flight OPTIONS request is issued" do
61
72
 
62
- context "and an OPTIONS request is issued" do
73
+ let(:request_headers) { access_control_request_headers }
63
74
 
64
- let(:request_method) { "OPTIONS" }
75
+ let(:allowed_request_methods) { access_control_request_method }
76
+ let(:allowed_request_headers) { access_control_request_header_names.join(",") }
65
77
 
66
78
  subject { options "/some_resource", {}, request_headers }
67
79
 
@@ -79,25 +91,23 @@ describe HttpStub::Server::Application::CrossOriginSupport do
79
91
 
80
92
  context "and cross origin support is disabled" do
81
93
 
82
- before(:example) do
83
- app_class.disable :cross_origin_support
84
- end
94
+ before(:example) { app_class.disable :cross_origin_support }
85
95
 
86
96
  context "and a non-OPTIONS request is issued" do
87
97
 
88
- subject { get "/some_resource", {}, request_headers }
98
+ subject { get "/some_resource", {}, application_headers }
89
99
 
90
100
  it "does not add access control headers" do
91
101
  subject
92
102
 
93
- header_names.each { |header_name| expect(header_name).to_not match(/^Access-Control/) }
103
+ response.headers.keys.each { |header_name| expect(header_name).to_not include("Access-Control") }
94
104
  end
95
105
 
96
106
  end
97
107
 
98
108
  context "and an OPTIONS request is issued" do
99
109
 
100
- subject { options "/some_resource" }
110
+ subject { options "/some_resource", {}, access_control_request_headers }
101
111
 
102
112
  it "returns a not found response" do
103
113
  subject
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http_stub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.24.1
4
+ version: 0.24.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - dueckes
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2016-07-18 00:00:00.000000000 Z
15
+ date: 2016-07-19 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rake