VirtualAccessKeyCredential.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <?php
  2. namespace AlibabaCloud\Client\Tests\Unit\Credentials\Ini;
  3. use org\bovigo\vfs\vfsStream;
  4. /**
  5. * Class VirtualAccessKeyCredential
  6. *
  7. * @codeCoverageIgnore
  8. *
  9. * @package AlibabaCloud\Client\Tests\Unit\Credentials\Ini
  10. */
  11. class VirtualAccessKeyCredential
  12. {
  13. /**
  14. * @var string Virtual Credential Content
  15. */
  16. private $content;
  17. /**
  18. * @var string File Name
  19. */
  20. private $fileName;
  21. /**
  22. * VirtualCredential constructor.
  23. *
  24. * @param string $content
  25. * @param string $fileName
  26. */
  27. public function __construct($content, $fileName = '')
  28. {
  29. $this->content = $content;
  30. $this->fileName = $fileName;
  31. }
  32. /**
  33. * @param string $clineName
  34. *
  35. * @return string
  36. */
  37. public static function akClientWithAttributes($clineName = 'phpunit')
  38. {
  39. $content = <<<EOT
  40. [{$clineName}]
  41. enable = true
  42. type = access_key
  43. access_key_id = access_key_id
  44. access_key_secret = access_key_secret
  45. security_token = security_token
  46. region_id = cn-hangzhou
  47. debug = true
  48. delay = 3.2
  49. timeout = 3.2
  50. connect_timeout = 3.2
  51. cert_file = /path/server.pem
  52. cert_password = password
  53. proxy = tcp://localhost:8125
  54. proxy_http = tcp://localhost:8125
  55. proxy_https = tcp://localhost:9124
  56. proxy_no = .mit.edu,foo.com
  57. EOT;
  58. return (new static($content))->url();
  59. }
  60. /**
  61. * @return string Virtual Credential Filename
  62. */
  63. public function url()
  64. {
  65. $fileName = 'credentials-1';
  66. if ($this->fileName) {
  67. $fileName .= "-$this->fileName";
  68. }
  69. return vfsStream::newFile($fileName)
  70. ->withContent($this->content)
  71. ->at(vfsStream::setup('AlibabaCloud'))
  72. ->url();
  73. }
  74. /**
  75. * @param string $clineName
  76. *
  77. * @return string
  78. */
  79. public static function akClientWithAttributesNoCertPassword($clineName = 'phpunit')
  80. {
  81. $content = <<<EOT
  82. [{$clineName}]
  83. enable = true
  84. type = access_key
  85. access_key_id = access_key_id
  86. access_key_secret = access_key_secret
  87. security_token = security_token
  88. debug = true
  89. delay = 3.2
  90. timeout = 3.2
  91. connect_timeout = 3.2
  92. cert_file = /path/server.pem
  93. proxy = tcp://localhost:8125
  94. proxy_http = tcp://localhost:8125
  95. proxy_https = tcp://localhost:9124
  96. proxy_no = .mit.edu,foo.com
  97. EOT;
  98. return (new static($content))->url();
  99. }
  100. /**
  101. * @return string
  102. */
  103. public static function noType()
  104. {
  105. $content = <<<EOT
  106. [phpunit]
  107. enable = true
  108. EOT;
  109. return (new static($content))->url();
  110. }
  111. /**
  112. * @return string
  113. */
  114. public static function noSecret()
  115. {
  116. $content = <<<EOT
  117. [phpunit]
  118. enable = true
  119. type = access_key
  120. access_key_id = access_key_id
  121. security_token = security_token
  122. debug = false
  123. EOT;
  124. return (new static($content))->url();
  125. }
  126. /**
  127. * @return string
  128. */
  129. public static function badFormat()
  130. {
  131. $content = <<<EOT
  132. badFormat
  133. EOT;
  134. return (new static($content, 'badFormat'))->url();
  135. }
  136. /**
  137. * @return string
  138. */
  139. public static function disable()
  140. {
  141. $content = <<<EOT
  142. [phpunit]
  143. enable = false
  144. type = access_key
  145. access_key_id = access_key_id
  146. access_key_secret = access_key_secret
  147. security_token = security_token
  148. debug = false
  149. EOT;
  150. return (new static($content))->url();
  151. }
  152. /**
  153. * @return string
  154. */
  155. public static function invalidType()
  156. {
  157. $content = <<<EOT
  158. [phpunit]
  159. enable = true
  160. type = invalidType
  161. EOT;
  162. return (new static($content))->url();
  163. }
  164. /**
  165. * @return string
  166. */
  167. public static function noKey()
  168. {
  169. $content = <<<EOT
  170. [phpunit]
  171. enable = true
  172. type = access_key
  173. access_key_secret = access_key_secret
  174. security_token = security_token
  175. debug = false
  176. EOT;
  177. return (new static($content))->url();
  178. }
  179. /**
  180. * @return string
  181. */
  182. public static function ok()
  183. {
  184. $content = <<<EOT
  185. [ok]
  186. enable = true
  187. type = access_key
  188. access_key_id = foo
  189. access_key_secret = bar
  190. region_id = cn-hangzhou
  191. debug = true
  192. timeout = 0.2
  193. connect_Timeout = 0.03
  194. cert_file = /path/server.pem
  195. cert_password = password
  196. proxy = tcp://localhost:8125
  197. proxy_http = tcp://localhost:8125
  198. proxy_https = tcp://localhost:9124
  199. proxy_no = .mit.edu,foo.com
  200. EOT;
  201. return (new static($content, 'ok'))->url();
  202. }
  203. }