browsermob-proxy 0.1.4 → 0.1.5
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/.gitignore +2 -1
- data/.travis.yml +3 -3
- data/README.md +2 -2
- data/lib/browsermob/proxy/client.rb +40 -0
- data/lib/browsermob/proxy/version.rb +1 -1
- data/spec/e2e/selenium_spec.rb +27 -0
- data/spec/spec_helper.rb +17 -1
- data/spec/unit/client_spec.rb +36 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12560fbaf3be7cee85565cdafc44429b393a3ca6
|
4
|
+
data.tar.gz: 2261e5b2be1871c539351af9b4cbd6a3beaa6591
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45fbe33909820112dc59664407358a01ad7b7600fe25558ff8db3623ca4beb3c3a003c85aacdbb873376c64e05235621c267fd6361fdf3f3c4addd88079a773b
|
7
|
+
data.tar.gz: 3d84b98806736425abefaebaf11e2805a80d4e02dff4aaa4c906b6395c5b6db457fba722e1fe2cba8b945d1f7f80fb7514a551e2f60556d46c7cfe9fa47892b0
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -3,9 +3,9 @@ rvm:
|
|
3
3
|
- 2.0.0
|
4
4
|
before_script:
|
5
5
|
- sudo apt-get install -y unzip
|
6
|
-
- curl -k -L -O https://s3-us-west-1.amazonaws.com/lightbody-bmp/browsermob-proxy-2.0-beta-
|
7
|
-
- unzip browsermob-proxy-2.0-beta-
|
8
|
-
- export BROWSERMOB_PROXY_HOME=`pwd`/browsermob-proxy-2.0-beta-
|
6
|
+
- curl -k -L -O https://s3-us-west-1.amazonaws.com/lightbody-bmp/browsermob-proxy-2.0-beta-9-bin.zip
|
7
|
+
- unzip browsermob-proxy-2.0-beta-9-bin.zip
|
8
|
+
- export BROWSERMOB_PROXY_HOME=`pwd`/browsermob-proxy-2.0-beta-9
|
9
9
|
- sudo chmod +x $BROWSERMOB_PROXY_HOME/bin/browsermob-proxy
|
10
10
|
- sh -e /etc/init.d/xvfb start
|
11
11
|
- export DISPLAY=:99
|
data/README.md
CHANGED
@@ -38,7 +38,7 @@ driver.quit
|
|
38
38
|
|
39
39
|
With event listener:
|
40
40
|
|
41
|
-
```
|
41
|
+
```ruby
|
42
42
|
require 'selenium/webdriver'
|
43
43
|
require 'browsermob/proxy'
|
44
44
|
require 'browsermob/proxy/webdriver_listener'
|
@@ -65,7 +65,7 @@ The HAR gem includes a HAR viewer. After running the code above, you can view th
|
|
65
65
|
See also
|
66
66
|
--------
|
67
67
|
|
68
|
-
* http://
|
68
|
+
* http://bmp.lightbody.net/
|
69
69
|
* https://github.com/lightbody/browsermob-proxy
|
70
70
|
|
71
71
|
Note on Patches/Pull Requests
|
@@ -93,11 +93,19 @@ module BrowserMob
|
|
93
93
|
@resource['whitelist'].put :regex => regex, :status => status_code
|
94
94
|
end
|
95
95
|
|
96
|
+
def clear_whitelist
|
97
|
+
@resource['whitelist'].delete
|
98
|
+
end
|
99
|
+
|
96
100
|
def blacklist(regexp, status_code)
|
97
101
|
regex = Regexp === regexp ? regexp.source : regexp.to_s
|
98
102
|
@resource['blacklist'].put :regex => regex, :status => status_code
|
99
103
|
end
|
100
104
|
|
105
|
+
def clear_blacklist
|
106
|
+
@resource['blacklist'].delete
|
107
|
+
end
|
108
|
+
|
101
109
|
def header(hash)
|
102
110
|
@resource['headers'].post hash.to_json, :content_type => "application/json"
|
103
111
|
end
|
@@ -108,6 +116,38 @@ module BrowserMob
|
|
108
116
|
@resource["auth/basic/#{domain}"].post data.to_json, :content_type => "application/json"
|
109
117
|
end
|
110
118
|
|
119
|
+
#
|
120
|
+
# Specify timeouts that will be used by a proxy
|
121
|
+
# (see README of browsermob-proxy itself for more info about what they mean)
|
122
|
+
#
|
123
|
+
# @param timeouts [Hash] options that specify desired timeouts (in seconds)
|
124
|
+
# @option timeouts [Numeric] :request request timeout
|
125
|
+
# @option timeouts [Numeric] :read read timeout
|
126
|
+
# @option timeouts [Numeric] :connection connection timeout
|
127
|
+
# @option timeouts [Numeric] :dns_cache dns cache timeout
|
128
|
+
#
|
129
|
+
|
130
|
+
TIMEOUTS = {
|
131
|
+
request: :requestTimeout,
|
132
|
+
read: :readTimeout,
|
133
|
+
connection: :connectionTimeout,
|
134
|
+
dns_cache: :dnsCacheTimeout
|
135
|
+
}
|
136
|
+
|
137
|
+
def timeouts(timeouts = {})
|
138
|
+
params = {}
|
139
|
+
|
140
|
+
timeouts.each do |key, value|
|
141
|
+
unless TIMEOUTS.member?(key)
|
142
|
+
raise ArgumentError, "invalid key: #{key.inspect}, should belong to: #{TIMEOUTS.keys.inspect}"
|
143
|
+
end
|
144
|
+
|
145
|
+
params[TIMEOUTS[key]] = (value * 1000).to_i
|
146
|
+
end
|
147
|
+
|
148
|
+
@resource['timeout'].put params
|
149
|
+
end
|
150
|
+
|
111
151
|
#
|
112
152
|
# Override normal DNS lookups (remap the given hosts with the associated IP address).
|
113
153
|
#
|
data/spec/e2e/selenium_spec.rb
CHANGED
@@ -86,6 +86,15 @@ describe "Proxy + WebDriver" do
|
|
86
86
|
driver.get url_for('2.html')
|
87
87
|
proxy.har.entries.first.response.status.should == 404
|
88
88
|
end
|
89
|
+
|
90
|
+
it "can be cleared" do
|
91
|
+
proxy.new_har('whitelist')
|
92
|
+
proxy.whitelist('foo\.bar\.com', 404)
|
93
|
+
|
94
|
+
proxy.clear_whitelist
|
95
|
+
driver.get url_for('2.html')
|
96
|
+
proxy.har.entries.first.response.status.should_not == 404
|
97
|
+
end
|
89
98
|
end
|
90
99
|
|
91
100
|
describe 'blacklist' do
|
@@ -105,6 +114,24 @@ describe "Proxy + WebDriver" do
|
|
105
114
|
|
106
115
|
wait.until { driver.title == '2' }
|
107
116
|
end
|
117
|
+
|
118
|
+
it "can be cleared" do
|
119
|
+
proxy.new_har('blacklist')
|
120
|
+
|
121
|
+
dest = url_for('1.html')
|
122
|
+
proxy.blacklist(Regexp.quote(dest), 404)
|
123
|
+
|
124
|
+
proxy.clear_blacklist
|
125
|
+
driver.get dest
|
126
|
+
|
127
|
+
proxy.har.entries.first.response.status.should_not == 404
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'should set timeouts' do
|
132
|
+
proxy.timeouts(read: 0.001)
|
133
|
+
driver.get url_for('slow')
|
134
|
+
wait.until { driver.title == 'Problem loading page' } # This title appears in Firefox
|
108
135
|
end
|
109
136
|
|
110
137
|
it "should set headers" do
|
data/spec/spec_helper.rb
CHANGED
@@ -9,7 +9,7 @@ module BrowserMob
|
|
9
9
|
module Proxy
|
10
10
|
module SpecHelper
|
11
11
|
def self.httpd
|
12
|
-
@httpd ||= HttpServer.new(Rack::File.new(fixture_dir))
|
12
|
+
@httpd ||= HttpServer.new(SpecApp.new(Rack::File.new(fixture_dir)))
|
13
13
|
end
|
14
14
|
|
15
15
|
def self.fixture_dir
|
@@ -68,6 +68,22 @@ module BrowserMob
|
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
|
+
class SpecApp
|
72
|
+
def initialize(app)
|
73
|
+
@app = app
|
74
|
+
end
|
75
|
+
|
76
|
+
def call(env)
|
77
|
+
case env['REQUEST_PATH']
|
78
|
+
when '/slow'
|
79
|
+
sleep 0.1
|
80
|
+
[200, {}, []]
|
81
|
+
else
|
82
|
+
@app.call(env)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
71
87
|
end
|
72
88
|
end
|
73
89
|
end
|
data/spec/unit/client_spec.rb
CHANGED
@@ -18,7 +18,8 @@ module BrowserMob
|
|
18
18
|
"limit" => double("resource[limit]"),
|
19
19
|
"headers" => double("resource[headers]"),
|
20
20
|
"auth/basic/#{DOMAIN}" => double("resource[auth/basic/#{DOMAIN}]"),
|
21
|
-
"hosts" => double("resource[hosts]")
|
21
|
+
"hosts" => double("resource[hosts]"),
|
22
|
+
"timeout" => double("resource[timeout]")
|
22
23
|
}.each do |path, mock|
|
23
24
|
resource.stub(:[]).with(path).and_return(mock)
|
24
25
|
end
|
@@ -120,6 +121,12 @@ module BrowserMob
|
|
120
121
|
client.blacklist(%r[http://example.com], 401)
|
121
122
|
end
|
122
123
|
|
124
|
+
it "clears the blacklist" do
|
125
|
+
resource['blacklist'].should_receive(:delete)
|
126
|
+
|
127
|
+
client.clear_blacklist
|
128
|
+
end
|
129
|
+
|
123
130
|
describe 'whitelist' do
|
124
131
|
it "supports a string" do
|
125
132
|
resource['whitelist'].should_receive(:put).
|
@@ -141,6 +148,12 @@ module BrowserMob
|
|
141
148
|
|
142
149
|
client.whitelist([%r{http://example\.com/1/.+}, 'http://example\.com/2/.+'], 401)
|
143
150
|
end
|
151
|
+
|
152
|
+
it "clears the whitelist" do
|
153
|
+
resource['whitelist'].should_receive(:delete)
|
154
|
+
|
155
|
+
client.clear_whitelist
|
156
|
+
end
|
144
157
|
end
|
145
158
|
|
146
159
|
it "sets the :downstream_kbps limit" do
|
@@ -189,6 +202,28 @@ module BrowserMob
|
|
189
202
|
client.basic_authentication(DOMAIN, user, password)
|
190
203
|
end
|
191
204
|
|
205
|
+
describe 'timeouts' do
|
206
|
+
it 'supports valid options' do
|
207
|
+
resource['timeout'].should_receive(:put).with(
|
208
|
+
:requestTimeout => 1,
|
209
|
+
:readTimeout => 2000,
|
210
|
+
:connectionTimeout => 3000,
|
211
|
+
:dnsCacheTimeout => 6_000_000
|
212
|
+
)
|
213
|
+
|
214
|
+
client.timeouts(
|
215
|
+
:request => 0.001,
|
216
|
+
:read => 2,
|
217
|
+
:connection => 3,
|
218
|
+
:dns_cache => 6000
|
219
|
+
)
|
220
|
+
end
|
221
|
+
|
222
|
+
it 'raises ArgumentError when invalid options are passed' do
|
223
|
+
expect { client.timeouts(:invalid => 2) }.to raise_error(ArgumentError, "invalid key: :invalid, should belong to: [:request, :read, :connection, :dns_cache]")
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
192
227
|
it 'sets mapped dns hosts' do
|
193
228
|
resource['hosts'].should_receive(:post).with(%({"#{DOMAIN}":"1.2.3.4"}),
|
194
229
|
:content_type => "application/json")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: browsermob-proxy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jari.bakken
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -186,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
186
186
|
version: '0'
|
187
187
|
requirements: []
|
188
188
|
rubyforge_project: browsermob-proxy-rb
|
189
|
-
rubygems_version: 2.1.
|
189
|
+
rubygems_version: 2.1.9
|
190
190
|
signing_key:
|
191
191
|
specification_version: 4
|
192
192
|
summary: Ruby client for the BrowserMob Proxy REST API
|
@@ -201,4 +201,3 @@ test_files:
|
|
201
201
|
- spec/spec_helper.rb
|
202
202
|
- spec/unit/client_spec.rb
|
203
203
|
- spec/unit/webdriver_listener_spec.rb
|
204
|
-
has_rdoc:
|