2020-05-19 16:07:59 -07:00
< ? php
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
2023-05-12 05:28:46 -07:00
2020-05-19 16:07:59 -07:00
/*
Relies on PHPUnit to test the functionality in ./SignPrivateDistribution.php.
Related custom constants are defined in ./phpunit.xml.
Example PHPUnit run command from this file's parent directory:
./vendor/bin/phpunit --testsuite cloudfront-signprivatedistribution
*/
2023-05-12 05:28:46 -07:00
namespace Cloudfront ;
use Aws\CloudFront\CloudFrontClient ;
2020-05-19 16:07:59 -07:00
use Aws\MockHandler ;
use Aws\Result ;
2023-05-12 05:28:46 -07:00
use PHPUnit\Framework\TestCase ;
2020-05-19 16:07:59 -07:00
class SignPrivateDistributionTest extends TestCase
{
2020-05-22 14:15:19 -07:00
public function testSignsTheURL ()
2020-05-19 16:07:59 -07:00
{
2023-05-12 05:28:46 -07:00
require ( __DIR__ . '/../SignPrivateDistribution.php' );
2020-05-19 16:07:59 -07:00
$mock = new MockHandler ();
$mock -> append ( new Result ( array ( true )));
$cloudFrontClient = new CloudFrontClient ([
'profile' => AWS_PROFILE ,
'version' => CLOUDFRONT_VERSION ,
'region' => AWS_REGION ,
'handler' => $mock
]);
2020-05-22 14:15:19 -07:00
$resourceKey = CLOUDFRONT_RESOURCE_KEY ;
$expires = time () + 300 ; // 5 minutes (5 * 60 seconds) from now.
$privateKey = dirname ( __DIR__ ) . '/tests/my-private-key.pem' ;
$keyPairId = CLOUDFRONT_KEY_PAIR_ID ;
2020-05-19 16:07:59 -07:00
2023-05-12 05:28:46 -07:00
$result = signPrivateDistribution (
$cloudFrontClient ,
$resourceKey ,
$expires ,
$privateKey ,
$keyPairId
);
2020-05-22 14:15:19 -07:00
$this -> assertStringContainsStringIgnoringCase ( $resourceKey , $result );
2020-05-19 16:07:59 -07:00
}
2023-05-12 05:28:46 -07:00
}