forked from doctrine/KeyValueStore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for Authorization, fighting with curlwrappers now.
- Loading branch information
Showing
6 changed files
with
161 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
lib/Doctrine/KeyValueStore/Storage/WindowsAzureTable/SharedKeyLiteAuthorization.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
/* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* This software consists of voluntary contributions made by many individuals | ||
* and is licensed under the LGPL. For more information, see | ||
* <http://www.doctrine-project.org>. | ||
*/ | ||
|
||
namespace Doctrine\KeyValueStore\Storage\WindowsAzureTable; | ||
|
||
class SharedKeyLiteAuthorization implements AuthorizationSchema | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $accountName; | ||
/** | ||
* @var string | ||
*/ | ||
private $accountKey; | ||
|
||
public function __construct($accountName, $accountKey) | ||
{ | ||
$this->accountName = $accountName; | ||
$this->accountKey = base64_decode($accountKey); | ||
} | ||
|
||
/** | ||
* @override | ||
* {@inheritDocs} | ||
*/ | ||
public function signRequest($method, $path, $queryString, $body, array $headers) | ||
{ | ||
$canonicalResource = "/" . $this->accountName . $path; | ||
$stringToSign = $headers['x-ms-date'] . "\n" . | ||
$canonicalResource; | ||
return "Authorization: SharedKeyLite " . $this->accountName . ":" . base64_encode(hash_hmac('sha256', $stringToSign, $this->accountKey, true)); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
tests/Doctrine/Tests/KeyValueStore/Storage/WindowsAzureTable/SharedKeyLiteTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Doctrine\Tests\KeyValueStore\Storage\WindowsAzureTable; | ||
|
||
use Doctrine\KeyValueStore\Storage\WindowsAzureTable\SharedKeyLiteAuthorization; | ||
|
||
class SharedKeyLiteTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
private $auth; | ||
|
||
public function setUp() | ||
{ | ||
$this->auth = new SharedKeyLiteAuthorization( | ||
"testing", | ||
"abcdefg" | ||
); | ||
} | ||
|
||
public function testKeyGeneration1() | ||
{ | ||
$authorization = $this->auth->signRequest('GET', '/', '', '', array( | ||
"x-ms-date" => "Wed, 29 Apr 2009 13:12:47 GMT" | ||
)); | ||
$this->assertEquals( | ||
"Authorization: SharedKeyLite testing:vZdOn/j0gW5FG0kAUG9NhSBO9eBjZqfe6RwALPYUtqU=", | ||
$authorization | ||
); | ||
} | ||
|
||
public function testKeyGeneration2() | ||
{ | ||
$authorization = $this->auth->signRequest('GET', '/test', '', '', array( | ||
"x-ms-date" => "Wed, 29 Apr 2009 13:12:47 GMT" | ||
)); | ||
$this->assertEquals( | ||
"Authorization: SharedKeyLite testing:HJTSiRDtMsQVsFVispSHkcODeFykLO+WEuOepwmh51o=", | ||
$authorization | ||
); | ||
} | ||
} | ||
|