http_stub 0.25.1 → 0.26.0
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.rb +32 -9
- data/lib/http_stub/configurer.rb +2 -10
- data/lib/http_stub/configurer/dsl/scenario_builder.rb +13 -11
- data/lib/http_stub/configurer/dsl/server.rb +32 -43
- data/lib/http_stub/configurer/dsl/server_endpoint_template.rb +23 -0
- data/lib/http_stub/configurer/dsl/session.rb +55 -0
- data/lib/http_stub/configurer/dsl/session_endpoint_template.rb +22 -0
- data/lib/http_stub/configurer/dsl/session_factory.rb +34 -0
- data/lib/http_stub/configurer/dsl/stub_builder.rb +18 -8
- data/lib/http_stub/configurer/dsl/stub_builder_template.rb +26 -0
- data/lib/http_stub/configurer/request/http/basic.rb +9 -3
- data/lib/http_stub/configurer/request/http/factory.rb +7 -16
- data/lib/http_stub/configurer/request/http/multipart.rb +5 -7
- data/lib/http_stub/configurer/request/stub.rb +3 -3
- data/lib/http_stub/configurer/request/triggers.rb +25 -0
- data/lib/http_stub/configurer/server/command_processor.rb +8 -10
- data/lib/http_stub/configurer/server/configuration.rb +33 -0
- data/lib/http_stub/configurer/server/facade.rb +21 -43
- data/lib/http_stub/configurer/server/request_processor.rb +2 -2
- data/lib/http_stub/configurer/server/session_facade.rb +64 -0
- data/lib/http_stub/extensions/core/uri.rb +28 -0
- data/lib/http_stub/extensions/rack/handler.rb +1 -0
- data/lib/http_stub/extensions/sinatra/namespace.rb +9 -0
- data/lib/http_stub/rake/server_tasks.rb +1 -4
- data/lib/http_stub/server/application/application.rb +17 -98
- data/lib/http_stub/server/application/configuration.rb +38 -0
- data/lib/http_stub/server/application/cross_origin_support.rb +7 -5
- data/lib/http_stub/server/application/request_support.rb +38 -0
- data/lib/http_stub/server/application/response_support.rb +19 -0
- data/lib/http_stub/server/application/routes/memory.rb +37 -0
- data/lib/http_stub/server/application/routes/resource.rb +23 -0
- data/lib/http_stub/server/application/routes/scenario.rb +52 -0
- data/lib/http_stub/server/application/routes/session.rb +65 -0
- data/lib/http_stub/server/application/routes/stub.rb +75 -0
- data/lib/http_stub/server/application/session_uri_support.rb +15 -0
- data/lib/http_stub/server/memory/controller.rb +25 -0
- data/lib/http_stub/server/memory/memory.rb +32 -0
- data/lib/http_stub/server/registry.rb +25 -8
- data/lib/http_stub/server/request/factory.rb +23 -0
- data/lib/http_stub/server/request/parameters.rb +2 -2
- data/lib/http_stub/server/request/request.rb +6 -11
- data/lib/http_stub/server/request/sinatra_request.rb +26 -0
- data/lib/http_stub/server/scenario/controller.rb +16 -11
- data/lib/http_stub/server/scenario/not_found_error.rb +15 -0
- data/lib/http_stub/server/session.rb +14 -0
- data/lib/http_stub/server/session/configuration.rb +32 -0
- data/lib/http_stub/server/session/controller.rb +40 -0
- data/lib/http_stub/server/session/empty.rb +15 -0
- data/lib/http_stub/server/session/identifier_strategy.rb +24 -0
- data/lib/http_stub/server/session/registry.rb +38 -0
- data/lib/http_stub/server/session/session.rb +80 -0
- data/lib/http_stub/server/stub/controller.rb +18 -12
- data/lib/http_stub/server/stub/empty.rb +1 -1
- data/lib/http_stub/server/stub/match/controller.rb +9 -5
- data/lib/http_stub/server/stub/payload/response_body_modifier.rb +3 -1
- data/lib/http_stub/server/stub/registry.rb +6 -13
- data/lib/http_stub/server/stub/triggers.rb +11 -9
- data/lib/http_stub/server/views/_home.haml +2 -0
- data/lib/http_stub/server/views/_post_link_function.haml +26 -0
- data/lib/http_stub/server/views/_session.haml +16 -0
- data/lib/http_stub/server/views/_stub.haml +8 -2
- data/lib/http_stub/server/views/_stubs.haml +4 -0
- data/lib/http_stub/server/views/application.sass +4 -1
- data/lib/http_stub/server/views/layout.haml +1 -0
- data/lib/http_stub/server/views/scenario.haml +4 -3
- data/lib/http_stub/server/views/scenarios.haml +7 -6
- data/lib/http_stub/server/views/session.haml +3 -0
- data/lib/http_stub/server/views/sessions.haml +6 -0
- data/lib/http_stub/server/views/stubs.haml +1 -4
- data/lib/http_stub/server/views/transactional_session.haml +2 -0
- data/lib/http_stub/version.rb +1 -1
- data/spec/acceptance/configurer_initialization_spec.rb +40 -51
- data/spec/acceptance/configurer_part_spec.rb +5 -7
- data/spec/acceptance/cross_origin_support_spec.rb +7 -13
- data/spec/acceptance/endpoint_template_spec.rb +2 -4
- data/spec/acceptance/request_reference_spec.rb +1 -3
- data/spec/acceptance/scenario_spec.rb +7 -9
- data/spec/acceptance/server_defaults_spec.rb +2 -4
- data/spec/acceptance/server_memory_spec.rb +20 -0
- data/spec/acceptance/session_spec.rb +125 -0
- data/spec/acceptance/stub_body_request_matching_spec.rb +2 -4
- data/spec/acceptance/stub_control_values_spec.rb +19 -18
- data/spec/acceptance/stub_match_last_spec.rb +0 -4
- data/spec/acceptance/stub_match_list_spec.rb +0 -4
- data/spec/acceptance/stub_miss_list_spec.rb +0 -4
- data/spec/acceptance/stub_spec.rb +11 -11
- data/spec/acceptance/stub_trigger_spec.rb +60 -13
- data/spec/lib/http_stub/configurer/dsl/scenario_builder_spec.rb +83 -30
- data/spec/lib/http_stub/configurer/dsl/server_endpoint_template_spec.rb +167 -0
- data/spec/lib/http_stub/configurer/dsl/server_spec.rb +306 -176
- data/spec/lib/http_stub/configurer/dsl/session_endpoint_template_spec.rb +150 -0
- data/spec/lib/http_stub/configurer/dsl/session_factory_spec.rb +97 -0
- data/spec/lib/http_stub/configurer/dsl/session_spec.rb +222 -0
- data/spec/lib/http_stub/configurer/dsl/stub_builder_spec.rb +209 -48
- data/spec/lib/http_stub/configurer/dsl/stub_builder_template_spec.rb +203 -0
- data/spec/lib/http_stub/configurer/request/http/basic_spec.rb +80 -4
- data/spec/lib/http_stub/configurer/request/http/factory_spec.rb +115 -56
- data/spec/lib/http_stub/configurer/request/http/multipart_spec.rb +39 -6
- data/spec/lib/http_stub/configurer/request/stub_spec.rb +50 -108
- data/spec/lib/http_stub/configurer/request/triggers_spec.rb +101 -0
- data/spec/lib/http_stub/configurer/server/command_processor_integration_spec.rb +11 -10
- data/spec/lib/http_stub/configurer/server/configuration_spec.rb +139 -0
- data/spec/lib/http_stub/configurer/server/facade_spec.rb +65 -142
- data/spec/lib/http_stub/configurer/server/request_processor_spec.rb +7 -6
- data/spec/lib/http_stub/configurer/server/session_facade_spec.rb +336 -0
- data/spec/lib/http_stub/configurer_spec.rb +105 -0
- data/spec/lib/http_stub/extensions/core/uri_spec.rb +75 -0
- data/spec/lib/http_stub/extensions/rack/handler_spec.rb +1 -1
- data/spec/lib/http_stub/extensions/sinatra/namespace_spec.rb +36 -0
- data/spec/lib/http_stub/rake/server_tasks_smoke_spec.rb +4 -3
- data/spec/lib/http_stub/rake/server_tasks_spec.rb +47 -10
- data/spec/lib/http_stub/server/application/application_spec.rb +44 -301
- data/spec/lib/http_stub/server/application/configuration_spec.rb +59 -0
- data/spec/lib/http_stub/server/application/cross_origin_support_spec.rb +23 -20
- data/spec/lib/http_stub/server/application/request_support_integration_spec.rb +93 -0
- data/spec/lib/http_stub/server/application/request_support_spec.rb +61 -0
- data/spec/lib/http_stub/server/application/response_support_spec.rb +30 -0
- data/spec/lib/http_stub/server/application/routes/memory_spec.rb +41 -0
- data/spec/lib/http_stub/server/application/routes/resource_spec.rb +16 -0
- data/spec/lib/http_stub/server/application/routes/scenario_spec.rb +117 -0
- data/spec/lib/http_stub/server/application/routes/session_integration_spec.rb +46 -0
- data/spec/lib/http_stub/server/application/routes/session_spec.rb +186 -0
- data/spec/lib/http_stub/server/application/{application_integration_spec.rb → routes/stub_integration_spec.rb} +16 -38
- data/spec/lib/http_stub/server/application/routes/stub_spec.rb +202 -0
- data/spec/lib/http_stub/server/application/session_uri_support_spec.rb +48 -0
- data/spec/lib/http_stub/server/application/text_formatting_support_spec.rb +3 -3
- data/spec/lib/http_stub/server/memory/controller_spec.rb +47 -0
- data/spec/lib/http_stub/server/memory/memory_spec.rb +122 -0
- data/spec/lib/http_stub/server/registry_spec.rb +153 -34
- data/spec/lib/http_stub/server/request/factory_spec.rb +74 -0
- data/spec/lib/http_stub/server/request/parameters_spec.rb +5 -8
- data/spec/lib/http_stub/server/request/request_spec.rb +52 -52
- data/spec/lib/http_stub/server/request/sinatra_request_spec.rb +132 -0
- data/spec/lib/http_stub/server/scenario/controller_spec.rb +121 -35
- data/spec/lib/http_stub/server/scenario/not_found_error_spec.rb +25 -0
- data/spec/lib/http_stub/server/session/configuration_spec.rb +94 -0
- data/spec/lib/http_stub/server/session/controller_spec.rb +106 -0
- data/spec/lib/http_stub/server/session/empty_spec.rb +13 -0
- data/spec/lib/http_stub/server/session/identifier_strategy_spec.rb +126 -0
- data/spec/lib/http_stub/server/session/registry_spec.rb +214 -0
- data/spec/lib/http_stub/server/session/session_spec.rb +444 -0
- data/spec/lib/http_stub/server/stub/controller_spec.rb +89 -37
- data/spec/lib/http_stub/server/stub/empty_spec.rb +2 -2
- data/spec/lib/http_stub/server/stub/match/controller_spec.rb +59 -16
- data/spec/lib/http_stub/server/stub/payload/response_body_modifier_spec.rb +7 -8
- data/spec/lib/http_stub/server/stub/registry_integration_spec.rb +42 -15
- data/spec/lib/http_stub/server/stub/registry_spec.rb +38 -59
- data/spec/lib/http_stub/server/stub/triggers_spec.rb +93 -34
- data/spec/spec_helper.rb +13 -1
- data/spec/support/contain_file.rb +23 -0
- data/spec/support/cross_origin_server/application.rb +1 -1
- data/spec/support/cross_origin_server/index_page.rb +2 -2
- data/spec/support/cross_origin_server/integration.rb +3 -2
- data/spec/support/cross_origin_server/public/index.html +2 -1
- data/spec/support/http_stub/configurer_integration.rb +12 -14
- data/spec/support/http_stub/server/application/http_stub_rack_application_test.rb +47 -0
- data/spec/support/http_stub/server/driver.rb +56 -0
- data/spec/support/http_stub/server/memory_fixture.rb +17 -0
- data/spec/support/http_stub/server/request_fixture.rb +7 -6
- data/spec/support/http_stub/server/scenario_fixture.rb +13 -0
- data/spec/support/http_stub/server/session_fixture.rb +27 -0
- data/spec/support/http_stub/server_integration.rb +12 -17
- data/spec/support/http_stub/stub_fixture.rb +19 -6
- data/spec/support/include_in_json.rb +4 -4
- data/spec/support/rack/rack_application_test.rb +9 -0
- data/spec/support/rack/request_fixture.rb +13 -0
- data/spec/support/surpressed_output.rb +10 -0
- metadata +149 -36
- data/lib/http_stub/configurer/dsl/deprecated.rb +0 -60
- data/lib/http_stub/configurer/dsl/endpoint_template.rb +0 -38
- data/lib/http_stub/configurer/dsl/scenario_activator.rb +0 -15
- data/lib/http_stub/configurer/dsl/stub_activator_builder.rb +0 -24
- data/lib/http_stub/configurer/dsl/stub_builder_producer.rb +0 -21
- data/lib/http_stub/server/request.rb +0 -12
- data/lib/http_stub/server/scenario/activator.rb +0 -25
- data/lib/http_stub/server/views/_activate_scenario.haml +0 -23
- data/lib/http_stub/server/views/index.haml +0 -8
- data/spec/acceptance/activator_spec.rb +0 -81
- data/spec/lib/http_stub/configurer/dsl/deprecated_spec.rb +0 -240
- data/spec/lib/http_stub/configurer/dsl/endpoint_template_spec.rb +0 -255
- data/spec/lib/http_stub/configurer/dsl/scenario_activator_spec.rb +0 -62
- data/spec/lib/http_stub/configurer/dsl/stub_activator_builder_spec.rb +0 -120
- data/spec/lib/http_stub/configurer/dsl/stub_builder_producer_spec.rb +0 -85
- data/spec/lib/http_stub/server/request_spec.rb +0 -24
- data/spec/lib/http_stub/server/scenario/activator_spec.rb +0 -111
- data/spec/support/http_stub/server/scenario/scenario_fixture.rb +0 -15
@@ -0,0 +1,25 @@
|
|
1
|
+
describe HttpStub::Server::Scenario::NotFoundError do
|
2
|
+
|
3
|
+
let(:scenario_name) { "Some scenario name" }
|
4
|
+
|
5
|
+
let(:error) { described_class.new(scenario_name) }
|
6
|
+
|
7
|
+
it "is a Standard Error" do
|
8
|
+
expect(error).to be_a(::StandardError)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#message" do
|
12
|
+
|
13
|
+
subject { error.message }
|
14
|
+
|
15
|
+
it "contains the name of the scenario" do
|
16
|
+
expect(subject).to include(scenario_name)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "indicates the scenario was not found" do
|
20
|
+
expect(subject).to include("not found")
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
describe HttpStub::Server::Session::Configuration do
|
2
|
+
|
3
|
+
let(:identifier_setting) { nil }
|
4
|
+
|
5
|
+
let(:configuration) { described_class.new(identifier_setting) }
|
6
|
+
|
7
|
+
describe "#identifer_configuration" do
|
8
|
+
|
9
|
+
subject { configuration.identifier_configuration }
|
10
|
+
|
11
|
+
shared_examples_for "an identifier configuration starting with the default configuration" do
|
12
|
+
|
13
|
+
it "has the http_stub session id parameter as the first entry" do
|
14
|
+
expect(subject.first).to eql(parameter: :http_stub_session_id)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "has the http_stub session id header as the second entry" do
|
18
|
+
expect(subject[1]).to eql(header: :http_stub_session_id)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
context "when a setting is provided" do
|
24
|
+
|
25
|
+
let(:identifier_setting) { { header: :custom_session_header } }
|
26
|
+
|
27
|
+
it_behaves_like "an identifier configuration starting with the default configuration"
|
28
|
+
|
29
|
+
it "returns a configuration containing the setting as the last entry" do
|
30
|
+
expect(subject.last).to eql(header: :custom_session_header)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "returns a configuration containing only the default settings and the provided setting" do
|
34
|
+
expect(subject.size).to eql(3)
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
context "when no setting is provided" do
|
40
|
+
|
41
|
+
let(:identifier_setting) { nil }
|
42
|
+
|
43
|
+
it_behaves_like "an identifier configuration starting with the default configuration"
|
44
|
+
|
45
|
+
it "returns a configuration containing only the default settings" do
|
46
|
+
expect(subject.size).to eql(2)
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "#default_identifier" do
|
54
|
+
|
55
|
+
subject { configuration.default_identifier }
|
56
|
+
|
57
|
+
it "has an original value that is the memory session id" do
|
58
|
+
expect(subject).to eql(HttpStub::Server::Session::MEMORY_SESSION_ID)
|
59
|
+
end
|
60
|
+
|
61
|
+
context "when changed" do
|
62
|
+
|
63
|
+
let(:new_identifier) { "some other identifier" }
|
64
|
+
|
65
|
+
before(:example) { configuration.default_identifier = new_identifier }
|
66
|
+
|
67
|
+
it "returns the newly assigned value" do
|
68
|
+
expect(subject).to eql(new_identifier)
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "#reset" do
|
76
|
+
|
77
|
+
subject { configuration.reset }
|
78
|
+
|
79
|
+
context "when the default indentifier has changed" do
|
80
|
+
|
81
|
+
before(:example) { configuration.default_identifier = "some other identifier" }
|
82
|
+
|
83
|
+
it "reverts the default identifier to it's original value" do
|
84
|
+
subject
|
85
|
+
|
86
|
+
expect(configuration.default_identifier).to eql(HttpStub::Server::Session::MEMORY_SESSION_ID)
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
describe HttpStub::Server::Session::Controller do
|
2
|
+
|
3
|
+
let(:session_configuration) { instance_double(HttpStub::Server::Session::Configuration) }
|
4
|
+
let(:session_registry) { instance_double(HttpStub::Server::Session::Registry) }
|
5
|
+
let(:server_memory) { instance_double(HttpStub::Server::Memory::Memory, sessions: session_registry) }
|
6
|
+
|
7
|
+
let(:session_id) { "some session id" }
|
8
|
+
let(:request) { instance_double(HttpStub::Server::Request::Request, session_id: session_id) }
|
9
|
+
let(:logger) { instance_double(Logger) }
|
10
|
+
|
11
|
+
let(:controller) { described_class.new(session_configuration, server_memory) }
|
12
|
+
|
13
|
+
describe "#find" do
|
14
|
+
|
15
|
+
subject { controller.find(request, logger) }
|
16
|
+
|
17
|
+
it "finds a session in the servers session registry with a session id matching that in the request" do
|
18
|
+
expect(session_registry).to receive(:find).with(session_id, logger)
|
19
|
+
|
20
|
+
subject
|
21
|
+
end
|
22
|
+
|
23
|
+
it "returns any found session" do
|
24
|
+
session = instance_double(HttpStub::Server::Session::Session)
|
25
|
+
allow(session_registry).to receive(:find).and_return(session)
|
26
|
+
|
27
|
+
expect(subject).to eql(session)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#find_transactional" do
|
33
|
+
|
34
|
+
subject { controller.find_transactional(logger) }
|
35
|
+
|
36
|
+
it "finds a session in the servers session registry with the transactional session id" do
|
37
|
+
expect(session_registry).to receive(:find).with(HttpStub::Server::Session::TRANSACTIONAL_SESSION_ID, logger)
|
38
|
+
|
39
|
+
subject
|
40
|
+
end
|
41
|
+
|
42
|
+
it "returns any found session" do
|
43
|
+
transactional_session = instance_double(HttpStub::Server::Session::Session)
|
44
|
+
allow(session_registry).to receive(:find).and_return(transactional_session)
|
45
|
+
|
46
|
+
expect(subject).to eql(transactional_session)
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "#find_all" do
|
52
|
+
|
53
|
+
subject { controller.find_all }
|
54
|
+
|
55
|
+
it "retrieves all sessions in the servers session reigstry" do
|
56
|
+
expect(session_registry).to receive(:all)
|
57
|
+
|
58
|
+
subject
|
59
|
+
end
|
60
|
+
|
61
|
+
it "returns the sessions" do
|
62
|
+
sessions = (1..3).map { instance_double(HttpStub::Server::Session::Session) }
|
63
|
+
allow(session_registry).to receive(:all).and_return(sessions)
|
64
|
+
|
65
|
+
expect(subject).to eql(sessions)
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "#mark_default" do
|
71
|
+
|
72
|
+
subject { controller.mark_default(request) }
|
73
|
+
|
74
|
+
it "establishes the default session identifier in the servers session configuration" do
|
75
|
+
expect(session_configuration).to receive(:default_identifier=).with(session_id)
|
76
|
+
|
77
|
+
subject
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "#delete" do
|
83
|
+
|
84
|
+
subject { controller.delete(request, logger) }
|
85
|
+
|
86
|
+
it "deletes the session identified in the request from servers session registry" do
|
87
|
+
expect(session_registry).to receive(:delete).with(session_id, logger)
|
88
|
+
|
89
|
+
subject
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "#clear" do
|
95
|
+
|
96
|
+
subject { controller.clear(logger) }
|
97
|
+
|
98
|
+
it "delegates to the servers session registry" do
|
99
|
+
expect(session_registry).to receive(:clear).with(logger)
|
100
|
+
|
101
|
+
subject
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
describe HttpStub::Server::Session::IdentifierStrategy do
|
2
|
+
|
3
|
+
let(:identifier_configuration) { {} }
|
4
|
+
let(:session_configuration) do
|
5
|
+
instance_double(HttpStub::Server::Session::Configuration, identifier_configuration: identifier_configuration)
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:identifier_strategy) { described_class.new(session_configuration) }
|
9
|
+
|
10
|
+
describe "#identifier_for" do
|
11
|
+
|
12
|
+
let(:request_headers) { {} }
|
13
|
+
let(:request_parameters) { {} }
|
14
|
+
let(:sinatra_request) do
|
15
|
+
instance_double(HttpStub::Server::Request::SinatraRequest, headers: request_headers,
|
16
|
+
parameters: request_parameters)
|
17
|
+
end
|
18
|
+
|
19
|
+
subject { identifier_strategy.identifier_for(sinatra_request) }
|
20
|
+
|
21
|
+
context "when the session identifier configuration has multiple entries" do
|
22
|
+
|
23
|
+
let(:identifier_configuration) do
|
24
|
+
[
|
25
|
+
{ header: :first_session_header },
|
26
|
+
{ parameter: :first_session_parameter },
|
27
|
+
{ header: :second_session_header },
|
28
|
+
{ parameter: :second_session_parameter }
|
29
|
+
]
|
30
|
+
end
|
31
|
+
|
32
|
+
context "and multiple session values are in the request" do
|
33
|
+
|
34
|
+
let(:request_headers) do
|
35
|
+
{ second_session_header: "second session header value", another_header: "another header value" }
|
36
|
+
end
|
37
|
+
let(:request_parameters) do
|
38
|
+
{ first_session_parameter: "first session parameter value", another_parameter: "another parameter value" }
|
39
|
+
end
|
40
|
+
|
41
|
+
it "returns the first value from the configuration in the request" do
|
42
|
+
expect(subject).to eql("first session parameter value")
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
context "and one session value is in the request" do
|
48
|
+
|
49
|
+
let(:request_headers) { { a_header: "a header value" } }
|
50
|
+
let(:request_parameters) do
|
51
|
+
{ second_session_parameter: "second session parameter value", another_parameter: "another parameter value" }
|
52
|
+
end
|
53
|
+
|
54
|
+
it "returns the value" do
|
55
|
+
expect(subject).to eql("second session parameter value")
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
context "and the session value is not in the request" do
|
61
|
+
|
62
|
+
it "returns nil" do
|
63
|
+
expect(subject).to eql(nil)
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
context "when the session identifier configuration has one entry" do
|
71
|
+
|
72
|
+
context "that is a header" do
|
73
|
+
|
74
|
+
let(:identifier_configuration) { [ { header: :session_header } ] }
|
75
|
+
|
76
|
+
context "and the session value is in the request" do
|
77
|
+
|
78
|
+
let(:request_headers) { { session_header: "session header value", another_header: "another header value" } }
|
79
|
+
|
80
|
+
it "returns the value" do
|
81
|
+
expect(subject).to eql("session header value")
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
context "and the session value is not in the request" do
|
87
|
+
|
88
|
+
it "returns nil" do
|
89
|
+
expect(subject).to eql(nil)
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
context "that is a parameter" do
|
97
|
+
|
98
|
+
let(:identifier_configuration) { [ { parameter: :session_parameter } ] }
|
99
|
+
|
100
|
+
context "and the session value is in the request" do
|
101
|
+
|
102
|
+
let(:request_parameters) do
|
103
|
+
{ session_parameter: "session parameter value", another_parameter: "another parameter value" }
|
104
|
+
end
|
105
|
+
|
106
|
+
it "returns the value" do
|
107
|
+
expect(subject).to eql("session parameter value")
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
context "and the session value is not in the request" do
|
113
|
+
|
114
|
+
it "returns nil" do
|
115
|
+
expect(subject).to eql(nil)
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
@@ -0,0 +1,214 @@
|
|
1
|
+
describe HttpStub::Server::Session::Registry do
|
2
|
+
|
3
|
+
let(:default_session_id) { "some default session id" }
|
4
|
+
let(:session_configuration) do
|
5
|
+
instance_double(HttpStub::Server::Session::Configuration, default_identifier: default_session_id)
|
6
|
+
end
|
7
|
+
let(:scenario_registry) { instance_double(HttpStub::Server::Registry) }
|
8
|
+
let(:memory_session) { instance_double(HttpStub::Server::Session::Session) }
|
9
|
+
|
10
|
+
let(:logger) { instance_double(Logger) }
|
11
|
+
let(:underlying_session_registry) { instance_double(HttpStub::Server::Registry) }
|
12
|
+
|
13
|
+
let(:session_registry) { described_class.new(session_configuration, scenario_registry, memory_session) }
|
14
|
+
|
15
|
+
before(:example) { allow(HttpStub::Server::Registry).to receive(:new).and_return(underlying_session_registry) }
|
16
|
+
|
17
|
+
it "uses an underlying simple registry that is initialized with the memory session" do
|
18
|
+
expect(HttpStub::Server::Registry).to receive(:new).with("session", [ memory_session ])
|
19
|
+
|
20
|
+
session_registry
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#find" do
|
24
|
+
|
25
|
+
let(:id) { SecureRandom.uuid }
|
26
|
+
|
27
|
+
let(:found_session) { instance_double(HttpStub::Server::Session::Session) }
|
28
|
+
|
29
|
+
subject { session_registry.find(id, logger) }
|
30
|
+
|
31
|
+
before(:example) { allow(underlying_session_registry).to receive(:find).and_return(found_session) }
|
32
|
+
|
33
|
+
it "delegates to an underlying simple registry" do
|
34
|
+
expect(underlying_session_registry).to receive(:find).with(id, logger)
|
35
|
+
|
36
|
+
subject
|
37
|
+
end
|
38
|
+
|
39
|
+
it "returns any found session" do
|
40
|
+
expect(subject).to eql(found_session)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "#find_or_create" do
|
46
|
+
|
47
|
+
let(:session_id) { "some session id" }
|
48
|
+
|
49
|
+
let(:found_session) { instance_double(HttpStub::Server::Session::Session) }
|
50
|
+
|
51
|
+
subject { session_registry.find_or_create(session_id, logger) }
|
52
|
+
|
53
|
+
before(:example) { allow(underlying_session_registry).to receive(:find).and_return(found_session) }
|
54
|
+
|
55
|
+
context "when an id is provided" do
|
56
|
+
|
57
|
+
it "attempts to find a session with the provided id in the underlying simple registry" do
|
58
|
+
expect(underlying_session_registry).to receive(:find).with(session_id, logger)
|
59
|
+
|
60
|
+
subject
|
61
|
+
end
|
62
|
+
|
63
|
+
context "and a session is not found" do
|
64
|
+
|
65
|
+
let(:found_session) { nil }
|
66
|
+
|
67
|
+
before(:example) { allow(underlying_session_registry).to receive(:add) }
|
68
|
+
|
69
|
+
it "creates a session with the provided id" do
|
70
|
+
expect(HttpStub::Server::Session::Session).to receive(:new).with(session_id, anything, anything)
|
71
|
+
|
72
|
+
subject
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
context "when an id is not provided" do
|
80
|
+
|
81
|
+
let(:session_id) { nil }
|
82
|
+
|
83
|
+
it "attempts to find a session with the default id defined in the session configuration" do
|
84
|
+
expect(underlying_session_registry).to receive(:find).with(default_session_id, logger)
|
85
|
+
|
86
|
+
subject
|
87
|
+
end
|
88
|
+
|
89
|
+
context "and a session is not found" do
|
90
|
+
|
91
|
+
let(:found_session) { nil }
|
92
|
+
|
93
|
+
before(:example) { allow(underlying_session_registry).to receive(:add) }
|
94
|
+
|
95
|
+
it "creates a session with the default session id" do
|
96
|
+
expect(HttpStub::Server::Session::Session).to receive(:new).with(default_session_id, anything, anything)
|
97
|
+
|
98
|
+
subject
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
context "when a session is found" do
|
106
|
+
|
107
|
+
let(:found_session) { instance_double(HttpStub::Server::Session::Session) }
|
108
|
+
|
109
|
+
it "returns the found session" do
|
110
|
+
expect(subject).to eql(found_session)
|
111
|
+
end
|
112
|
+
|
113
|
+
it "does not add a session to the underlying simple registry" do
|
114
|
+
expect(underlying_session_registry).to_not receive(:add)
|
115
|
+
|
116
|
+
subject
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
context "when a session is not found" do
|
122
|
+
|
123
|
+
let(:found_session) { nil }
|
124
|
+
let(:created_session) { instance_double(HttpStub::Server::Session::Session) }
|
125
|
+
|
126
|
+
before(:example) do
|
127
|
+
allow(HttpStub::Server::Session::Session).to receive(:new).and_return(created_session)
|
128
|
+
allow(underlying_session_registry).to receive(:add)
|
129
|
+
end
|
130
|
+
|
131
|
+
it "creates a session with the provided scenario registry" do
|
132
|
+
expect(HttpStub::Server::Session::Session).to receive(:new).with(anything, scenario_registry, anything)
|
133
|
+
|
134
|
+
subject
|
135
|
+
end
|
136
|
+
|
137
|
+
it "creates a session with the provided memory session" do
|
138
|
+
expect(HttpStub::Server::Session::Session).to receive(:new).with(anything, anything, memory_session)
|
139
|
+
|
140
|
+
subject
|
141
|
+
end
|
142
|
+
|
143
|
+
it "adds the created session to the underlying simple registry" do
|
144
|
+
expect(underlying_session_registry).to receive(:add).with(created_session, logger)
|
145
|
+
|
146
|
+
subject
|
147
|
+
end
|
148
|
+
|
149
|
+
it "returns the created session" do
|
150
|
+
expect(subject).to eql(created_session)
|
151
|
+
end
|
152
|
+
|
153
|
+
end
|
154
|
+
|
155
|
+
end
|
156
|
+
|
157
|
+
describe "#all" do
|
158
|
+
|
159
|
+
let(:sessions) { (1..3).map { instance_double(HttpStub::Server::Session::Session) } }
|
160
|
+
|
161
|
+
subject { session_registry.all }
|
162
|
+
|
163
|
+
before(:example) { allow(underlying_session_registry).to receive(:all).and_return(sessions) }
|
164
|
+
|
165
|
+
it "delegates to an underlying simple registry" do
|
166
|
+
expect(underlying_session_registry).to receive(:all)
|
167
|
+
|
168
|
+
subject
|
169
|
+
end
|
170
|
+
|
171
|
+
it "returns the result from the underlying simple registry" do
|
172
|
+
expect(subject).to eql(sessions)
|
173
|
+
end
|
174
|
+
|
175
|
+
end
|
176
|
+
|
177
|
+
describe "#delete" do
|
178
|
+
|
179
|
+
let(:id) { SecureRandom.uuid }
|
180
|
+
|
181
|
+
subject { session_registry.delete(id, logger) }
|
182
|
+
|
183
|
+
it "delegates to the underlying simple registry" do
|
184
|
+
expect(underlying_session_registry).to receive(:delete).with(id, logger)
|
185
|
+
|
186
|
+
subject
|
187
|
+
end
|
188
|
+
|
189
|
+
end
|
190
|
+
|
191
|
+
describe "#clear" do
|
192
|
+
|
193
|
+
subject { session_registry.clear(logger) }
|
194
|
+
|
195
|
+
before(:example) do
|
196
|
+
allow(memory_session).to receive(:clear)
|
197
|
+
allow(underlying_session_registry).to receive(:replace)
|
198
|
+
end
|
199
|
+
|
200
|
+
it "clears the memory session" do
|
201
|
+
expect(memory_session).to receive(:clear).with(logger)
|
202
|
+
|
203
|
+
subject
|
204
|
+
end
|
205
|
+
|
206
|
+
it "replaces all sessions in the underlying simple registry with the memory session" do
|
207
|
+
expect(underlying_session_registry).to receive(:replace).with([ memory_session ], logger)
|
208
|
+
|
209
|
+
subject
|
210
|
+
end
|
211
|
+
|
212
|
+
end
|
213
|
+
|
214
|
+
end
|