CdnClientSample.php 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353
  1. <?php
  2. /*
  3. * Copyright (c) 2014 Baidu.com, Inc. All Rights Reserved
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  6. * use this file except in compliance with the License. You may obtain a copy of
  7. * the License at
  8. *
  9. * Http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  14. * License for the specific language governing permissions and limitations under
  15. * the License.
  16. */
  17. include 'BaiduBce.phar';
  18. require 'CdnSampleConf.php';
  19. use BaiduBce\Services\Cdn\CdnClient;
  20. use BaiduBce\BceClientConfigOptions;
  21. use BaiduBce\Log\LogFactory;
  22. class CdnClientTest extends PHPUnit_Framework_TestCase
  23. {
  24. public function __construct()
  25. {
  26. global $g_CDN_TEST_CONFIG;
  27. parent::__construct();
  28. $this->client = new CdnClient($g_CDN_TEST_CONFIG);
  29. $this->logger = LogFactory::getLogger(get_class($this));
  30. }
  31. /**
  32. * test create domain
  33. */
  34. public static function setUpBeforeClass()
  35. {
  36. global $g_CDN_TEST_CONFIG;
  37. $client = new CdnClient($g_CDN_TEST_CONFIG);
  38. $domain = "test-sdk.sys-qa.com";
  39. $origins = array(
  40. array("peer" => "test.origin.domain.com"),
  41. );
  42. $client->createDomain($domain, $origins);
  43. }
  44. /**
  45. * test delete domain
  46. */
  47. public static function tearDownAfterClass()
  48. {
  49. global $g_CDN_TEST_CONFIG;
  50. $client = new CdnClient($g_CDN_TEST_CONFIG);
  51. $domain = "test-sdk.sys-qa.com";
  52. $client->deleteDomain($domain);
  53. }
  54. /**
  55. * test list domain
  56. */
  57. public function testListDomain()
  58. {
  59. $resp = $this->client->listDomains();
  60. $this->assertNotNull($resp);
  61. }
  62. /**
  63. * test valid domain
  64. */
  65. public function testValidDomain() {
  66. global $g_CDN_TEST_CONFIG;
  67. $client = new CdnClient($g_CDN_TEST_CONFIG);
  68. $domain = "test-sdk.sys-qa.com";
  69. $resp = $client->validDomain($domain);
  70. $this->assertNotNull($resp);
  71. }
  72. /**
  73. * test list user domains
  74. */
  75. public function testListUserDomains() {
  76. global $g_CDN_TEST_CONFIG;
  77. $client = new CdnClient($g_CDN_TEST_CONFIG);
  78. $status = "RUNNING";
  79. $rule = "www";
  80. $param = array(
  81. 'status' => $status,
  82. 'rule' => $rule
  83. );
  84. $resp = $client->listUserDomains($param);
  85. $this->assertNotNull($resp);
  86. }
  87. /**
  88. * test valid domain
  89. * @expectedException Exception
  90. * @throws \BaiduBce\Exception\BceClientException
  91. */
  92. public function testValidDomainThrow() {
  93. global $g_CDN_TEST_CONFIG;
  94. $client = new CdnClient($g_CDN_TEST_CONFIG);
  95. $domain = "";
  96. $resp = $client->validDomain($domain);
  97. }
  98. /**
  99. * test start domain
  100. */
  101. public function testEnableDomain()
  102. {
  103. $domain = "test-sdk.sys-qa.com";
  104. $resp = $this->client->enableDomain($domain);
  105. $this->assertNotNull($resp);
  106. }
  107. /**
  108. * test stop domain
  109. */
  110. public function testDisableDomain()
  111. {
  112. $domain = "test-sdk.sys-qa.com";
  113. $resp = $this->client->disableDomain($domain);
  114. $this->assertNotNull($resp);
  115. }
  116. /**
  117. * test update domain origin address
  118. */
  119. public function testSetDomainOrigin()
  120. {
  121. $domain = "test-sdk.sys-qa.com";
  122. $origins = array(
  123. array(
  124. "peer" => "test.origin-new.domain.com",
  125. 'host' => 'www.origin-host.com'
  126. ),
  127. );
  128. $resp = $this->client->setDomainOrigin($domain, $origins);
  129. $this->assertNotNull($resp);
  130. }
  131. /**
  132. * test get domain config
  133. */
  134. public function testGetDomainConfig()
  135. {
  136. $domain = "test-sdk.sys-qa.com";
  137. $resp = $this->client->getDomainConfig($domain);
  138. $this->assertNotNull($resp);
  139. }
  140. /**
  141. * test get domain cacheFullUrl
  142. */
  143. public function testGetDomainCacheFullUrl() {
  144. global $g_CDN_TEST_CONFIG;
  145. $client = new CdnClient($g_CDN_TEST_CONFIG);
  146. $domain = "test-sdk.sys-qa.com";
  147. $resp = $client->getDomainCacheFullUrl($domain);
  148. $this->assertNotNull($resp);
  149. }
  150. /**
  151. * test get domain cacheFullUrl
  152. * @expectedException Exception
  153. * @throws \BaiduBce\Exception\BceClientException
  154. */
  155. public function testGetDomainCacheFullUrlThrow() {
  156. global $g_CDN_TEST_CONFIG;
  157. $client = new CdnClient($g_CDN_TEST_CONFIG);
  158. $domain = "";
  159. $resp = $client->getDomainCacheFullUrl($domain);
  160. }
  161. /**
  162. * test set domain errorPage
  163. */
  164. public function testSetDomainErrorPage() {
  165. global $g_CDN_TEST_CONFIG;
  166. $errorPage = array(
  167. 'errorPage' => array(
  168. array(
  169. 'code' => 404,
  170. "redirectCode" => 302,
  171. "url" => "customer_404.html"
  172. ),
  173. array(
  174. 'code' => 403,
  175. "url" => "customer_403.html"
  176. )
  177. )
  178. );
  179. $client = new CdnClient($g_CDN_TEST_CONFIG);
  180. $domain = "test-sdk.sys-qa.com";
  181. $resp = $client->setDomainErrorPage($domain, $errorPage);
  182. $this->assertNotNull($resp);
  183. }
  184. /**
  185. * test set domain errorPage
  186. * @expectedException Exception
  187. * @throws \BaiduBce\Exception\BceClientException
  188. */
  189. public function testSetDomainErrorPageThrow() {
  190. global $g_CDN_TEST_CONFIG;
  191. $client = new CdnClient($g_CDN_TEST_CONFIG);
  192. $domain = "";
  193. $errorPage = array();
  194. $resp = $client->setDomainErrorPage($domain, $errorPage);
  195. }
  196. /**
  197. * test get domain errorPage
  198. */
  199. public function testGetDomainErrorPage() {
  200. global $g_CDN_TEST_CONFIG;
  201. $client = new CdnClient($g_CDN_TEST_CONFIG);
  202. $domain = "test-sdk.sys-qa.com";
  203. $resp = $client->getDomainErrorPage($domain);
  204. $this->assertNotNull($resp);
  205. }
  206. /**
  207. * test get domain errorPage
  208. * @expectedException Exception
  209. * @throws \BaiduBce\Exception\BceClientException
  210. */
  211. public function testGetDomainErrorPageThrow() {
  212. global $g_CDN_TEST_CONFIG;
  213. $client = new CdnClient($g_CDN_TEST_CONFIG);
  214. $domain = "";
  215. $resp = $client->getDomainErrorPage($domain);
  216. }
  217. /**
  218. * test set domain requestAuth
  219. */
  220. public function testSetDomainRequestAuth() {
  221. global $g_CDN_TEST_CONFIG;
  222. $requestAuth = array(
  223. 'requestAuth' => array(
  224. "type" => "c",
  225. "key1" => "secretekey1",
  226. "key2" => "secretekey2",
  227. "timeout" => 300,
  228. "whiteList" => array("/crossdomain.xml"),
  229. "signArg" => "sign",
  230. "timeArg" => "t"
  231. )
  232. );
  233. $client = new CdnClient($g_CDN_TEST_CONFIG);
  234. $domain = "test-sdk.sys-qa.com";
  235. $resp = $client->setDomainRequestAuth($domain, $requestAuth);
  236. $this->assertNotNull($resp);
  237. }
  238. /**
  239. * test set domain requestAuth
  240. * @expectedException Exception
  241. * @throws \BaiduBce\Exception\BceClientException
  242. */
  243. public function testSetDomainRequestAuthThrow() {
  244. global $g_CDN_TEST_CONFIG;
  245. $client = new CdnClient($g_CDN_TEST_CONFIG);
  246. $domain = "";
  247. $requestAuth = array();
  248. $client->setDomainRequestAuth($domain, $requestAuth);
  249. }
  250. /**
  251. * test set domain cors
  252. */
  253. public function testSetDomainCors() {
  254. global $g_CDN_TEST_CONFIG;
  255. $cors = array(
  256. 'cors' => array(
  257. "allow" => "on",
  258. 'originList' => array(
  259. "www.baidu.com",
  260. )
  261. )
  262. );
  263. $client = new CdnClient($g_CDN_TEST_CONFIG);
  264. $domain = "test-sdk.sys-qa.com";
  265. $resp = $client->setDomainCors($domain, $cors);
  266. $this->assertNotNull($resp);
  267. }
  268. /**
  269. * test set domain cors
  270. * @expectedException Exception
  271. * @throws \BaiduBce\Exception\BceClientException
  272. */
  273. public function testSetDomainCorsThrow() {
  274. global $g_CDN_TEST_CONFIG;
  275. $client = new CdnClient($g_CDN_TEST_CONFIG);
  276. $domain = "";
  277. $cors = array();
  278. $client->setDomainCors($domain, $cors);
  279. }
  280. /**
  281. * test get domain cors
  282. */
  283. public function testGetDomainCors() {
  284. global $g_CDN_TEST_CONFIG;
  285. $client = new CdnClient($g_CDN_TEST_CONFIG);
  286. $domain = "test-sdk.sys-qa.com";
  287. $resp = $client->getDomainCors($domain);
  288. $this->assertNotNull($resp);
  289. }
  290. /**
  291. * test get domain cors
  292. * @expectedException Exception
  293. * @throws \BaiduBce\Exception\BceClientException
  294. */
  295. public function testGetDomainCorsThrow() {
  296. global $g_CDN_TEST_CONFIG;
  297. $client = new CdnClient($g_CDN_TEST_CONFIG);
  298. $domain = "";
  299. $client->getDomainCors($domain);
  300. }
  301. /**
  302. * test set domain accessLimit
  303. */
  304. public function testSetDomainAccessLimit() {
  305. global $g_CDN_TEST_CONFIG;
  306. $accessLimit = array(
  307. 'accessLimit' => array(
  308. "enabled" => true,
  309. "limit" => 200
  310. )
  311. );
  312. $client = new CdnClient($g_CDN_TEST_CONFIG);
  313. $domain = "test-sdk.sys-qa.com";
  314. $resp = $client->setDomainAccessLimit($domain, $accessLimit);
  315. $this->assertNotNull($resp);
  316. }
  317. /**
  318. * test set domain accessLimit
  319. * @expectedException Exception
  320. * @throws \BaiduBce\Exception\BceClientException
  321. */
  322. public function testSetDomainAccessLimitThrow() {
  323. global $g_CDN_TEST_CONFIG;
  324. $client = new CdnClient($g_CDN_TEST_CONFIG);
  325. $domain = "";
  326. $accessLimit = array();
  327. $client->setDomainAccessLimit($domain, $accessLimit);
  328. }
  329. /**
  330. * test get domain accessLimit
  331. */
  332. public function testGetDomainAccessLimit() {
  333. global $g_CDN_TEST_CONFIG;
  334. $client = new CdnClient($g_CDN_TEST_CONFIG);
  335. $domain = "test-sdk.sys-qa.com";
  336. $resp = $client->getDomainAccessLimit($domain);
  337. $this->assertNotNull($resp);
  338. }
  339. /**
  340. * test get domain accessLimit
  341. * @expectedException Exception
  342. * @throws \BaiduBce\Exception\BceClientException
  343. */
  344. public function testGetDomainAccessLimitThrow() {
  345. global $g_CDN_TEST_CONFIG;
  346. $client = new CdnClient($g_CDN_TEST_CONFIG);
  347. $domain = "";
  348. $client->getDomainAccessLimit($domain);
  349. }
  350. /**
  351. * test set domain clientIp
  352. */
  353. public function testSetDomainClientIp() {
  354. global $g_CDN_TEST_CONFIG;
  355. $clientIp = array(
  356. 'clientIp' => array(
  357. "enabled" => true,
  358. "name" => "X-Real-IP"
  359. )
  360. );
  361. $client = new CdnClient($g_CDN_TEST_CONFIG);
  362. $domain = "test-sdk.sys-qa.com";
  363. $resp = $client->setDomainClientIp($domain, $clientIp);
  364. $this->assertNotNull($resp);
  365. }
  366. /**
  367. * test set domain clientIp
  368. * @expectedException Exception
  369. * @throws \BaiduBce\Exception\BceClientException
  370. */
  371. public function testSetDomainClientIpThrow() {
  372. global $g_CDN_TEST_CONFIG;
  373. $client = new CdnClient($g_CDN_TEST_CONFIG);
  374. $domain = "";
  375. $clientIp = array();
  376. $client->setDomainClientIp($domain, $clientIp);
  377. }
  378. /**
  379. * test get domain clientIp
  380. */
  381. public function testGetDomainClientIp() {
  382. global $g_CDN_TEST_CONFIG;
  383. $client = new CdnClient($g_CDN_TEST_CONFIG);
  384. $domain = "test-sdk.sys-qa.com";
  385. $resp = $client->getDomainClientIp($domain);
  386. $this->assertNotNull($resp);
  387. }
  388. /**
  389. * test get domain clientIp
  390. * @expectedException Exception
  391. * @throws \BaiduBce\Exception\BceClientException
  392. */
  393. public function testGetDomainClientIpThrow() {
  394. global $g_CDN_TEST_CONFIG;
  395. $client = new CdnClient($g_CDN_TEST_CONFIG);
  396. $domain = "";
  397. $client->getDomainClientIp($domain);
  398. }
  399. /**
  400. * test set domain followProtocol
  401. */
  402. public function testSetDomainFollowProtocol() {
  403. global $g_CDN_TEST_CONFIG;
  404. $followProtocol = array(
  405. 'followProtocol' => true
  406. );
  407. $client = new CdnClient($g_CDN_TEST_CONFIG);
  408. $domain = "test-sdk.sys-qa.com";
  409. $resp = $client->setDomainFollowProtocol($domain, $followProtocol);
  410. $this->assertNotNull($resp);
  411. }
  412. /**
  413. * test set domain followProtocol
  414. * @expectedException Exception
  415. * @throws \BaiduBce\Exception\BceClientException
  416. */
  417. public function testSetDomainFollowProtocolThrow() {
  418. global $g_CDN_TEST_CONFIG;
  419. $client = new CdnClient($g_CDN_TEST_CONFIG);
  420. $domain = "";
  421. $followProtocol = array();
  422. $client->setDomainFollowProtocol($domain, $followProtocol);
  423. }
  424. /**
  425. * test set domain rangeSwitch
  426. */
  427. public function testSetDomainRangeSwitch() {
  428. global $g_CDN_TEST_CONFIG;
  429. $rangeSwitch = array(
  430. 'rangeSwitch' => true
  431. );
  432. $client = new CdnClient($g_CDN_TEST_CONFIG);
  433. $domain = "test-sdk.sys-qa.com";
  434. $resp = $client->setDomainRangeSwitch($domain, $rangeSwitch);
  435. $this->assertNotNull($resp);
  436. }
  437. /**
  438. * test set domain rangeSwitch
  439. * @expectedException Exception
  440. * @throws \BaiduBce\Exception\BceClientException
  441. */
  442. public function testSetDomainRangeSwitchThrow() {
  443. global $g_CDN_TEST_CONFIG;
  444. $client = new CdnClient($g_CDN_TEST_CONFIG);
  445. $domain = "";
  446. $rangeSwitch = array();
  447. $client->setDomainRangeSwitch($domain, $rangeSwitch);
  448. }
  449. /**
  450. * test get domain rangeSwitch
  451. */
  452. public function testGetDomainRangeSwitch() {
  453. global $g_CDN_TEST_CONFIG;
  454. $client = new CdnClient($g_CDN_TEST_CONFIG);
  455. $domain = "test-sdk.sys-qa.com";
  456. $resp = $client->getDomainRangeSwitch($domain);
  457. $this->assertNotNull($resp);
  458. }
  459. /**
  460. * test get domain rangeSwitch
  461. * @expectedException Exception
  462. * @throws \BaiduBce\Exception\BceClientException
  463. */
  464. public function testGetDomainRangeSwitchThrow() {
  465. global $g_CDN_TEST_CONFIG;
  466. $client = new CdnClient($g_CDN_TEST_CONFIG);
  467. $domain = "";
  468. $client->getDomainRangeSwitch($domain);
  469. }
  470. /**
  471. * test set domain cacheShare off
  472. */
  473. public function testSetDomainCacheShareOff() {
  474. global $g_CDN_TEST_CONFIG;
  475. $cacheShare = array(
  476. 'cacheShare' => array(
  477. "enabled" => false,
  478. )
  479. );
  480. $client = new CdnClient($g_CDN_TEST_CONFIG);
  481. $domain = "test-sdk.sys-qa.com";
  482. $resp = $client->setDomainCacheShare($domain, $cacheShare);
  483. $this->assertNotNull($resp);
  484. }
  485. /**
  486. * test set domain cacheShare on
  487. */
  488. public function testSetDomainCacheShareOn() {
  489. global $g_CDN_TEST_CONFIG;
  490. $cacheShare = array(
  491. 'cacheShare' => array(
  492. "enabled" => true,
  493. "domain" => "duanhuiyan.top"
  494. )
  495. );
  496. $client = new CdnClient($g_CDN_TEST_CONFIG);
  497. $domain = "test-sdk.sys-qa.com";
  498. $resp = $client->setDomainCacheShare($domain, $cacheShare);
  499. $this->assertNotNull($resp);
  500. }
  501. /**
  502. * test get domain cacheShare
  503. */
  504. public function testGetDomainCacheShare() {
  505. global $g_CDN_TEST_CONFIG;
  506. $client = new CdnClient($g_CDN_TEST_CONFIG);
  507. $domain = "test-sdk.sys-qa.com";
  508. $resp = $client->getDomainCacheShare($domain);
  509. $this->assertNotNull($resp);
  510. }
  511. /**
  512. * test set domain trafficLimit off
  513. */
  514. public function testSetDomainTrafficLimitOff() {
  515. global $g_CDN_TEST_CONFIG;
  516. $trafficLimit = array(
  517. 'trafficLimit' => array(
  518. "enable" => false,
  519. )
  520. );
  521. $client = new CdnClient($g_CDN_TEST_CONFIG);
  522. $domain = "test-sdk.sys-qa.com";
  523. $resp = $client->setDomainTrafficLimit($domain, $trafficLimit);
  524. $this->assertNotNull($resp);
  525. }
  526. /**
  527. * test set domain trafficLimit on
  528. */
  529. public function testSetDomainTrafficLimitOn() {
  530. global $g_CDN_TEST_CONFIG;
  531. $trafficLimit = array(
  532. 'trafficLimit' => array(
  533. "enable" => true,
  534. "limitRate" => 10485760,
  535. "limitStartHour" => 10,
  536. "limitEndHour" => 19,
  537. "limitRateAfter" => 0,
  538. "trafficLimitArg" => "rate",
  539. "trafficLimitUnit" => "m"
  540. )
  541. );
  542. $client = new CdnClient($g_CDN_TEST_CONFIG);
  543. $domain = "test-sdk.sys-qa.com";
  544. $resp = $client->setDomainTrafficLimit($domain, $trafficLimit);
  545. $this->assertNotNull($resp);
  546. }
  547. /**
  548. * test get domain trafficLimit
  549. */
  550. public function testGetDomainTrafficLimit() {
  551. global $g_CDN_TEST_CONFIG;
  552. $client = new CdnClient($g_CDN_TEST_CONFIG);
  553. $domain = "test-sdk.sys-qa.com";
  554. $resp = $client->getDomainTrafficLimit($domain);
  555. $this->assertNotNull($resp);
  556. }
  557. /**
  558. * test set domain ua whiteList
  559. */
  560. public function testSetDomainUaWhiteList() {
  561. global $g_CDN_TEST_CONFIG;
  562. $flag = "white";
  563. $aclList = array(
  564. "MQQBrowser/5.3/Mozilla/5.0",
  565. "Mozilla/5.0 (Linux; Android 7.0"
  566. );
  567. $client = new CdnClient($g_CDN_TEST_CONFIG);
  568. $domain = "test-sdk.sys-qa.com";
  569. $resp = $client->setDomainUaAcl($domain, $flag, $aclList);
  570. $this->assertNotNull($resp);
  571. }
  572. /**
  573. * test delete domain ua whiteList
  574. */
  575. public function testDeleteDomainUaWhiteList() {
  576. global $g_CDN_TEST_CONFIG;
  577. $flag = "white";
  578. $aclList = array();
  579. $client = new CdnClient($g_CDN_TEST_CONFIG);
  580. $domain = "test-sdk.sys-qa.com";
  581. $resp = $client->setDomainUaAcl($domain, $flag, $aclList);
  582. $this->assertNotNull($resp);
  583. }
  584. /**
  585. * test set domain ua blackList
  586. */
  587. public function testSetDomainUaBlackList() {
  588. global $g_CDN_TEST_CONFIG;
  589. $flag = "black";
  590. $aclList = array(
  591. "MQQBrowser/5.3/Mozilla/5.0",
  592. "Mozilla/5.0 (Linux; Android 7.0"
  593. );
  594. $client = new CdnClient($g_CDN_TEST_CONFIG);
  595. $domain = "test-sdk.sys-qa.com";
  596. $resp = $client->setDomainUaAcl($domain, $flag, $aclList);
  597. $this->assertNotNull($resp);
  598. }
  599. /**
  600. * test delete domain ua blackList
  601. */
  602. public function testDeleteDomainUaBlackList() {
  603. global $g_CDN_TEST_CONFIG;
  604. $flag = "black";
  605. $aclList = array();
  606. $client = new CdnClient($g_CDN_TEST_CONFIG);
  607. $domain = "test-sdk.sys-qa.com";
  608. $resp = $client->setDomainUaAcl($domain, $flag, $aclList);
  609. $this->assertNotNull($resp);
  610. }
  611. /**
  612. * test get domain uaAcl
  613. */
  614. public function testGetDomainUaAcl() {
  615. global $g_CDN_TEST_CONFIG;
  616. $client = new CdnClient($g_CDN_TEST_CONFIG);
  617. $domain = "test-sdk.sys-qa.com";
  618. $resp = $client->getDomainUaACL($domain);
  619. $this->assertNotNull($resp);
  620. }
  621. /**
  622. * test set domain originProtocol https, you need to turn on HTTPS first
  623. */
  624. public function testSetDomainOriginProtocolHttps() {
  625. global $g_CDN_TEST_CONFIG;
  626. $this->testSetDomainHttpsOn();
  627. $originProtocol = array(
  628. "originProtocol" => array(
  629. "value" => "https"
  630. )
  631. );
  632. $client = new CdnClient($g_CDN_TEST_CONFIG);
  633. $domain = "test-sdk.sys-qa.com";
  634. $resp = $client->setDomainOriginProtocol($domain, $originProtocol);
  635. $this->assertNotNull($resp);
  636. }
  637. /**
  638. * test set domain originProtocol http
  639. */
  640. public function testSetDomainOriginProtocolHttp() {
  641. global $g_CDN_TEST_CONFIG;
  642. $originProtocol = array(
  643. "originProtocol" => array(
  644. "value" => "http"
  645. )
  646. );
  647. $client = new CdnClient($g_CDN_TEST_CONFIG);
  648. $domain = "test-sdk.sys-qa.com";
  649. $resp = $client->setDomainOriginProtocol($domain, $originProtocol);
  650. $this->assertNotNull($resp);
  651. }
  652. /**
  653. * test set domain originProtocol follow
  654. */
  655. public function testSetDomainOriginProtocolFollow() {
  656. global $g_CDN_TEST_CONFIG;
  657. $originProtocol = array(
  658. "originProtocol" => array(
  659. "value" => "*"
  660. )
  661. );
  662. $client = new CdnClient($g_CDN_TEST_CONFIG);
  663. $domain = "test-sdk.sys-qa.com";
  664. $resp = $client->setDomainOriginProtocol($domain, $originProtocol);
  665. $this->assertNotNull($resp);
  666. }
  667. /**
  668. * test set domain retryOrigin
  669. */
  670. public function testSetDomainRetryOrigin() {
  671. global $g_CDN_TEST_CONFIG;
  672. $retryOrigin = array(
  673. "retryOrigin" => array(
  674. "codes" => array(
  675. 500,
  676. 502,
  677. 503
  678. )
  679. )
  680. );
  681. $client = new CdnClient($g_CDN_TEST_CONFIG);
  682. $domain = "test-sdk.sys-qa.com";
  683. $resp = $client->setDomainRetryOrigin($domain, $retryOrigin);
  684. $this->assertNotNull($resp);
  685. }
  686. /**
  687. * test set domain retryOrigin off
  688. */
  689. public function testSetDomainRetryOriginOff() {
  690. global $g_CDN_TEST_CONFIG;
  691. $retryOrigin = array(
  692. "retryOrigin" => array(
  693. "codes" => array()
  694. )
  695. );
  696. $client = new CdnClient($g_CDN_TEST_CONFIG);
  697. $domain = "test-sdk.sys-qa.com";
  698. $resp = $client->setDomainRetryOrigin($domain, $retryOrigin);
  699. $this->assertNotNull($resp);
  700. }
  701. /**
  702. * test get domain retryOrigin
  703. */
  704. public function testGetDomainRetryOrigin() {
  705. global $g_CDN_TEST_CONFIG;
  706. $client = new CdnClient($g_CDN_TEST_CONFIG);
  707. $domain = "test-sdk.sys-qa.com";
  708. $resp = $client->getDomainRetryOrigin($domain);
  709. $this->assertNotNull($resp);
  710. }
  711. /**
  712. * test set domain ipv6Dispatch off
  713. */
  714. public function testSetDomainIpv6DispatchOff() {
  715. global $g_CDN_TEST_CONFIG;
  716. $ipv6Dispatch = array(
  717. "ipv6Dispatch" => array(
  718. "enable" => false
  719. )
  720. );
  721. $client = new CdnClient($g_CDN_TEST_CONFIG);
  722. $domain = "test-sdk.sys-qa.com";
  723. $resp = $client->setDomainIpv6Dispatch($domain, $ipv6Dispatch);
  724. $this->assertNotNull($resp);
  725. }
  726. /**
  727. * test get domain ipv6Dispatch
  728. */
  729. public function testGetDomainIpv6Dispatch() {
  730. global $g_CDN_TEST_CONFIG;
  731. $client = new CdnClient($g_CDN_TEST_CONFIG);
  732. $domain = "test-sdk.sys-qa.com";
  733. $resp = $client->getDomainIpv6Dispatch($domain);
  734. $this->assertNotNull($resp);
  735. }
  736. /**
  737. * test set domain quic on
  738. */
  739. public function testSetDomainQuicOn() {
  740. global $g_CDN_TEST_CONFIG;
  741. $this->testSetDomainHttpsOn();
  742. $quic = array(
  743. "quic" => true
  744. );
  745. $client = new CdnClient($g_CDN_TEST_CONFIG);
  746. $domain = "test-sdk.sys-qa.com";
  747. $resp = $client->setDomainQuic($domain, $quic);
  748. $this->assertNotNull($resp);
  749. }
  750. /**
  751. * test set domain quic off
  752. */
  753. public function testSetDomainQuicOff() {
  754. global $g_CDN_TEST_CONFIG;
  755. $quic = array(
  756. "quic" => false
  757. );
  758. $client = new CdnClient($g_CDN_TEST_CONFIG);
  759. $domain = "test-sdk.sys-qa.com";
  760. $resp = $client->setDomainQuic($domain, $quic);
  761. $this->assertNotNull($resp);
  762. }
  763. /**
  764. * test get domain quic
  765. */
  766. public function testGetDomainQuic() {
  767. global $g_CDN_TEST_CONFIG;
  768. $client = new CdnClient($g_CDN_TEST_CONFIG);
  769. $domain = "test-sdk.sys-qa.com";
  770. $resp = $client->getDomainQuic($domain);
  771. $this->assertNotNull($resp);
  772. }
  773. /**
  774. * test set domain offlineMode on
  775. */
  776. public function testSetDomainOfflineModeOn() {
  777. global $g_CDN_TEST_CONFIG;
  778. $offlineMode = array(
  779. "offlineMode" => true
  780. );
  781. $client = new CdnClient($g_CDN_TEST_CONFIG);
  782. $domain = "test-sdk.sys-qa.com";
  783. $resp = $client->setDomainOfflineMode($domain, $offlineMode);
  784. $this->assertNotNull($resp);
  785. }
  786. /**
  787. * test set domain offlineMode off
  788. */
  789. public function testSetDomainOfflineModeOff() {
  790. global $g_CDN_TEST_CONFIG;
  791. $offlineMode = array(
  792. "offlineMode" => false
  793. );
  794. $client = new CdnClient($g_CDN_TEST_CONFIG);
  795. $domain = "test-sdk.sys-qa.com";
  796. $resp = $client->setDomainOfflineMode($domain, $offlineMode);
  797. $this->assertNotNull($resp);
  798. }
  799. /**
  800. * test get domain offlineMode
  801. */
  802. public function testGetDomainOfflineMode() {
  803. global $g_CDN_TEST_CONFIG;
  804. $client = new CdnClient($g_CDN_TEST_CONFIG);
  805. $domain = "test-sdk.sys-qa.com";
  806. $resp = $client->getDomainOfflineMode($domain);
  807. $this->assertNotNull($resp);
  808. }
  809. /**
  810. * test set domain ocsp on
  811. */
  812. public function testSetDomainOcspOn() {
  813. global $g_CDN_TEST_CONFIG;
  814. $this->testSetDomainHttpsOn();
  815. $ocsp = array(
  816. "ocsp" => true
  817. );
  818. $client = new CdnClient($g_CDN_TEST_CONFIG);
  819. $domain = "test-sdk.sys-qa.com";
  820. $resp = $client->setDomainOcsp($domain, $ocsp);
  821. $this->assertNotNull($resp);
  822. }
  823. /**
  824. * test set domain ocsp off
  825. */
  826. public function testSetDomainOcspOff() {
  827. global $g_CDN_TEST_CONFIG;
  828. $ocsp = array(
  829. "ocsp" => false
  830. );
  831. $client = new CdnClient($g_CDN_TEST_CONFIG);
  832. $domain = "test-sdk.sys-qa.com";
  833. $resp = $client->setDomainOcsp($domain, $ocsp);
  834. $this->assertNotNull($resp);
  835. }
  836. /**
  837. * test get domain ocsp
  838. */
  839. public function testGetDomainOcsp() {
  840. global $g_CDN_TEST_CONFIG;
  841. $client = new CdnClient($g_CDN_TEST_CONFIG);
  842. $domain = "test-sdk.sys-qa.com";
  843. $resp = $client->getDomainOcsp($domain);
  844. $this->assertNotNull($resp);
  845. }
  846. /**
  847. * test get nodes list
  848. */
  849. public function testGetNodesList() {
  850. global $g_CDN_TEST_CONFIG;
  851. $client = new CdnClient($g_CDN_TEST_CONFIG);
  852. $resp = $client->getNodesList();
  853. $this->assertNotNull($resp);
  854. }
  855. /**
  856. * test set domain mobileAccess
  857. */
  858. public function testSetDomainMobileAccess() {
  859. global $g_CDN_TEST_CONFIG;
  860. $mobileAccess = array(
  861. 'mobileAccess' => array(
  862. "distinguishClient" => true
  863. )
  864. );
  865. $client = new CdnClient($g_CDN_TEST_CONFIG);
  866. $domain = "test-sdk.sys-qa.com";
  867. $resp = $client->setDomainMobileAccess($domain, $mobileAccess);
  868. $this->assertNotNull($resp);
  869. }
  870. /**
  871. * test set domain mobileAccess
  872. * @expectedException Exception
  873. * @throws \BaiduBce\Exception\BceClientException
  874. */
  875. public function testSetDomainMobileAccessThrow() {
  876. global $g_CDN_TEST_CONFIG;
  877. $client = new CdnClient($g_CDN_TEST_CONFIG);
  878. $domain = "";
  879. $mobileAccess = array();
  880. $client->setDomainMobileAccess($domain, $mobileAccess);
  881. }
  882. /**
  883. * test get domain mobileAccess
  884. */
  885. public function testGetDomainMobileAccess() {
  886. global $g_CDN_TEST_CONFIG;
  887. $client = new CdnClient($g_CDN_TEST_CONFIG);
  888. $domain = "test-sdk.sys-qa.com";
  889. $resp = $client->getDomainMobileAccess($domain);
  890. $this->assertNotNull($resp);
  891. }
  892. /**
  893. * test get domain mobileAccess
  894. * @expectedException Exception
  895. * @throws \BaiduBce\Exception\BceClientException
  896. */
  897. public function testGetDomainMobileAccessThrow() {
  898. global $g_CDN_TEST_CONFIG;
  899. $client = new CdnClient($g_CDN_TEST_CONFIG);
  900. $domain = "";
  901. $client->getDomainMobileAccess($domain);
  902. }
  903. /**
  904. * test set domain httpHeader
  905. */
  906. public function testSetDomainHttpHeader() {
  907. global $g_CDN_TEST_CONFIG;
  908. $httpHeader = array(
  909. 'httpHeader' => array(
  910. array(
  911. "type" => "origin",
  912. "header" => "x-auth-cn",
  913. "value" => "xxxxxxxxx",
  914. "action" => "add"
  915. )
  916. )
  917. );
  918. $client = new CdnClient($g_CDN_TEST_CONFIG);
  919. $domain = "test-sdk.sys-qa.com";
  920. $resp = $client->setDomainHttpHeader($domain, $httpHeader);
  921. $this->assertNotNull($resp);
  922. }
  923. /**
  924. * test set domain httpHeader
  925. * @expectedException Exception
  926. * @throws \BaiduBce\Exception\BceClientException
  927. */
  928. public function testSetDomainHttpHeaderThrow() {
  929. global $g_CDN_TEST_CONFIG;
  930. $client = new CdnClient($g_CDN_TEST_CONFIG);
  931. $domain = "";
  932. $httpHeader = array();
  933. $client->setDomainHttpHeader($domain, $httpHeader);
  934. }
  935. /**
  936. * test get domain httpHeader
  937. */
  938. public function testGetDomainHttpHeader() {
  939. global $g_CDN_TEST_CONFIG;
  940. $client = new CdnClient($g_CDN_TEST_CONFIG);
  941. $domain = "test-sdk.sys-qa.com";
  942. $resp = $client->getDomainHttpHeader($domain);
  943. $this->assertNotNull($resp);
  944. }
  945. /**
  946. * test get domain httpHeader
  947. * @expectedException Exception
  948. * @throws \BaiduBce\Exception\BceClientException
  949. */
  950. public function testGetDomainHttpHeaderThrow() {
  951. global $g_CDN_TEST_CONFIG;
  952. $client = new CdnClient($g_CDN_TEST_CONFIG);
  953. $domain = "";
  954. $client->getDomainHttpHeader($domain);
  955. }
  956. /**
  957. * test set domain seoSwitch
  958. */
  959. public function testSetDomainSeoSwitch() {
  960. global $g_CDN_TEST_CONFIG;
  961. $seoSwitch = array(
  962. 'seoSwitch' => array(
  963. "diretlyOrigin" => "ON",
  964. "pushRecord" => "OFF"
  965. )
  966. );
  967. $client = new CdnClient($g_CDN_TEST_CONFIG);
  968. $domain = "test-sdk.sys-qa.com";
  969. $resp = $client->setDomainSeoSwitch($domain, $seoSwitch);
  970. $this->assertNotNull($resp);
  971. }
  972. /**
  973. * test set domain seoSwitch
  974. * @expectedException Exception
  975. * @throws \BaiduBce\Exception\BceClientException
  976. */
  977. public function testSetDomainSeoSwitchThrow() {
  978. global $g_CDN_TEST_CONFIG;
  979. $client = new CdnClient($g_CDN_TEST_CONFIG);
  980. $domain = "";
  981. $seoSwitch = array();
  982. $client->setDomainSeoSwitch($domain, $seoSwitch);
  983. }
  984. /**
  985. * test get domain seoSwitch
  986. */
  987. public function testGetDomainSeoSwitch() {
  988. global $g_CDN_TEST_CONFIG;
  989. $client = new CdnClient($g_CDN_TEST_CONFIG);
  990. $domain = "test-sdk.sys-qa.com";
  991. $resp = $client->getDomainSeoSwitch($domain);
  992. $this->assertNotNull($resp);
  993. }
  994. /**
  995. * test get domain seoSwitch
  996. * @expectedException Exception
  997. * @throws \BaiduBce\Exception\BceClientException
  998. */
  999. public function testGetDomainSeoSwitchThrow() {
  1000. global $g_CDN_TEST_CONFIG;
  1001. $client = new CdnClient($g_CDN_TEST_CONFIG);
  1002. $domain = "";
  1003. $client->getDomainSeoSwitch($domain);
  1004. }
  1005. /**
  1006. * test set domain fileTrim
  1007. */
  1008. public function testSetDomainFileTrim() {
  1009. global $g_CDN_TEST_CONFIG;
  1010. $fileTrim = array(
  1011. 'fileTrim' => true
  1012. );
  1013. $client = new CdnClient($g_CDN_TEST_CONFIG);
  1014. $domain = "test-sdk.sys-qa.com";
  1015. $resp = $client->setDomainFileTrim($domain, $fileTrim);
  1016. $this->assertNotNull($resp);
  1017. }
  1018. /**
  1019. * test set domain fileTrim
  1020. * @expectedException Exception
  1021. * @throws \BaiduBce\Exception\BceClientException
  1022. */
  1023. public function testSetDomainFileTrimThrow() {
  1024. global $g_CDN_TEST_CONFIG;
  1025. $client = new CdnClient($g_CDN_TEST_CONFIG);
  1026. $domain = "";
  1027. $fileTrim = array();
  1028. $client->setDomainFileTrim($domain, $fileTrim);
  1029. }
  1030. /**
  1031. * test get domain fileTrim
  1032. */
  1033. public function testGetDomainFileTrim() {
  1034. global $g_CDN_TEST_CONFIG;
  1035. $client = new CdnClient($g_CDN_TEST_CONFIG);
  1036. $domain = "test-sdk.sys-qa.com";
  1037. $resp = $client->getDomainFileTrim($domain);
  1038. $this->assertNotNull($resp);
  1039. }
  1040. /**
  1041. * test get domain fileTrim
  1042. * @expectedException Exception
  1043. * @throws \BaiduBce\Exception\BceClientException
  1044. */
  1045. public function testGetDomainFileTrimThrow() {
  1046. global $g_CDN_TEST_CONFIG;
  1047. $client = new CdnClient($g_CDN_TEST_CONFIG);
  1048. $domain = "";
  1049. $client->getDomainFileTrim($domain);
  1050. }
  1051. /**
  1052. * test set domain mediaDrag
  1053. */
  1054. public function testSetDomainMediaDrag() {
  1055. global $g_CDN_TEST_CONFIG;
  1056. $mediaDrag = array(
  1057. 'mediaDragConf' => array(
  1058. 'mp4' => array(
  1059. 'fileSuffix' => array('mp4'),
  1060. 'startArgName' => 'startIndex',
  1061. 'dragMode' => 'second',
  1062. 'endArgName' => 'end'
  1063. )
  1064. )
  1065. );
  1066. $client = new CdnClient($g_CDN_TEST_CONFIG);
  1067. $domain = "test-sdk.sys-qa.com";
  1068. $resp = $client->setDomainMediaDrag($domain, $mediaDrag);
  1069. $this->assertNotNull($resp);
  1070. }
  1071. /**
  1072. * test set domain mediaDrag
  1073. * @expectedException Exception
  1074. * @throws \BaiduBce\Exception\BceClientException
  1075. */
  1076. public function testSetDomainMediaDragThrow() {
  1077. global $g_CDN_TEST_CONFIG;
  1078. $client = new CdnClient($g_CDN_TEST_CONFIG);
  1079. $domain = "";
  1080. $mediaDrag = array();
  1081. $client->setDomainMediaDrag($domain, $mediaDrag);
  1082. }
  1083. /**
  1084. * test get domain mediaDrag
  1085. */
  1086. public function testGetDomainMediaDrag() {
  1087. global $g_CDN_TEST_CONFIG;
  1088. $client = new CdnClient($g_CDN_TEST_CONFIG);
  1089. $domain = "test-sdk.sys-qa.com";
  1090. $resp = $client->getDomainMediaDrag($domain);
  1091. $this->assertNotNull($resp);
  1092. }
  1093. /**
  1094. * test get domain mediaDrag
  1095. * @expectedException Exception
  1096. * @throws \BaiduBce\Exception\BceClientException
  1097. */
  1098. public function testGetDomainMediaDragThrow() {
  1099. global $g_CDN_TEST_CONFIG;
  1100. $client = new CdnClient($g_CDN_TEST_CONFIG);
  1101. $domain = "";
  1102. $client->getDomainMediaDrag($domain);
  1103. }
  1104. /**
  1105. * test set domain compress
  1106. */
  1107. public function testSetDomainCompress() {
  1108. global $g_CDN_TEST_CONFIG;
  1109. $compress = array(
  1110. 'compress' => array(
  1111. "allow" => true,
  1112. "type" => "br"
  1113. )
  1114. );
  1115. $client = new CdnClient($g_CDN_TEST_CONFIG);
  1116. $domain = "test-sdk.sys-qa.com";
  1117. $resp = $client->setDomainCompress($domain, $compress);
  1118. $this->assertNotNull($resp);
  1119. }
  1120. /**
  1121. * test set domain compress
  1122. * @expectedException Exception
  1123. * @throws \BaiduBce\Exception\BceClientException
  1124. */
  1125. public function testSetDomainCompressThrow() {
  1126. global $g_CDN_TEST_CONFIG;
  1127. $client = new CdnClient($g_CDN_TEST_CONFIG);
  1128. $domain = "";
  1129. $compress = array();
  1130. $client->setDomainCompress($domain, $compress);
  1131. }
  1132. /**
  1133. * test get domain compress
  1134. */
  1135. public function testGetDomainCompress() {
  1136. global $g_CDN_TEST_CONFIG;
  1137. $client = new CdnClient($g_CDN_TEST_CONFIG);
  1138. $domain = "test-sdk.sys-qa.com";
  1139. $resp = $client->getDomainCompress($domain);
  1140. $this->assertNotNull($resp);
  1141. }
  1142. /**
  1143. * test get domain compress
  1144. * @expectedException Exception
  1145. * @throws \BaiduBce\Exception\BceClientException
  1146. */
  1147. public function testGetDomainCompressThrow() {
  1148. global $g_CDN_TEST_CONFIG;
  1149. $client = new CdnClient($g_CDN_TEST_CONFIG);
  1150. $domain = "";
  1151. $client->getDomainCompress($domain);
  1152. }
  1153. /**
  1154. * test set domain https off
  1155. */
  1156. public function testSetDomainHttpsOff() {
  1157. global $g_CDN_TEST_CONFIG;
  1158. $https = array(
  1159. 'https' => array(
  1160. "enabled" => false,
  1161. "certId" => "----"//当enabled为true时该参数要为有效当证书id
  1162. )
  1163. );
  1164. $client = new CdnClient($g_CDN_TEST_CONFIG);
  1165. $domain = "test-sdk.sys-qa.com";
  1166. $resp = $client->setDomainHttps($domain, $https);
  1167. $this->assertNotNull($resp);
  1168. }
  1169. /**
  1170. * test set domain https on
  1171. */
  1172. public function testSetDomainHttpsOn() {
  1173. global $g_CDN_TEST_CONFIG;
  1174. $https = array(
  1175. 'https' => array(
  1176. "enabled" => true,
  1177. "certId" => "cert-qtah8qqwki6w"
  1178. )
  1179. );
  1180. $client = new CdnClient($g_CDN_TEST_CONFIG);
  1181. $domain = "test-sdk.sys-qa.com";
  1182. $resp = $client->setDomainHttps($domain, $https);
  1183. $this->assertNotNull($resp);
  1184. }
  1185. /**
  1186. * test set domain https
  1187. * @expectedException Exception
  1188. * @throws \BaiduBce\Exception\BceClientException
  1189. */
  1190. public function testSetDomainHttpsThrow() {
  1191. global $g_CDN_TEST_CONFIG;
  1192. $client = new CdnClient($g_CDN_TEST_CONFIG);
  1193. $domain = "";
  1194. $https = array();
  1195. $client->setDomainHttps($domain, $https);
  1196. }
  1197. /**
  1198. * test cache records
  1199. */
  1200. public function testGetRecords()
  1201. {
  1202. $resp = $this->client->getRecords();
  1203. $this->assertNotNull($resp);
  1204. }
  1205. /**
  1206. * test get domain cache ttl
  1207. */
  1208. public function testGetDomainCacheTTL()
  1209. {
  1210. $domain = "test-sdk.sys-qa.com";
  1211. $resp = $this->client->getDomainCacheTTL($domain);
  1212. $this->assertNotNull($resp);
  1213. }
  1214. /**
  1215. * test set domain cache ttl
  1216. */
  1217. public function testSetDomainCacheTTL()
  1218. {
  1219. $domain = "test-sdk.sys-qa.com";
  1220. $rules = array(
  1221. array(
  1222. "type" => "suffix",
  1223. "value" => ".jpg",
  1224. "ttl" => 36000,
  1225. "weight" => 30,
  1226. ),
  1227. );
  1228. $resp = $this->client->setDomainCacheTTL($domain, $rules);
  1229. $this->assertNotNull($resp);
  1230. }
  1231. /**
  1232. * test set domain cache full url
  1233. */
  1234. public function testSetDomainCacheFullUrl()
  1235. {
  1236. $domain = "test-sdk.sys-qa.com";
  1237. $flag = true;
  1238. $resp = $this->client->setDomainCacheFullUrl($domain, $flag);
  1239. $this->assertNotNull($resp);
  1240. }
  1241. /**
  1242. * test set domain ip acl
  1243. */
  1244. public function testSetDomainIpAcl()
  1245. {
  1246. $domain = "test-sdk.sys-qa.com";
  1247. $aclList = array(
  1248. "1.2.3.4",
  1249. "5.6.7.8",
  1250. );
  1251. $flag = "white";
  1252. $resp = $this->client->setDomainIpAcl($domain, $flag, $aclList);
  1253. $this->assertNotNull($resp);
  1254. }
  1255. /**
  1256. * test get domain ip acl
  1257. */
  1258. public function testGetDomainIpACL() {
  1259. global $g_CDN_TEST_CONFIG;
  1260. $client = new CdnClient($g_CDN_TEST_CONFIG);
  1261. $domain = "test-sdk.sys-qa.com";
  1262. $resp = $client->getDomainIpACL($domain);
  1263. $this->assertNotNull($resp);
  1264. }
  1265. /**
  1266. * test set domain refererAcl
  1267. */
  1268. public function testSetDomainRefererAcl()
  1269. {
  1270. $domain = "test-sdk.sys-qa.com";
  1271. $aclList = array(
  1272. "your.black.list1",
  1273. "your.black.list2",
  1274. );
  1275. $flag = "black";
  1276. $allowEmpty=true;
  1277. $resp = $this->client->setDomainRefererAcl($domain, $flag, $allowEmpty, $aclList);
  1278. $this->assertNotNull($resp);
  1279. }
  1280. /**
  1281. * test get domain refererAcl
  1282. */
  1283. public function testGetDomainRefererACL() {
  1284. global $g_CDN_TEST_CONFIG;
  1285. $client = new CdnClient($g_CDN_TEST_CONFIG);
  1286. $domain = "test-sdk.sys-qa.com";
  1287. $resp = $client->getDomainRefererAcl($domain);
  1288. $this->assertNotNull($resp);
  1289. }
  1290. /**
  1291. * test set domain limit rate
  1292. */
  1293. public function testSetDomainLimitRate()
  1294. {
  1295. $domain = "test-sdk.sys-qa.com";
  1296. $rate = 1024;
  1297. $resp = $this->client->setDomainLimitRate($domain, $rate);
  1298. $this->assertNotNull($resp);
  1299. }
  1300. /**
  1301. * test get domain pv stat
  1302. */
  1303. public function testGetDomainPvStat()
  1304. {
  1305. $domain = 'test-sdk.sys-qa.com';
  1306. $period = 300;
  1307. $withRegion = 'true';
  1308. $endTime = time();
  1309. $startTime = $endTime - $period * 10;
  1310. $endTime = gmdate("Y-m-d\TH:i:s\Z", $endTime);
  1311. $startTime = gmdate("Y-m-d\TH:i:s\Z", $startTime);
  1312. $resp = $this->client->getDomainPvStat($domain, $startTime, $endTime,
  1313. $period, $withRegion);
  1314. $this->assertNotNull($resp);
  1315. }
  1316. /**
  1317. * test get domain uv stat
  1318. */
  1319. public function testGetDomainUvStat()
  1320. {
  1321. $domain = 'test-sdk.sys-qa.com';
  1322. $period = 3600;
  1323. $withRegion = 'true';
  1324. $endTime = time();
  1325. $startTime = $endTime - $period * 10;
  1326. $endTime = gmdate("Y-m-d\TH:i:s\Z", $endTime);
  1327. $startTime = gmdate("Y-m-d\TH:i:s\Z", $startTime);
  1328. $resp = $this->client->getDomainUvStat($domain, $startTime, $endTime, $period);
  1329. $this->assertNotNull($resp);
  1330. }
  1331. /**
  1332. * test get domain avg speed stat
  1333. */
  1334. public function testGetDomainAvgSpeedStat()
  1335. {
  1336. $domain = 'test-sdk.sys-qa.com';
  1337. $period = 300;
  1338. $endTime = time();
  1339. $startTime = $endTime - $period * 10;
  1340. $endTime = gmdate("Y-m-d\TH:i:s\Z", $endTime);
  1341. $startTime = gmdate("Y-m-d\TH:i:s\Z", $startTime);
  1342. $resp = $this->client->getDomainAvgSpeedStat($domain, $startTime, $endTime, $period);
  1343. $this->assertNotNull($resp);
  1344. }
  1345. /**
  1346. * test get domain flow stat
  1347. */
  1348. public function testGetDomainFlowStat()
  1349. {
  1350. $domain = 'test-sdk.sys-qa.com';
  1351. $period = 300;
  1352. $withRegion = 'true';
  1353. $endTime = time();
  1354. $startTime = $endTime - $period * 10;
  1355. $endTime = gmdate("Y-m-d\TH:i:s\Z", $endTime);
  1356. $startTime = gmdate("Y-m-d\TH:i:s\Z", $startTime);
  1357. $resp = $this->client->getDomainFlowStat($domain, $startTime, $endTime,
  1358. $period, $withRegion);
  1359. $this->assertNotNull($resp);
  1360. }
  1361. /**
  1362. * test get domain src flow stat
  1363. */
  1364. public function testGetDomainSrcFlowStat()
  1365. {
  1366. $domain = 'test-sdk.sys-qa.com';
  1367. $period = 300;
  1368. $endTime = time();
  1369. $startTime = $endTime - $period * 10;
  1370. $endTime = gmdate("Y-m-d\TH:i:s\Z", $endTime);
  1371. $startTime = gmdate("Y-m-d\TH:i:s\Z", $startTime);
  1372. $resp = $this->client->getDomainSrcFlowStat($domain, $startTime, $endTime, $period);
  1373. $this->assertNotNull($resp);
  1374. }
  1375. /**
  1376. * test get domain hit rate stat
  1377. */
  1378. public function testGetDomainHitRateStat()
  1379. {
  1380. $domain = 'test-sdk.sys-qa.com';
  1381. $period = 300;
  1382. $endTime = time();
  1383. $startTime = $endTime - $period * 10;
  1384. $endTime = gmdate("Y-m-d\TH:i:s\Z", $endTime);
  1385. $startTime = gmdate("Y-m-d\TH:i:s\Z", $startTime);
  1386. $resp = $this->client->getDomainHitRateStat($domain, $startTime, $endTime, $period);
  1387. $this->assertNotNull($resp);
  1388. }
  1389. /**
  1390. * test get domain http code stat
  1391. */
  1392. public function testGetDomainHttpCodeStat()
  1393. {
  1394. $domain = 'test-sdk.sys-qa.com';
  1395. $period = 300;
  1396. $withRegion = 'true';
  1397. $endTime = time();
  1398. $startTime = $endTime - $period * 10;
  1399. $endTime = gmdate("Y-m-d\TH:i:s\Z", $endTime);
  1400. $startTime = gmdate("Y-m-d\TH:i:s\Z", $startTime);
  1401. $resp = $this->client->getDomainHttpCodeStat($domain, $startTime, $endTime,
  1402. $period, $withRegion);
  1403. $this->assertNotNull($resp);
  1404. }
  1405. /**
  1406. * test get domain top url stat
  1407. */
  1408. public function testGetDomainTopUrlStat()
  1409. {
  1410. $domain = 'test-sdk.sys-qa.com';
  1411. $period = 300;
  1412. $endTime = time();
  1413. $startTime = $endTime - $period * 10;
  1414. $endTime = gmdate("Y-m-d\TH:i:s\Z", $endTime);
  1415. $startTime = gmdate("Y-m-d\TH:i:s\Z", $startTime);
  1416. $resp = $this->client->getDomainTopUrlStat($domain, $startTime, $endTime, $period);
  1417. $this->assertNotNull($resp);
  1418. }
  1419. /**
  1420. * test get domain top referer stat
  1421. */
  1422. public function testGetDomainTopRefererStat()
  1423. {
  1424. $domain = 'test-sdk.sys-qa.com';
  1425. $period = 300;
  1426. $endTime = time();
  1427. $startTime = $endTime - $period * 10;
  1428. $endTime = gmdate("Y-m-d\TH:i:s\Z", $endTime);
  1429. $startTime = gmdate("Y-m-d\TH:i:s\Z", $startTime);
  1430. $resp = $this->client->getDomainTopRefererStat($domain, $startTime, $endTime, $period);
  1431. $this->assertNotNull($resp);
  1432. }
  1433. /**
  1434. * test get domain stats avg speed, new version
  1435. */
  1436. public function testGetDomainStatsAvgSpeed() {
  1437. $period = 300;
  1438. $endTime = time();
  1439. $startTime = $endTime - $period * 10;
  1440. $endTime = gmdate("Y-m-d\TH:i:s\Z", $endTime);
  1441. $startTime = gmdate("Y-m-d\TH:i:s\Z", $startTime);
  1442. $statParam = array(
  1443. 'startTime' => $startTime,
  1444. 'endTime' => $endTime,
  1445. 'period' => $period,
  1446. 'key_type' => 0,
  1447. 'key' => array('test-sdk.sys-qa.com'),
  1448. 'groupBy' => '',
  1449. 'metric' => 'avg_speed',
  1450. );
  1451. $resp = $this->client->getDomainStats($statParam);
  1452. $this->assertNotNull($resp);
  1453. }
  1454. /**
  1455. * test get domain stats avg speed by region, new version
  1456. */
  1457. public function testGetDomainStatsAvgSpeedRegion() {
  1458. $period = 300;
  1459. $endTime = time();
  1460. $startTime = $endTime - $period * 10;
  1461. $endTime = gmdate("Y-m-d\TH:i:s\Z", $endTime);
  1462. $startTime = gmdate("Y-m-d\TH:i:s\Z", $startTime);
  1463. $statParam = array(
  1464. 'startTime' => $startTime,
  1465. 'endTime' => $endTime,
  1466. 'period' => $period,
  1467. 'key_type' => 0,
  1468. 'key' => array('test-sdk.sys-qa.com'),
  1469. 'groupBy' => '',
  1470. 'prov' => 'beijing',
  1471. 'isp' => 'ct',
  1472. 'metric' => 'avg_speed_region',
  1473. );
  1474. $resp = $this->client->getDomainStats($statParam);
  1475. $this->assertNotNull($resp);
  1476. }
  1477. /**
  1478. * test get domain stats pv, new version
  1479. */
  1480. public function testGetDomainStatsPv() {
  1481. $period = 300;
  1482. $endTime = time();
  1483. $startTime = $endTime - $period * 10;
  1484. $endTime = gmdate("Y-m-d\TH:i:s\Z", $endTime);
  1485. $startTime = gmdate("Y-m-d\TH:i:s\Z", $startTime);
  1486. $statParam = array(
  1487. 'startTime' => $startTime,
  1488. 'endTime' => $endTime,
  1489. 'period' => $period,
  1490. 'key_type' => 0,
  1491. 'key' => array('test-sdk.sys-qa.com'),
  1492. 'groupBy' => '',
  1493. 'level' => 'edge',
  1494. 'metric' => 'pv',
  1495. );
  1496. $resp = $this->client->getDomainStats($statParam);
  1497. $this->assertNotNull($resp);
  1498. }
  1499. /**
  1500. * test get domain stats pv by region, new version
  1501. */
  1502. public function testGetDomainStatsPvRegion() {
  1503. $period = 300;
  1504. $endTime = time();
  1505. $startTime = $endTime - $period * 10;
  1506. $endTime = gmdate("Y-m-d\TH:i:s\Z", $endTime);
  1507. $startTime = gmdate("Y-m-d\TH:i:s\Z", $startTime);
  1508. $statParam = array(
  1509. 'startTime' => $startTime,
  1510. 'endTime' => $endTime,
  1511. 'period' => $period,
  1512. 'key_type' => 0,
  1513. 'key' => array('test-sdk.sys-qa.com'),
  1514. 'groupBy' => '',
  1515. 'prov' => 'beijing',
  1516. 'isp' => 'ct',
  1517. 'metric' => 'pv_region',
  1518. );
  1519. $resp = $this->client->getDomainStats($statParam);
  1520. $this->assertNotNull($resp);
  1521. }
  1522. /**
  1523. * test get domain stats pv src, new version
  1524. */
  1525. public function testGetDomainStatsPvSrc() {
  1526. $period = 300;
  1527. $endTime = time();
  1528. $startTime = $endTime - $period * 10;
  1529. $endTime = gmdate("Y-m-d\TH:i:s\Z", $endTime);
  1530. $startTime = gmdate("Y-m-d\TH:i:s\Z", $startTime);
  1531. $statParam = array(
  1532. 'startTime' => $startTime,
  1533. 'endTime' => $endTime,
  1534. 'period' => $period,
  1535. 'key_type' => 0,
  1536. 'key' => array('test-sdk.sys-qa.com'),
  1537. 'groupBy' => '',
  1538. 'metric' => 'pv_src',
  1539. );
  1540. $resp = $this->client->getDomainStats($statParam);
  1541. $this->assertNotNull($resp);
  1542. }
  1543. /**
  1544. * test get domain stats uv, new version
  1545. */
  1546. public function testGetDomainStatsUv() {
  1547. $period = 300;
  1548. $endTime = time();
  1549. $startTime = $endTime - $period * 10;
  1550. $endTime = gmdate("Y-m-d\TH:i:s\Z", $endTime);
  1551. $startTime = gmdate("Y-m-d\TH:i:s\Z", $startTime);
  1552. $statParam = array(
  1553. 'startTime' => $startTime,
  1554. 'endTime' => $endTime,
  1555. 'period' => $period,
  1556. 'key_type' => 0,
  1557. 'key' => array('test-sdk.sys-qa.com'),
  1558. 'groupBy' => '',
  1559. 'metric' => 'uv',
  1560. );
  1561. $resp = $this->client->getDomainStats($statParam);
  1562. $this->assertNotNull($resp);
  1563. }
  1564. /**
  1565. * test get domain stats flow, new version
  1566. */
  1567. public function testGetDomainStatsFlow() {
  1568. $period = 300;
  1569. $endTime = time();
  1570. $startTime = $endTime - $period * 10;
  1571. $endTime = gmdate("Y-m-d\TH:i:s\Z", $endTime);
  1572. $startTime = gmdate("Y-m-d\TH:i:s\Z", $startTime);
  1573. $statParam = array(
  1574. 'startTime' => $startTime,
  1575. 'endTime' => $endTime,
  1576. 'period' => $period,
  1577. 'key_type' => 0,
  1578. 'key' => array('test-sdk.sys-qa.com'),
  1579. 'groupBy' => '',
  1580. 'level' => 'edge',
  1581. 'metric' => 'flow',
  1582. );
  1583. $resp = $this->client->getDomainStats($statParam);
  1584. $this->assertNotNull($resp);
  1585. }
  1586. /**
  1587. * test get domain stats flow by protocol, new version
  1588. */
  1589. public function testGetDomainStatsFlowProtocol() {
  1590. $period = 300;
  1591. $endTime = time();
  1592. $startTime = $endTime - $period * 10;
  1593. $endTime = gmdate("Y-m-d\TH:i:s\Z", $endTime);
  1594. $startTime = gmdate("Y-m-d\TH:i:s\Z", $startTime);
  1595. $statParam = array(
  1596. 'startTime' => $startTime,
  1597. 'endTime' => $endTime,
  1598. 'period' => $period,
  1599. 'key_type' => 0,
  1600. 'key' => array('test-sdk.sys-qa.com'),
  1601. 'groupBy' => '',
  1602. 'protocol' => 'https',
  1603. 'metric' => 'flow_protocol',
  1604. );
  1605. $resp = $this->client->getDomainStats($statParam);
  1606. $this->assertNotNull($resp);
  1607. }
  1608. /**
  1609. * test get domain stats flow by region, new version
  1610. */
  1611. public function testGetDomainStatsFLowRegion() {
  1612. $period = 300;
  1613. $endTime = time();
  1614. $startTime = $endTime - $period * 10;
  1615. $endTime = gmdate("Y-m-d\TH:i:s\Z", $endTime);
  1616. $startTime = gmdate("Y-m-d\TH:i:s\Z", $startTime);
  1617. $statParam = array(
  1618. 'startTime' => $startTime,
  1619. 'endTime' => $endTime,
  1620. 'period' => $period,
  1621. 'key_type' => 0,
  1622. 'key' => array('test-sdk.sys-qa.com'),
  1623. 'groupBy' => '',
  1624. 'prov' => 'beijing',
  1625. 'isp' => 'ct',
  1626. 'metric' => 'flow_region',
  1627. );
  1628. $resp = $this->client->getDomainStats($statParam);
  1629. $this->assertNotNull($resp);
  1630. }
  1631. /**
  1632. * test get domain stats flow src, new version
  1633. */
  1634. public function testGetDomainStatsFlowSrc() {
  1635. $period = 300;
  1636. $endTime = time();
  1637. $startTime = $endTime - $period * 10;
  1638. $endTime = gmdate("Y-m-d\TH:i:s\Z", $endTime);
  1639. $startTime = gmdate("Y-m-d\TH:i:s\Z", $startTime);
  1640. $statParam = array(
  1641. 'startTime' => $startTime,
  1642. 'endTime' => $endTime,
  1643. 'period' => $period,
  1644. 'key_type' => 0,
  1645. 'key' => array('test-sdk.sys-qa.com'),
  1646. 'groupBy' => '',
  1647. 'metric' => 'src_flow',
  1648. );
  1649. $resp = $this->client->getDomainStats($statParam);
  1650. $this->assertNotNull($resp);
  1651. }
  1652. /**
  1653. * test get domain stats hit rate, new version
  1654. */
  1655. public function testGetDomainStatsHit() {
  1656. $period = 300;
  1657. $endTime = time();
  1658. $startTime = $endTime - $period * 10;
  1659. $endTime = gmdate("Y-m-d\TH:i:s\Z", $endTime);
  1660. $startTime = gmdate("Y-m-d\TH:i:s\Z", $startTime);
  1661. $statParam = array(
  1662. 'startTime' => $startTime,
  1663. 'endTime' => $endTime,
  1664. 'period' => $period,
  1665. 'key_type' => 0,
  1666. 'key' => array('test-sdk.sys-qa.com'),
  1667. 'groupBy' => '',
  1668. 'metric' => 'real_hit',
  1669. );
  1670. $resp = $this->client->getDomainStats($statParam);
  1671. $this->assertNotNull($resp);
  1672. }
  1673. /**
  1674. * test get domain stats hit by pv, new version
  1675. */
  1676. public function testGetDomainStatsHitPv() {
  1677. $period = 300;
  1678. $endTime = time();
  1679. $startTime = $endTime - $period * 10;
  1680. $endTime = gmdate("Y-m-d\TH:i:s\Z", $endTime);
  1681. $startTime = gmdate("Y-m-d\TH:i:s\Z", $startTime);
  1682. $statParam = array(
  1683. 'startTime' => $startTime,
  1684. 'endTime' => $endTime,
  1685. 'period' => $period,
  1686. 'key_type' => 0,
  1687. 'key' => array('test-sdk.sys-qa.com'),
  1688. 'groupBy' => '',
  1689. 'metric' => 'pv_hit',
  1690. );
  1691. $resp = $this->client->getDomainStats($statParam);
  1692. $this->assertNotNull($resp);
  1693. }
  1694. /**
  1695. * test get domain stats http code, new version
  1696. */
  1697. public function testGetDomainStatsHttpCode() {
  1698. $period = 300;
  1699. $endTime = time();
  1700. $startTime = $endTime - $period * 10;
  1701. $endTime = gmdate("Y-m-d\TH:i:s\Z", $endTime);
  1702. $startTime = gmdate("Y-m-d\TH:i:s\Z", $startTime);
  1703. $statParam = array(
  1704. 'startTime' => $startTime,
  1705. 'endTime' => $endTime,
  1706. 'period' => $period,
  1707. 'key_type' => 0,
  1708. 'key' => array('test-sdk.sys-qa.com'),
  1709. 'groupBy' => '',
  1710. 'metric' => 'httpcode',
  1711. );
  1712. $resp = $this->client->getDomainStats($statParam);
  1713. $this->assertNotNull($resp);
  1714. }
  1715. /**
  1716. * test get domain stats http code by region, new version
  1717. */
  1718. public function testGetDomainStatsHttpCodeRegion() {
  1719. $period = 300;
  1720. $endTime = time();
  1721. $startTime = $endTime - $period * 10;
  1722. $endTime = gmdate("Y-m-d\TH:i:s\Z", $endTime);
  1723. $startTime = gmdate("Y-m-d\TH:i:s\Z", $startTime);
  1724. $statParam = array(
  1725. 'startTime' => $startTime,
  1726. 'endTime' => $startTime,
  1727. 'period' => $period,
  1728. 'key_type' => 0,
  1729. 'key' => array('test-sdk.sys-qa.com'),
  1730. 'groupBy' => '',
  1731. 'prov' => 'beijing',
  1732. 'isp' => 'ct',
  1733. 'metric' => 'httpcode_region',
  1734. );
  1735. $resp = $this->client->getDomainStats($statParam);
  1736. $this->assertNotNull($resp);
  1737. }
  1738. /**
  1739. * test get domain stats http code src, new version
  1740. */
  1741. public function testGetDomainStatsHttpCodeSrc() {
  1742. $period = 300;
  1743. $endTime = time();
  1744. $startTime = $endTime - $period * 10;
  1745. $endTime = gmdate("Y-m-d\TH:i:s\Z", $endTime);
  1746. $startTime = gmdate("Y-m-d\TH:i:s\Z", $startTime);
  1747. $statParam = array(
  1748. 'startTime' => $startTime,
  1749. 'endTime' => $endTime,
  1750. 'period' => $period,
  1751. 'key_type' => 0,
  1752. 'key' => array('test-sdk.sys-qa.com'),
  1753. 'groupBy' => '',
  1754. 'metric' => 'src_httpcode',
  1755. );
  1756. $resp = $this->client->getDomainStats($statParam);
  1757. $this->assertNotNull($resp);
  1758. }
  1759. /**
  1760. * test get domain stats top urls, new version
  1761. */
  1762. public function testGetDomainStatsTopUrls() {
  1763. $period = 300;
  1764. $endTime = time();
  1765. $startTime = $endTime - $period * 10;
  1766. $endTime = gmdate("Y-m-d\TH:i:s\Z", $endTime);
  1767. $startTime = gmdate("Y-m-d\TH:i:s\Z", $startTime);
  1768. $statParam = array(
  1769. 'startTime' => $startTime,
  1770. 'endTime' => $endTime,
  1771. 'period' => $period,
  1772. 'key_type' => 0,
  1773. 'key' => array('test-sdk.sys-qa.com'),
  1774. 'groupBy' => '',
  1775. 'extra' => 200,
  1776. 'metric' => 'top_urls',
  1777. );
  1778. $resp = $this->client->getDomainStats($statParam);
  1779. $this->assertNotNull($resp);
  1780. }
  1781. /**
  1782. * test get domain stats top referers, new version
  1783. */
  1784. public function testGetDomainStatsTopReferers() {
  1785. $period = 300;
  1786. $endTime = time();
  1787. $startTime = $endTime - $period * 10;
  1788. $endTime = gmdate("Y-m-d\TH:i:s\Z", $endTime);
  1789. $startTime = gmdate("Y-m-d\TH:i:s\Z", $startTime);
  1790. $statParam = array(
  1791. 'startTime' => $startTime,
  1792. 'endTime' => $endTime,
  1793. 'period' => $period,
  1794. 'key_type' => 0,
  1795. 'key' => array('test-sdk.sys-qa.com'),
  1796. 'groupBy' => '',
  1797. 'extra' => 200,
  1798. 'metric' => 'top_referers',
  1799. );
  1800. $resp = $this->client->getDomainStats($statParam);
  1801. $this->assertNotNull($resp);
  1802. }
  1803. /**
  1804. * test get domain stats top domains, new version
  1805. */
  1806. public function testGetDomainStatsTopDomains() {
  1807. $period = 300;
  1808. $endTime = time();
  1809. $startTime = $endTime - $period * 10;
  1810. $endTime = gmdate("Y-m-d\TH:i:s\Z", $endTime);
  1811. $startTime = gmdate("Y-m-d\TH:i:s\Z", $startTime);
  1812. $statParam = array(
  1813. 'startTime' => $startTime,
  1814. 'endTime' => $endTime,
  1815. 'period' => $period,
  1816. 'groupBy' => '',
  1817. 'extra' => 200,
  1818. 'metric' => 'top_domains',
  1819. );
  1820. $resp = $this->client->getDomainStats($statParam);
  1821. $this->assertNotNull($resp);
  1822. }
  1823. /**
  1824. * test get domain stats 4xx/5xx error reason, new version
  1825. */
  1826. public function testGetDomainStatsError() {
  1827. $period = 300;
  1828. $endTime = time();
  1829. $startTime = $endTime - $period * 10;
  1830. $endTime = gmdate("Y-m-d\TH:i:s\Z", $endTime);
  1831. $startTime = gmdate("Y-m-d\TH:i:s\Z", $startTime);
  1832. $statParam = array(
  1833. 'startTime' => $startTime,
  1834. 'endTime' => $endTime,
  1835. 'period' => $period,
  1836. 'key_type' => 0,
  1837. 'key' => array('test-sdk.sys-qa.com'),
  1838. 'groupBy' => '',
  1839. 'metric' => 'error',
  1840. );
  1841. $resp = $this->client->getDomainStats($statParam);
  1842. $this->assertNotNull($resp);
  1843. }
  1844. /**
  1845. * test prefetch
  1846. */
  1847. public function testPrefetch()
  1848. {
  1849. $this->markTestSkipped(
  1850. 'skip'
  1851. );
  1852. $tasks = array(
  1853. array(
  1854. 'url' => 'http://test-sdk.sys-qa.com/path/to/file',
  1855. ),
  1856. );
  1857. $resp = $this->client->prefetch($tasks);
  1858. $this->assertNotNull($resp);
  1859. $this->assertNotNull($resp->id);
  1860. $resp = $this->client->listPrefetchStatus($resp->id);
  1861. $this->assertNotNull($resp);
  1862. }
  1863. /**
  1864. * test get prefetch status
  1865. */
  1866. public function testListPrefetchStatus()
  1867. {
  1868. $url = 'http://test-sdk.sys-qa.com/1.jpg';
  1869. $endTime = time();
  1870. $startTime = $endTime - 1000;
  1871. $endTime = gmdate("Y-m-d\TH:i:s\Z", $endTime);
  1872. $startTime = gmdate("Y-m-d\TH:i:s\Z", $startTime);
  1873. $resp = $this->client->listPrefetchStatus('', $url, $startTime, $endTime);
  1874. $this->assertNotNull($resp);
  1875. }
  1876. /**
  1877. * test purge
  1878. */
  1879. public function testPurge()
  1880. {
  1881. $this->markTestSkipped(
  1882. 'skip'
  1883. );
  1884. $tasks = array(
  1885. array(
  1886. 'url' => 'http://test-sdk.sys-qa.com/path/to/file',
  1887. ),
  1888. array(
  1889. 'url' => 'http://test-sdk.sys-qa.com/path/to/directory/',
  1890. 'type' => 'directory',
  1891. ),
  1892. );
  1893. $resp = $this->client->purge($tasks);
  1894. $this->assertNotNull($resp);
  1895. $this->assertNotNull($resp->id);
  1896. $resp = $this->client->listPurgeStatus($resp->id);
  1897. $this->assertNotNull($resp);
  1898. }
  1899. /**
  1900. * test purge status
  1901. */
  1902. public function testListPurgeStatus()
  1903. {
  1904. $url = 'http://test-sdk.sys-qa.com/1.jpg';
  1905. $endTime = time();
  1906. $startTime = $endTime - 1000;
  1907. $endTime = gmdate("Y-m-d\TH:i:s\Z", $endTime);
  1908. $startTime = gmdate("Y-m-d\TH:i:s\Z", $startTime);
  1909. $resp = $this->client->listPurgeStatus('', $url, $startTime, $endTime);
  1910. $this->assertNotNull($resp);
  1911. }
  1912. /**
  1913. * test list purge/prefetch quota
  1914. */
  1915. public function testListQuota()
  1916. {
  1917. $resp = $this->client->listQuota();
  1918. $this->assertNotNull($resp);
  1919. }
  1920. /**
  1921. * test get domain log
  1922. */
  1923. public function testGetDomainLog()
  1924. {
  1925. $domain = "test-sdk.sys-qa.com";
  1926. $startTime = "2017-12-07T16:00:00Z";
  1927. $endTime = "2017-12-07T18:00:00Z";
  1928. $resp = $this->client->getDomainLog($domain, $startTime, $endTime);
  1929. $this->assertNotNull($resp);
  1930. }
  1931. /**
  1932. * test get domains log
  1933. */
  1934. public function testGetDomainsLog()
  1935. {
  1936. $domain = "test-sdk.sys-qa.com";
  1937. $startTime = "2017-12-07T16:00:00Z";
  1938. $endTime = "2017-12-07T18:00:00Z";
  1939. $options = array(
  1940. 'startTime' => $startTime,
  1941. 'endTime' => $endTime,
  1942. 'domains' => array(
  1943. $domain
  1944. )
  1945. );
  1946. $resp = $this->client->getDomainsLog($options);
  1947. $this->assertNotNull($resp);
  1948. }
  1949. /**
  1950. * test get domains log
  1951. * @expectedException Exception
  1952. * @throws \BaiduBce\Exception\BceClientException
  1953. */
  1954. public function testGetDomainsLogThrow() {
  1955. global $g_CDN_TEST_CONFIG;
  1956. $client = new CdnClient($g_CDN_TEST_CONFIG);
  1957. $options = array();
  1958. $client->getDomainsLog($options);
  1959. }
  1960. /**
  1961. * test query ip
  1962. */
  1963. public function testIpQuery()
  1964. {
  1965. $ip = '1.2.3.4';
  1966. $action = 'describeIp';
  1967. $resp = $this->client->ipQuery($action, $ip);
  1968. $this->assertNotNull($resp);
  1969. }
  1970. /**
  1971. * test cache set das
  1972. */
  1973. public function testSetDsa()
  1974. {
  1975. $this->markTestSkipped(
  1976. 'skip'
  1977. );
  1978. $action = array(
  1979. "action" => "enable"
  1980. );
  1981. $resp = $this->client->setDsa($action);
  1982. $this->assertEquals($resp, '');
  1983. }
  1984. /**
  1985. * test set domain dsa config
  1986. */
  1987. public function testSetDomainDsa()
  1988. {
  1989. $dsa = array(
  1990. 'dsa' => array(
  1991. 'enabled' => true,
  1992. 'rules' => array(
  1993. array(
  1994. 'type' => 'suffix',
  1995. 'value' => '.mp4;.jpg;.php'
  1996. )
  1997. )
  1998. )
  1999. );
  2000. $domain = "test-sdk.sys-qa.com";
  2001. $resp = $this->client->setDomainDsa($domain, $dsa);
  2002. $this->assertNotNull($resp);
  2003. }
  2004. /**
  2005. * test cache set domain dsa config
  2006. * @expectedException Exception
  2007. * @throws \BaiduBce\Exception\BceClientException
  2008. */
  2009. public function testSetDomainDsaThrow() {
  2010. global $g_CDN_TEST_CONFIG;
  2011. $client = new CdnClient($g_CDN_TEST_CONFIG);
  2012. $domain = "";
  2013. $dsa = array();
  2014. $client->setDomainDsa($domain, $dsa);
  2015. }
  2016. /**
  2017. * test get dsa domain list
  2018. */
  2019. public function testGetDomainDsa()
  2020. {
  2021. $domain = "test-sdk.sys-qa.com";
  2022. $resp = $this->client->getDomainDsa();
  2023. $this->assertNotNull($resp);
  2024. }
  2025. }