| | 297 | def testEncodeKeyValues(self): |
| | 298 | self.assertEqual(self.packet._EncodeKeyValues(1, "1234"), (1, "1234")) |
| | 299 | |
| | 300 | |
| | 301 | def testEncodeKey(self): |
| | 302 | self.assertEqual(self.packet._EncodeKey(1), 1) |
| | 303 | |
| | 304 | |
| | 305 | def testAddAttribute(self): |
| | 306 | self.packet.AddAttribute(1, 1) |
| | 307 | self.assertEqual(self.packet.data[1], [1]) |
| | 308 | self.packet.AddAttribute(1, 1) |
| | 309 | self.assertEqual(self.packet.data[1], [1, 1]) |
| | 310 | |
| | 311 | |
| | 312 | |
| | 321 | |
| | 322 | class AuthPacketTests(unittest.TestCase): |
| | 323 | |
| | 324 | def setUp(self): |
| | 325 | self.path=os.path.join(home, "tests", "data") |
| | 326 | self.dict=Dictionary(os.path.join(self.path, "full")) |
| | 327 | self.packet=packet.AuthPacket(id=0, secret="secret", |
| | 328 | authenticator="01234567890ABCDEF", dict=self.dict) |
| | 329 | |
| | 330 | |
| | 331 | def testCreateReply(self): |
| | 332 | reply=self.packet.CreateReply(Test_Integer=10) |
| | 333 | self.assertEqual(reply.code, packet.AccessAccept) |
| | 334 | self.assertEqual(reply.id, self.packet.id) |
| | 335 | self.assertEqual(reply.secret, self.packet.secret) |
| | 336 | self.assertEqual(reply.authenticator, self.packet.authenticator) |
| | 337 | self.assertEqual(reply["Test-Integer"], [10]) |
| | 338 | |
| | 339 | |
| | 340 | def testRequestPacket(self): |
| | 341 | self.assertEqual(self.packet.RequestPacket(), |
| | 342 | "\x01\x00\x00\x1401234567890ABCDE") |
| | 343 | |
| | 344 | def testRequestPacketCreatesAuthenticator(self): |
| | 345 | self.packet.authenticator=None |
| | 346 | self.packet.RequestPacket() |
| | 347 | self.failUnless(self.packet.authenticator is not None) |
| | 348 | |
| | 349 | |
| | 350 | def testRequestPacketCreatesID(self): |
| | 351 | self.packet.id=None |
| | 352 | self.packet.RequestPacket() |
| | 353 | self.failUnless(self.packet.id is not None) |
| | 354 | |
| | 355 | |
| | 356 | def testPwCryptEmptyPassword(self): |
| | 357 | self.assertEqual(self.packet.PwCrypt(""), "") |
| | 358 | |
| | 359 | |
| | 360 | def testPwCryptPassword(self): |
| | 361 | self.assertEqual(self.packet.PwCrypt("Simplon"), |
| | 362 | "\xd3U;\xb23\r\x11\xba\x07\xe3\xa8*\xa8x\x14\x01") |
| | 363 | |
| | 364 | |
| | 365 | def testPwCryptSetsAuthenticator(self): |
| | 366 | self.packet.authenticator=None |
| | 367 | self.packet.PwCrypt("") |
| | 368 | self.failUnless(self.packet.authenticator is not None) |
| | 369 | |
| | 370 | |
| | 371 | def testPwDecryptEmptyPassword(self): |
| | 372 | self.assertEqual(self.packet.PwDecrypt(""), "") |
| | 373 | |
| | 374 | |
| | 375 | def testPwDecryptPassword(self): |
| | 376 | self.assertEqual(self.packet.PwDecrypt( |
| | 377 | "\xd3U;\xb23\r\x11\xba\x07\xe3\xa8*\xa8x\x14\x01"), |
| | 378 | "Simplon") |
| | 379 | |
| | 380 | |
| | 381 | |
| | 389 | |
| | 390 | def testConstructorRawPacket(self): |
| | 391 | raw="\x00\x00\x00\x14\xb0\x5e\x4b\xfb\xcc\x1c" \ |
| | 392 | "\x8c\x8e\xc4\x72\xac\xea\x87\x45\x63\xa7" |
| | 393 | pkt=self.klass(packet=raw) |
| | 394 | self.assertEqual(pkt.raw_packet, raw) |
| | 395 | |
| | 396 | |
| | 397 | class AcctPacketTests(unittest.TestCase): |
| | 398 | |
| | 399 | def setUp(self): |
| | 400 | self.path=os.path.join(home, "tests", "data") |
| | 401 | self.dict=Dictionary(os.path.join(self.path, "full")) |
| | 402 | self.packet=packet.AcctPacket(id=0, secret="secret", |
| | 403 | authenticator="01234567890ABCDEF", dict=self.dict) |
| | 404 | |
| | 405 | |
| | 406 | def testCreateReply(self): |
| | 407 | reply=self.packet.CreateReply(Test_Integer=10) |
| | 408 | self.assertEqual(reply.code, packet.AccountingResponse) |
| | 409 | self.assertEqual(reply.id, self.packet.id) |
| | 410 | self.assertEqual(reply.secret, self.packet.secret) |
| | 411 | self.assertEqual(reply.authenticator, self.packet.authenticator) |
| | 412 | self.assertEqual(reply["Test-Integer"], [10]) |
| | 413 | |
| | 414 | |
| | 415 | def testVerifyAcctRequest(self): |
| | 416 | rawpacket=self.packet.RequestPacket() |
| | 417 | pkt=packet.AcctPacket(secret="secret", packet=rawpacket) |
| | 418 | self.assertEqual(pkt.VerifyAcctRequest(), True) |
| | 419 | |
| | 420 | pkt.secret="different" |
| | 421 | self.assertEqual(pkt.VerifyAcctRequest(), False) |
| | 422 | pkt.secret="secret" |
| | 423 | |
| | 424 | pkt.raw_packet="X" + pkt.raw_packet[1:] |
| | 425 | self.assertEqual(pkt.VerifyAcctRequest(), False) |
| | 426 | |
| | 427 | |
| | 428 | def testRequestPacket(self): |
| | 429 | self.assertEqual(self.packet.RequestPacket(), |
| | 430 | "\x04\x00\x00\x14\x95\xdf\x90\xccbn\xfb\x15G!\x13\xea\xfa>6\x0f") |
| | 431 | |
| | 432 | |
| | 433 | def testRequestPacketSetsId(self): |
| | 434 | self.packet.id=None |
| | 435 | self.packet.RequestPacket() |
| | 436 | self.failUnless(self.packet.id is not None) |
| | 437 | |