getSocket(ZMQ::SOCKET_SUB); $pubsub->connect("tcp://127.0.0.1:".get_cfg_var('PUB_PORT')); usleep(50*1000); $pubsub->setSockOpt(ZMQ::SOCKOPT_SUBSCRIBE, ""); $pubsub->setSockOpt(ZMQ::SOCKOPT_RCVTIMEO, 1000); $logging = $zmqCtx->getSocket(ZMQ::SOCKET_SUB); $logging->connect("tcp://127.0.0.1:".get_cfg_var('LOGIF_PORT')); usleep(50*1000); $logging->setSockOpt(ZMQ::SOCKOPT_SUBSCRIBE, ""); $logging->setSockOpt(ZMQ::SOCKOPT_RCVTIMEO, 1000); sleep(1); /////////////////////////////////////////////////////////////////////////////// $test->step("1. Start Secure Multi Proxy server"); /////////////////////////////////////////////////////////////////////////////// sleep(1); // Wait for SMP to startup /////////////////////////////////////////////////////////////////////////////// $test->step("2. Open connection on the device interface"); /////////////////////////////////////////////////////////////////////////////// $sock = fsockopen("localhost", get_cfg_var('TCP_PORT')); $test->isTrue(is_resource($sock)); usleep(300 * 1000); /////////////////////////////////////////////////////////////////////////////// $test->step("3. Send the handshake"); /////////////////////////////////////////////////////////////////////////////// $ret = fwrite($sock, hex2bin("444A52010026" . bin2hex("0200deadbeef00beef00cafebabe0000")), 38); $test->equal(38, $ret); $ret = fread($sock, 6); $ret = bin2hex($ret); $test->equal(12, strlen($ret)); $bytesRemain = hexdec(substr($ret, 8)) - 6; $ret = fread($sock, $bytesRemain); $test->equal('MKAY', $ret); /////////////////////////////////////////////////////////////////////////////// $test->step("4. Check if a connection:connect message is sent on the publish interface"); /////////////////////////////////////////////////////////////////////////////// $msg = $pubsub->recv(); $msg = json_decode($msg, true); $test->equal(1, $msg['dinetrpc']); $test->equal('connection:connect', $msg['pub']); $test->equal('0200deadbeef00beef00cafebabe0000', $msg['device:uid']); $test->isTrue(isset($msg['time'])); $test->isTrue(isset($msg['result'][0]['peer'])); /////////////////////////////////////////////////////////////////////////////// $test->step("5. Check if a connection:connect message is sent on the logging interface"); /////////////////////////////////////////////////////////////////////////////// $msg = $logging->recv(); $msg = json_decode($msg, true); $test->equal(1, $msg['dinetrpc']); $test->equal('connection:connect', $msg['pub']); $test->equal('0200deadbeef00beef00cafebabe0000', $msg['device:uid']); $test->isTrue(isset($msg['time'])); $test->isTrue(isset($msg['result'][0]['peer'])); /////////////////////////////////////////////////////////////////////////////// $test->step("6. Disconnect"); /////////////////////////////////////////////////////////////////////////////// fclose($sock); /////////////////////////////////////////////////////////////////////////////// $test->step("7. Check if a connection:disconnect message is sent on the publish interface"); /////////////////////////////////////////////////////////////////////////////// $msg = $pubsub->recv(); $msg = json_decode($msg, true); $test->equal(1, $msg['dinetrpc']); $test->equal('connection:disconnect', $msg['pub']); $test->equal('0200deadbeef00beef00cafebabe0000', $msg['device:uid']); $test->isTrue(isset($msg['time'])); $test->isTrue(isset($msg['result'][0]['peer'])); $test->isTrue(isset($msg['result'][0]['code'])); /////////////////////////////////////////////////////////////////////////////// $test->step("8. Check if a connection:disconnect message is sent on the logging interface"); /////////////////////////////////////////////////////////////////////////////// $msg = $logging->recv(); $msg = json_decode($msg, true); $test->equal(1, $msg['dinetrpc']); $test->equal('connection:disconnect', $msg['pub']); $test->equal('0200deadbeef00beef00cafebabe0000', $msg['device:uid']); $test->isTrue(isset($msg['time'])); $test->isTrue(isset($msg['result'][0]['peer'])); $test->isTrue(isset($msg['result'][0]['code'])); /////////////////////////////////////////////////////////////////////////////// $test->step("9. Open connection on the device interface"); /////////////////////////////////////////////////////////////////////////////// $sock = fsockopen("localhost", get_cfg_var('TCP_PORT')); $test->isTrue(is_resource($sock)); usleep(300 * 1000); /////////////////////////////////////////////////////////////////////////////// $test->step("10. Send the handshake with a device:uid of only 31 characters"); /////////////////////////////////////////////////////////////////////////////// $ret = fwrite($sock, hex2bin("444A52010025" . bin2hex("0200deadbeef00beef00cafebabe000")), 37); $test->equal(37, $ret); $ret = fread($sock, 6); $ret = bin2hex($ret); $test->equal(12, strlen($ret)); $bytesRemain = hexdec(substr($ret, 8)) - 6; $ret = fread($sock, $bytesRemain); $test->equal('WTF', $ret); /////////////////////////////////////////////////////////////////////////////// $test->step("11. Check if no connection:connect message is sent on the publish interface"); /////////////////////////////////////////////////////////////////////////////// $ret = $pubsub->recv(); $test->isFalse($ret); /////////////////////////////////////////////////////////////////////////////// $test->step("12. Check if no connection:connect message is sent on the logging interface"); /////////////////////////////////////////////////////////////////////////////// $ret = $logging->recv(); $test->isFalse($ret); /////////////////////////////////////////////////////////////////////////////// $test->step("13. Disconnect"); /////////////////////////////////////////////////////////////////////////////// fclose($sock); /////////////////////////////////////////////////////////////////////////////// $test->step("14. Check if no connection:disconnect message is sent on the publish interface"); /////////////////////////////////////////////////////////////////////////////// $ret = $pubsub->recv(); $test->isFalse($ret); /////////////////////////////////////////////////////////////////////////////// $test->step("15. Check if no connection:disconnect message is sent on the logging interface"); /////////////////////////////////////////////////////////////////////////////// $ret = $logging->recv(); $test->isFalse($ret); /////////////////////////////////////////////////////////////////////////////// $test->step("16. Open connection on the device interface"); /////////////////////////////////////////////////////////////////////////////// $sock = fsockopen("localhost", get_cfg_var('TCP_PORT')); $test->isTrue(is_resource($sock)); usleep(300 * 1000); /////////////////////////////////////////////////////////////////////////////// $test->step("17. Send the handshake with a device:uid of 33 characters"); /////////////////////////////////////////////////////////////////////////////// $ret = fwrite($sock, hex2bin("444A52010027" . bin2hex("0200deadbeef00beef00cafebabe00000")), 39); $test->equal(39, $ret); $ret = fread($sock, 6); $ret = bin2hex($ret); $test->equal(12, strlen($ret)); $bytesRemain = hexdec(substr($ret, 8)) - 6; $ret = fread($sock, $bytesRemain); $test->equal('WTF', $ret); /////////////////////////////////////////////////////////////////////////////// $test->step("18. Check if no connection:connect message is sent on the publish interface"); /////////////////////////////////////////////////////////////////////////////// $ret = $pubsub->recv(); $test->isFalse($ret); /////////////////////////////////////////////////////////////////////////////// $test->step("19. Check if no connection:connect message is sent on the logging interface"); /////////////////////////////////////////////////////////////////////////////// $ret = $logging->recv(); $test->isFalse($ret); /////////////////////////////////////////////////////////////////////////////// $test->step("20. Disconnect"); /////////////////////////////////////////////////////////////////////////////// fclose($sock); /////////////////////////////////////////////////////////////////////////////// $test->step("21. Check if no connection:disconnect message is sent on the publish interface"); /////////////////////////////////////////////////////////////////////////////// $ret = $pubsub->recv(); $test->isFalse($ret); /////////////////////////////////////////////////////////////////////////////// $test->step("22. Check if no connection:disconnect message is sent on the logging interface"); /////////////////////////////////////////////////////////////////////////////// $ret = $logging->recv(); $test->isFalse($ret); /////////////////////////////////////////////////////////////////////////////// $test->step("23. Open connection on the device interface"); /////////////////////////////////////////////////////////////////////////////// $sock = fsockopen("localhost", get_cfg_var('TCP_PORT')); $test->isTrue(is_resource($sock)); usleep(300 * 1000); /////////////////////////////////////////////////////////////////////////////// $test->step("24. Send the handshake with an empty device:uid"); /////////////////////////////////////////////////////////////////////////////// $ret = fwrite($sock, hex2bin("444A52010006"), 6); $test->equal(6, $ret); $ret = fread($sock, 6); $ret = bin2hex($ret); $test->equal(12, strlen($ret)); $bytesRemain = hexdec(substr($ret, 8)) - 6; $ret = fread($sock, $bytesRemain); $test->equal('WTF', $ret); /////////////////////////////////////////////////////////////////////////////// $test->step("25. Check if no connection:connect message is sent on the publish interface"); /////////////////////////////////////////////////////////////////////////////// $ret = $pubsub->recv(); $test->isFalse($ret); /////////////////////////////////////////////////////////////////////////////// $test->step("26. Check if no connection:connect message is sent on the logging interface"); /////////////////////////////////////////////////////////////////////////////// $ret = $logging->recv(); $test->isFalse($ret); /////////////////////////////////////////////////////////////////////////////// $test->step("27. Disconnect"); /////////////////////////////////////////////////////////////////////////////// fclose($sock); /////////////////////////////////////////////////////////////////////////////// $test->step("28. Check if no connection:disconnect message is sent on the publish interface"); /////////////////////////////////////////////////////////////////////////////// $ret = $pubsub->recv(); $test->isFalse($ret); /////////////////////////////////////////////////////////////////////////////// $test->step("29. Check if no connection:disconnect message is sent on the logging interface"); /////////////////////////////////////////////////////////////////////////////// $ret = $logging->recv(); $test->isFalse($ret); $test->finish();