Skip to content

Commit

Permalink
Merge pull request #21 from clue-labs/selective-uri
Browse files Browse the repository at this point in the history
Ignore URI scheme when matching selective connectors
  • Loading branch information
clue authored Jun 23, 2017
2 parents 787cb97 + 2f50827 commit 45f1a81
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,15 @@ $selective = new ConnectionManagerSelective(array(
));
```

Each entry in the list MUST be in the form `host` or `host:port`, where
`host` may contain the `*` wildcard character and `port` may be given as
either an exact port number or as a range in the form of `min-max`.
Passing anything else will result in an `InvalidArgumentException`.

> Note that the host will be matched exactly as-is otherwise. This means that
if you only block `youtube.com`, this has no effect on `www.youtube.com`.
You may want to add a second rule for `*.youtube.com` in this case.

## Install

The recommended way to install this library is [through Composer](http://getcomposer.org).
Expand Down
2 changes: 1 addition & 1 deletion src/Multiple/ConnectionManagerSelective.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function __construct(array $managers)

public function connect($uri)
{
$parts = parse_url('tcp://' . $uri);
$parts = parse_url((strpos($uri, '://') === false ? 'tcp://' : '') . $uri);
if (!isset($parts) || !isset($parts['scheme'], $parts['host'], $parts['port'])) {
return Promise\reject(new InvalidArgumentException('Invalid URI'));
}
Expand Down
5 changes: 4 additions & 1 deletion tests/Multiple/ConnectionManagerSelectiveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public function testNotMatchingDomainWillReject()
$this->assertPromiseReject($promise);
}

public function testReject()
public function testRejectIfNotMatching()
{
$will = $this->createConnectionManagerMock(true);

Expand All @@ -154,10 +154,13 @@ public function testReject()
));

$this->assertPromiseResolve($cm->connect('www.google.com:443'));
$this->assertPromiseResolve($cm->connect('tls://www.google.com:443'));

$this->assertPromiseReject($cm->connect('www.google.com:80'));
$this->assertPromiseReject($cm->connect('tcp://www.google.com:80'));

$this->assertPromiseResolve($cm->connect('www.youtube.com:80'));
$this->assertPromiseResolve($cm->connect('tcp://www.youtube.com:80'));
}

public function testFirstEntryWinsIfMultipleMatch()
Expand Down

0 comments on commit 45f1a81

Please sign in to comment.