mirror of
https://github.com/awslabs/aws-crt-php.git
synced 2026-08-17 17:47:12 +00:00
Implemented async callbacks to PHP regardless of thread model, Sigv4 signing (#24)
* Updated to get latest aws-crt-ffi * Added implementation for signing_result * Added main thread queue and callback queueing to signing process * Updated to get support for date on signing_config_aws * added date support to SigningConfigAWS, fixed up reference issues on http message signing * Broke C code into separate files, moved common stuff to php_aws_crt.h * Use a unity build to make PHP do the right thing with our lib * Updated aws-crt-ffi to v0.1.3 to get sigv4 changes * Added CRT::isAvailable for safe runtime detection of CRT * Fixed up test resource safety, added tests to prove it * Added CI jobs for every version of PHP on linux (#26)
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
use AWS\CRT\CRT;
|
||||
|
||||
require_once('common.inc');
|
||||
|
||||
// This intentionally does not inherit from CrtTestCase because it needs a clean-room environment
|
||||
final class CoreTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
// The CRT should always be available in this test suite
|
||||
public function testIsAvailable() {
|
||||
$this->assertTrue(CRT::isAvailable());
|
||||
}
|
||||
|
||||
// We have done nothing to necessitate loading the CRT, it should not be loaded
|
||||
public function testIsLoaded() {
|
||||
$this->assertTrue(!CRT::isLoaded());
|
||||
}
|
||||
}
|
||||
@@ -6,14 +6,6 @@
|
||||
use AWS\CRT\CRT;
|
||||
|
||||
final class ErrorTest extends PHPUnit_Framework_TestCase {
|
||||
private static $crt = null;
|
||||
public static function setUpBeforeClass() {
|
||||
self::$crt = new CRT();
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass() {
|
||||
self::$crt = null;
|
||||
}
|
||||
|
||||
public function testNoInitialError() {
|
||||
$this->assertEquals(0, CRT::last_error());
|
||||
|
||||
+13
-3
@@ -61,7 +61,6 @@ final class SigningTest extends CrtTestCase {
|
||||
const SIGV4TEST_SERVICE = 'service';
|
||||
const SIGV4TEST_REGION = 'us-east-1';
|
||||
public function testSigv4HeaderSigning() {
|
||||
$this->markTestSkipped('WIP');
|
||||
$date = mktime(12, 36, 0, 8, 30, 2015);
|
||||
$credentials_provider = new StaticCredentialsProvider([
|
||||
'access_key_id' => self::SIGV4TEST_ACCESS_KEY_ID,
|
||||
@@ -74,14 +73,25 @@ final class SigningTest extends CrtTestCase {
|
||||
'credentials_provider' => $credentials_provider,
|
||||
'region' => self::SIGV4TEST_REGION,
|
||||
'service' => self::SIGV4TEST_SERVICE,
|
||||
'date' => $date,
|
||||
]);
|
||||
$http_request = new Request('GET', '/', [], ['Host' => 'example.amazonaws.com']);
|
||||
$this->assertNotNull($http_request, "Unable to create HttpRequest for signing");
|
||||
$signable = Signable::fromHttpRequest($http_request);
|
||||
$this->assertNotNull($signable, "Unable to create signable from HttpRequest");
|
||||
|
||||
Signing::signRequestAws($signable, $signing_config, function() {
|
||||
Signing::signRequestAws(
|
||||
$signable, $signing_config,
|
||||
function($signing_result, $error_code) use (&$http_request) {
|
||||
$this->assertEquals(0, $error_code);
|
||||
$signing_result->applyToHttpRequest($http_request);
|
||||
}
|
||||
);
|
||||
|
||||
});
|
||||
$headers = $http_request->headers();
|
||||
$this->assertEquals(
|
||||
'AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=5fa00fa31553b73ebf1942676e86291e8372ff2a2260956d9b8aae1d763fbf31',
|
||||
$headers->get('Authorization'));
|
||||
$this->assertEquals('20150830T123600Z', $headers->get('X-Amz-Date'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,10 +6,24 @@
|
||||
use AWS\CRT\CRT as CRT;
|
||||
|
||||
abstract class CrtTestCase extends PHPUnit_Framework_TestCase {
|
||||
private static $crt = null;
|
||||
public static function setUpBeforeClass() {
|
||||
self::$crt = new CRT();
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass() {
|
||||
self::$crt = null;
|
||||
}
|
||||
|
||||
// Ensure that after every test there are no errors in the CRT itself
|
||||
protected function assertPostConditions() {
|
||||
if (CRT::last_error()) {
|
||||
$this->fail("Test left an error on the stack: " . CRT::error_name(CRT::last_error()));
|
||||
}
|
||||
}
|
||||
|
||||
// shim expectException -> setExpectedException for PHPUnit 4.8.x
|
||||
public function expectException($exceptionName) {
|
||||
$this->setExpectedException($exceptionName);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user