[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/_test/tests/inc/ -> init_checkssl.test.php (source)

   1  <?php
   2  
   3  class init_checkssl_test extends DokuWikiTest
   4  {
   5  
   6      /**
   7       * Running behind an SSL proxy, HTTP between server and proxy
   8       * Proxy (REMOTE_ADDR) is matched by default trustedproxy config regex
   9       * HTTPS not set
  10       * HTTP_X_FORWARDED_PROTO
  11       * set to https
  12       */
  13      function test1a()
  14      {
  15          global $conf;
  16          $conf['trustedproxy'] = '^(::1|[fF][eE]80:|127\.|10\.|192\.168\.|172\.((1[6-9])|(2[0-9])|(3[0-1]))\.)';
  17          $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
  18          $_SERVER['HTTP_X_FORWARDED_PROTO'] = 'https';
  19  
  20          $this->assertTrue(is_ssl());
  21      }
  22  
  23      /**
  24       * Running behind an SSL proxy, HTTP between server and proxy
  25       * Proxy (REMOTE_ADDR) is not matched by default trustedproxy config regex
  26       * HTTPS not set
  27       * HTTP_X_FORWARDED_PROTO
  28       * set to https
  29       */
  30      function test1b()
  31      {
  32          global $conf;
  33          $conf['trustedproxy'] = '^(::1|[fF][eE]80:|127\.|10\.|192\.168\.|172\.((1[6-9])|(2[0-9])|(3[0-1]))\.)';
  34          $_SERVER['REMOTE_ADDR'] = '8.8.8.8';
  35          $_SERVER['HTTP_X_FORWARDED_PROTO'] = 'https';
  36  
  37          $this->assertFalse(is_ssl());
  38      }
  39  
  40      /**
  41       * Running behind a plain HTTP proxy, HTTP between server and proxy
  42       * HTTPS not set
  43       * HTTP_X_FORWARDED_PROTO set to http
  44       */
  45      function test2()
  46      {
  47          global $conf;
  48          $conf['trustedproxy'] = '^(::1|[fF][eE]80:|127\.|10\.|192\.168\.|172\.((1[6-9])|(2[0-9])|(3[0-1]))\.)';
  49          $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
  50          $_SERVER['HTTP_X_FORWARDED_PROTO'] = 'http';
  51  
  52          $this->assertFalse(is_ssl());
  53      }
  54  
  55      /**
  56       * Running behind an SSL proxy, HTTP between server and proxy
  57       * HTTPS set to off,
  58       * HTTP_X_FORWARDED_PROTO set to https
  59       */
  60      function test3()
  61      {
  62          global $conf;
  63          $conf['trustedproxy'] = '^(::1|[fF][eE]80:|127\.|10\.|192\.168\.|172\.((1[6-9])|(2[0-9])|(3[0-1]))\.)';
  64          $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
  65          $_SERVER['HTTP_X_FORWARDED_PROTO'] = 'https';
  66          $_SERVER['HTTPS'] = 'off';
  67  
  68          $this->assertTrue(is_ssl());
  69      }
  70  
  71      /**
  72       * Not running behind a proxy, HTTPS server
  73       * HTTPS set to on,
  74       * HTTP_X_FORWARDED_PROTO not set
  75       */
  76      function test4()
  77      {
  78          $_SERVER['HTTPS'] = 'on';
  79  
  80          $this->assertTrue(is_ssl());
  81      }
  82  
  83      /**
  84       * Not running behind a proxy, plain HTTP server
  85       * HTTPS not set
  86       * HTTP_X_FORWARDED_PROTO not set
  87       */
  88      function test5()
  89      {
  90          $this->assertFalse(is_ssl());
  91      }
  92  
  93      /**
  94       * Not running behind a proxy, plain HTTP server
  95       * HTTPS set to off
  96       * HTTP_X_FORWARDED_PROTO not set
  97       */
  98      function test6()
  99      {
 100          $_SERVER['HTTPS'] = 'off';
 101          $this->assertFalse(is_ssl());
 102      }
 103  
 104      /**
 105       * Running behind an SSL proxy, SSL between proxy and HTTP server
 106       * HTTPS set to on,
 107       * HTTP_X_FORWARDED_PROTO set to https
 108       */
 109      function test7()
 110      {
 111          global $conf;
 112          $conf['trustedproxy'] = '^(::1|[fF][eE]80:|127\.|10\.|192\.168\.|172\.((1[6-9])|(2[0-9])|(3[0-1]))\.)';
 113          $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
 114          $_SERVER['HTTP_X_FORWARDED_PROTO'] = 'https';
 115          $_SERVER['HTTPS'] = 'on';
 116  
 117          $this->assertTrue(is_ssl());
 118      }
 119  }