Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
solarium
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
solarium
Commits
69f330de
Commit
69f330de
authored
Jul 13, 2012
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Small fix for authentication and added a unittest
parent
eed1f2e5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
6 deletions
+26
-6
library/Solarium/Client/Adapter/Http.php
library/Solarium/Client/Adapter/Http.php
+4
-6
tests/Solarium/Client/Adapter/HttpTest.php
tests/Solarium/Client/Adapter/HttpTest.php
+22
-0
No files found.
library/Solarium/Client/Adapter/Http.php
View file @
69f330de
...
...
@@ -111,6 +111,10 @@ class Solarium_Client_Adapter_Http extends Solarium_Client_Adapter
}
}
if
(
isset
(
$this
->
_options
[
'username'
])
&&
isset
(
$this
->
_options
[
'password'
]))
{
$request
->
addHeader
(
'Authorization: Basic '
.
base64_encode
(
$this
->
_options
[
'username'
]
.
':'
.
$this
->
_options
[
'password'
]
));
}
$headers
=
$request
->
getHeaders
();
if
(
count
(
$headers
)
>
0
)
{
stream_context_set_option
(
...
...
@@ -121,12 +125,6 @@ class Solarium_Client_Adapter_Http extends Solarium_Client_Adapter
);
}
if
(
isset
(
$this
->
_options
[
'username'
])
&&
isset
(
$this
->
_options
[
'password'
]))
{
$request
->
addHeader
(
'Authorization: Basic '
.
base64_encode
(
$this
->
_options
[
'username'
]
.
':'
.
$this
->
_options
[
'password'
]
));
}
return
$context
;
}
...
...
tests/Solarium/Client/Adapter/HttpTest.php
View file @
69f330de
...
...
@@ -150,4 +150,26 @@ class Solarium_Client_Adapter_HttpTest extends PHPUnit_Framework_TestCase
);
}
public
function
testCreateContextWithAuthorization
()
{
$timeout
=
13
;
$method
=
Solarium_Client_Request
::
METHOD_HEAD
;
$request
=
new
Solarium_Client_Request
();
$request
->
setMethod
(
$method
);
$this
->
_adapter
->
setOptions
(
array
(
'username'
=>
'someone'
,
'password'
=>
'S0M3p455'
));
$this
->
_adapter
->
setTimeout
(
$timeout
);
$context
=
$this
->
_adapter
->
createContext
(
$request
);
$this
->
assertEquals
(
array
(
'http'
=>
array
(
'method'
=>
$method
,
'timeout'
=>
$timeout
,
'header'
=>
'Authorization: Basic c29tZW9uZTpTME0zcDQ1NQ=='
)),
stream_context_get_options
(
$context
)
);
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment