Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

explicitly check the headers to find out if we already set it #10

Merged
merged 4 commits into from

2 participants

@rwos
Owner

Under certain conditions the old check would wrongly report "already set".

@rwos rwos explicitly check the headers to find out if we already set it
Under certain conditions the old check would wrongly report "already
set".
33a8177
@rwos rwos added this to the Current milestone
@yitznewton

@rwos can you write a test case for the "certain conditions?" Also, one of the other tests is broken

@rwos
Owner

@yitznewton sure, will do, in a minute - just trying to get the whole package to work first :)

@yitznewton

This all started with commit 9ce42c6 ... We might be able to get away with simply reverting that commit. I believe it was a mistaken solution for a mysterious problem. The goal was to ensure that we never send more than one Authorization header

@rwos rwos self-assigned this
rwos added some commits
@rwos rwos updated test for Auth-Bearer header plugin to actually test the headers aae2935
@rwos rwos added test for Auth-Bearer header plugin
For the case that the same plugin instance is used over multiple
requests.

This used to break at the second request, see
easybiblabs#10
7ff93b3
@rwos rwos deleted unused statement b8ddb81
@rwos
Owner

@yitznewton I pushed the tests, ready for review/merge

@rwos
Owner

note to self: after merge:

  • PR update to api-client-php
@yitznewton yitznewton merged commit e453b2b into easybiblabs:master

1 check passed

Details default The Travis CI build passed
@yitznewton

Tagged 0.3.1

@rwos rwos deleted the rwos:bugfix/bearer-auth-header branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 3, 2014
  1. @rwos

    explicitly check the headers to find out if we already set it

    rwos authored
    Under certain conditions the old check would wrongly report "already
    set".
  2. @rwos
  3. @rwos

    added test for Auth-Bearer header plugin

    rwos authored
    For the case that the same plugin instance is used over multiple
    requests.
    
    This used to break at the second request, see
    easybiblabs#10
  4. @rwos

    deleted unused statement

    rwos authored
This page is out of date. Refresh to see the latest.
View
9 src/EasyBib/Guzzle/Plugin/BearerAuth/BearerAuth.php
@@ -21,11 +21,6 @@ class BearerAuth implements EventSubscriberInterface
private $session;
/**
- * @var bool
- */
- private $headerAlreadySet = false;
-
- /**
* @param AbstractSession $session
*/
public function __construct(AbstractSession $session)
@@ -49,7 +44,7 @@ public static function getSubscribedEvents()
*/
public function onRequestBeforeSend(Event $event)
{
- if ($this->headerAlreadySet) {
+ if ($event['request']->getHeader('Authorization') instanceof Guzzle\Http\Message\Header) {
return;
}
@@ -57,8 +52,6 @@ public function onRequestBeforeSend(Event $event)
'Authorization',
sprintf('Bearer %s', $this->session->getToken())
);
-
- $this->headerAlreadySet = true;
}
/**
View
24 tests/EasyBib/Tests/Guzzle/Plugin/BearerAuth/BearerAuthTest.php
@@ -32,15 +32,27 @@ public function testMultipleSendsSetOnlyOneHeader()
{
$plugin = new BearerAuth($this->session);
- $request = $this->getMockBuilder('\Guzzle\Http\Message\Request')
- ->setConstructorArgs(['GET', '/'])
- ->getMock();
-
- $request->expects($this->once())
- ->method('setHeader');
+ $request = new \Guzzle\Http\Message\Request('GET', '/');
$event = new Event(['request' => $request]);
+
$plugin->onRequestBeforeSend($event);
+ $this->assertSame('Bearer token_123', $request->getHeader('Authorization') . '');
$plugin->onRequestBeforeSend($event);
+ $this->assertSame('Bearer token_123', $request->getHeader('Authorization') . '');
+ }
+
+ public function testReusedPluginInstanceStillSetsHeader()
+ {
+ $plugin = new BearerAuth($this->session);
+
+ $request1 = new \Guzzle\Http\Message\Request('GET', '/');
+ $request2 = new \Guzzle\Http\Message\Request('GET', '/');
+
+ $plugin->onRequestBeforeSend(new Event(['request' => $request1]));
+ $this->assertSame('Bearer token_123', $request1->getHeader('Authorization') . '');
+
+ $plugin->onRequestBeforeSend(new Event(['request' => $request2]));
+ $this->assertSame('Bearer token_123', $request2->getHeader('Authorization') . '');
}
}
Something went wrong with that request. Please try again.