Skip to content

Commit d498f4f

Browse files
committed
Allow setting basic authentication
1 parent 86cf64c commit d498f4f

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

browsermobproxy/client.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,19 @@ def blacklist(self, regexp, status_code):
113113
urlencode({'regex': regexp, 'status': status_code}))
114114
return r.status_code
115115

116+
def basic_authentication(self, domain, username, password):
117+
"""
118+
This add automatic basic authentication
119+
:Args:
120+
- domain: domain to set authentication credentials for
121+
- username: valid username to use when authenticating
122+
- password: valid password to use when authenticating
123+
"""
124+
r = requests.post(url='%s/proxy/%s/auth/basic/%s' % (self.host, self.port, domain),
125+
data=json.dumps({'username': username, 'password': password}),
126+
headers={'content-type': 'application/json'})
127+
return r.status_code
128+
116129
LIMITS = {
117130
'upstream_kbps': 'upstreamKbps',
118131
'downstream_kbps': 'downstreamKbps',

test/test_client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ def test_blacklist(self):
102102
status_code = self.client.blacklist("http://www\\.facebook\\.com/.*", 200)
103103
assert(status_code == 200)
104104

105+
def test_basic_authentication(self):
106+
"""
107+
/proxy/:port/auth/basic
108+
adds automatic basic authentication
109+
"""
110+
status_code = self.client.basic_authentication("www.example.com", "myUsername", "myPassword")
111+
assert(status_code == 200)
112+
105113
def test_limits_invalid_key(self):
106114
"""
107115
/proxy/:port/limits

0 commit comments

Comments
 (0)