Path: blob/master/src/infrastructure/util/__tests__/PhabricatorPreambleTestCase.php
12242 views
<?php12final class PhabricatorPreambleTestCase3extends PhabricatorTestCase {45/**6* @phutil-external-symbol function preamble_get_x_forwarded_for_address7*/8public function testXForwardedForLayers() {9$tests = array(10// This is normal behavior with one load balancer.11array(12'header' => '1.2.3.4',13'layers' => 1,14'expect' => '1.2.3.4',15),1617// In this case, the LB received a request which already had an18// "X-Forwarded-For" header. This might be legitimate (in the case of19// a CDN request) or illegitimate (in the case of a client making20// things up). We don't want to trust it.21array(22'header' => '9.9.9.9, 1.2.3.4',23'layers' => 1,24'expect' => '1.2.3.4',25),2627// Multiple layers of load balancers.28array(29'header' => '9.9.9.9, 1.2.3.4',30'layers' => 2,31'expect' => '9.9.9.9',32),3334// Multiple layers of load balancers, plus a client-supplied value.35array(36'header' => '8.8.8.8, 9.9.9.9, 1.2.3.4',37'layers' => 2,38'expect' => '9.9.9.9',39),4041// Multiple layers of load balancers, but this request came from42// somewhere inside the network.43array(44'header' => '1.2.3.4',45'layers' => 2,46'expect' => '1.2.3.4',47),4849array(50'header' => 'A, B, C, D, E, F, G, H, I',51'layers' => 7,52'expect' => 'C',53),54);5556foreach ($tests as $test) {57$header = $test['header'];58$layers = $test['layers'];59$expect = $test['expect'];6061$actual = preamble_get_x_forwarded_for_address($header, $layers);6263$this->assertEqual(64$expect,65$actual,66pht(67'Address after stripping %d layers from: %s',68$layers,69$header));70}71}7273}747576