aria2/test/DHTTokenTrackerTest.cc
Tatsuhiro Tsujikawa 3349fe0811 2009-10-22 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Moved generateRandomData to Util.cc Moved flipBit to bitfield.cc.
	Moved generateRandomKey to bittorrent_helper.cc.
	* src/DHTBucket.cc
	* src/DHTGetPeersMessage.cc
	* src/DHTGetPeersReplyMessage.cc
	* src/DHTMessage.cc
	* src/DHTNode.cc
	* src/DHTTokenTracker.cc
	* src/DHTUtil.cc: Removed.
	* src/DHTUtil.h: Removed.
	* src/Makefile.am
	* src/Util.cc
	* src/Util.h
	* src/bitfield.h
	* src/bittorrent_helper.cc
	* src/bittorrent_helper.h
	* test/ARC4Test.cc
	* test/BNodeTest.cc
	* test/DHTAnnouncePeerMessageTest.cc
	* test/DHTAnnouncePeerReplyMessageTest.cc
	* test/DHTFindNodeMessageTest.cc
	* test/DHTFindNodeReplyMessageTest.cc
	* test/DHTGetPeersMessageTest.cc
	* test/DHTGetPeersReplyMessageTest.cc
	* test/DHTPingMessageTest.cc
	* test/DHTPingReplyMessageTest.cc
	* test/DHTTokenTrackerTest.cc
	* test/DHTUtilTest.cc: Removed.
	* test/Makefile.am
	* test/UtilTest.cc
2009-10-22 14:43:42 +00:00

46 lines
1.2 KiB
C++

#include "DHTTokenTracker.h"
#include <cppunit/extensions/HelperMacros.h>
#include "Exception.h"
#include "Util.h"
#include "DHTConstants.h"
namespace aria2 {
class DHTTokenTrackerTest:public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(DHTTokenTrackerTest);
CPPUNIT_TEST(testGenerateToken);
CPPUNIT_TEST_SUITE_END();
public:
void setUp() {}
void tearDown() {}
void testGenerateToken();
};
CPPUNIT_TEST_SUITE_REGISTRATION(DHTTokenTrackerTest);
void DHTTokenTrackerTest::testGenerateToken()
{
unsigned char infohash[DHT_ID_LENGTH];
util::generateRandomData(infohash, DHT_ID_LENGTH);
std::string ipaddr = "192.168.0.1";
uint16_t port = 6881;
DHTTokenTracker tracker;
std::string token = tracker.generateToken(infohash, ipaddr, port);
CPPUNIT_ASSERT(tracker.validateToken(token, infohash, ipaddr, port));
tracker.updateTokenSecret();
CPPUNIT_ASSERT(tracker.validateToken(token, infohash, ipaddr, port));
std::string newtoken = tracker.generateToken(infohash, ipaddr, port);
tracker.updateTokenSecret();
CPPUNIT_ASSERT(!tracker.validateToken(token, infohash, ipaddr, port));
CPPUNIT_ASSERT(tracker.validateToken(newtoken, infohash, ipaddr, port));
}
} // namespace aria2