def check_chquery_reply(self, data, nickname): d = bdecode(data) self.assert_(type(d) == DictType) self.assert_(d.has_key('a')) self.assert_(d.has_key('id')) id = d['id'] self.assert_(type(id) == StringType) self.assert_(validChannelCastMsg(d['a'])==True) self.assert_(len(d['a']) > 0) for key,val in d['a'].iteritems(): self.assert_(val['publisher_name'] == nickname.encode("UTF-8")) self.assert_(val['publisher_id'] == self.hispermid)
def subtest_channelcast(self): print >>sys.stderr,time.asctime(),'-', "test: channelcast----------------------" s = OLConnection(self.my_keypair,'localhost',self.hisport) chcast = ChannelCastCore(None, s, self.session, None, log = '', dnsindb = None) #Send Empty ChannelCast message chdata = {} print >> sys.stderr, time.asctime(),'-', "Test Good ChannelCast", `chdata` msg = CHANNELCAST+bencode(chdata) s.send(msg) resp = s.recv() if len(resp) > 0: print >>sys.stderr,time.asctime(),'-', "test: channelcast: got",getMessageName(resp[0]) self.assert_(resp[0]==CHANNELCAST) print >>sys.stderr, time.asctime(),'-', "test: channelcast: got msg", `bdecode(resp[1:])` chdata_rcvd = bdecode(resp[1:]) self.assert_(validChannelCastMsg(chdata_rcvd)==True) s.close() #Now, send a bad ChannelCast message. # The other side should close the connection # Create bad message by manipulating a good one #bad infohash chdata = deepcopy(chdata_rcvd) for k,v in chdata.items(): v['infohash'] = 234 self.subtest_bad_channelcast(chdata) #bad torrentname chdata = deepcopy(chdata_rcvd) for k,v in chdata.items(): v['torrentname'] = 1231 self.subtest_bad_channelcast(chdata) #bad signature.. temporarily disabled. # Got to enable when signature validation in validChannelCastMsg are enabled # chdata = deepcopy(chdata_rcvd) # value_list = chdata.values() # if len(value_list)>0: # chdata['sdfg234sadf'] = value_list[0] # self.subtest_bad_channelcast(chdata) #Bad message format chdata = {'2343ww34':''} self.subtest_bad_channelcast(chdata) #Bad print>>sys.stderr, time.asctime(),'-', "End of channelcast test---------------------------"
def subtest_channelcastPlusMetadata(self): ''' Extends channelcast test to channelcast messages enriched with metadata (subtitles) informations ''' print >>sys.stderr,"test: channelcast_subtitles ---------------------------" s = OLConnection(self.my_keypair,'localhost',self.hisport) chcast = ChannelCastCore(None, s, self.session, None, log = '', dnsindb = None) #test send standard channelcast chdata = {} print >> sys.stderr, "Test Good ChannelCast Plus Subtitles", `chdata` msg = CHANNELCAST+bencode(chdata) s.send(msg) resp = s.recv() if len(resp) > 0: print >>sys.stderr,"test: channelcast_subtitles: got",getMessageName(resp[0]) self.assert_(resp[0]==CHANNELCAST) print >>sys.stderr, "test: channelcast_subtitles: got msg", `bdecode(resp[1:])` chdata_rcvd = bdecode(resp[1:]) self.assertTrue(validChannelCastMsg(chdata_rcvd)) for entry in chdata_rcvd.itervalues(): if entry['infohash'] == self.infohash1: #the torrent for which two subtitles exist self.assertTrue('rich_metadata' in entry.keys()) richMetadata = entry['rich_metadata'] print >> sys.stderr, "test: channelcast_subtitles: richMetadata entry is ", richMetadata self.assertEquals(6, len(richMetadata)) self.assertEquals(self.mdto.description, richMetadata[0]) self.assertEquals(4, len(richMetadata[2])) #the subtitles mask 4 bytes self.assertTrue(isinstance(richMetadata[3],list)) #the subtitles checsums for checksum in richMetadata[3]: self.assertEquals(20,len(checksum)) #160 bit sha1 checksum self.assertEquals(self.mdto.signature, richMetadata[4]) self.assertEquals(4,len(richMetadata[5])) #the subtitles have mask 32 bit #also must (in this case) be equal to the subtitles mask self.assertEquals(richMetadata[2], richMetadata[5]) print >> sys.stderr, "test: channelcast_subtitles; richMetadata entry is valid and correct" else: self.assertFalse('rich_metadata' in entry.keys()) s.close() #Now, send a bad ChannelCast message. # The other side should close the connection # Create bad message by manipulating a good one #bad bitmask chdata = deepcopy(chdata_rcvd) for k,v in chdata.items(): if 'rich_metadata' in v: v['rich_metadata'][2] = 44 #an integer instead of a 4bytes bitmask self.subtest_bad_channelcast(chdata) #Bad message format chdata = deepcopy(chdata_rcvd) for k,v in chdata.items(): if 'rich_metadata' in v: v['rich_metadata'].insert(0, u"asdfafa22") self.subtest_bad_channelcast(chdata) #Bad print>>sys.stderr, "End of channelcast_subtitles test ---------------------------"