123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- <?php
- namespace AlibabaCloud\Client\Tests\LowerthanVersion7_2\Feature\Request;
- use AlibabaCloud\Client\SDK;
- use PHPUnit\Framework\TestCase;
- use AlibabaCloud\Client\AlibabaCloud;
- use AlibabaCloud\Client\Exception\ClientException;
- use AlibabaCloud\Client\Exception\ServerException;
- use AlibabaCloud\Client\Credentials\Providers\CredentialsProvider;
- use AlibabaCloud\Client\Tests\LowerthanVersion7_2\Unit\Credentials\Ini\VirtualAccessKeyCredential;
- /**
- * Class ChainRequestTest
- *
- * @package AlibabaCloud\Client\Tests\LowerthanVersion7_2\Feature\Request
- */
- class ChainProviderRequestTest extends TestCase
- {
- /**
- * @throws ClientException
- * @throws ServerException
- */
- public function testDefaultProviderOnInstance()
- {
- // Setup
- CredentialsProvider::chain(
- CredentialsProvider::ini(),
- CredentialsProvider::instance(),
- CredentialsProvider::env()
- );
- $role = 'EcsRamRoleTest';
- putenv("ALIBABA_CLOUD_ECS_METADATA=$role");
- // Void ini
- $content = <<<EOT
- [void_client]
- enable = true
- type = access_key
- access_key_id = foo
- access_key_secret = var
- region_id = cn-hangzhou
- EOT;
- $file = (new VirtualAccessKeyCredential($content, 'testDefaultProviderOnInstance'))->url();
- putenv("ALIBABA_CLOUD_CREDENTIALS_FILE=$file");
- AlibabaCloud::flush();
- // Test
- AlibabaCloud::setDefaultRegionId('cn-hangzhou');
- try {
- AlibabaCloud::rpc()
- ->method('POST')
- ->product('Cdn')
- ->version('2014-11-11')
- ->action('DescribeCdnService')
- ->connectTimeout(25)
- ->timeout(30)
- ->debug(true)
- ->request();
- } catch (ClientException $e) {
- self::assertEquals(SDK::SERVER_UNREACHABLE, $e->getErrorCode());
- }
- }
- /**
- * @expectedException \AlibabaCloud\Client\Exception\ServerException
- * @expectedExceptionMessageRegExp /Forbidden.RAM: User not authorized to operate on the specified resource, or this API doesn't support RAM/
- * @throws ClientException
- * @throws ServerException
- */
- public function testDefaultProviderOnEnv()
- {
- // Setup
- $id = \AlibabaCloud\Client\env('ACCESS_KEY_ID');
- $secret = \AlibabaCloud\Client\env('ACCESS_KEY_SECRET');
- putenv("ALIBABA_CLOUD_ACCESS_KEY_ID=$id");
- putenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET=$secret");
- // Test
- AlibabaCloud::setDefaultRegionId('cn-hangzhou');
- $result = AlibabaCloud::rpc()
- ->method('POST')
- ->product('Cdn')
- ->version('2014-11-11')
- ->action('DescribeCdnService')
- ->connectTimeout(25)
- ->timeout(30)
- ->request();
- // self::assertNotEmpty('PayByTraffic', $result['ChangingChargeType']);
- }
- /**
- * @depends testDefaultProviderOnEnv
- * @expectedException \AlibabaCloud\Client\Exception\ServerException
- * @expectedExceptionMessageRegExp /Forbidden.RAM: User not authorized to operate on the specified resource, or this API doesn't support RAM/
- * @throws ServerException
- * @throws ClientException
- */
- public function testDefaultProviderOnIni()
- {
- // Setup
- $id = \AlibabaCloud\Client\env('ACCESS_KEY_ID');
- $secret = \AlibabaCloud\Client\env('ACCESS_KEY_SECRET');
- $content = <<<EOT
- [testDefaultProviderOnIni]
- enable = true
- type = access_key
- access_key_id = $id
- access_key_secret = $secret
- region_id = cn-hangzhou
- EOT;
- $file = (new VirtualAccessKeyCredential($content, 'testDefaultProviderOnIni'))->url();
- putenv("ALIBABA_CLOUD_CREDENTIALS_FILE=$file");
- // Test
- AlibabaCloud::setDefaultRegionId('cn-hangzhou');
- $result = AlibabaCloud::rpc()
- ->client('testDefaultProviderOnIni')
- ->method('POST')
- ->product('Cdn')
- ->version('2014-11-11')
- ->action('DescribeCdnService')
- ->connectTimeout(25)
- ->timeout(30)
- ->request();
- // self::assertNotEmpty('PayByTraffic', $result['ChangingChargeType']);
- }
- protected function setUp()
- {
- AlibabaCloud::flush();
- CredentialsProvider::flush();
- }
- }
|