import tempfile import pyrad.packet import yaml from pyrad.client import Client from pyrad.dictionary import Dictionary with open("config.sample.yaml", "r", encoding="utf-8") as f: config = yaml.load(f, Loader=yaml.SafeLoader) with tempfile.NamedTemporaryFile() as tmpfile: with open(tmpfile.name, "w", encoding="utf-8") as f: for attribute in config["dictionary"]: f.write(f"ATTRIBUTE {attribute['name']} {attribute['id']} {attribute['type']}\n") dictionary = Dictionary(tmpfile.name) srv = Client( server="127.0.0.1", secret=b"0f5c6a8b-bb18-46fc-8fea-2c2032cb0754z", dict=dictionary ) req = srv.CreateAuthPacket( code=pyrad.packet.AccessRequest, User_Name="9273D98A6337", NAS_Identifier="9273D98A6337" ) req["User-Password"] = req.PwCrypt("9273D98A6337") reply = srv.SendPacket(req) assert reply.code == pyrad.packet.AccessAccept assert reply["Tunnel-Type"] == [13] assert reply["Tunnel-Medium-Type"] == [6] assert reply["Tunnel-Private-Group-ID"] == ["20"]