1+ import * as semver from "semver"
12import * as zmq from "../../src"
23
34import { assert } from "chai"
@@ -15,7 +16,7 @@ for (const proto of testProtos("tcp", "ipc")) {
1516 } )
1617
1718 afterEach ( function ( ) {
18- handler . stop ( )
19+ if ( handler ) handler . stop ( )
1920 sockA . close ( )
2021 sockB . close ( )
2122 global . gc ( )
@@ -49,6 +50,9 @@ for (const proto of testProtos("tcp", "ipc")) {
4950 } )
5051
5152 it ( "should report authentication error" , async function ( ) {
53+ /* ZMQ < 4.3.0 does not have these event details. */
54+ if ( semver . satisfies ( zmq . version , "< 4.3.0" ) ) this . skip ( )
55+
5256 handler = new ValidatingZapHandler ( {
5357 domain : "test" ,
5458 mechanism : "PLAIN" ,
@@ -86,7 +90,10 @@ for (const proto of testProtos("tcp", "ipc")) {
8690 assert . equal ( eventB . error . status , 400 )
8791 } )
8892
89- it ( "should report protocol error" , async function ( ) {
93+ it ( "should report protocol version error" , async function ( ) {
94+ /* ZMQ < 4.3.0 does not have these event details. */
95+ if ( semver . satisfies ( zmq . version , "< 4.3.0" ) ) this . skip ( )
96+
9097 handler = new CustomZapHandler (
9198 ( [ path , delim , version , id , ...rest ] ) => {
9299 return [ path , delim , "9.9" , id , "200" , "OK" , null , null ]
@@ -97,7 +104,6 @@ for (const proto of testProtos("tcp", "ipc")) {
97104 sockA . zapDomain = "test"
98105
99106 sockB . plainUsername = "user"
100- sockB . plainPassword = "BAD PASS"
101107
102108 const address = uniqAddress ( proto )
103109 await sockA . bind ( address )
@@ -110,6 +116,52 @@ for (const proto of testProtos("tcp", "ipc")) {
110116 assert . equal ( eventA . error . message , "ZAP protocol error" )
111117 assert . equal ( eventA . error . code , "ERR_ZAP_BAD_VERSION" )
112118 } )
119+
120+ it ( "should report protocol format error" , async function ( ) {
121+ /* ZMQ < 4.3.0 does not have these event details. */
122+ if ( semver . satisfies ( zmq . version , "< 4.3.0" ) ) this . skip ( )
123+
124+ handler = new CustomZapHandler (
125+ ( [ path , delim , ...rest ] ) => {
126+ return [ path , delim , null , null ]
127+ } ,
128+ )
129+
130+ sockA . plainServer = true
131+ sockA . zapDomain = "test"
132+
133+ sockB . plainUsername = "user"
134+
135+ const address = uniqAddress ( proto )
136+ await sockA . bind ( address )
137+ await sockB . connect ( address )
138+
139+ const eventA = await captureEvent ( sockA , "handshake:error:protocol" )
140+ assert . equal ( eventA . type , "handshake:error:protocol" )
141+ assert . equal ( eventA . address , address )
142+ assert . instanceOf ( eventA . error , Error )
143+ assert . equal ( eventA . error . message , "ZAP protocol error" )
144+ assert . equal ( eventA . error . code , "ERR_ZAP_MALFORMED_REPLY" )
145+ } )
146+
147+ it ( "should report mechanism mismatch error" , async function ( ) {
148+ /* ZMQ < 4.3.0 does not have these event details. */
149+ if ( semver . satisfies ( zmq . version , "< 4.3.0" ) ) this . skip ( )
150+
151+ sockA . plainServer = true
152+ sockB . curveServer = true
153+
154+ const address = uniqAddress ( proto )
155+ await sockA . bind ( address )
156+ await sockB . connect ( address )
157+
158+ const eventA = await captureEvent ( sockA , "handshake:error:protocol" )
159+ assert . equal ( eventA . type , "handshake:error:protocol" )
160+ assert . equal ( eventA . address , address )
161+ assert . instanceOf ( eventA . error , Error )
162+ assert . equal ( eventA . error . message , "ZMTP protocol error" )
163+ assert . equal ( eventA . error . code , "ERR_ZMTP_MECHANISM_MISMATCH" )
164+ } )
113165 } )
114166 } )
115167}
0 commit comments