当前位置: 首页>>代码示例>>PHP>>正文


PHP curl::get_security方法代码示例

本文整理汇总了PHP中curl::get_security方法的典型用法代码示例。如果您正苦于以下问题:PHP curl::get_security方法的具体用法?PHP curl::get_security怎么用?PHP curl::get_security使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在curl的用法示例。


在下文中一共展示了curl::get_security方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: test_curl_basics_with_security_helper

 /**
  * Test a curl basic request with security enabled.
  */
 public function test_curl_basics_with_security_helper()
 {
     $this->resetAfterTest();
     // Test a request with a basic hostname filter applied.
     $testhtml = $this->getExternalTestFileUrl('/test.html');
     $url = new moodle_url($testhtml);
     $host = $url->get_host();
     set_config('curlsecurityblockedhosts', $host);
     // Blocks $host.
     // Create curl with the default security enabled. We expect this to be blocked.
     $curl = new curl();
     $contents = $curl->get($testhtml);
     $expected = $curl->get_security()->get_blocked_url_string();
     $this->assertSame($expected, $contents);
     $this->assertSame(0, $curl->get_errno());
     // Now, create a curl using the 'ignoresecurity' override.
     // We expect this request to pass, despite the admin setting having been set earlier.
     $curl = new curl(['ignoresecurity' => true]);
     $contents = $curl->get($testhtml);
     $this->assertSame('47250a973d1b88d9445f94db4ef2c97a', md5($contents));
     $this->assertSame(0, $curl->get_errno());
     // Now, try injecting a mock security helper into curl. This will override the default helper.
     $mockhelper = $this->getMockBuilder('\\core\\files\\curl_security_helper')->getMock();
     // Make the mock return a different string.
     $mockhelper->expects($this->any())->method('get_blocked_url_string')->will($this->returnValue('You shall not pass'));
     // And make the mock security helper block all URLs. This helper instance doesn't care about config.
     $mockhelper->expects($this->any())->method('url_is_blocked')->will($this->returnValue(true));
     $curl = new curl(['securityhelper' => $mockhelper]);
     $contents = $curl->get($testhtml);
     $this->assertSame('You shall not pass', $curl->get_security()->get_blocked_url_string());
     $this->assertSame($curl->get_security()->get_blocked_url_string(), $contents);
 }
开发者ID:Chocolate-lightning,项目名称:moodle,代码行数:35,代码来源:filelib_test.php


注:本文中的curl::get_security方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。