browsermob-proxy 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 81d8e0cc87644ed0cd3fa3d345810a84a5c37290
4
- data.tar.gz: 1c240176d5d088fd887d7e3459dfdc43384eb439
3
+ metadata.gz: 3a912d832abea44539c98c6637c24219d051287b
4
+ data.tar.gz: 82ecdd480bfdf34b6fadff244ed19a23e01585b7
5
5
  SHA512:
6
- metadata.gz: a7213d41a4deb8f17eb879baa0d7af2dabcc29802988fe28c89715164c7783c5fac0f0b47ab428e5c3e27ebe06679ea240746b9d5dda189d2f0a55ab0d349138
7
- data.tar.gz: a42bed98b29774661379eb23ed6761d69aea7de8582339e332c15533684bdc33fa078c892a1b6551a7a82a415421992aa6a97f92d6c155a4c85ce49ca9c61911
6
+ metadata.gz: 87c2537dab9542d0348d1f81b756572f9fa1e790b5454d05a18b8a3fc6374483ded51caddc9a11a0e5af4825ab34b2abc314ec222ca6f7f682748bdb46fa8565
7
+ data.tar.gz: 248d729cb942ba5eb61a68fe03ad0510760893de9ff0476485e0f4637b2bd8572cbfe91aec4ffd251d380b5fa0d35b32d19ed7aa4a9a3180afcafd8cfe00d842
data/README.md CHANGED
@@ -82,7 +82,7 @@ Note on Patches/Pull Requests
82
82
  Copyright
83
83
  ---------
84
84
 
85
- Copyright 2011-2012 Jari Bakken
85
+ Copyright 2011-2013 Jari Bakken
86
86
 
87
87
  Licensed under the Apache License, Version 2.0 (the "License");
88
88
  you may not use this file except in compliance with the License.
@@ -70,8 +70,19 @@ module BrowserMob
70
70
  Selenium::WebDriver::Proxy.new(proxy_mapping)
71
71
  end
72
72
 
73
+ #
74
+ # Set a list of URL regexes to whitelist
75
+ #
76
+ # Note that passed regexp/string should match string as a whole
77
+ # (i.e. if /example\.com/ is whitelisted "http://www.example.com" won't be allowed
78
+ # though if /.+example\.com" is whitelisted "http://www.example.com" will be allowed)
79
+ #
80
+ # @param regexp [Regexp, String, Array<String, Regexp>] a regexp, string or an array of regexps/strings that urls should match to
81
+ # @param status_code [Integer] the HTTP status code to return for URLs that do not match the whitelist
82
+ #
83
+
73
84
  def whitelist(regexp, status_code)
74
- regex = Regexp === regexp ? regexp.source : regexp.to_s
85
+ regex = Array(regexp).map { |rx| Regexp === rx ? rx.source : rx.to_s }.join(',')
75
86
  @resource['whitelist'].put :regex => regex, :status => status_code
76
87
  end
77
88
 
@@ -90,6 +101,20 @@ module BrowserMob
90
101
  @resource["auth/basic/#{domain}"].post data.to_json, :content_type => "application/json"
91
102
  end
92
103
 
104
+ #
105
+ # Override normal DNS lookups (remap the given hosts with the associated IP address).
106
+ #
107
+ # Each invocation of the method will add given hosts to existing BrowserMob's DNS cache
108
+ # instead of overriding it.
109
+ #
110
+ # @example remap_dns_hosts('example.com' => '1.2.3.4')
111
+ # @param hash [Hash] a hash with domains as keys and IPs as values
112
+ #
113
+
114
+ def remap_dns_hosts(hash)
115
+ @resource['hosts'].post hash.to_json, :content_type => 'application/json'
116
+ end
117
+
93
118
  LIMITS = {
94
119
  :upstream_kbps => 'upstreamKbps',
95
120
  :downstream_kbps => 'downstreamKbps',
@@ -1,5 +1,5 @@
1
1
  module BrowserMob
2
2
  module Proxy
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  end
@@ -44,9 +44,40 @@ describe "Proxy + WebDriver" do
44
44
  entry.request.headers.should_not be_empty
45
45
  end
46
46
 
47
- it "should set whitelist and blacklist" do
48
- proxy.whitelist(/example\.com/, 201)
49
- proxy.blacklist(/bad\.com/, 404)
47
+ describe 'whitelist' do
48
+ it "allows access to urls in whitelist" do
49
+ dest = url_for('1.html')
50
+
51
+ proxy.whitelist(Regexp.quote(dest), 404)
52
+ driver.get dest
53
+ wait.until { driver.title == '1' }
54
+ end
55
+
56
+ it "disallows access to urls outside whitelist" do
57
+ proxy.new_har('whitelist')
58
+ proxy.whitelist('foo\.bar\.com', 404)
59
+ driver.get url_for('2.html')
60
+ proxy.har.entries.first.response.status.should == 404
61
+ end
62
+ end
63
+
64
+ describe 'blacklist' do
65
+ it "disallows access to urls in blacklist" do
66
+ proxy.new_har('blacklist')
67
+
68
+ dest = url_for('1.html')
69
+ proxy.blacklist(Regexp.quote(dest), 404)
70
+ driver.get dest
71
+
72
+ proxy.har.entries.first.response.status.should == 404
73
+ end
74
+
75
+ it "allows access to urls outside blacklist" do
76
+ proxy.blacklist('foo\.bar\.com', 404)
77
+ driver.get url_for('2.html')
78
+
79
+ wait.until { driver.title == '2' }
80
+ end
50
81
  end
51
82
 
52
83
  it "should set headers" do
@@ -57,4 +88,15 @@ describe "Proxy + WebDriver" do
57
88
  proxy.limit(:downstream_kbps => 100, :upstream_kbps => 100, :latency => 2)
58
89
  end
59
90
 
91
+ it 'should remap given DNS hosts' do
92
+ uri = URI.parse url_for('1.html')
93
+ host = 'plus.google.com'
94
+
95
+ proxy.remap_dns_hosts(host => uri.host)
96
+ uri.host = host
97
+
98
+ driver.get uri
99
+ wait.until { driver.title == '1' }
100
+ end
101
+
60
102
  end
@@ -17,7 +17,8 @@ module BrowserMob
17
17
  "blacklist" => double("resource[blacklist]"),
18
18
  "limit" => double("resource[limit]"),
19
19
  "headers" => double("resource[headers]"),
20
- "auth/basic/#{DOMAIN}" => double("resource[auth/basic/#{DOMAIN}]")
20
+ "auth/basic/#{DOMAIN}" => double("resource[auth/basic/#{DOMAIN}]"),
21
+ "hosts" => double("resource[hosts]")
21
22
  }.each do |path, mock|
22
23
  resource.stub(:[]).with(path).and_return(mock)
23
24
  end
@@ -84,11 +85,27 @@ module BrowserMob
84
85
  client.blacklist(%r[http://example.com], 401)
85
86
  end
86
87
 
87
- it "sets the whitelist" do
88
- resource['whitelist'].should_receive(:put).
89
- with(:regex => "http://example.com", :status => 401)
88
+ describe 'whitelist' do
89
+ it "supports a string" do
90
+ resource['whitelist'].should_receive(:put).
91
+ with(:regex => 'https?://example\.com', :status => 401)
92
+
93
+ client.whitelist('https?://example\.com', 401)
94
+ end
95
+
96
+ it "supports a regexp" do
97
+ resource['whitelist'].should_receive(:put).
98
+ with(:regex => 'https?://example\.com', :status => 401)
99
+
100
+ client.whitelist(%r{https?://example\.com}, 401)
101
+ end
90
102
 
91
- client.whitelist(%r[http://example.com], 401)
103
+ it "supports an array of regexps and strings" do
104
+ resource['whitelist'].should_receive(:put).
105
+ with(:regex => 'http://example\.com/1/.+,http://example\.com/2/.+', :status => 401)
106
+
107
+ client.whitelist([%r{http://example\.com/1/.+}, 'http://example\.com/2/.+'], 401)
108
+ end
92
109
  end
93
110
 
94
111
  it "sets the :downstream_kbps limit" do
@@ -137,6 +154,13 @@ module BrowserMob
137
154
  client.basic_authentication(DOMAIN, user, password)
138
155
  end
139
156
 
157
+ it 'sets mapped dns hosts' do
158
+ resource['hosts'].should_receive(:post).with(%({"#{DOMAIN}":"1.2.3.4"}),
159
+ :content_type => "application/json")
160
+
161
+ client.remap_dns_hosts(DOMAIN => '1.2.3.4')
162
+ end
163
+
140
164
  context "#selenium_proxy" do
141
165
  it "defaults to HTTP proxy only" do
142
166
  proxy = client.selenium_proxy
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.1
4
+ version: 0.1.2
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-07-12 00:00:00.000000000 Z
11
+ date: 2013-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -184,7 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
184
184
  version: '0'
185
185
  requirements: []
186
186
  rubyforge_project: browsermob-proxy-rb
187
- rubygems_version: 2.0.0
187
+ rubygems_version: 2.0.7
188
188
  signing_key:
189
189
  specification_version: 4
190
190
  summary: Ruby client for the BrowserMob Proxy REST API