github.com/n00py/Slackor@v0.0.0-20200610224921-d007fcea1740/impacket/tests/dot11/test_wps.py (about)

     1  #!/usr/bin/env python
     2  # Copyright (c) 2003-2013 CORE Security Technologies
     3  #
     4  # This software is provided under under a slightly modified version
     5  # of the Apache Software License. See the accompanying LICENSE file
     6  # for more information.
     7  #
     8  # $Id$
     9  #
    10  # Description:
    11  #  Tests for WPS packets
    12  #
    13  # Author:
    14  # Aureliano Calvo
    15  
    16  
    17  # sorry, this is very ugly, but I'm in python 2.5
    18  import sys
    19  sys.path.insert(0,"../../..")
    20  
    21  
    22  import unittest
    23  from impacket import wps
    24  import array
    25  
    26  
    27  class TestTLVContainer(unittest.TestCase):
    28  
    29      def testNormalUsageContainer(self):
    30          BUILDERS={
    31              1: wps.StringBuilder(),
    32              2: wps.ByteBuilder(),
    33              3: wps.NumBuilder(2)
    34          }
    35          tlvc = wps.TLVContainer(builders=BUILDERS)
    36          
    37          KINDS_N_VALUES = (
    38              (1, b"Sarlanga"),
    39              (2, 1),
    40              (3, 1024),
    41              (4, array.array("B", [1,2,3]))
    42          )
    43          for k,v in KINDS_N_VALUES:
    44              tlvc.append(k,v)
    45          
    46          tlvc2 = wps.TLVContainer(builders=BUILDERS)
    47          tlvc2.from_ary(tlvc.to_ary())
    48          
    49          for k,v in KINDS_N_VALUES:
    50              self.assertEqual(v, tlvc2.first(k))
    51          
    52          self.assertEqual(tlvc.to_ary(), tlvc2.to_ary())
    53          self.assertEquals(b"Sarlanga", tlvc.first(1))
    54  
    55  suite = unittest.TestLoader().loadTestsFromTestCase(TestTLVContainer)
    56  unittest.TextTestRunner(verbosity=1).run(suite)