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'])); $sum = 0; //for ($i = 0; $i < 100; $i++) { /////////////////////////////////////////////////////////////////////////////// $test->step("6. Send a 'device:info' publish message"); /////////////////////////////////////////////////////////////////////////////// // it is {"device:uid":"012d2d2d4c45474143592d2d0000026f","dinetrpc":1,"pub":"device:info","result":[{"type":"ZKL 3000 RC"}],"time":1452243176109} $mpackHex = '85A864696E657472706301AA6465766963653A756964D9203031326432643264346334353437343134333539326432643030303030323666A3707562AB6465766963653A696E666FA6726573756C749181A474797065AB5A4B4C2033303030205243A474696D65CF0000015220704AAD'; $start = microtime(true); $ret = fwrite($sock, hex2bin("444A52100076" . $mpackHex), (strlen($mpackHex) / 2) + 6); $test->equal((strlen($mpackHex) / 2) + 6, $ret); /////////////////////////////////////////////////////////////////////////////// $test->step("7. Check if a 'device:info' message is sent on the publish interface"); /////////////////////////////////////////////////////////////////////////////// $msg = $pubsub->recv(); $end = microtime(true); $msg = json_decode($msg, true); $test->equal(1, $msg['dinetrpc']); $test->equal('device:info', $msg['pub']); $test->equal('012d2d2d4c45474143592d2d0000026f', $msg['device:uid']); $test->equal($msg['time'], 1452243176109); $t = round(($end - $start) * 1000, 3); $sum += $t; $test->info("pub took " . $t . 'ms'); /////////////////////////////////////////////////////////////////////////////// $test->step("8. Check if a 'device:info' message is sent on the logging interface"); /////////////////////////////////////////////////////////////////////////////// $msg = $logging->recv(); $msg = json_decode($msg, true); $test->equal(1, $msg['dinetrpc']); $test->equal('device:info', $msg['pub']); $test->equal('012d2d2d4c45474143592d2d0000026f', $msg['device:uid']); $test->equal($msg['time'], 1452243176109); //} //$test->info("pub took an average of " . ($sum / 100) . 'ms'); /////////////////////////////////////////////////////////////////////////////// $test->step("9. Send a 'device:info' publish message without 'dinetrpc'"); /////////////////////////////////////////////////////////////////////////////// // it is {"device:uid":"012d2d2d4c45474143592d2d0000026f","pub":"device:info","result":[{"type":"ZKL 3000 RC"}],"time":1452243176109} $mpackHex = '84AA6465766963653A756964D9203031326432643264346334353437343134333539326432643030303030323666A3707562AB6465766963653A696E666FA6726573756C749181A474797065AB5A4B4C2033303030205243A474696D65CF0000015220704AAD'; $start = microtime(true); $ret = fwrite($sock, hex2bin("444A521000" . dechex((strlen($mpackHex) / 2) + 6) . $mpackHex), (strlen($mpackHex) / 2) + 6); $test->equal((strlen($mpackHex) / 2) + 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("10. Check if no message is sent on the publish interface"); /////////////////////////////////////////////////////////////////////////////// $ret = $pubsub->recv(); $test->isFalse($ret); /////////////////////////////////////////////////////////////////////////////// $test->step("11. Check if no message is sent on the logging interface"); /////////////////////////////////////////////////////////////////////////////// $ret = $logging->recv(); $test->isFalse($ret); /////////////////////////////////////////////////////////////////////////////// $test->step("12. Send a 'device:info' publish message without 'time'"); /////////////////////////////////////////////////////////////////////////////// // it is {"device:uid":"012d2d2d4c45474143592d2d0000026f","dinetrpc":1,"pub":"device:info","result":[{"type":"ZKL 3000 RC"}]} $mpackHex = '84A864696E657472706301AA6465766963653A756964D9203031326432643264346334353437343134333539326432643030303030323666A3707562AB6465766963653A696E666FA6726573756C749181A474797065AB5A4B4C2033303030205243'; $start = microtime(true); $ret = fwrite($sock, hex2bin("444A521000" . dechex((strlen($mpackHex) / 2) + 6) . $mpackHex), (strlen($mpackHex) / 2) + 6); $test->equal((strlen($mpackHex) / 2) + 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("13. Check if no message is sent on the publish interface"); /////////////////////////////////////////////////////////////////////////////// $ret = $pubsub->recv(); $test->isFalse($ret); /////////////////////////////////////////////////////////////////////////////// $test->step("14. Check if no message is sent on the logging interface"); /////////////////////////////////////////////////////////////////////////////// $ret = $logging->recv(); $test->isFalse($ret); /////////////////////////////////////////////////////////////////////////////// $test->step("15. Send a 'device:info' publish message without 'device:uid'"); /////////////////////////////////////////////////////////////////////////////// // it is {"dinetrpc":1,"pub":"device:info","result":[{"type":"ZKL 3000 RC"}],"time":1452243176109} $mpackHex = '84A864696E657472706301A3707562AB6465766963653A696E666FA6726573756C749181A474797065AB5A4B4C2033303030205243A474696D65CF0000015220704AAD'; $start = microtime(true); $ret = fwrite($sock, hex2bin("444A521000" . dechex((strlen($mpackHex) / 2) + 6) . $mpackHex), (strlen($mpackHex) / 2) + 6); $test->equal((strlen($mpackHex) / 2) + 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("16. Check if no message is sent on the publish interface"); /////////////////////////////////////////////////////////////////////////////// $ret = $pubsub->recv(); $test->isFalse($ret); /////////////////////////////////////////////////////////////////////////////// $test->step("17. Check if no message is sent on the logging interface"); /////////////////////////////////////////////////////////////////////////////// $ret = $logging->recv(); $test->isFalse($ret); /////////////////////////////////////////////////////////////////////////////// $test->step("18. Send a 'device:info' publish message with a 'device:uid' of 31 characters"); /////////////////////////////////////////////////////////////////////////////// // it is {"device:uid":"012d2d2d4c45474143592d2d0000026","dinetrpc":1,"pub":"device:info","result":[{"type":"ZKL 3000 RC"}],"time":1452243176109} $mpackHex = '85A864696E657472706301AA6465766963653A756964D91F30313264326432643463343534373431343335393264326430303030303236A3707562AB6465766963653A696E666FA6726573756C749181A474797065AB5A4B4C2033303030205243A474696D65CF0000015220704AAD'; $start = microtime(true); $ret = fwrite($sock, hex2bin("444A52100075" . $mpackHex), (strlen($mpackHex) / 2) + 6); $test->equal((strlen($mpackHex) / 2) + 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("19. Check if no message is sent on the publish interface"); /////////////////////////////////////////////////////////////////////////////// $ret = $pubsub->recv(); $test->isFalse($ret); /////////////////////////////////////////////////////////////////////////////// $test->step("20. Check if no message is sent on the logging interface"); /////////////////////////////////////////////////////////////////////////////// $ret = $logging->recv(); $test->isFalse($ret); /////////////////////////////////////////////////////////////////////////////// $test->step("21. Send a 'device:info' publish message with a 'device:uid' of 33 characters"); /////////////////////////////////////////////////////////////////////////////// // it is {"device:uid":"012d2d2d4c45474143592d2d00000026f","dinetrpc":1,"pub":"device:info","result":[{"type":"ZKL 3000 RC"}],"time":1452243176109} $mpackHex = '85A864696E657472706301AA6465766963653A756964D921303132643264326434633435343734313433353932643264303030303030323666A3707562AB6465766963653A696E666FA6726573756C749181A474797065AB5A4B4C2033303030205243A474696D65CF0000015220704AAD'; $start = microtime(true); $ret = fwrite($sock, hex2bin("444A52100077" . $mpackHex), (strlen($mpackHex) / 2) + 6); $test->equal((strlen($mpackHex) / 2) + 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("22. Check if no message is sent on the publish interface"); /////////////////////////////////////////////////////////////////////////////// $ret = $pubsub->recv(); $test->isFalse($ret); /////////////////////////////////////////////////////////////////////////////// $test->step("23. Check if no message is sent on the logging interface"); /////////////////////////////////////////////////////////////////////////////// $ret = $logging->recv(); $test->isFalse($ret); /////////////////////////////////////////////////////////////////////////////// $test->step("24. Disconnect"); /////////////////////////////////////////////////////////////////////////////// fclose($sock); /////////////////////////////////////////////////////////////////////////////// $test->step("25. 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("26. 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("27. Open connection on the device interface"); /////////////////////////////////////////////////////////////////////////////// $sock = fsockopen("localhost", get_cfg_var('TCP_PORT')); $test->isTrue(is_resource($sock)); usleep(300 * 1000); /////////////////////////////////////////////////////////////////////////////// $test->step("28. Send a 'device:info' publish message"); /////////////////////////////////////////////////////////////////////////////// // it is {"device:uid":"012d2d2d4c45474143592d2d0000026f","dinetrpc":1,"pub":"device:info","result":[{"type":"ZKL 3000 RC"}],"time":1452243176109} $mpackHex = '85A864696E657472706301AA6465766963653A756964D9203031326432643264346334353437343134333539326432643030303030323666A3707562AB6465766963653A696E666FA6726573756C749181A474797065AB5A4B4C2033303030205243A474696D65CF0000015220704AAD'; $start = microtime(true); $ret = fwrite($sock, hex2bin("444A52100076" . $mpackHex), (strlen($mpackHex) / 2) + 6); $test->equal((strlen($mpackHex) / 2) + 6, $ret); /////////////////////////////////////////////////////////////////////////////// $test->step("29. Check if the generic error message is returned"); /////////////////////////////////////////////////////////////////////////////// $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("30. Check if no message is sent on the publish interface"); /////////////////////////////////////////////////////////////////////////////// $ret = $pubsub->recv(); $test->isFalse($ret); /////////////////////////////////////////////////////////////////////////////// $test->step("31. Check if no message is sent on the logging interface"); /////////////////////////////////////////////////////////////////////////////// $ret = $logging->recv(); $test->isFalse($ret); $test->finish();