def test_encode_packet(self): p = packet.RadiusPacket(1, 33) pwstring = 'u\x9dw8\x81\xe9\xcfXb\xdb\x152\x9bR\xef\xf5' p.addAttribute('User-Name', 'testuser') p.addAttribute('User-Password', pwstring) raw_packet = p.encodeDatagram('testpass') newp = packet.RadiusPacket(datagram=raw_packet) self.assertEqual(p.get('User-Name'), ['testuser']) self.assertEqual(p.get('User-Password'), [pwstring])
def test_build_response(self): pkt = packet.RadiusPacket(packet.AccessRequest) eapm = eap.EAPMessage(pkt, 'testseekrit', eap.EAPResponse, 0, eap.EAPRequestIdentity) pkt = eapm.createReplyPacket(packet.AccessRequest, 'test') dg = pkt.encodeDatagram('testseekrit') newpkt = packet.RadiusPacket(datagram=dg) eap_data = newpkt.get('EAP-Message')[0] eapm = eap.EAPMessage(newpkt, 'testseekrit', data=eap_data)
def test_add_attributes(self): p = packet.RadiusPacket() p.addAttribute('User-Name', 'testuser') self.assertEqual(p.get('User-Name'), ['testuser']) self.assertEqual(p.raw_attributes[1], ['testuser'])
def test_decode_packet(self): p = packet.RadiusPacket(datagram=EAPDatagram) self.assertEqual(p.rad_code, 1) self.assertEqual(p.rad_id, 0) self.assertEqual(p.get('User-Name'), ['test']) self.assertEqual(p.get('NAS-IP-Address'), ['127.0.0.1'])
def test_decoders(self): p = packet.RadiusPacket() raw = '\x01\x02\x03' p.addAttribute('CHAP-Password', raw) self.assertEqual(p.raw_attributes[3], [raw]) num = 12345123 p.addAttribute('Login-Service', num) self.assertEqual(p.raw_attributes[15], ['\x00\xbc_#']) p.addAttribute('Login-IP-Host', '10.0.0.1') self.assertEqual(p.raw_attributes[14], ['\n\x00\x00\x01'])
def setUp(self): self.pkt = packet.RadiusPacket(datagram=EAPDatagram) eap_data = self.pkt.get('EAP-Message')[0] self.eap_message = eap.EAPMessage(self.pkt, 'testseekrit', data=eap_data) self.config = ConfigParser.SafeConfigParser() self.config.add_section('main') self.config.set('main', 'secret', 'testseekrit') self.config.set('main', 'ssl_cert', '/etc/ssl/certs/ssl-cert-snakeoil.pem') self.config.set('main', 'ssl_key', '/home/colin/googleradius/ssl.key')
def test_eapmd5(self): # Build a challenge request eapmd5 = eap.EAPMD5ChallengeRequest(self.pkt, 1, 'testseekrit') dg = eapmd5.createPacket().encodeDatagram('testseekrit') pkt = packet.RadiusPacket(datagram=dg) eap_data = pkt.get('EAP-Message')[0] # Verify it can be decoded eapm = eap.EAPMessage(self.pkt, 'testseekrit', data=eap_data) self.assertEquals(eapm.eap_id, 1) self.assertEquals(eapm.eap_type, 4) self.assertEquals(eapm.eap_code, 1)
def datagramReceived(self, datagram, hp): "Creates a packet object for received datagrams" pkt = packet.RadiusPacket(datagram=datagram) reactor.callLater(0, self.processPacket, pkt, hp)