Skip to content

Commit cd78802

Browse files
author
Inbal Tako
committed
Add basic rails, hanami and sinatra tests
1 parent 610875d commit cd78802

File tree

4 files changed

+254
-4
lines changed

4 files changed

+254
-4
lines changed

Gemfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@ gem "rspec"
55
gem "rake"
66
gem "httpclient"
77
gem "parseconfig"
8-
gem "webmock"
9-
gem "simplecov"
8+
gem "simplecov", :require => false, :group => :test
9+
gem "webmock", :require => false, :group => :test
10+
gem "rails", :require => false, :group => :test
11+
gem "hanami", :require => false, :group => :test
12+
gem "sinatra", :require => false, :group => :test

Gemfile.lock

Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,202 @@ PATH
66
GEM
77
remote: https://rubygems.org/
88
specs:
9+
actioncable (6.0.3.2)
10+
actionpack (= 6.0.3.2)
11+
nio4r (~> 2.0)
12+
websocket-driver (>= 0.6.1)
13+
actionmailbox (6.0.3.2)
14+
actionpack (= 6.0.3.2)
15+
activejob (= 6.0.3.2)
16+
activerecord (= 6.0.3.2)
17+
activestorage (= 6.0.3.2)
18+
activesupport (= 6.0.3.2)
19+
mail (>= 2.7.1)
20+
actionmailer (6.0.3.2)
21+
actionpack (= 6.0.3.2)
22+
actionview (= 6.0.3.2)
23+
activejob (= 6.0.3.2)
24+
mail (~> 2.5, >= 2.5.4)
25+
rails-dom-testing (~> 2.0)
26+
actionpack (6.0.3.2)
27+
actionview (= 6.0.3.2)
28+
activesupport (= 6.0.3.2)
29+
rack (~> 2.0, >= 2.0.8)
30+
rack-test (>= 0.6.3)
31+
rails-dom-testing (~> 2.0)
32+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
33+
actiontext (6.0.3.2)
34+
actionpack (= 6.0.3.2)
35+
activerecord (= 6.0.3.2)
36+
activestorage (= 6.0.3.2)
37+
activesupport (= 6.0.3.2)
38+
nokogiri (>= 1.8.5)
39+
actionview (6.0.3.2)
40+
activesupport (= 6.0.3.2)
41+
builder (~> 3.1)
42+
erubi (~> 1.4)
43+
rails-dom-testing (~> 2.0)
44+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
45+
activejob (6.0.3.2)
46+
activesupport (= 6.0.3.2)
47+
globalid (>= 0.3.6)
48+
activemodel (6.0.3.2)
49+
activesupport (= 6.0.3.2)
50+
activerecord (6.0.3.2)
51+
activemodel (= 6.0.3.2)
52+
activesupport (= 6.0.3.2)
53+
activestorage (6.0.3.2)
54+
actionpack (= 6.0.3.2)
55+
activejob (= 6.0.3.2)
56+
activerecord (= 6.0.3.2)
57+
marcel (~> 0.3.1)
58+
activesupport (6.0.3.2)
59+
concurrent-ruby (~> 1.0, >= 1.0.2)
60+
i18n (>= 0.7, < 2)
61+
minitest (~> 5.1)
62+
tzinfo (~> 1.1)
63+
zeitwerk (~> 2.2, >= 2.2.2)
964
addressable (2.7.0)
1065
public_suffix (>= 2.0.2, < 5.0)
66+
builder (3.2.4)
67+
concurrent-ruby (1.1.7)
1168
crack (0.4.3)
1269
safe_yaml (~> 1.0.0)
70+
crass (1.0.6)
1371
diff-lcs (1.3)
1472
docile (1.3.2)
73+
dry-configurable (0.11.6)
74+
concurrent-ruby (~> 1.0)
75+
dry-core (~> 0.4, >= 0.4.7)
76+
dry-equalizer (~> 0.2)
77+
dry-container (0.7.2)
78+
concurrent-ruby (~> 1.0)
79+
dry-configurable (~> 0.1, >= 0.1.3)
80+
dry-core (0.4.9)
81+
concurrent-ruby (~> 1.0)
82+
dry-equalizer (0.3.0)
83+
dry-logic (0.4.2)
84+
dry-container (~> 0.2, >= 0.2.6)
85+
dry-core (~> 0.2)
86+
dry-equalizer (~> 0.2)
87+
dry-types (0.12.3)
88+
concurrent-ruby (~> 1.0)
89+
dry-configurable (~> 0.1)
90+
dry-container (~> 0.3)
91+
dry-core (~> 0.2, >= 0.2.1)
92+
dry-equalizer (~> 0.2)
93+
dry-logic (~> 0.4, >= 0.4.2)
94+
inflecto (~> 0.0.0, >= 0.0.2)
95+
dry-validation (0.11.2)
96+
concurrent-ruby (~> 1.0)
97+
dry-configurable (~> 0.1, >= 0.1.3)
98+
dry-core (~> 0.2, >= 0.2.1)
99+
dry-equalizer (~> 0.2)
100+
dry-logic (~> 0.4.2)
101+
dry-types (~> 0.12.0)
102+
erubi (1.9.0)
103+
globalid (0.4.2)
104+
activesupport (>= 4.2.0)
105+
hanami (1.3.3)
106+
bundler (>= 1.6, < 3)
107+
concurrent-ruby (~> 1.0)
108+
hanami-assets (~> 1.3)
109+
hanami-cli (~> 0.3)
110+
hanami-controller (~> 1.3)
111+
hanami-helpers (~> 1.3)
112+
hanami-mailer (~> 1.3)
113+
hanami-router (~> 1.3)
114+
hanami-utils (~> 1.3)
115+
hanami-validations (>= 1.3, < 3)
116+
hanami-view (~> 1.3)
117+
hanami-assets (1.3.4)
118+
hanami-helpers (~> 1.3)
119+
hanami-utils (~> 1.3)
120+
tilt (~> 2.0, >= 2.0.2)
121+
hanami-cli (0.3.1)
122+
concurrent-ruby (~> 1.0)
123+
hanami-utils (~> 1.3)
124+
hanami-controller (1.3.3)
125+
hanami-utils (~> 1.3)
126+
rack (~> 2.0)
127+
hanami-helpers (1.3.3)
128+
hanami-utils (~> 1.3)
129+
hanami-mailer (1.3.2)
130+
hanami-utils (~> 1.3)
131+
mail (~> 2.6)
132+
tilt (~> 2.0, >= 2.0.1)
133+
hanami-router (1.3.2)
134+
hanami-utils (~> 1.3)
135+
http_router (= 0.11.2)
136+
rack (~> 2.0)
137+
hanami-utils (1.3.6)
138+
concurrent-ruby (~> 1.0)
139+
transproc (~> 1.0)
140+
hanami-validations (1.3.6)
141+
dry-logic (~> 0.4.2, < 0.5)
142+
dry-validation (~> 0.11, < 0.12)
143+
hanami-utils (~> 1.3)
144+
hanami-view (1.3.3)
145+
hanami-utils (~> 1.3)
146+
tilt (~> 2.0, >= 2.0.1)
15147
hashdiff (1.0.1)
148+
http_router (0.11.2)
149+
rack (>= 1.0.0)
150+
url_mount (~> 0.2.1)
16151
httpclient (2.8.3)
152+
i18n (1.8.5)
153+
concurrent-ruby (~> 1.0)
154+
inflecto (0.0.2)
155+
loofah (2.6.0)
156+
crass (~> 1.0.2)
157+
nokogiri (>= 1.5.9)
158+
mail (2.7.1)
159+
mini_mime (>= 0.1.1)
160+
marcel (0.3.3)
161+
mimemagic (~> 0.3.2)
162+
method_source (1.0.0)
163+
mimemagic (0.3.5)
164+
mini_mime (1.0.2)
165+
mini_portile2 (2.4.0)
166+
minitest (5.14.1)
167+
mustermann (1.1.1)
168+
ruby2_keywords (~> 0.0.1)
169+
nio4r (2.5.2)
170+
nokogiri (1.10.10)
171+
mini_portile2 (~> 2.4.0)
17172
parseconfig (1.0.8)
18173
public_suffix (4.0.5)
174+
rack (2.2.3)
175+
rack-protection (2.0.8.1)
176+
rack
177+
rack-test (1.1.0)
178+
rack (>= 1.0, < 3)
179+
rails (6.0.3.2)
180+
actioncable (= 6.0.3.2)
181+
actionmailbox (= 6.0.3.2)
182+
actionmailer (= 6.0.3.2)
183+
actionpack (= 6.0.3.2)
184+
actiontext (= 6.0.3.2)
185+
actionview (= 6.0.3.2)
186+
activejob (= 6.0.3.2)
187+
activemodel (= 6.0.3.2)
188+
activerecord (= 6.0.3.2)
189+
activestorage (= 6.0.3.2)
190+
activesupport (= 6.0.3.2)
191+
bundler (>= 1.3.0)
192+
railties (= 6.0.3.2)
193+
sprockets-rails (>= 2.0.0)
194+
rails-dom-testing (2.0.3)
195+
activesupport (>= 4.2.0)
196+
nokogiri (>= 1.6)
197+
rails-html-sanitizer (1.3.0)
198+
loofah (~> 2.3)
199+
railties (6.0.3.2)
200+
actionpack (= 6.0.3.2)
201+
activesupport (= 6.0.3.2)
202+
method_source
203+
rake (>= 0.8.7)
204+
thor (>= 0.20.3, < 2.0)
19205
rake (13.0.1)
20206
rspec (3.8.0)
21207
rspec-core (~> 3.8.0)
@@ -30,27 +216,55 @@ GEM
30216
diff-lcs (>= 1.2.0, < 2.0)
31217
rspec-support (~> 3.8.0)
32218
rspec-support (3.8.2)
219+
ruby2_keywords (0.0.2)
33220
safe_yaml (1.0.5)
34221
simplecov (0.19.0)
35222
docile (~> 1.1)
36223
simplecov-html (~> 0.11)
37224
simplecov-html (0.12.2)
225+
sinatra (2.0.8.1)
226+
mustermann (~> 1.0)
227+
rack (~> 2.0)
228+
rack-protection (= 2.0.8.1)
229+
tilt (~> 2.0)
230+
sprockets (4.0.2)
231+
concurrent-ruby (~> 1.0)
232+
rack (> 1, < 3)
233+
sprockets-rails (3.2.1)
234+
actionpack (>= 4.0)
235+
activesupport (>= 4.0)
236+
sprockets (>= 3.0.0)
237+
thor (1.0.1)
238+
thread_safe (0.3.6)
239+
tilt (2.0.10)
240+
transproc (1.1.1)
241+
tzinfo (1.2.7)
242+
thread_safe (~> 0.1)
243+
url_mount (0.2.1)
244+
rack
38245
webmock (3.8.3)
39246
addressable (>= 2.3.6)
40247
crack (>= 0.3.2)
41248
hashdiff (>= 0.4.0, < 2.0.0)
249+
websocket-driver (0.7.3)
250+
websocket-extensions (>= 0.1.0)
251+
websocket-extensions (0.1.5)
252+
zeitwerk (2.4.0)
42253

43254
PLATFORMS
44255
ruby
45256

46257
DEPENDENCIES
47258
bundler (~> 2.0)
259+
hanami
48260
httpclient
49261
parseconfig
262+
rails
50263
rake
51264
rspec
52265
securenative!
53266
simplecov
267+
sinatra
54268
webmock
55269

56270
BUNDLED WITH

lib/utils/request_utils.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ class RequestUtils
55
SECURENATIVE_HEADER = 'x-securenative'
66

77
def self.get_secure_header_from_request(headers)
8-
return headers[SECURENATIVE_HEADER] unless headers.nil?
9-
8+
begin
9+
return headers[SECURENATIVE_HEADER] unless headers.nil?
10+
rescue StandardError
11+
[]
12+
end
1013
[]
1114
end
1215

spec/spec_context_builder.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
require 'context/securenative_context'
44
require 'webmock/rspec'
5+
require 'rails'
6+
require 'hanami'
7+
require 'sinatra'
58
require 'rspec'
69

710
RSpec.describe SecureNativeContext do
@@ -22,12 +25,39 @@
2225
end
2326

2427
it 'creates context from rails request' do
28+
request = ActionDispatch::Request.new(nil)
29+
context = SecureNativeContext.from_http_request(request)
30+
31+
expect(context.ip).to eq('')
32+
expect(context.http_method).to eq('')
33+
expect(context.url).to eq('')
34+
expect(context.remote_ip).to eq('')
35+
expect(context.headers).to eq([])
36+
expect(context.body).to eq('')
2537
end
2638

2739
it 'creates context from sinatra request' do
40+
request = Sinatra::Request.new(nil)
41+
context = SecureNativeContext.from_http_request(request)
42+
43+
expect(context.ip).to eq('')
44+
expect(context.http_method).to eq('')
45+
expect(context.url).to eq('')
46+
expect(context.remote_ip).to eq('')
47+
expect(context.headers).to eq([])
48+
expect(context.body).to eq('')
2849
end
2950

3051
it 'creates context from hanami request' do
52+
request = Hanami::Action::Request
53+
context = SecureNativeContext.from_http_request(request)
54+
55+
expect(context.ip).to eq('')
56+
expect(context.http_method).to eq('')
57+
expect(context.url).to eq('')
58+
expect(context.remote_ip).to eq('')
59+
expect(context.headers).to eq([])
60+
expect(context.body).to eq('')
3161
end
3262

3363
it 'creates default context builder' do

0 commit comments

Comments
 (0)