Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The ZMQAuth class wraps the CZMQ zauth API. Instances of the ZMQAuth class can: * install a ZAP handler for a ZMQContext * whitelist/blacklist IP addresses * use plain or curve authentication for one or more domains
- Loading branch information
Showing
7 changed files
with
308 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--TEST-- | ||
Test a ZMQAuth can be constructed. | ||
--SKIPIF-- | ||
<?php | ||
require_once __DIR__ . '/skipif.inc'; | ||
|
||
if (!class_exists('ZMQAuth')) { | ||
die('skip'); | ||
} | ||
--FILE-- | ||
<?php | ||
|
||
$context = new ZMQContext(); | ||
$auth = new ZMQAuth($context); | ||
var_dump((bool)$auth); | ||
--EXPECT-- | ||
bool(true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--TEST-- | ||
Test a ZMQAuth can whitelist or blacklist an IP address. | ||
--SKIPIF-- | ||
<?php | ||
require_once __DIR__ . '/skipif.inc'; | ||
|
||
if (!class_exists('ZMQAuth')) { | ||
die('skip'); | ||
} | ||
--FILE-- | ||
<?php | ||
|
||
$context = new ZMQContext(); | ||
$auth = new ZMQAuth($context); | ||
var_dump($auth->allow('127.0.0.1') === $auth); | ||
var_dump($auth->deny('192.168.0.1') === $auth); | ||
--EXPECT-- | ||
bool(true) | ||
bool(true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--TEST-- | ||
Test a ZMQAuth can be configured. | ||
--SKIPIF-- | ||
<?php | ||
require_once __DIR__ . '/skipif.inc'; | ||
|
||
if (!class_exists('ZMQAuth')) { | ||
die('skip'); | ||
} | ||
--FILE-- | ||
<?php | ||
|
||
define('TEST_DIR', '/tmp'); | ||
define('PASSWORDS_FILE', TEST_DIR . '/passwords'); | ||
define('CERTS_DIR', '/tmp/certs'); | ||
define('CERT_FILE', CERTS_DIR . '/cert'); | ||
|
||
$context = new ZMQContext(); | ||
$auth = new ZMQAuth($context); | ||
|
||
// Test a ZMQAuth can be configured to use PLAIN authentication. | ||
touch(PASSWORDS_FILE); | ||
var_dump($auth->configure(ZMQAuth::AUTH_TYPE_PLAIN, '*', PASSWORDS_FILE) === $auth); | ||
unlink(PASSWORDS_FILE); | ||
|
||
// Test a ZMQAuth can be configured to use CURVE authentication. | ||
mkdir(CERTS_DIR); | ||
$cert = new ZMQCert(); | ||
$cert->save(CERT_FILE); | ||
|
||
var_dump($auth->configure(ZMQAuth::AUTH_TYPE_CURVE, '*', CERTS_DIR) === $auth); | ||
|
||
// Test ZMQAuth#configure throws an exception when the auth type isn't | ||
// recognised. | ||
try { | ||
$auth->configure(-1, '*', CERTS_DIR); | ||
} catch (ZMQAuthException $e) { | ||
var_dump($e->getMessage()); | ||
} | ||
|
||
unlink(CERT_FILE); | ||
unlink(CERT_FILE . '_secret'); | ||
rmdir(CERTS_DIR); | ||
--EXPECT-- | ||
bool(true) | ||
bool(true) | ||
string(62) "Unknown auth type. Are you using one of the ZMQAuth constants?" |
Oops, something went wrong.