Exemplo n.º 1
0
 public function testSaveLoad()
 {
     $runName = uniqid('', true);
     $fileName = 'testfile_msg_' . date('Ymd_His') . '_' . $runName . '.yml';
     $msg = new Msg('test_data/' . $fileName);
     $msg->setDatadirBasePath('test_data');
     $msg->setDataChanged(true);
     $msg->setVersion(21);
     $this->assertEquals(21, $msg->getVersion());
     $msg->setId('cafed00d-2131-4159-8e11-0b4dbadb1738');
     $this->assertEquals('cafed00d-2131-4159-8e11-0b4dbadb1738', $msg->getId());
     $msg->setRelayNodeId('cafed00d-2231-4159-8e11-0b4dbadb1738');
     $this->assertEquals('cafed00d-2231-4159-8e11-0b4dbadb1738', $msg->getRelayNodeId());
     $msg->setSrcNodeId('cafed00d-2331-4159-8e11-0b4dbadb1738');
     $this->assertEquals('cafed00d-2331-4159-8e11-0b4dbadb1738', $msg->getSrcNodeId());
     $msg->setSrcSslKeyPub(static::SRC1_SSL_KEY_PUB);
     $this->assertEquals(static::SRC1_SSL_KEY_PUB, $msg->getSrcSslKeyPub());
     $msg->setSrcUserNickname('thefox');
     $this->assertEquals('thefox', $msg->getSrcUserNickname());
     $msg->setDstNodeId('cafed00d-2431-4159-8e11-0b4dbadb1738');
     $this->assertEquals('cafed00d-2431-4159-8e11-0b4dbadb1738', $msg->getDstNodeId());
     $msg->setDstSslPubKey(static::DST1_SSL_KEY_PUB);
     $this->assertEquals(static::DST1_SSL_KEY_PUB, $msg->getDstSslPubKey());
     $msg->setSubject('my first subject');
     $this->assertEquals('my first subject', $msg->getSubject());
     $msg->setText('hello world! this is a test');
     $this->assertEquals('hello world! this is a test', $msg->getText());
     $msg->setPassword('my_password01');
     $this->assertEquals('my_password01', $msg->getPassword());
     $msg->setChecksum('checksuuuum_sum');
     $this->assertEquals('checksuuuum_sum', $msg->getChecksum());
     $msg->setSentNodes(array(21, 2, 1987));
     $msg->addSentNode(42);
     $this->assertEquals(array(21, 2, 1987, 42), $msg->getSentNodes());
     $msg->setRelayCount(22);
     $this->assertEquals(22, $msg->getRelayCount());
     $msg->setForwardCycles(23);
     $msg->incForwardCycles();
     $this->assertEquals(24, $msg->getForwardCycles());
     $msg->setEncryptionMode('D');
     $this->assertEquals('D', $msg->getEncryptionMode());
     $msg->setStatus('O');
     $this->assertEquals('O', $msg->getStatus());
     $msg->setTimeCreated(679874400);
     $this->assertEquals(679874400, $msg->getTimeCreated());
     $msg->setSslKeyPrv(static::SRC1_SSL_KEY_PRV, static::SSL_KEY_PRV_PASS);
     $this->assertTrue($msg->encrypt());
     $this->assertTrue((bool) $msg->save());
     $finder = new Finder();
     $files = $finder->in('test_data')->depth(0)->name($fileName)->files();
     $this->assertEquals(1, count($files));
     $msg = new Msg('test_data/' . $fileName);
     $msg->setDatadirBasePath('test_data');
     $this->assertTrue($msg->load());
     $this->assertEquals(21, $msg->getVersion());
     $this->assertEquals('cafed00d-2131-4159-8e11-0b4dbadb1738', $msg->getId());
     $this->assertEquals('cafed00d-2231-4159-8e11-0b4dbadb1738', $msg->getRelayNodeId());
     $this->assertEquals('cafed00d-2331-4159-8e11-0b4dbadb1738', $msg->getSrcNodeId());
     $this->assertEquals(static::SRC1_SSL_KEY_PUB, $msg->getSrcSslKeyPub());
     $this->assertEquals('cafed00d-2431-4159-8e11-0b4dbadb1738', $msg->getDstNodeId());
     $this->assertEquals(array(21, 2, 1987, 42), $msg->getSentNodes());
     $this->assertEquals(22, $msg->getRelayCount());
     $this->assertEquals(24, $msg->getForwardCycles());
     $this->assertEquals('D', $msg->getEncryptionMode());
     $this->assertEquals('O', $msg->getStatus());
     $this->assertEquals(679874400, $msg->getTimeCreated());
     $msg = new Msg('test_data/' . $fileName);
     $msg->setDatadirBasePath('test_data');
     $this->assertTrue($msg->load());
     $msg->setDstSslPubKey(static::DST1_SSL_KEY_PUB);
     $msg->setSslKeyPrv(static::DST1_SSL_KEY_PRV, static::SSL_KEY_PRV_PASS);
     $subject = 'N/A';
     $text = 'N/A';
     try {
         $text = $msg->decrypt();
         $subject = $msg->getSubject();
     } catch (Exception $e) {
         $text = $e->getMessage();
     }
     $this->assertEquals('my first subject', $subject);
     $this->assertEquals('hello world! this is a test', $text);
     $this->assertEquals('thefox', $msg->getSrcUserNickname());
     $msg = new Msg('test_data/' . $fileName);
     $msg->setDatadirBasePath('test_data');
     $this->assertTrue($msg->load());
     $msg->setDstSslPubKey(static::DST2_SSL_KEY_PUB);
     $msg->setSslKeyPrv(static::DST2_SSL_KEY_PRV, static::SSL_KEY_PRV_PASS);
     $subject = 'N/A';
     $text = 'N/A';
     try {
         $text = $msg->decrypt();
         $subject = $msg->getSubject();
     } catch (Exception $e) {
         $text = 'FAILED OK';
     }
     $this->assertEquals('N/A', $subject);
     $this->assertEquals('FAILED OK', $text);
     $this->assertEquals('', $msg->getSrcUserNickname());
     $msg = new Msg('test_data/not_existing.yml');
     $this->assertFalse($msg->load());
 }
Exemplo n.º 2
0
 public function testMsgUpdate()
 {
     $db = new MsgDb();
     $msg1 = new Msg();
     $msg1->setId('76cabb4d-e729-4a50-a792-e223704c2944');
     $msg1->setSentNodes(array('76cabb4d-e729-4a50-a792-e223704c2948'));
     $msg1->setDataChanged(true);
     $db->msgAdd($msg1);
     $msg2 = new Msg();
     $msg2->setId('76cabb4d-e729-4a50-a792-e223704c2945');
     $this->assertFalse($db->msgUpdate($msg2));
     $msg2 = new Msg();
     $msg2->setId('76cabb4d-e729-4a50-a792-e223704c2944');
     $this->assertFalse($db->msgUpdate($msg2));
     $msg2->setVersion(2);
     $msg2->setSrcNodeId('76cabb4d-e729-4a50-a792-e223704c2946');
     $msg2->setSrcSslKeyPub(static::SSL_KEY_PUB1);
     $msg2->setDstNodeId('76cabb4d-e729-4a50-a792-e223704c2947');
     $msg2->setDstSslPubKey(static::SSL_KEY_PUB2);
     $msg2->setSubject('subj1');
     $msg2->setBody('body1');
     $msg2->setText('text1');
     $msg2->setPassword('pwd1');
     $msg2->setChecksum('checksum1');
     $msg2->setSentNodes(array('76cabb4d-e729-4a50-a792-e223704c2949'));
     $msg2->setRelayCount(1);
     $msg2->setForwardCycles(1);
     $msg2->setEncryptionMode('S');
     $msg2->setStatus('D');
     $msg2->setTimeCreated(24);
     $this->assertTrue($db->msgUpdate($msg2));
     $this->assertEquals(array('76cabb4d-e729-4a50-a792-e223704c2948', '76cabb4d-e729-4a50-a792-e223704c2949'), $msg1->getSentNodes());
 }