hawkei 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -0
  3. data/.rspec +1 -0
  4. data/.rubocop.yml +48 -0
  5. data/.ruby-version +1 -0
  6. data/.tool-versions +1 -0
  7. data/.travis.yml +11 -0
  8. data/Gemfile +12 -0
  9. data/LICENCE +21 -0
  10. data/Makefile +9 -0
  11. data/README.md +17 -0
  12. data/Rakefile +4 -0
  13. data/hawkei.gemspec +28 -0
  14. data/lib/hawkei/api_operation/delete.rb +38 -0
  15. data/lib/hawkei/api_operation/save.rb +57 -0
  16. data/lib/hawkei/api_resource.rb +130 -0
  17. data/lib/hawkei/batch.rb +18 -0
  18. data/lib/hawkei/config.rb +123 -0
  19. data/lib/hawkei/errors.rb +41 -0
  20. data/lib/hawkei/formated_logger.rb +45 -0
  21. data/lib/hawkei/hawkei_object.rb +179 -0
  22. data/lib/hawkei/library_name.rb +3 -0
  23. data/lib/hawkei/message.rb +79 -0
  24. data/lib/hawkei/plugins/rack/middleware.rb +139 -0
  25. data/lib/hawkei/plugins/rails/data.rb +19 -0
  26. data/lib/hawkei/plugins/rails/middleware_data.rb +28 -0
  27. data/lib/hawkei/plugins/rails/railtie.rb +23 -0
  28. data/lib/hawkei/plugins/sidekiq/client_middleware.rb +19 -0
  29. data/lib/hawkei/plugins/sidekiq/load.rb +14 -0
  30. data/lib/hawkei/plugins/sidekiq/server_middleware.rb +48 -0
  31. data/lib/hawkei/plugins.rb +17 -0
  32. data/lib/hawkei/processor/async.rb +50 -0
  33. data/lib/hawkei/processor/batch.rb +84 -0
  34. data/lib/hawkei/processor/worker.rb +113 -0
  35. data/lib/hawkei/request.rb +134 -0
  36. data/lib/hawkei/store.rb +49 -0
  37. data/lib/hawkei/util.rb +180 -0
  38. data/lib/hawkei/version.rb +3 -0
  39. data/lib/hawkei/watcher.rb +15 -0
  40. data/lib/hawkei.rb +170 -0
  41. data/spec/lib/hawkei/api_resource_spec.rb +109 -0
  42. data/spec/lib/hawkei/batch_spec.rb +14 -0
  43. data/spec/lib/hawkei/config_spec.rb +36 -0
  44. data/spec/lib/hawkei/formated_logger_spec.rb +99 -0
  45. data/spec/lib/hawkei/hawkei_object_spec.rb +123 -0
  46. data/spec/lib/hawkei/message_spec.rb +178 -0
  47. data/spec/lib/hawkei/plugins/rack/middleware_spec.rb +88 -0
  48. data/spec/lib/hawkei/plugins/rails/data_spec.rb +22 -0
  49. data/spec/lib/hawkei/plugins/rails/middleware_data_spec.rb +46 -0
  50. data/spec/lib/hawkei/plugins/sidekiq/client_middleware_spec.rb +15 -0
  51. data/spec/lib/hawkei/plugins/sidekiq/server_middleware_spec.rb +58 -0
  52. data/spec/lib/hawkei/processor/async_spec.rb +36 -0
  53. data/spec/lib/hawkei/processor/batch_spec.rb +51 -0
  54. data/spec/lib/hawkei/processor/worker_spec.rb +100 -0
  55. data/spec/lib/hawkei/store_spec.rb +82 -0
  56. data/spec/lib/hawkei/util_spec.rb +132 -0
  57. data/spec/lib/hawkei/watcher_spec.rb +25 -0
  58. data/spec/lib/hawkei_spec.rb +175 -0
  59. data/spec/spec_helper.rb +33 -0
  60. data/spec/support/rack_app.rb +12 -0
  61. metadata +206 -0
@@ -0,0 +1,109 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hawkei::APIResource do
4
+
5
+ describe '#request' do
6
+ subject(:resource) { Hawkei::APIResource.request(:post, '/test') }
7
+
8
+ context 'valid request' do
9
+ let(:response) { double('response', code: '200', code_type: Net::HTTPOK, body: {}.to_json) }
10
+
11
+ context 'default payload' do
12
+ let(:expected_payload) {{
13
+ method: :post,
14
+ url: 'http://localhost:4003/test',
15
+ payload: match(''),
16
+ use_ssl: false,
17
+ headers: {
18
+ accept: 'application/json',
19
+ content_type: 'application/json',
20
+ x_api_key: 'acc_xx',
21
+ x_space_name: 'Hawkei',
22
+ x_environment_name: 'test'
23
+ },
24
+ }}
25
+
26
+ after { resource }
27
+
28
+ it { expect(Hawkei::Request).to receive(:execute).with(expected_payload).and_return(response) }
29
+ end
30
+
31
+ context 'with body and post' do
32
+ let(:expected_payload) {{
33
+ method: :post,
34
+ url: 'http://localhost:4003/test',
35
+ payload: match("\"test\":true"),
36
+ use_ssl: false,
37
+ headers: {
38
+ accept: 'application/json',
39
+ content_type: 'application/json',
40
+ x_api_key: 'acc_xx',
41
+ x_space_name: 'Hawkei',
42
+ x_environment_name: 'test'
43
+ }
44
+ }}
45
+
46
+ after { Hawkei::APIResource.request(:post, '/test', { test: true }) }
47
+
48
+ it { expect(Hawkei::Request).to receive(:execute).with(expected_payload).and_return(response) }
49
+ end
50
+
51
+ context 'with body and get' do
52
+ let(:expected_payload) {{
53
+ method: :get,
54
+ url: match("http://localhost:4003/test\\?test=true"),
55
+ payload: match("\"test\":true"),
56
+ use_ssl: false,
57
+ headers: {
58
+ accept: 'application/json',
59
+ content_type: 'application/json',
60
+ x_api_key: 'acc_xx',
61
+ x_space_name: 'Hawkei',
62
+ x_environment_name: 'test'
63
+ }
64
+ }}
65
+
66
+ after { Hawkei::APIResource.request(:get, '/test', { test: true }) }
67
+
68
+ it { expect(Hawkei::Request).to receive(:execute).with(expected_payload).and_return(response) }
69
+ end
70
+
71
+ context 'with overwrite headers tokens' do
72
+ let(:expected_payload) {{
73
+ method: :post,
74
+ url: match('http://localhost:4003/test'),
75
+ payload: match(''),
76
+ use_ssl: false,
77
+ headers: {
78
+ accept: 'application/json',
79
+ content_type: 'application/json',
80
+ x_api_key: 'acc_42',
81
+ x_space_name: 'MySpace',
82
+ x_environment_name: 'staging'
83
+ }
84
+ }}
85
+
86
+ after { Hawkei::APIResource.request(:post, '/test', {}, api_key: 'acc_42', space_name: 'MySpace', environment_name: 'staging') }
87
+
88
+ it { expect(Hawkei::Request).to receive(:execute).with(expected_payload).and_return(response) }
89
+ end
90
+ end
91
+
92
+ context 'with errors' do
93
+ before { allow(Hawkei::Request).to receive(:execute).and_raise(Hawkei::RequestError.new(response)) }
94
+
95
+ context 'with Net::HTTPUnprocessableEntity' do
96
+ let(:response) { double('response', code: '422', code_type: Net::HTTPUnprocessableEntity, body: {}.to_json, message: 'failed') }
97
+
98
+ it { expect { resource }.to_not raise_error }
99
+ end
100
+
101
+ context 'with Net::HTTPBadRequest' do
102
+ let(:response) { double('response', code: '400', code_type: Net::HTTPBadRequest, body: {}.to_json, message: 'failed') }
103
+
104
+ it { expect { resource }.to raise_error(Hawkei::RequestError) }
105
+ end
106
+ end
107
+ end
108
+
109
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hawkei::Batch do
4
+
5
+ describe '.create' do
6
+ let(:response) { double('Hawkei::Request', body: "{\"object\":\"batch\",\"id\":41}") }
7
+ before { allow(Hawkei::Request).to receive(:execute).and_return(response) }
8
+
9
+ subject(:create) { Hawkei::Batch.create(data: []) }
10
+
11
+ it { is_expected.to be_successful }
12
+ end
13
+
14
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hawkei::Config do
4
+ subject(:config) { Hawkei::Config.new(params) }
5
+
6
+ describe '#initialize' do
7
+ let(:params) {{ api_key: 'acc_xx', space_name: 'Hawkei', environment_name: 'test' }}
8
+
9
+ it { expect(config.valid!).to be_truthy }
10
+
11
+ %i[api_key environment_name api_host api_version].each do |field|
12
+ context "validate #{field}" do
13
+ let(:params) {
14
+ {
15
+ api_key: 'acc_xx',
16
+ space_name: 'Hawkei',
17
+ environment_name: 'test',
18
+ api_host: 'host',
19
+ api_version: 'v1',
20
+ }.merge(field => '')
21
+ }
22
+
23
+ it { expect { config.valid! }.to raise_error(Hawkei::ConfigurationError, "#{field} can't be blank") }
24
+ end
25
+ end
26
+
27
+ context 'format obfuscated_fields' do
28
+ let(:params) {{ api_key: 'acc_xx', space_name: 'Hawkei', environment_name: 'test', obfuscated_fields: %i[another_password password_confirmation] }}
29
+
30
+ before { config.valid! }
31
+
32
+ it { expect(config.obfuscated_fields).to match_array(%w[another_password password_confirmation password access_token api_key authenticity_token ccv credit_card_number cvv secret secret_token token]) }
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,99 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hawkei::FormatedLogger do
4
+ let(:default_logger) { Logger.new(STDOUT) }
5
+ let(:logger) { Hawkei::FormatedLogger.build(default_logger) }
6
+
7
+ describe 'debug' do
8
+
9
+ context 'active' do
10
+ before do
11
+ allow(default_logger).to receive(:debug)
12
+ logger.debug('test')
13
+ end
14
+
15
+ it { expect(default_logger).to have_received(:debug).with('[Hawkei] test') }
16
+ end
17
+
18
+ context 'inactive' do
19
+ before do
20
+ Hawkei.configurations.log = false
21
+ allow(default_logger).to receive(:debug)
22
+ logger.debug('test')
23
+ end
24
+
25
+ it { expect(default_logger).to_not have_received(:debug) }
26
+ end
27
+
28
+ end
29
+
30
+ describe 'info' do
31
+
32
+ context 'active' do
33
+ before do
34
+ allow(default_logger).to receive(:info)
35
+ logger.info('test')
36
+ end
37
+
38
+ it { expect(default_logger).to have_received(:info).with('[Hawkei] test') }
39
+ end
40
+
41
+ context 'inactive' do
42
+ before do
43
+ Hawkei.configurations.log = false
44
+ allow(default_logger).to receive(:info)
45
+ logger.info('test')
46
+ end
47
+
48
+ it { expect(default_logger).to_not have_received(:info) }
49
+ end
50
+
51
+ end
52
+
53
+ describe 'info' do
54
+
55
+ context 'active' do
56
+ before do
57
+ allow(default_logger).to receive(:info)
58
+ logger.info('test')
59
+ end
60
+
61
+ it { expect(default_logger).to have_received(:info).with('[Hawkei] test') }
62
+ end
63
+
64
+ context 'inactive' do
65
+ before do
66
+ Hawkei.configurations.log = false
67
+ allow(default_logger).to receive(:info)
68
+ logger.info('test')
69
+ end
70
+
71
+ it { expect(default_logger).to_not have_received(:info) }
72
+ end
73
+
74
+ end
75
+
76
+ describe 'error' do
77
+
78
+ context 'active' do
79
+ before do
80
+ allow(default_logger).to receive(:error)
81
+ logger.error('test')
82
+ end
83
+
84
+ it { expect(default_logger).to have_received(:error).with('[Hawkei] test') }
85
+ end
86
+
87
+ context 'inactive' do
88
+ before do
89
+ Hawkei.configurations.log = false
90
+ allow(default_logger).to receive(:error)
91
+ logger.error('test')
92
+ end
93
+
94
+ it { expect(default_logger).to_not have_received(:error) }
95
+ end
96
+
97
+ end
98
+
99
+ end
@@ -0,0 +1,123 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hawkei::HawkeiObject do
4
+
5
+ let(:klass) { Class.new(Hawkei::HawkeiObject) }
6
+ subject(:instance) { klass.new(id: 42, name: 'test', test: true) }
7
+
8
+ let(:api_response) {{
9
+ object: 'event',
10
+ id: 42,
11
+ other: 'other test'
12
+ }}
13
+
14
+ let(:api_responses) {{
15
+ object: 'list',
16
+ currentPage: 10,
17
+ data: [{
18
+ object: 'watcher',
19
+ id: 42,
20
+ other: 'other test'
21
+ }],
22
+ links: {
23
+ self: 'http://www.hawkei.io/test'
24
+ }
25
+ }}
26
+
27
+ describe 'add attribute accessors' do
28
+ it { expect(instance.id).to eq(42) }
29
+ it { expect(instance.name).to eq('test') }
30
+ it { expect(instance.test).to be_truthy }
31
+ it { expect(instance.test?).to be_truthy }
32
+ end
33
+
34
+ describe 'add array attribute' do
35
+ it { expect(instance[:id]).to eq(42) }
36
+ it { expect(instance[:name]).to eq('test') }
37
+ it { expect(instance[:test]).to be_truthy }
38
+ end
39
+
40
+ describe 'set array attribute' do
41
+ before { instance[:id] = 84 }
42
+
43
+ it { expect(instance.id).to eq(84) }
44
+ it { expect(instance[:id]).to eq(84) }
45
+ end
46
+
47
+ describe 'method missing' do
48
+ before { instance.card = '42' }
49
+
50
+ it { expect(instance.card).to eq('42') }
51
+ it { expect { instance.other }.to raise_error(NameError) }
52
+ end
53
+
54
+ describe '#keys' do
55
+ it { expect(instance.keys).to match_array([:id, :name, :test]) }
56
+ end
57
+
58
+ describe '#to_hash' do
59
+ it { expect(instance.to_hash).to eq(id: 42, name: 'test', test: true) }
60
+ end
61
+
62
+ describe '#to_json' do
63
+ it { expect(instance.to_json).to eq(JSON.generate(id: 42, name: 'test', test: true)) }
64
+ end
65
+
66
+ describe '#add_data' do
67
+ before { instance.add_data(:test) }
68
+
69
+ it { expect(instance.data).to match_array([:test]) }
70
+ end
71
+
72
+ describe '#update_attributes' do
73
+ before { instance.update_attributes(id: 84, other: 'other test') }
74
+
75
+ it { expect(instance.id).to eq(84) }
76
+ it { expect(instance.other).to eq('other test') }
77
+ it { expect(instance.name).to eq('test') }
78
+ end
79
+
80
+ describe '.initialize_from' do
81
+ context 'with single object' do
82
+ subject(:instance) { klass.initialize_from(api_response.to_json) }
83
+
84
+ it { is_expected.to be_successful }
85
+ it { expect(instance.id).to eq(42) }
86
+ it { expect(instance.other).to eq('other test') }
87
+ it { expect { instance.name }.to raise_error(NameError) }
88
+ end
89
+
90
+ context 'with array' do
91
+ subject(:instance) { klass.initialize_from(api_responses.to_json) }
92
+
93
+ it { is_expected.to be_successful }
94
+ it { expect(instance.data.size).to eq(1) }
95
+ it { expect(instance.data.first).to be_a(Hawkei::Watcher) }
96
+ it { expect(instance.current_page).to eq(10) }
97
+ it { expect(instance.links[:self]).to eq('http://www.hawkei.io/test') }
98
+ end
99
+
100
+ context 'with empty string' do
101
+ subject(:instance) { klass.initialize_from('') }
102
+
103
+ it { is_expected.to be_successful }
104
+ end
105
+
106
+ context 'with nil' do
107
+ subject(:instance) { klass.initialize_from(nil) }
108
+
109
+ it { is_expected.to be_successful }
110
+ end
111
+ end
112
+
113
+ describe '#update_from' do
114
+ before { instance.update_from(api_response) }
115
+
116
+ it { is_expected.to be_successful }
117
+ it { expect(instance.id).to eq(42) }
118
+ it { expect(instance.other).to eq('other test') }
119
+ it { expect { instance.name }.to raise_error(NameError) }
120
+ end
121
+
122
+
123
+ end
@@ -0,0 +1,178 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hawkei::Message do
4
+ subject(:base) { Hawkei::Message }
5
+
6
+ describe '#base' do
7
+ let(:expected_hash) {{
8
+ message_id: kind_of(String),
9
+ timestamp: kind_of(String),
10
+ session_tracker_id: kind_of(String),
11
+ }}
12
+
13
+ it { expect(base.base).to match(expected_hash) }
14
+
15
+ context 'with store' do
16
+ before do
17
+ Hawkei::Store.set(:session_tracker_id, 'hello')
18
+ end
19
+
20
+ let(:expected_hash) {{
21
+ message_id: kind_of(String),
22
+ timestamp: kind_of(String),
23
+ session_tracker_id: 'hello',
24
+ }}
25
+
26
+ it { expect(base.base).to match(expected_hash) }
27
+ end
28
+ end
29
+
30
+ describe '#extended' do
31
+ let(:expected_hash) {{
32
+ message_id: kind_of(String),
33
+ timestamp: kind_of(String),
34
+ session_tracker_id: kind_of(String),
35
+ environment: 'test',
36
+ library: {
37
+ name: "hawkei",
38
+ language: "ruby",
39
+ version: kind_of(String)
40
+ },
41
+ server: {
42
+ host: kind_of(String),
43
+ pid: kind_of(Numeric),
44
+ software: 'rspec'
45
+ }
46
+ }}
47
+
48
+ it { expect(base.extended).to match(expected_hash) }
49
+
50
+ context 'with store' do
51
+ before do
52
+ Hawkei::Store.set(:session_tracker_id, 'hello')
53
+ Hawkei::Store.set(:request,
54
+ url: 'http://www.test.com/',
55
+ ssl: true,
56
+ host: 'www.test.com',
57
+ port: 4242,
58
+ path: '/',
59
+ referrer: 'http://www.google.com/',
60
+ method: 'GET',
61
+ xhr: false,
62
+ user_agent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36',
63
+ ip: '127.0.0.1',
64
+ )
65
+ Hawkei::Store.set(:worker,
66
+ name: 'sidekiq',
67
+ version: '5.0.4',
68
+ queue: 'chameleon',
69
+ class: 'Hawkei::AsyncHandlers::Sidekiq',
70
+ id: '106a61579bc0e7e3d18e3b1c',
71
+ created_at: '2017-12-15T03:45:10Z',
72
+ process_at: '2017-12-15T03:45:10Z',
73
+ args: ['Hawkei::Event']
74
+ )
75
+
76
+ Hawkei::Store.bulk_set(
77
+ environment: 'production',
78
+ server_software: 'WEBrick/1.3.1 (Ruby/2.2.7/2017-03-28)'
79
+ )
80
+ end
81
+
82
+ let(:expected_hash) {{
83
+ message_id: kind_of(String),
84
+ timestamp: kind_of(String),
85
+ session_tracker_id: 'hello',
86
+ library: {
87
+ name: 'hawkei',
88
+ language: 'ruby',
89
+ version: kind_of(String)
90
+ },
91
+ server: {
92
+ host: kind_of(String),
93
+ pid: kind_of(Numeric),
94
+ software: 'WEBrick/1.3.1 (Ruby/2.2.7/2017-03-28)'
95
+ },
96
+ request: {
97
+ url: 'http://www.test.com/',
98
+ ssl: true,
99
+ host: 'www.test.com',
100
+ port: 4242,
101
+ path: '/',
102
+ referrer: 'http://www.google.com/',
103
+ method: 'GET',
104
+ xhr: false,
105
+ user_agent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36',
106
+ ip: '127.0.0.1',
107
+ },
108
+ worker: {
109
+ name: 'sidekiq',
110
+ version: '5.0.4',
111
+ queue: 'chameleon',
112
+ class: 'Hawkei::AsyncHandlers::Sidekiq',
113
+ id: '106a61579bc0e7e3d18e3b1c',
114
+ created_at: '2017-12-15T03:45:10Z',
115
+ process_at: '2017-12-15T03:45:10Z',
116
+ args: ['Hawkei::Event']
117
+ },
118
+ environment: 'production'
119
+ }}
120
+
121
+ it { expect(base.extended).to match(expected_hash) }
122
+ end
123
+
124
+ context 'with metadata' do
125
+ let(:expected_hash) {{
126
+ message_id: kind_of(String),
127
+ timestamp: kind_of(String),
128
+ session_tracker_id: kind_of(String),
129
+ environment: 'test',
130
+ library: {
131
+ name: "hawkei",
132
+ language: "ruby",
133
+ version: kind_of(String)
134
+ },
135
+ server: {
136
+ host: kind_of(String),
137
+ pid: kind_of(Numeric),
138
+ software: 'rspec'
139
+ },
140
+ metadata: {
141
+ deployment_id: 42
142
+ },
143
+ }}
144
+
145
+ context 'hash type' do
146
+ before do
147
+ Hawkei.configurations.metadata = {
148
+ deployment_id: 42
149
+ }
150
+ end
151
+
152
+ it { expect(base.extended).to match(expected_hash) }
153
+ end
154
+
155
+ context 'proc type' do
156
+ before do
157
+ Hawkei.configurations.metadata = {
158
+ deployment_id: lambda { 84 / 2 }
159
+ }
160
+ end
161
+
162
+ it { expect(base.extended).to match(expected_hash) }
163
+ end
164
+
165
+ context 'proc & raise type' do
166
+ before do
167
+ Hawkei.configurations.metadata = {
168
+ deployment_id: -> { 84 / 2 },
169
+ other_id: -> { hello }
170
+ }
171
+ end
172
+
173
+ it { expect(base.extended).to match(expected_hash) }
174
+ end
175
+ end
176
+ end
177
+
178
+ end
@@ -0,0 +1,88 @@
1
+ require 'spec_helper'
2
+ require 'rack'
3
+ require 'hawkei/plugins/rack/middleware'
4
+
5
+ describe Hawkei::Plugins::Rack::Middleware do
6
+
7
+ let(:app) { lambda { |env| [200, {'Content-Type' => 'text/plain'}, ['All responses are OK']] } }
8
+ let(:middleware) { Hawkei::Plugins::Rack::Middleware.new(app) }
9
+
10
+ context 'reset the store' do
11
+ before do
12
+ 2.times { middleware.call({}) }
13
+ end
14
+
15
+ it { expect(Hawkei::Store.store).to eq({}) }
16
+ end
17
+
18
+ it 'reset the store with error' do
19
+ allow(middleware).to receive(:call).and_raise(RuntimeError)
20
+ expect { middleware.call(error: true) }.to raise_error(RuntimeError)
21
+
22
+ expect(Hawkei::Store.store).to eq({})
23
+ end
24
+
25
+ it 'set correct value for cookies' do
26
+ _status, headers, _body = middleware.call({})
27
+
28
+ expect(headers['Set-Cookie']).to match(%r{path=/})
29
+ expect(headers['Set-Cookie']).to match(%r{max-age=315360000})
30
+ expect(headers['Set-Cookie']).to_not match(%r{domain})
31
+ end
32
+
33
+ it 'set correct value for cookies with domain' do
34
+ Hawkei.configurations.domain = "hawkei.io"
35
+ _status, headers, _body = middleware.call({})
36
+
37
+ expect(headers['Set-Cookie']).to match(%r{path=/})
38
+ expect(headers['Set-Cookie']).to match(%r{max-age=315360000})
39
+ expect(headers['Set-Cookie']).to match(%r{domain=hawkei.io})
40
+ end
41
+
42
+ it 'store the request' do
43
+ _status, headers, _body = middleware.call({
44
+ 'hawkei_test' => true,
45
+ 'HTTP_HOST' => '127.0.0.1:3000',
46
+ 'HTTP_REFERER' => 'http://127.0.0.1:3000/?hello=test&password=1234',
47
+ 'HTTP_COOKIE' => 'other',
48
+ 'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
49
+ 'HTTP_VERSION' => 'HTTP/1.1',
50
+ 'HTTP_USER_AGENT' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36',
51
+ 'HTTP_CONTENT_TYPE' => 'application/x-www-form-urlencoded',
52
+ 'HTTP_CACHE_CONTROL' => 'max-age=0',
53
+ 'HTTP_CONTENT_LENGTH' => '190',
54
+ 'HTTP_ACCEPT_ENCODING' => 'gzip, deflate, br',
55
+ 'HTTP_ACCEPT_LANGUAGE' => 'en-US,en;q=0.9,fr;q=0.8,ru;q=0.7',
56
+ })
57
+
58
+ expected = {
59
+ :url => "",
60
+ :ssl => false,
61
+ :host => "127.0.0.1",
62
+ :port => 3000,
63
+ :path => "",
64
+ :referrer => "http://127.0.0.1:3000/?hello=test&password=HIDDEN",
65
+ :method => nil,
66
+ :xhr => false,
67
+ :user_agent => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36",
68
+ :ip => nil,
69
+ :get_params => {},
70
+ :post_params => {},
71
+ :headers => {
72
+ "Accept" => "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
73
+ "Accept-Encoding" => "gzip, deflate, br",
74
+ "Accept-Language" => "en-US,en;q=0.9,fr;q=0.8,ru;q=0.7",
75
+ "Cache-Control" => "max-age=0",
76
+ "Content-Length" => "190",
77
+ "Content-Type" => "application/x-www-form-urlencoded",
78
+ "Host" => "127.0.0.1:3000",
79
+ "Referer" => "http://127.0.0.1:3000/?hello=test&password=1234",
80
+ "User-Agent" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36",
81
+ "Version" => "HTTP/1.1"
82
+ }
83
+ }
84
+
85
+ expect(Hawkei::Store.store[:request]).to include(expected)
86
+ end
87
+
88
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+ require 'rails'
3
+ require 'hawkei/plugins/rails/data'
4
+
5
+ describe Hawkei::Plugins::Rails::Data do
6
+
7
+ let(:middleware) { Hawkei::Plugins::Rails::Data }
8
+
9
+ describe '#store_data' do
10
+
11
+ context 'blank store' do
12
+ before { middleware.store_data }
13
+
14
+ let(:expected) {{
15
+ environment: kind_of(String)
16
+ }}
17
+
18
+ it { expect(Hawkei::Store.store).to match(expected) }
19
+ end
20
+
21
+ end
22
+ end