DistinguishSignatureAndCredentialErrorsTest.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace AlibabaCloud\Client\Tests\Feature\Request;
  3. use PHPUnit\Framework\TestCase;
  4. use AlibabaCloud\Client\AlibabaCloud;
  5. use AlibabaCloud\Client\Exception\ServerException;
  6. use AlibabaCloud\Client\Exception\ClientException;
  7. /**
  8. * Distinguish signature and credential errors
  9. *
  10. * @package AlibabaCloud\Tests\Feature
  11. */
  12. class DistinguishSignatureAndCredentialErrorsTest extends TestCase
  13. {
  14. /**
  15. * @before
  16. * @throws ClientException
  17. */
  18. protected function initialize()
  19. {
  20. parent::setUp();
  21. AlibabaCloud::accessKeyClient(\getenv('ACCESS_KEY_ID'), 'bad')
  22. ->regionId('cn-shanghai')
  23. ->asDefaultClient();
  24. }
  25. /**
  26. * @throws ClientException
  27. */
  28. public function testInvalidAccessKeySecret()
  29. {
  30. try {
  31. AlibabaCloud::roa()
  32. ->pathPattern('/pop/2018-05-18/tokens')
  33. ->product('nls-cloud-meta')
  34. ->version('2018-05-18')
  35. ->method('POST')
  36. ->action('CreateToken')
  37. ->connectTimeout(25)
  38. ->timeout(30)
  39. ->request();
  40. } catch (ServerException $e) {
  41. self::assertEquals('Specified Access Key Secret is not valid.', $e->getErrorMessage());
  42. }
  43. }
  44. }