Beispiel #1
0
 /**
  * @expectedException RuntimeException
  * @expectedExceptionCode 203
  */
 public function testDecryptionRuntimeException203()
 {
     $msg = new Msg();
     $msg->setVersion(1);
     $msg->setId('cafed00d-2131-4159-8e11-0b4dbadb1738');
     $msg->setSrcNodeId('cafed00d-2331-4159-8e11-0b4dbadb1738');
     $msg->setSrcSslKeyPub(static::SRC1_SSL_KEY_PUB);
     $msg->setSrcUserNickname('username1');
     $msg->setDstNodeId('cafed00d-2431-4159-8e11-0b4dbadb1738');
     $msg->setDstSslPubKey(static::DST1_SSL_KEY_PUB);
     $msg->setSubject('subj1');
     $msg->setText('text1');
     $msg->setSslKeyPrv(static::SRC1_SSL_KEY_PRV, static::SSL_KEY_PRV_PASS);
     $msg->setIgnore(false);
     $this->assertTrue($msg->encrypt());
     $body = $msg->getBody();
     $timeCreated = $msg->getTimeCreated();
     $password = $msg->getPassword();
     $checksum = $msg->getChecksum();
     $body = base64_decode($body);
     $body = gzdecode($body);
     $body = json_decode($body, true);
     $body['data'] = 'invalid';
     $body = json_encode($body);
     $body = gzencode($body, 9);
     $body = base64_encode($body);
     $msg = new Msg();
     $msg->setVersion(1);
     $msg->setId('cafed00d-2131-4159-8e11-0b4dbadb1738');
     $msg->setSrcNodeId('cafed00d-2331-4159-8e11-0b4dbadb1738');
     $msg->setBody($body);
     $msg->setSrcSslKeyPub(static::SRC1_SSL_KEY_PUB);
     $msg->setDstSslPubKey(static::DST1_SSL_KEY_PUB);
     $msg->setSslKeyPrv(static::DST1_SSL_KEY_PRV, static::SSL_KEY_PRV_PASS);
     $msg->setDstNodeId('cafed00d-2431-4159-8e11-0b4dbadb1738');
     $msg->setTimeCreated($timeCreated);
     $msg->setPassword($password);
     $msg->setChecksum($checksum);
     $msg->decrypt();
 }
Beispiel #2
0
 public function testSendMsg()
 {
     list($client1, $client2) = $this->sendGenTestDataDefault();
     // Send Msg before ID should cause an error.
     $msg = new Msg();
     $msg->setVersion(1);
     $msg->setSrcNodeId($client1->getSettings()->data['node']['id']);
     $msg->setSrcSslKeyPub(static::NODE_LOCAL_SSL_KEY_PUB1);
     $msg->setSrcUserNickname('thefox');
     $msg->setDstNodeId($client2->getSettings()->data['node']['id']);
     $msg->setDstSslPubKey(static::NODE_LOCAL_SSL_KEY_PUB2);
     $msg->setSubject('my first subject');
     $msg->setText('hello world! this is a test');
     $msg->setSslKeyPrv(static::NODE_LOCAL_SSL_KEY_PRV1, 'my_password');
     $msg->encrypt();
     $raw = $client1->sendMsg($msg);
     #ve($raw);
     $raw = $client2->dataRecv($raw);
     #ve($raw);
     $json = $this->rawMsgToJson($raw);
     #ve($json);
     $this->assertEquals('error', $json[0]['name']);
     $this->assertEquals(1000, $json[0]['data']['code']);
     $this->sendClientsId($client1, $client2);
     // Send Msg
     $msg = new Msg();
     $msg->setVersion(1);
     #$msg->setId('200b9758-2d34-4152-8ada-fc09fc9c9da0');
     $msg->setSrcNodeId('cafed00d-2131-4159-8e11-0b4dbadb1738');
     $msg->setSrcSslKeyPub(static::NODE_LOCAL_SSL_KEY_PUB1);
     $msg->setSrcUserNickname('thefox');
     $msg->setDstNodeId('cafed00d-2131-4159-8e11-0b4dbadb1739');
     $msg->setDstSslPubKey(static::NODE_LOCAL_SSL_KEY_PUB2);
     $msg->setSubject('my first subject');
     $msg->setText('hello world! this is a test');
     $msg->setSslKeyPrv(static::NODE_LOCAL_SSL_KEY_PRV1, 'my_password');
     $msg->encrypt();
     $raw = $client1->sendMsg($msg);
     $json = $this->rawMsgToJson($raw);
     #ve($json);
     $rid = $json[0]['data']['rid'];
     $this->assertEquals('msg', $json[0]['name']);
     $this->assertEquals('cafed00d-2131-4159-8e11-0b4dbadb1738', $json[0]['data']['srcNodeId']);
     $this->assertEquals('cafed00d-2131-4159-8e11-0b4dbadb1739', $json[0]['data']['dstNodeId']);
     $raw = $client2->dataRecv($raw);
     $json = $this->rawMsgToJson($raw);
     #ve($json);
     $this->assertEquals('msg_response', $json[0]['name']);
     $this->assertEquals($rid, $json[0]['data']['rid']);
     $client1->getServer()->getKernel()->shutdown();
     $client2->getServer()->getKernel()->shutdown();
 }