http_stub 0.24.1 → 0.24.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/http_stub/server/application/cross_origin_support.rb +12 -2
- data/lib/http_stub/version.rb +1 -1
- data/spec/acceptance/cross_origin_support_spec.rb +23 -11
- data/spec/lib/http_stub/configurer/dsl/server_spec.rb +58 -0
- data/spec/lib/http_stub/server/application/cross_origin_support_spec.rb +26 -16
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19a6a02a024a22ad07ff458e4076ac6b3edae3c9
|
4
|
+
data.tar.gz: 2a8a5a9f5d0e4dd10e1e6e8471f7e263045b72d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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" =>
|
13
|
-
"Access-Control-Allow-Headers" =>
|
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)
|
data/lib/http_stub/version.rb
CHANGED
@@ -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(:
|
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
|
-
|
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:
|
70
|
+
let(:response) { HTTParty.options("#{server_uri}/some_path", headers: access_control_request_headers) }
|
60
71
|
|
61
|
-
it "ignores the stub and replays
|
72
|
+
it "ignores the stub and replays the cross origin response" do
|
62
73
|
expect(response.code).to eql(200)
|
63
|
-
|
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
|
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-
|
121
|
-
|
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(:
|
5
|
-
let(:
|
6
|
-
|
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(
|
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
|
-
|
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(:
|
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
|
-
|
73
|
+
let(:request_headers) { access_control_request_headers }
|
63
74
|
|
64
|
-
let(:
|
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)
|
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", {},
|
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
|
-
|
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.
|
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-
|
15
|
+
date: 2016-07-19 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: rake
|