[ Index ]

PHP Cross Reference of YOURLS

title

Body

[close]

/tests/tests/http/ -> proxy.php (source)

   1  <?php
   2  
   3  /**
   4   * HTTP proxy support functions
   5   *
   6   * @group http
   7   * @since 0.1
   8   */
   9  class HTTP_Proxy_Tests extends PHPUnit\Framework\TestCase {
  10  
  11      protected function tearDown(): void {
  12          yourls_remove_all_filters( 'http_get_proxy_bypass_host' );
  13      }
  14  
  15      /**
  16       * List of hosts and wether they should go through proxy or not
  17       */
  18      public function proxy() {
  19          return array(
  20              array( 'invalid', false ),
  21              array( 'http://localhost', false ),
  22              array( 'http://127.0.0.1', false ),
  23              array( 'http://127.1', false ),
  24              array( 'http://[::1]', false ),
  25              array( YOURLS_SITE, false ),
  26              array( 'http://' . rand_str() , true ),
  27  
  28              array( 'http://bypass.me' , true ),    // these two will be added to the by-pass list
  29              array( 'http://skipthem.all' , true ),   // in the next test
  30          );
  31      }
  32  
  33      /**
  34       * Check what URLs we should send through a proxy, if defined
  35       *
  36       * @dataProvider proxy
  37       * @since 0.1
  38       */
  39      public function test_proxy( $url, $goes_through_proxy ) {
  40          $this->assertSame( $goes_through_proxy, yourls_send_through_proxy( $url ) );
  41      }
  42  
  43      /**
  44       * List of hosts and wether they should go through proxy or not, with 'bypass.me, *.skipthem.all' defined as by-passing hosts
  45       */
  46      public function proxy_bypass_wildcard() {
  47          return array(
  48              array( 'invalid', false ),
  49              array( 'http://localhost', false ),
  50              array( 'http://127.0.0.1', false ),
  51              array( 'http://127.1', false ),
  52              array( 'http://[::1]', false ),
  53              array( YOURLS_SITE, false ),
  54              array( 'http://' . rand_str() , true ),
  55  
  56              array( 'http://bypass.me' , false ),
  57              array( 'http://bypass.me/some/thing' , false ),
  58              array( 'http://notbypass.me' , true ),
  59              array( 'http://bypass.menot' , true ),
  60              array( 'http://dont.bypass.me' , true ),
  61  
  62              array( 'http://skipthem.all' , false ),
  63              array( 'http://notskipthem.all' , true ),
  64              array( 'http://skipthem.allnot' , true ),
  65              array( 'http://really.skipthem.all' , false ),
  66              array( 'http://yeah.really.skipthem.all/some/thing' , false ),
  67          );
  68      }
  69  
  70      public function bypass_hosts_wildcard() {
  71          return 'bypass.me, *.skipthem.all';
  72      }
  73  
  74      /**
  75       * Check what URLs we should send through a proxy with 'bypass.me, *.skipthem.all' defined as by-passing hosts
  76       *
  77       * @dataProvider proxy_bypass_wildcard
  78       * @since 0.1
  79       */
  80      public function test_proxy_bypass_wildcard( $url, $goes_through_proxy ) {
  81          yourls_add_filter( 'http_get_proxy_bypass_host', array( $this, 'bypass_hosts_wildcard' ) );
  82          $this->assertSame( $goes_through_proxy, yourls_send_through_proxy( $url ) );
  83      }
  84  
  85      /**
  86       * Check that we can get some proxy information
  87       *
  88       * This test is pretty limited since we're not toying with define(). We just want to check that the function
  89       * call returns something
  90       *
  91       * @since 0.1
  92       */
  93      public function test_proxy_get_info() {
  94          $before = $after = rand_str();
  95          $after = yourls_http_get_proxy();
  96          $this->assertNotSame( $before, $after );
  97      }
  98  
  99      /**
 100       * Check that we can get something regarding hosts bypassing the proxy
 101       *
 102       * This test is pretty limited since we're not toying with define(). We just want to check that the function
 103       * call returns something
 104       *
 105       * @since 0.1
 106       */
 107      public function test_proxy_get_bypass_hosts() {
 108          $before = $after = rand_str();
 109          $after = yourls_http_get_proxy_bypass_host();
 110          $this->assertNotSame( $before, $after );
 111      }
 112  
 113  }


Generated: Wed Sep 28 05:10:02 2022 Cross-referenced by PHPXref 0.7.1