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 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); $test->isTrue(is_resource($sock)); usleep(300 * 1000); /////////////////////////////////////////////////////////////////////////////// $test->step("3. Send the handshake"); /////////////////////////////////////////////////////////////////////////////// $ret = sendUDP(hex2bin("444A52010026" . bin2hex("0200deadbeef00beef00cafebabe0000")), 38); $test->equal(38, $ret); /////////////////////////////////////////////////////////////////////////////// $test->step("4. Test for no reply"); /////////////////////////////////////////////////////////////////////////////// $res = recvUDPWithTimeout(1000); $test->equal(0, strlen($res[0])); /////////////////////////////////////////////////////////////////////////////// $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'; $ret = sendUDP(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(); $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->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->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'; $ret = sendUDP(hex2bin("444A521000" . dechex((strlen($mpackHex) / 2) + 6) . $mpackHex), (strlen($mpackHex) / 2) + 6); $test->equal((strlen($mpackHex) / 2) + 6, $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'; $ret = sendUDP(hex2bin("444A521000" . dechex((strlen($mpackHex) / 2) + 6) . $mpackHex), (strlen($mpackHex) / 2) + 6); $test->equal((strlen($mpackHex) / 2) + 6, $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'; $ret = sendUDP(hex2bin("444A521000" . dechex((strlen($mpackHex) / 2) + 6) . $mpackHex), (strlen($mpackHex) / 2) + 6); $test->equal((strlen($mpackHex) / 2) + 6, $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'; $ret = sendUDP(hex2bin("444A52100075" . $mpackHex), (strlen($mpackHex) / 2) + 6); $test->equal((strlen($mpackHex) / 2) + 6, $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'; $ret = sendUDP(hex2bin("444A52100077" . $mpackHex), (strlen($mpackHex) / 2) + 6); $test->equal((strlen($mpackHex) / 2) + 6, $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"); /////////////////////////////////////////////////////////////////////////////// socket_close($sock); $test->finish();