Skip to content

Commit d0ff285

Browse files
committed
Test for IPv6 address sanitization
1 parent 77ace61 commit d0ff285

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

tests/SocketTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,46 @@ public function testCreatePair()
141141

142142
$this->loop->run();
143143
}
144+
145+
public function provideSanitizeAddress()
146+
{
147+
return array(
148+
array(
149+
'127.0.0.1:1337',
150+
),
151+
array(
152+
'[::1]:1337',
153+
),
154+
);
155+
}
156+
157+
/**
158+
* @dataProvider provideSanitizeAddress
159+
*/
160+
public function testSanitizeAddress($address)
161+
{
162+
$promise = $this->factory->createServer($address);
163+
$server = $this->getValueFromResolvedPromise($promise);
164+
165+
$promise = $this->factory->createClient($server->getLocalAddress());
166+
$client = $this->getValueFromResolvedPromise($promise);
167+
168+
$that = $this;
169+
$server->on('message', function ($message, $remote, $server) use ($that) {
170+
// once the server receives a message, send it pack to client and stop server
171+
$server->send('response:' . $message, $remote);
172+
$server->end();
173+
});
174+
175+
$client->on('message', function ($message, $remote, $client) use ($that, $address) {
176+
$that->assertEquals($address, $remote);
177+
178+
// once the client receives a message, stop client
179+
$client->end();
180+
});
181+
182+
$client->send('test');
183+
184+
$this->loop->run();
185+
}
144186
}

0 commit comments

Comments
 (0)