updated-packages

This commit is contained in:
RafficMohammed
2023-01-08 00:13:22 +05:30
parent 3ff7df7487
commit da241bacb6
12659 changed files with 563377 additions and 510538 deletions

View File

@@ -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());
}
}

View File

@@ -0,0 +1,90 @@
<?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');
final class CrcTest extends CrtTestCase {
public function testCrc32ZeroesOneShot() {
$input = implode(array_map("chr", array_fill(0, 32, 0)));
$output = CRT::crc32($input);
$expected = 0x190A55AD;
$this->assertEquals($output, $expected);
}
public function testCrc32ZeroesIterated() {
$output = 0;
for ($i = 0; $i < 32; $i++) {
$output = CRT::crc32("\x00", $output);
}
$expected = 0x190A55AD;
$this->assertEquals($output, $expected);
}
public function testCrc32ValuesOneShot() {
$input = implode(array_map("chr", range(0, 31)));
$output = CRT::crc32($input);
$expected = 0x91267E8A;
$this->assertEquals($output, $expected);
}
public function testCrc32ValuesIterated() {
$output = 0;
foreach (range(0, 31) as $n) {
$output = CRT::crc32(chr($n), $output);
}
$expected = 0x91267E8A;
$this->assertEquals($output, $expected);
}
public function testCrc32LargeBuffer() {
$input = implode(array_map("chr", array_fill(0, 1 << 20, 0)));
$output = CRT::crc32($input);
$expected = 0xA738EA1C;
$this->assertEquals($output, $expected);
}
public function testCrc32cZeroesOneShot() {
$input = implode(array_map("chr", array_fill(0, 32, 0)));
$output = CRT::crc32c($input);
$expected = 0x8A9136AA;
$this->assertEquals($output, $expected);
}
public function testCrc32cZeroesIterated() {
$output = 0;
for ($i = 0; $i < 32; $i++) {
$output = CRT::crc32c("\x00", $output);
}
$expected = 0x8A9136AA;
$this->assertEquals($output, $expected);
}
public function testCrc32cValuesOneShot() {
$input = implode(array_map("chr", range(0, 31)));
$output = CRT::crc32c($input);
$expected = 0x46DD794E;
$this->assertEquals($output, $expected);
}
public function testCrc32cValuesIterated() {
$output = 0;
foreach (range(0, 31) as $n) {
$output = CRT::crc32c(chr($n), $output);
}
$expected = 0x46DD794E;
$this->assertEquals($output, $expected);
}
public function testCrc32cLargeBuffer() {
$input = implode(array_map("chr", array_fill(0, 1 << 20, 0)));
$output = CRT::crc32c($input);
$expected = 0x14298C12;
$this->assertEquals($output, $expected);
}
}

View File

@@ -0,0 +1,46 @@
<?php
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
use AWS\CRT\Auth\AwsCredentials as AwsCredentials;
use AWS\CRT\Auth\StaticCredentialsProvider as StaticCredentialsProvider;
require_once('common.inc');
final class CredentialsTest extends CrtTestCase {
public function testEmptyCredentials() {
$this->expectException(InvalidArgumentException::class);
$creds = new AwsCredentials(AwsCredentials::defaults());
$this->assertNotNull($creds, "Failed to create default/empty credentials");
$creds = null;
}
private function getCredentialsConfig() {
$options = AwsCredentials::defaults();
$options['access_key_id'] = 'TESTAWSACCESSKEYID';
$options['secret_access_key'] = 'TESTSECRETaccesskeyThatDefinitelyDoesntWork';
$options['session_token'] = 'ThisIsMyTestSessionTokenIMadeItUpMyself';
$options['expiration_timepoint_seconds'] = 42;
return $options;
}
public function testCredentialsLifetime() {
$options = $this->getCredentialsConfig();
$creds = new AwsCredentials($options);
$this->assertNotNull($creds, "Failed to create Credentials with options");
$this->assertEquals($creds->access_key_id, $options['access_key_id']);
$this->assertEquals($creds->secret_access_key, $options['secret_access_key']);
$this->assertEquals($creds->session_token, $options['session_token']);
$this->assertEquals($creds->expiration_timepoint_seconds, $options['expiration_timepoint_seconds']);
$creds = null;
}
public function testStaticCredentialsProviderLifetime() {
$options = $this->getCredentialsConfig();
$provider = new StaticCredentialsProvider($options);
$this->assertNotNull($provider, "Failed to create StaticCredentialsProvider");
$provider = null;
}
}

View File

@@ -0,0 +1,21 @@
<?php
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
use AWS\CRT\CRT;
final class ErrorTest extends PHPUnit_Framework_TestCase {
public function testNoInitialError() {
$this->assertEquals(0, CRT::last_error());
}
public function testCanResolveErrorName() {
$this->assertEquals("AWS_ERROR_SUCCESS", CRT::error_name(0));
}
public function testCanResolveErrorStr() {
$this->assertEquals("Success.", CRT::error_str(0));
}
}

View File

@@ -0,0 +1,25 @@
<?php
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
use AWS\CRT\IO\EventLoopGroup as EventLoopGroup;
require_once('common.inc');
final class EventLoopGroupTest extends CrtTestCase {
public function testLifetime() {
$elg = new EventLoopGroup();
$this->assertNotNull($elg, "Failed to create default EventLoopGroup");
$elg = null;
}
public function testConstructionWithOptions() {
$options = EventLoopGroup::defaults();
$options['num_threads'] = 1;
$elg = new EventLoopGroup($options);
$this->assertNotNull($elg, "Failed to create EventLoopGroup with 1 thread");
$elg = null;
}
}

View File

@@ -0,0 +1,95 @@
<?php
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
use AWS\CRT\HTTP\Headers;
use AWS\CRT\HTTP\Request;
use AWS\CRT\HTTP\Response;
require_once('common.inc');
final class HttpMessageTest extends CrtTestCase {
public function testHeaders() {
$headers = new Headers();
$this->assertSame(0, $headers->count());
}
public function testHeadersMarshalling() {
$headers_array = [
"host" => "s3.amazonaws.com",
"test" => "this is a test header value"
];
$headers = new Headers($headers_array);
$this->assertSame(2, $headers->count());
$this->assertSame($headers_array['host'], $headers->get('host'));
$this->assertSame($headers_array['test'], $headers->get('test'));
$buffer = Headers::marshall($headers);
$headers_copy = Headers::unmarshall($buffer);
$this->assertSame(2, $headers_copy->count());
$this->assertSame($headers_array['host'], $headers_copy->get('host'));
$this->assertSame($headers_array['test'], $headers_copy->get('test'));
}
private function assertMessagesMatch($a, $b) {
$this->assertSame($a->method(), $b->method());
$this->assertSame($a->path(), $b->path());
$this->assertSame($a->query(), $b->query());
$this->assertSame($a->headers()->toArray(), $b->headers()->toArray());
}
public function testRequestMarshalling() {
$headers = [
"host" => "s3.amazonaws.com",
"test" => "this is a test header value"
];
$method = "GET";
$path = "/index.php";
$query = [];
$msg = new Request($method, $path, $query, $headers);
$msg_buf = Request::marshall($msg);
$msg_copy = Request::unmarshall($msg_buf);
$this->assertMessagesMatch($msg, $msg_copy);
}
public function testRequestMarshallingWithQueryParams() {
$headers = [
"host" => "s3.amazonaws.com",
"test" => "this is a test header value"
];
$method = "GET";
$path = "/index.php";
$query = [
'request' => '1',
'test' => 'true',
'answer' => '42',
'foo' => 'bar',
];
$msg = new Request($method, $path, $query, $headers);
$msg_buf = Request::marshall($msg);
$msg_copy = Request::unmarshall($msg_buf);
$this->assertMessagesMatch($msg, $msg_copy);
}
public function testResponseMarshalling() {
$headers = [
"content-length" => "42",
"test" => "this is a test header value"
];
$method = "GET";
$path = "/index.php";
$query = [
'response' => '1'
];
$msg = new Response($method, $path, $query, $headers, 200);
$msg_buf = Request::marshall($msg);
$msg_copy = Request::unmarshall($msg_buf);
$this->assertMessagesMatch($msg, $msg_copy);
}
}

View File

@@ -0,0 +1,23 @@
<?php
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
use AWS\CRT\Log;
require_once('common.inc');
class LogTest extends CrtTestCase {
public function testLogToStream() {
$log_stream = fopen("php://memory", "r+");
$this->assertNotNull($log_stream);
Log::toStream($log_stream);
Log::setLogLevel(Log::TRACE);
Log::log(Log::TRACE, "THIS IS A TEST");
$this->assertTrue(rewind($log_stream));
$log_contents = stream_get_contents($log_stream, -1, 0);
$this->assertStringEndsWith("THIS IS A TEST", trim($log_contents));
Log::stop();
}
}

View File

@@ -0,0 +1,176 @@
<?php
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
use AWS\CRT\Auth\SignatureType;
use AWS\CRT\Auth\SigningAlgorithm;
use AWS\CRT\Auth\SigningConfigAWS;
use AWS\CRT\Auth\Signing;
use AWS\CRT\Auth\Signable;
use AWS\CRT\Auth\StaticCredentialsProvider;
use AWS\CRT\HTTP\Request;
require_once('common.inc');
final class SigningTest extends CrtTestCase {
public function testConfigAWSLifetime() {
$config = new SigningConfigAWS();
$this->assertNotNull($config, "Failed to create default SigningConfigAWS");
$config = null;
}
public function testConfigAWSConstructionWithOptions() {
$options = SigningConfigAWS::defaults();
$options['service'] = 'CRT';
$options['region'] = 'CRT';
$config = new SigningConfigAWS($options);
$this->assertNotNull($config, "Failed to create SigningConfigAWS with custom options");
$config = null;
}
public function testSignableFromHttpRequestLifetime() {
$request = new Request('GET', '/');
$signable = Signable::fromHttpRequest($request);
$this->assertNotNull($signable, "Failed to create Signable from HTTP::Request");
$signable = null;
}
public function testSignableFromChunkLifetime() {
$chunk = "THIS IS A TEST CHUNK IT CONTAINS MULTITUDES";
$stream = fopen("php://memory", 'r+');
fputs($stream, $chunk);
rewind($stream);
$signable = Signable::fromChunk($stream);
$this->assertNotNull($signable, "Failed to create Signable from chunk stream");
$signable = null;
}
public function testSignableFromCanonicalRequestLifetime() {
$canonical_request = "THIS IS A CANONICAL_REQUEST. IT IS DEEPLY CANONICAL";
$signable = Signable::fromCanonicalRequest($canonical_request);
$this->assertNotNull($signable, "Failed to create Signable from canonical request");
$signable = null;
}
const SIGV4TEST_ACCESS_KEY_ID = 'AKIDEXAMPLE';
const SIGV4TEST_SECRET_ACCESS_KEY = 'wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY';
const SIGV4TEST_SESSION_TOKEN = null;
const SIGV4TEST_SERVICE = 'service';
const SIGV4TEST_REGION = 'us-east-1';
private static function SIGV4TEST_DATE() {
return mktime(12, 36, 0, 8, 30, 2015);
}
public function testShouldSignHeader() {
$credentials_provider = new StaticCredentialsProvider([
'access_key_id' => self::SIGV4TEST_ACCESS_KEY_ID,
'secret_access_key' => self::SIGV4TEST_SECRET_ACCESS_KEY,
'session_token' => self::SIGV4TEST_SESSION_TOKEN,
]);
$signing_config = new SigningConfigAWS([
'algorithm' => SigningAlgorithm::SIGv4,
'signature_type' => SignatureType::HTTP_REQUEST_HEADERS,
'credentials_provider' => $credentials_provider,
'region' => self::SIGV4TEST_REGION,
'service' => self::SIGV4TEST_SERVICE,
'date' => self::SIGV4TEST_DATE(),
'should_sign_header' => function($header) {
return strtolower($header) != 'x-do-not-sign';
}
]);
$http_request = new Request('GET', '/', [], [
'Host' => 'example.amazonaws.com',
'X-Do-Not-Sign' => 'DO NOT SIGN THIS']);
$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_result, $error_code) use (&$http_request) {
$this->assertEquals(0, $error_code);
$signing_result->applyToHttpRequest($http_request);
}
);
// This signature value is computed without the X-Do-Not-Sign header above
$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'));
}
public function testSigv4HeaderSigning() {
$credentials_provider = new StaticCredentialsProvider([
'access_key_id' => self::SIGV4TEST_ACCESS_KEY_ID,
'secret_access_key' => self::SIGV4TEST_SECRET_ACCESS_KEY,
'session_token' => self::SIGV4TEST_SESSION_TOKEN,
]);
$signing_config = new SigningConfigAWS([
'algorithm' => SigningAlgorithm::SIGv4,
'signature_type' => SignatureType::HTTP_REQUEST_HEADERS,
'credentials_provider' => $credentials_provider,
'region' => self::SIGV4TEST_REGION,
'service' => self::SIGV4TEST_SERVICE,
'date' => self::SIGV4TEST_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_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'));
}
public function testSigV4aHeaderSigning() {
$credentials_provider = new StaticCredentialsProvider([
'access_key_id' => self::SIGV4TEST_ACCESS_KEY_ID,
'secret_access_key' => self::SIGV4TEST_SECRET_ACCESS_KEY,
'session_token' => self::SIGV4TEST_SESSION_TOKEN,
]);
$signing_config = new SigningConfigAWS([
'algorithm' => SigningAlgorithm::SIGv4_ASYMMETRIC,
'signature_type' => SignatureType::HTTP_REQUEST_HEADERS,
'credentials_provider' => $credentials_provider,
'region' => self::SIGV4TEST_REGION,
'service' => self::SIGV4TEST_SERVICE,
'date' => self::SIGV4TEST_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_result, $error_code) use (&$http_request) {
$this->assertEquals(0, $error_code);
$signing_result->applyToHttpRequest($http_request);
}
);
$headers = $http_request->headers();
$auth_header_value = $headers->get('Authorization');
$this->assertNotNull($auth_header_value);
$this->assertStringStartsWith(
'AWS4-ECDSA-P256-SHA256 Credential=AKIDEXAMPLE/20150830/service/aws4_request, SignedHeaders=host;x-amz-date;x-amz-region-set, Signature=',
$auth_header_value);
$this->assertEquals('20150830T123600Z', $headers->get('X-Amz-Date'));
}
}

View File

@@ -0,0 +1,34 @@
<?php
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
use AWS\CRT\IO\InputStream as InputStream;
require_once('common.inc');
final class InputStreamTest extends CrtTestCase {
const MEM_STREAM_CONTENTS = "THIS IS A TEST";
private function getMemoryStream() {
$stream = fopen("php://memory", 'r+');
fputs($stream, self::MEM_STREAM_CONTENTS);
rewind($stream);
return $stream;
}
public function testMemoryStream() {
$mem_stream = $this->getMemoryStream();
$stream = new InputStream($mem_stream);
$this->assertNotNull($stream, "Failed to create InputStream from PHP memory stream");
$this->assertEquals(strlen(self::MEM_STREAM_CONTENTS), $stream->length(), "Stream length doesn't match source buffer");
$this->assertEquals(self::MEM_STREAM_CONTENTS, $stream->read(), "Stream doesn't match source buffer");
$this->assertTrue($stream->eof(), "Stream is not EOF after reading");
$this->assertEquals(0, $stream->seek(0, InputStream::SEEK_BEGIN), "Unable to rewind stream");
$this->assertFalse($stream->eof(), "Stream is EOF after rewinding");
$this->assertEquals(0, $stream->seek(0, InputStream::SEEK_END), "Unable to seek to end of stream");
$this->assertTrue($stream->eof(), "Stream is not EOF after seeking to end");
$stream = null;
}
}

34
vendor/aws/aws-crt-php/tests/common.inc vendored Normal file
View File

@@ -0,0 +1,34 @@
<?php
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
use AWS\CRT\CRT as CRT;
ini_set("memory_limit", "512M");
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 missing calls in older versions of PHPUnit
public function __call($name, $arguments) {
// shim expectException -> setExpectedException for PHPUnit 4.8.x
if ($name == 'expectException') {
$this->setExpectedException($arguments[0]);
}
}
}