Skip to content
Permalink
Browse files

HttpSocket: not overwriting auth header if it is set in request confi…

…guration
  • Loading branch information...
jeremyharris committed Aug 21, 2014
1 parent 3619e81 commit 8f420d74fa0be96e678ee8f37546c8bf5337fee5
Showing with 24 additions and 2 deletions.
  1. +5 −2 lib/Cake/Network/Http/HttpSocket.php
  2. +19 −0 lib/Cake/Test/Case/Network/Http/HttpSocketTest.php
@@ -326,8 +326,11 @@ public function request($request = array()) {
} elseif (isset($this->request['auth'], $this->request['auth']['method'], $this->request['auth']['user'], $this->request['auth']['pass'])) {
$this->configAuth($this->request['auth']['method'], $this->request['auth']['user'], $this->request['auth']['pass']);
}
$this->_setAuth();
$this->request['auth'] = $this->_auth;
$authHeader = Hash::get($this->request, 'header.Authorization');
if (empty($authHeader)) {
$this->_setAuth();
$this->request['auth'] = $this->_auth;
}
if (is_array($this->request['body'])) {
$this->request['body'] = http_build_query($this->request['body'], '', '&');
@@ -1074,6 +1074,16 @@ public function testAuth() {
));
$this->assertEquals($this->Socket->request['auth'], array('Basic' => array('user' => 'joel', 'pass' => 'hunter2')));
$this->assertTrue(strpos($this->Socket->request['header'], 'Authorization: Basic am9lbDpodW50ZXIy') !== false);
$this->Socket->configAuth('Basic', 'mark', 'password');
$this->Socket->request(array(
'method' => 'GET',
'uri' => 'http://example.com/test',
'header' => array(
'Authorization' => 'OtherAuth Hi.There'
)
));
$this->assertPattern('/Authorization: OtherAuth Hi\.There/m', $this->Socket->request['header']);
}
/**
@@ -1090,6 +1100,15 @@ public function testConsecutiveGetResetsAuthCredentials() {
$this->Socket->get('/test2');
$this->assertTrue(strpos($this->Socket->request['header'], 'Authorization: Basic bWFyazpzZWNyZXQ=') !== false);
$this->Socket->request(array(
'method' => 'GET',
'uri' => 'http://example.com/test',
'header' => array(
'Authorization' => 'OtherAuth Hi.There'
)
));
$this->assertPattern('/Authorization: OtherAuth Hi\.There/m', $this->Socket->request['header']);
$this->Socket->get('/test3');
$this->assertTrue(strpos($this->Socket->request['header'], 'Authorization: Basic bWFyazpzZWNyZXQ=') !== false);
}

0 comments on commit 8f420d7

Please sign in to comment.
You can’t perform that action at this time.