@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at upstream/main 74 lines 1.9 kB view raw
1<?php 2 3final class PhabricatorPreambleTestCase 4 extends PhabricatorTestCase { 5 6 /** 7 * @phutil-external-symbol function preamble_get_x_forwarded_for_address 8 */ 9 public function testXForwardedForLayers() { 10 $tests = array( 11 // This is normal behavior with one load balancer. 12 array( 13 'header' => '1.2.3.4', 14 'layers' => 1, 15 'expect' => '1.2.3.4', 16 ), 17 18 // In this case, the LB received a request which already had an 19 // "X-Forwarded-For" header. This might be legitimate (in the case of 20 // a CDN request) or illegitimate (in the case of a client making 21 // things up). We don't want to trust it. 22 array( 23 'header' => '9.9.9.9, 1.2.3.4', 24 'layers' => 1, 25 'expect' => '1.2.3.4', 26 ), 27 28 // Multiple layers of load balancers. 29 array( 30 'header' => '9.9.9.9, 1.2.3.4', 31 'layers' => 2, 32 'expect' => '9.9.9.9', 33 ), 34 35 // Multiple layers of load balancers, plus a client-supplied value. 36 array( 37 'header' => '8.8.8.8, 9.9.9.9, 1.2.3.4', 38 'layers' => 2, 39 'expect' => '9.9.9.9', 40 ), 41 42 // Multiple layers of load balancers, but this request came from 43 // somewhere inside the network. 44 array( 45 'header' => '1.2.3.4', 46 'layers' => 2, 47 'expect' => '1.2.3.4', 48 ), 49 50 array( 51 'header' => 'A, B, C, D, E, F, G, H, I', 52 'layers' => 7, 53 'expect' => 'C', 54 ), 55 ); 56 57 foreach ($tests as $test) { 58 $header = $test['header']; 59 $layers = $test['layers']; 60 $expect = $test['expect']; 61 62 $actual = preamble_get_x_forwarded_for_address($header, $layers); 63 64 $this->assertEqual( 65 $expect, 66 $actual, 67 pht( 68 'Address after stripping %d layers from: %s', 69 $layers, 70 $header)); 71 } 72 } 73 74}