x-real-ip 0.1.1 → 0.1.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/x-real-ip/middleware.rb +4 -1
- data/lib/x-real-ip/version.rb +1 -1
- data/spec/x_forwarded_for_spec.rb +168 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf291cf813934ff5cea79959fccb44d84318d1e3
|
4
|
+
data.tar.gz: dea854479ed1c78e8b928abd4b9c57286b176152
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fea58c026d438d9b6166dbc89f2db035bec441b3659aac781e11a0d670eaf289a71540e7cef885d5878b8ebf59a6931e918dc2879ea9aa488a41559cb7c4b76d
|
7
|
+
data.tar.gz: 614fc853b2beb3cfec20993faaf87f05b130afcb25810a851dbc29367ad2b2a2230650f8fc92d24accabccb872382958f53cf6d726383a500a0f2ed392fe7c29
|
data/lib/x-real-ip/middleware.rb
CHANGED
@@ -18,7 +18,10 @@ module XRealIp
|
|
18
18
|
if real_ips
|
19
19
|
# for Rails logger
|
20
20
|
env["HTTP_X_FORWARDED_FOR"] = real_ips
|
21
|
-
|
21
|
+
else
|
22
|
+
real_ips = env["HTTP_X_FORWARDED_FOR"]
|
23
|
+
end
|
24
|
+
if real_ips
|
22
25
|
proxies = []
|
23
26
|
list = real_ips.split(',')
|
24
27
|
return @app.call(env) if list.empty?
|
data/lib/x-real-ip/version.rb
CHANGED
@@ -0,0 +1,168 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'X-Forwarded-For' do
|
5
|
+
before :each do
|
6
|
+
app = lambda { |env| @env = env; [ 200, {}, [] ] }
|
7
|
+
@req = Rack::MockRequest.new(XRealIp::Middleware.new(app))
|
8
|
+
end
|
9
|
+
|
10
|
+
context 'no proxy' do
|
11
|
+
context 'local ip' do
|
12
|
+
context 'http' do
|
13
|
+
before :each do
|
14
|
+
env = {
|
15
|
+
"REMOTE_ADDR" => "127.0.0.1",
|
16
|
+
}
|
17
|
+
@resp = @req.get("http://example.com/", env)
|
18
|
+
end
|
19
|
+
it 'sets ip' do
|
20
|
+
@env["REMOTE_ADDR"].should eq '127.0.0.1'
|
21
|
+
end
|
22
|
+
it 'sets proxy ip' do
|
23
|
+
@env["x.proxies"].should be_nil
|
24
|
+
end
|
25
|
+
it 'keeps http' do
|
26
|
+
@env["rack.url_scheme"].should eq 'http'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
context 'https' do
|
30
|
+
before :each do
|
31
|
+
env = {
|
32
|
+
"HTTP_X_FORWARDED_PROTO" => "https",
|
33
|
+
"REMOTE_ADDR" => "127.0.0.1",
|
34
|
+
}
|
35
|
+
@resp = @req.get("http://test.com/", env)
|
36
|
+
end
|
37
|
+
it 'sets ip' do
|
38
|
+
@env["REMOTE_ADDR"].should eq '127.0.0.1'
|
39
|
+
end
|
40
|
+
it 'sets proxy ip' do
|
41
|
+
@env["x.proxies"].should be_nil
|
42
|
+
end
|
43
|
+
it 'keeps http' do
|
44
|
+
@env["rack.url_scheme"].should eq 'http'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'one proxy' do
|
51
|
+
context 'local ip' do
|
52
|
+
context 'http' do
|
53
|
+
before :each do
|
54
|
+
env = {
|
55
|
+
"HTTP_X_FORWARDED_FOR" => "1.1.1.1",
|
56
|
+
"REMOTE_ADDR" => "127.0.0.1",
|
57
|
+
}
|
58
|
+
@resp = @req.get("http://test.com/", env)
|
59
|
+
end
|
60
|
+
it 'sets ip' do
|
61
|
+
@env["REMOTE_ADDR"].should eq '1.1.1.1'
|
62
|
+
end
|
63
|
+
it 'sets proxy ip' do
|
64
|
+
@env["x.proxies"].should eq '127.0.0.1'
|
65
|
+
end
|
66
|
+
it 'keeps http' do
|
67
|
+
@env["rack.url_scheme"].should eq 'http'
|
68
|
+
end
|
69
|
+
end
|
70
|
+
context 'https' do
|
71
|
+
before :each do
|
72
|
+
env = {
|
73
|
+
"HTTP_X_FORWARDED_FOR" => "1.1.1.1",
|
74
|
+
"HTTP_X_FORWARDED_PROTO" => "https",
|
75
|
+
"REMOTE_ADDR" => "127.0.0.1",
|
76
|
+
}
|
77
|
+
@resp = @req.get("http://test.com/", env)
|
78
|
+
end
|
79
|
+
it 'sets ip' do
|
80
|
+
@env["REMOTE_ADDR"].should eq '1.1.1.1'
|
81
|
+
end
|
82
|
+
it 'sets proxy ip' do
|
83
|
+
@env["x.proxies"].should eq '127.0.0.1'
|
84
|
+
end
|
85
|
+
it 'sets url scheme to https' do
|
86
|
+
@env["rack.url_scheme"].should eq 'https'
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context '2 proxies' do
|
93
|
+
context 'http' do
|
94
|
+
before :each do
|
95
|
+
env = {
|
96
|
+
"HTTP_X_FORWARDED_FOR" => "1.1.1.1,10.0.0.1",
|
97
|
+
"REMOTE_ADDR" => "127.0.0.1",
|
98
|
+
}
|
99
|
+
@resp = @req.get("http://test.com/", env)
|
100
|
+
end
|
101
|
+
it 'sets ip' do
|
102
|
+
@env["REMOTE_ADDR"].should eq '1.1.1.1'
|
103
|
+
end
|
104
|
+
it 'sets proxy ip' do
|
105
|
+
@env["x.proxies"].should eq '127.0.0.1,10.0.0.1'
|
106
|
+
end
|
107
|
+
it 'keeps http' do
|
108
|
+
@env["rack.url_scheme"].should eq 'http'
|
109
|
+
end
|
110
|
+
end
|
111
|
+
context 'https' do
|
112
|
+
before :each do
|
113
|
+
env = {
|
114
|
+
"HTTP_X_FORWARDED_FOR" => "1.1.1.1,10.0.0.1",
|
115
|
+
"HTTP_X_FORWARDED_PROTO" => "https",
|
116
|
+
"REMOTE_ADDR" => "127.0.0.1",
|
117
|
+
}
|
118
|
+
@resp = @req.get("http://test.com/", env)
|
119
|
+
end
|
120
|
+
it 'sets ip' do
|
121
|
+
@env["REMOTE_ADDR"].should eq '1.1.1.1'
|
122
|
+
end
|
123
|
+
it 'sets proxy ip' do
|
124
|
+
@env["x.proxies"].should eq '127.0.0.1,10.0.0.1'
|
125
|
+
end
|
126
|
+
it 'sets url scheme to https' do
|
127
|
+
@env["rack.url_scheme"].should eq 'https'
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
context 'spoofed' do
|
133
|
+
context 'one' do
|
134
|
+
before :each do
|
135
|
+
env = {
|
136
|
+
"HTTP_X_FORWARDED_FOR" => "1.1.1.1,2.2.2.2",
|
137
|
+
"REMOTE_ADDR" => "3.3.3.3",
|
138
|
+
}
|
139
|
+
@resp = @req.get("http://test.com/", env)
|
140
|
+
end
|
141
|
+
it 'sets ip' do
|
142
|
+
@env["REMOTE_ADDR"].should eq '3.3.3.3'
|
143
|
+
end
|
144
|
+
it 'doesnt st proxy ip' do
|
145
|
+
@env["x.proxies"].should eq ''
|
146
|
+
end
|
147
|
+
end
|
148
|
+
context 'chain' do
|
149
|
+
before :each do
|
150
|
+
env = {
|
151
|
+
"HTTP_X_FORWARDED_FOR" => "1.1.1.1,2.2.2.2",
|
152
|
+
"REMOTE_ADDR" => "127.0.0.1",
|
153
|
+
}
|
154
|
+
@resp = @req.get("http://test.com/", env)
|
155
|
+
end
|
156
|
+
it 'sets ip' do
|
157
|
+
@env["REMOTE_ADDR"].should eq '2.2.2.2'
|
158
|
+
end
|
159
|
+
it 'sets proxy ip' do
|
160
|
+
@env["x.proxies"].should eq '127.0.0.1'
|
161
|
+
end
|
162
|
+
it 'keeps http' do
|
163
|
+
@env["rack.url_scheme"].should eq 'http'
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: x-real-ip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- 55ideas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rpatricia
|
@@ -113,6 +113,7 @@ files:
|
|
113
113
|
- lib/x-real-ip/railtie.rb
|
114
114
|
- lib/x-real-ip/version.rb
|
115
115
|
- spec/spec_helper.rb
|
116
|
+
- spec/x_forwarded_for_spec.rb
|
116
117
|
- spec/x_real_ip_spec.rb
|
117
118
|
- x-real-ip.gemspec
|
118
119
|
homepage: https://github.com/55ideas/x-real-ip
|
@@ -141,4 +142,5 @@ specification_version: 4
|
|
141
142
|
summary: Replace REMOTE_IP with X-Real-Ip if it's trusted (useful for Nginx)
|
142
143
|
test_files:
|
143
144
|
- spec/spec_helper.rb
|
145
|
+
- spec/x_forwarded_for_spec.rb
|
144
146
|
- spec/x_real_ip_spec.rb
|