File tree 7 files changed +308
-1
lines changed
7 files changed +308
-1
lines changed Original file line number Diff line number Diff line change @@ -625,6 +625,7 @@ public function __construct(ZMQContext $context) {}
625
625
* whitelisted addresses are treated as if they were blacklisted.
626
626
*
627
627
* @param string $address
628
+ * @return ZMQAuth Provides a fluent interface
628
629
*/
629
630
public function allow ($ address ) {}
630
631
@@ -638,6 +639,7 @@ public function allow($address) {}
638
639
* whitelist will be used to authenticate incoming connections.
639
640
*
640
641
* @param string $address
642
+ * @return ZMQAuth Provides a fluent interface
641
643
*/
642
644
public function deny ($ address ) {}
643
645
@@ -659,6 +661,7 @@ public function deny($address) {}
659
661
* @param string $domain The ZAP domain. Use "*" to configure the PLAIN or
660
662
* CURVE authentication mechanism for all domains
661
663
* @param string $filename
664
+ * @return ZMQAuth Provides a fluent interface
662
665
*/
663
666
public function configure ($ type , $ domain , $ filename ) {}
664
667
}
Original file line number Diff line number Diff line change 96
96
<file name =" 041-cert-meta.phpt" role =" test" />
97
97
<file name =" 042-cert-save.phpt" role =" test" />
98
98
<file name =" 043-cert-load.phpt" role =" test" />
99
+ <file name =" 044-auth-construct.phpt" role =" test" />
100
+ <file name =" 045-auth-allow-deny.phpt" role =" test" />
99
101
<file name =" 046-cert-apply.phpt" role =" test" />
102
+ <file name =" 047-auth-configure.phpt" role =" test" />
100
103
<file name =" bug_gh_43.phpt" role =" test" />
101
104
<file name =" bug_gh_49.phpt" role =" test" />
102
105
<file name =" bug_gh_50.phpt" role =" test" />
Original file line number Diff line number Diff line change @@ -245,6 +245,11 @@ typedef struct _php_zmq_device_object {
245
245
246
246
#define PHP_ZMQ_VERSION_LEN 24
247
247
248
+ #ifdef HAVE_CZMQ_2
249
+ # define PHP_ZMQ_AUTH_TYPE_PLAIN 0
250
+ # define PHP_ZMQ_AUTH_TYPE_CURVE 1
251
+ #endif
252
+
248
253
PHP_METHOD (zmqsocket , getsockopt );
249
254
PHP_METHOD (zmqsocket , setsockopt );
250
255
zend_bool php_zmq_device (php_zmq_device_object * intern TSRMLS_DC );
@@ -275,6 +280,12 @@ typedef struct _php_zmq_cert {
275
280
zend_object zend_object ;
276
281
zcert_t * zcert ;
277
282
} php_zmq_cert ;
283
+
284
+ typedef struct _php_zmq_auth {
285
+ zend_object zend_object ;
286
+ zctx_t * shadow_context ;
287
+ zauth_t * zauth ;
288
+ } php_zmq_auth ;
278
289
#endif
279
290
280
291
#endif /* _PHP_ZMQ_PRIVATE_H_ */
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ Test a ZMQAuth can be constructed.
3
+ --SKIPIF--
4
+ <?php
5
+ require_once __DIR__ . '/skipif.inc ' ;
6
+
7
+ if (!class_exists ('ZMQAuth ' )) {
8
+ die ('skip ' );
9
+ }
10
+ --FILE --
11
+ <?php
12
+
13
+ $ context = new ZMQContext();
14
+ $ auth = new ZMQAuth($ context );
15
+ var_dump ((bool )$ auth );
16
+ --EXPECT --
17
+ bool (true )
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ Test a ZMQAuth can whitelist or blacklist an IP address.
3
+ --SKIPIF--
4
+ <?php
5
+ require_once __DIR__ . '/skipif.inc ' ;
6
+
7
+ if (!class_exists ('ZMQAuth ' )) {
8
+ die ('skip ' );
9
+ }
10
+ --FILE --
11
+ <?php
12
+
13
+ $ context = new ZMQContext();
14
+ $ auth = new ZMQAuth($ context );
15
+ var_dump ($ auth ->allow ('127.0.0.1 ' ) === $ auth );
16
+ var_dump ($ auth ->deny ('192.168.0.1 ' ) === $ auth );
17
+ --EXPECT --
18
+ bool (true )
19
+ bool (true )
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ Test a ZMQAuth can be configured.
3
+ --SKIPIF--
4
+ <?php
5
+ require_once __DIR__ . '/skipif.inc ' ;
6
+
7
+ if (!class_exists ('ZMQAuth ' )) {
8
+ die ('skip ' );
9
+ }
10
+ --FILE --
11
+ <?php
12
+
13
+ define ('TEST_DIR ' , '/tmp ' );
14
+ define ('PASSWORDS_FILE ' , TEST_DIR . '/passwords ' );
15
+ define ('CERTS_DIR ' , '/tmp/certs ' );
16
+ define ('CERT_FILE ' , CERTS_DIR . '/cert ' );
17
+
18
+ $ context = new ZMQContext ();
19
+ $ auth = new ZMQAuth ($ context );
20
+
21
+ // Test a ZMQAuth can be configured to use PLAIN authentication.
22
+ touch (PASSWORDS_FILE );
23
+ var_dump ($ auth ->configure (ZMQAuth::AUTH_TYPE_PLAIN , '* ' , PASSWORDS_FILE ) === $ auth );
24
+ unlink (PASSWORDS_FILE );
25
+
26
+ // Test a ZMQAuth can be configured to use CURVE authentication.
27
+ mkdir (CERTS_DIR );
28
+ $ cert = new ZMQCert ();
29
+ $ cert ->save (CERT_FILE );
30
+
31
+ var_dump ($ auth ->configure (ZMQAuth::AUTH_TYPE_CURVE , '* ' , CERTS_DIR ) === $ auth );
32
+
33
+ // Test ZMQAuth#configure throws an exception when the auth type isn't
34
+ // recognised.
35
+ try {
36
+ $ auth ->configure (-1 , '* ' , CERTS_DIR );
37
+ } catch (ZMQAuthException $ e ) {
38
+ var_dump ($ e ->getMessage ());
39
+ }
40
+
41
+ unlink (CERT_FILE );
42
+ unlink (CERT_FILE . '_secret ' );
43
+ rmdir (CERTS_DIR );
44
+ --EXPECT --
45
+ bool (true )
46
+ bool (true )
47
+ string (62 ) "Unknown auth type. Are you using one of the ZMQAuth constants? "
You can’t perform that action at this time.
0 commit comments