|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/* |
| 6 | + * This file is part of Ymir WordPress plugin. |
| 7 | + * |
| 8 | + * (c) Carl Alexander <support@ymirapp.com> |
| 9 | + * |
| 10 | + * For the full copyright and license information, please view the LICENSE |
| 11 | + * file that was distributed with this source code. |
| 12 | + */ |
| 13 | + |
| 14 | +namespace Ymir\Plugin\Tests\Unit\CloudProvider\Aws; |
| 15 | + |
| 16 | +use Ymir\Plugin\CloudProvider\Aws\S3Client; |
| 17 | +use Ymir\Plugin\Tests\Mock\FunctionMockTrait; |
| 18 | +use Ymir\Plugin\Tests\Mock\HttpClientMockTrait; |
| 19 | +use Ymir\Plugin\Tests\Unit\TestCase; |
| 20 | + |
| 21 | +class AbstractClientTest extends TestCase |
| 22 | +{ |
| 23 | + use FunctionMockTrait; |
| 24 | + use HttpClientMockTrait; |
| 25 | + |
| 26 | + public function testCreatePresignedRequestWithSecurityToken() |
| 27 | + { |
| 28 | + $gmdate = $this->getFunctionMock($this->getNamespace(S3Client::class), 'gmdate'); |
| 29 | + $gmdate->expects($this->exactly(5)) |
| 30 | + ->withConsecutive( |
| 31 | + [$this->identicalTo('Ymd')], |
| 32 | + [$this->identicalTo('Ymd\THis\Z')], |
| 33 | + [$this->identicalTo('Ymd\THis\Z')], |
| 34 | + [$this->identicalTo('Ymd')], |
| 35 | + [$this->identicalTo('Ymd')] |
| 36 | + ) |
| 37 | + ->willReturnOnConsecutiveCalls('20200515', '20200515T181004Z', '20200515T181004Z', '20200515', '20200515'); |
| 38 | + |
| 39 | + $client = new S3Client($this->getHttpClientMock(), 'test-bucket', 'aws-key', 'us-east-1', 'aws-secret', 'security-token'); |
| 40 | + $createPresignedRequestMethod = new \ReflectionMethod(S3Client::class, 'createPresignedRequest'); |
| 41 | + $createPresignedRequestMethod->setAccessible(true); |
| 42 | + |
| 43 | + $request = $createPresignedRequestMethod->invoke($client, '/object-key', 'put'); |
| 44 | + |
| 45 | + $this->assertIsString($request); |
| 46 | + |
| 47 | + $query = parse_url($request, PHP_URL_QUERY); |
| 48 | + |
| 49 | + $this->assertIsString($query); |
| 50 | + |
| 51 | + parse_str($query, $parameters); |
| 52 | + |
| 53 | + $this->assertSame('security-token', $parameters['X-Amz-Security-Token']); |
| 54 | + } |
| 55 | +} |
0 commit comments