Skip to content

Commit

Permalink
Merge branch 'master' of github.com:btimby/py-radius into unknown-att…
Browse files Browse the repository at this point in the history
…ributes
  • Loading branch information
btimby committed May 4, 2018
2 parents 06df136 + 97b8b38 commit 1e92243
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
12 changes: 6 additions & 6 deletions radius.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,9 @@ def unpack(data):
"""
pos, attrs = 0, {}
while pos < len(data):
code, l = struct.unpack('BB', data[pos:pos + 2])
attrs[code] = data[pos + 2:pos + l]
pos += l
code, length = struct.unpack('BB', data[pos:pos + 2])
attrs[code] = data[pos + 2:pos + length]
pos += length
return Attributes(attrs)


Expand Down Expand Up @@ -452,10 +452,10 @@ def pack(self):
@staticmethod
def unpack(secret, data):
"""Unpack the data into it's fields."""
code, id, l, authenticator = struct.unpack('!BBH16s', data[:20])
if l != len(data):
code, id, length, authenticator = struct.unpack('!BBH16s', data[:20])
if length != len(data):
LOGGER.warning('Too much data!')
attrs = Attributes.unpack(data[20:l])
attrs = Attributes.unpack(data[20:length])
return Message(secret, code, id, authenticator, attrs)

def verify(self, data):
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
six
19 changes: 10 additions & 9 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import socket
import threading
import logging
import time

try:
from hashlib import md5
Expand Down Expand Up @@ -153,6 +154,12 @@ def setUp(self):
def tearDown(self):
self.sock.close()

def startServer(self, target):
t = threading.Thread(target=target)
t.daemon = True
t.start()
time.sleep(0.1)

def test_connect(self):
"""Test connecting."""
r = radius.Radius(TEST_SECRET, host='localhost', port=self.port)
Expand All @@ -170,9 +177,7 @@ def _reply_to_client():
m2 = create_reply(m1)
self.sock.sendto(m2.pack(), addr)

t = threading.Thread(target=_reply_to_client)
t.daemon = True
t.start()
self.startServer(_reply_to_client)

r = radius.Radius(TEST_SECRET, host='localhost', port=self.port)
self.assertFalse(r.authenticate('username', 'password'))
Expand All @@ -186,9 +191,7 @@ def _reply_to_client():
m2 = create_reply(m1, radius.CODE_ACCESS_ACCEPT)
self.sock.sendto(m2.pack(), addr)

t = threading.Thread(target=_reply_to_client)
t.daemon = True
t.start()
self.startServer(_reply_to_client)

r = radius.Radius(TEST_SECRET, host='localhost', port=self.port)
self.assertTrue(r.authenticate('username', 'password'))
Expand All @@ -205,9 +208,7 @@ def _reply_to_client():
})
self.sock.sendto(m2.pack(), addr)

t = threading.Thread(target=_reply_to_client)
t.daemon = True
t.start()
self.startServer(_reply_to_client)

r = radius.Radius(TEST_SECRET, host='localhost', port=self.port)
try:
Expand Down

0 comments on commit 1e92243

Please sign in to comment.