Skip to content

Commit

Permalink
Trim whitespace on credentials/max-body size
Browse files Browse the repository at this point in the history
Fixes #3
  • Loading branch information
dshafik committed Sep 1, 2017
1 parent fdb94f7 commit 7ff4d64
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
1.0.1
---
[01 Sep, 2017]
* Fixed an issue with handling trailing whitespace in credentials (see: #3)

1.0.0
---
[19 May, 2017]
Expand Down
12 changes: 8 additions & 4 deletions src/Authentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ public function getPath()
/**
* Set signing timestamp
*
* @param mixed $timestamp
* @param Timestamp|string $timestamp
* @return $this
*/
public function setTimestamp($timestamp = null)
Expand All @@ -320,7 +320,7 @@ public function setTimestamp($timestamp = null)
/**
* Set signing nonce
*
* @param Nonce $nonce
* @param Nonce|string $nonce
* @return $this
*/
public function setNonce($nonce = null)
Expand Down Expand Up @@ -352,7 +352,7 @@ public function setHeadersToSign($headers_to_sign)
*/
public function setMaxBodySize($max_body_size)
{
$this->max_body_size = $max_body_size;
$this->max_body_size = trim($max_body_size);
return $this;
}

Expand All @@ -366,7 +366,11 @@ public function setMaxBodySize($max_body_size)
*/
public function setAuth($client_token, $client_secret, $access_token)
{
$this->auth = compact('client_token', 'client_secret', 'access_token');
$this->auth = array(
'client_token' => trim($client_token),
'client_secret' => trim($client_secret),
'access_token' => trim($access_token),
);
return $this;
}

Expand Down
35 changes: 35 additions & 0 deletions tests/AuthenticationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,41 @@ public function testCreateAuthHeader(
$this->assertEquals($expected, $result);
}

public function testCreateAuthHeaderTrailingSpaces() {
$mockTimestamp = $this->prophesize('\Akamai\Open\EdgeGrid\Authentication\Timestamp');
$mockTimestamp->__toString()->willReturn("20170831T19:34:21+0000");
$mockTimestamp->isValid()->willReturn(true);
$mockNonce = $this->prophesize('\Akamai\Open\EdgeGrid\Authentication\Nonce');
$mockNonce->__toString()->willReturn("nonce-xx-xxxx-xxxx-xxxx-xxxxxxxxxxxx");

$authentication = new \Akamai\Open\EdgeGrid\Authentication();
$authentication->setHttpMethod("POST");
$authentication->setPath("/ccu/v3/invalidate/url/production");
$authentication->setHost("akaa-baseurl-xxxxxxxxxxx-xxxxxxxxxxxxx.luna.akamaiapis.net");
$authentication->setBody("{\"objects\":[\"https:\/\/example.org\/\",\"https:\/\/example.org\/test.html\"]}");
$authentication->setTimestamp($mockTimestamp->reveal());
$authentication->setNonce($mockNonce->reveal());

$authentication->setAuth(
'akab-client-token-xxx-xxxxxxxxxxxxxxxx',
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=',
'akab-access-token-xxx-xxxxxxxxxxxxxxxx'
);
$authentication->setMaxBodySize("15");
$noSpacesResult = $authentication->createAuthHeader();


$authentication->setAuth(
'akab-client-token-xxx-xxxxxxxxxxxxxxxx ',
' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx= ',
' akab-access-token-xxx-xxxxxxxxxxxxxxxx'
);
$authentication->setMaxBodySize(" 15 ");
$spacesResult = $authentication->createAuthHeader();

$this->assertEquals($noSpacesResult, $spacesResult);
}

public function testDefaultTimestamp()
{
$authentication = new \Akamai\Open\EdgeGrid\Authentication();
Expand Down

0 comments on commit 7ff4d64

Please sign in to comment.