Internal browser and ip_address() inconsistent

catch - May 10, 2008 - 09:14
Project:Drupal
Version:7.x-dev
Component:simpletest.module
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs work
Description

When writing tests for: http://drupal.org/node/256152 I needed to check something which validates against ip_address() (which is pretty much a wrapper for $_SERVER['REMOTE_ADDR'])

debian etch: libcurl3 (>= 7.15.5-1) - fails
ubuntu gutsy: - libcurl3 (>= 7.16.2-1) - passes
MAMP on OSX: fails (not sure of curl version).

Another option might be to try to fake $_SERVER['REMOTE_ADDR'] within the simpletest browser to something consistent - then test against that for any similar tests, bit nasty but for what it's worth.

#1

boombatower - May 12, 2008 - 22:30

The IP could be set to something in a similar manor to the db prefix. What should it be set to?

#2

boombatower - May 12, 2008 - 22:31
Status:active» postponed (maintainer needs more info)

Marking accordingly.

#3

catch - May 13, 2008 - 08:40
Status:postponed (maintainer needs more info)» active

Not sure really, 127.0.0.1 maybe?

#4

chx - May 16, 2008 - 07:00

just pass on the real ip_address

#5

boombatower - June 6, 2008 - 16:31

This would be very simple to fix, just check for SimpleTest user-agent then set IP to x if it doesn't come through.

I can't test this because it passes on my machine.

#6

boombatower - June 26, 2008 - 07:30
Status:active» postponed (maintainer needs more info)

Bump, we need to pick an IP address and get this fixed. I would second 127.0.0.1.

#7

catch - June 26, 2008 - 08:45
Status:postponed (maintainer needs more info)» active

@boombatower - do you mean in the test itself or somewhere more central?

#8

boombatower - June 26, 2008 - 19:57

More central, but if this is the only place where it occurs perhaps just in the test would be fine.

For consistency and to ensure this doesn't come up again it should probably be more central.

#9

catch - June 26, 2008 - 20:13
Status:active» needs review

Since this appears to be a curl bug, here's a patch to simply roll back that part of the test - we can then mark this postponed against a curl issue (which I believe chx is arranging).

General consensus has been to keep test passes at 100% (once they all pass), and not commit tests that we know are going to fail - this one kinda breaks that rule so I think it's acceptable to remove.

AttachmentSize
rollbackip.test 867 bytes

#10

catch - June 26, 2008 - 20:32
Status:needs review» won't fix

Since I can't reproduce this anymore myself, marking as won't fix. Can re-open if someone else does.

#11

catch - June 26, 2008 - 20:40
Status:won't fix» needs review

Sorry, I can indeed reproduce this.

#12

boombatower - June 28, 2008 - 21:35
Status:needs review» reviewed & tested by the community

This patch makes sense, but I think we need to contact the cURL developers and inform them of this issue.

Once resolved this needs to be reverted.

Once this is committed lets mark this as postponed.

Otherwise we can just ignore the environments that this doesn't pass on. :)

#13

catch - June 29, 2008 - 10:06

Ideally we want all tests passing on any environments they can be run on - otherwise we'll get bogus test failures while people are trying to write patches or just showing up in the bug queue over and over again. Another option might be to wrap that part of the tests in an if, to ensure ip_address() returns something before doing the assertion - but ideally it can be dealt with on the cURL end.

#14

Dries - June 29, 2008 - 11:40
Status:reviewed & tested by the community» needs work

I've decided to comment out this test instead of deleting it. I've also added a note to explain why it was commented out.

I'm marking this issue 'code needs work'. I think we should mark it 'fixed' once we have reported this bug to the cURL maintainers.

#15

Wim Leers - June 29, 2008 - 12:45

curl version info on Mac OS X Leopard:

curl 7.16.3 (powerpc-apple-darwin9.0) libcurl/7.16.3 OpenSSL/0.9.7l zlib/1.2.3

(Note that I did NOT check if tests are working or failing for me.)

#16

Damien Tournoud - June 30, 2008 - 00:23

Isn't this probably a PHP and/or Apache bug rather than a cURL bug?

I can't understand why the client (here cURL) could have any impact on the server's ability to detect it's IP address. After all, this is done at the TCP layer, not at the HTTP one. We need more information on this.

#17

Damien Tournoud - June 30, 2008 - 00:26

What is the return of $_SERVER['REMOTE_ADDR'] in the case it fails?

#18

Damien Tournoud - June 30, 2008 - 00:58
Title:internal browser and ip_address() inconsistent» Internal browser and ip_address() inconsistent

Ok, here is a fix for that.

Tested in the both cases I could think of (the hostname specified in $base_url points to 127.0.0.1 and that hostname points to the IP of an external interface), tests pass.

About the debate on whether we should "teach" ip_address() to fake it's return when we are in a test request: I think we shouldn't, because there are no needs to at that point.

AttachmentSize
256886-block-own-ip.patch 1.37 KB
Testbed results
256886-block-own-ip.patchfailedFailed: Failed to apply patch. Detailed results

#19

Damien Tournoud - June 30, 2008 - 00:59
Status:needs work» needs review

#20

catch - July 1, 2008 - 20:36
Status:needs review» reviewed & tested by the community

Works for me :)

#21

Dries - July 5, 2008 - 08:03

Doesn't work for me yet.

In the test, $parsed['host'] is 'localhost' and the IP in $edit['ip'] is '127.0.0.1'.

Given that, I've put the following two lines in system_ip_blocking_form_validate():

  file_put_contents('/tmp/drupal.log', "$ip -- ". ip_address() ."\n", FILE_APPEND);
  flush();

This is what ends up in the log file when running the tests:

$ tail -f /tmp/drupal.log
192.168.1.1 -- ::1
192.168.1.1 -- ::1
255.255.255.255 -- ::1
test.example.com -- ::1
-- ::1
127.0.0.1 -- ::1

It looks like ip_address() doesn't return a proper IP address (when running simpletest)?

#22

catch - July 5, 2008 - 09:08
Status:reviewed & tested by the community» needs work

Hmm. I'll try again on my system where it seemed to fix the problem, but looks like we might have to leave this postponed against cURL still.

#23

Damien Tournoud - July 5, 2008 - 09:25

@Dries#21: ip_address() can't be wrong, it just report the IP address of the client as seen by the server. Except that here it's the address of the IPv6 loopback interface.

What's wrong is my code that tries to guess what the IP address of the client *as seen by the server* could possibly be if we call the server from the same box as the client.

Can you paste your /etc/hosts? I guess there is a localhost ::1 there.

#24

Dries - July 5, 2008 - 10:15

Damien, you're right! Here is my /etc/hosts:

127.0.0.1 localhost
255.255.255.255 broadcasthost
::1             localhost
192.168.2.2     metis

I checked on both my Macs and they both have that line.

#25

Dave Reid - July 9, 2009 - 02:10
Status:needs work» needs review

So this sounds like it's a configuration problem then? We should probably add this test back in.

#26

System Message - August 25, 2009 - 00:20
Status:needs review» needs work

The last submitted patch failed testing.

 
 

Drupal is a registered trademark of Dries Buytaert.