Skip to content

Commit

Permalink
use local squid docker instance for proxy testing
Browse files Browse the repository at this point in the history
  • Loading branch information
splitbrain committed Apr 26, 2023
1 parent e002c05 commit 605810e
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 29 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/testLinux.yml
Expand Up @@ -34,6 +34,10 @@ jobs:
POSTGRES_PASSWORD: postgres
ports:
- 5432:5432
squid:
image: ubuntu/squid
ports:
- 3128:3128
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -56,6 +60,7 @@ jobs:
cd _test
cp mysql.conf.php.dist mysql.conf.php
cp pgsql.conf.php.dist pgsql.conf.php
cp proxy.conf.php.dist proxy.conf.php
- name: Run PHPUnit
run: |
Expand Down
6 changes: 6 additions & 0 deletions _test/proxy.conf.php.dist
@@ -0,0 +1,6 @@
<?php
/**
* This configures the access to a proxy server for HTTP related proxy tests.
*/
$conf['host'] = '127.0.0.1';
$conf['port'] = 3128;
37 changes: 29 additions & 8 deletions _test/tests/inc/httpclient_http_proxy.test.php
@@ -1,21 +1,42 @@
<?php

require_once (__DIR__ . '/httpclient_mock.php');
require_once(__DIR__ . '/httpclient_mock.php');

class httpclient_http_proxy_test extends DokuWikiTest
{
protected $url = 'http://httpbingo.org/user-agent';
protected $host;
protected $port;


public function setUp(): void
{
parent::setUp();
$configuration = DOKU_UNITTEST . "proxy.conf.php";
if (file_exists($configuration)) {
/** @var $conf array */
include $configuration;
$this->host = $conf['host'];
$this->port = $conf['port'];
}

if (!$this->host || !$this->port) {
$this->markTestSkipped("Skipped proxy tests. Missing configuration");
}
}

class httpclient_http_proxy_test extends DokuWikiTest {
protected $url = 'http://eu.httpbin.org/user-agent';

/**
* @group internet
*/
function test_simpleget(){
function testSimpleGet()
{
$http = new HTTPMockClient();
// proxy provided by Andrwe Lord Weber <dokuwiki@andrwe.org>
$http->proxy_host = 'proxy.andrwe.org';
$http->proxy_port = 8080;
$http->proxy_host = $this->host;
$http->proxy_port = $this->port;

$data = $http->get($this->url);
$this->assertFalse($data === false, $http->errorInfo($this->url));
$this->assertTrue(strpos($data,'DokuWiki') !== false, 'response content');
$this->assertStringContainsString('DokuWiki', $data, 'response content');
}
}
27 changes: 7 additions & 20 deletions _test/tests/inc/httpclient_https_proxy.test.php
@@ -1,30 +1,17 @@
<?php
require_once dirname(__FILE__).'/httpclient_http_proxy.test.php';
require_once dirname(__FILE__) . '/httpclient_http_proxy.test.php';

class httpclient_https_proxy_test extends httpclient_http_proxy_test {
protected $url = 'https://eu.httpbin.org/user-agent';
class httpclient_https_proxy_test extends httpclient_http_proxy_test
{
protected $url = 'http://httpbingo.org/user-agent';

public function setUp() : void {
public function setUp(): void
{
// skip tests when this PHP has no SSL support
$transports = stream_get_transports();
if(!in_array('ssl',$transports)){
if (!in_array('ssl', $transports)) {
$this->markTestSkipped('No SSL support available.');
}
parent::setUp();
}

/**
* @group internet
*/
function test_connectfail(){
$http = new HTTPMockClient();
// proxy provided by Andrwe Lord Weber <dokuwiki@andrwe.org>
$http->proxy_host = 'proxy.andrwe.org';
$http->proxy_port = 8080;

// the proxy accepts connections to defined URLs only - the connect call should fail
$data = $http->get('https://www.google.com');
$this->assertFalse($data);
$this->assertEquals(-150, $http->status);
}
}
2 changes: 1 addition & 1 deletion inc/HTTP/HTTPClient.php
Expand Up @@ -554,7 +554,7 @@ protected function ssltunnel(&$socket, &$requesturl){
}

if (@stream_socket_enable_crypto($socket, true, $cryptoMethod)) {
$requesturl = $requestinfo['path'].
$requesturl = ($requestinfo['path'] ?? '/').
(!empty($requestinfo['query'])?'?'.$requestinfo['query']:'');
return true;
}
Expand Down

0 comments on commit 605810e

Please sign in to comment.