Changeset 1052

Show
Ignore:
Timestamp:
09/09/07 14:55:29 (15 months ago)
Author:
wichert
Message:

More packet tests

Location:
trunk/pyrad
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/pyrad/packet.py

    r1051 r1052  
    109109 
    110110        def _EncodeKeyValues(self, key, values): 
    111                 if type(key)!=types.StringType: 
     111                if not isinstance(key, str): 
    112112                        return (key, values) 
    113113 
  • trunk/pyrad/tests/testPacket.py

    r1040 r1052  
    150150                                "\x8c\x8e\xc4\x72\xac\xea\x87\x45\x63\xa7") 
    151151 
     152    def testVerifyReply(self): 
     153        reply=self.packet.CreateReply() 
     154        self.assertEqual(self.packet.VerifyReply(reply), True) 
     155 
     156        reply.id+=1 
     157        self.assertEqual(self.packet.VerifyReply(reply), False) 
     158        reply.id=self.packet.id 
     159 
     160        reply.secret="different" 
     161        self.assertEqual(self.packet.VerifyReply(reply), False) 
     162        reply.secret=self.packet.secret 
     163 
     164        reply.authenticator="X"*16 
     165        self.assertEqual(self.packet.VerifyReply(reply), False) 
     166        reply.authenticator=self.packet.authenticator 
     167 
     168 
     169    def testPktEncodeAttribute(self): 
     170        encode=self.packet._PktEncodeAttribute 
     171 
     172        # Encode a normal attribute 
     173        self.assertEqual(encode(1, "value"), "\x01\x07value") 
     174        # Encode a vendor attribute 
     175        self.assertEqual(encode((1,2), "value"), 
     176                "\x1a\x0d\x00\x00\x00\x01\x02\x07value") 
     177 
     178 
     179    def testPktEncodeAttributes(self): 
     180        self.packet[1]=["value"] 
     181        self.assertEqual(self.packet._PktEncodeAttributes(), 
     182                "\x01\x07value") 
     183 
     184        self.packet.clear() 
     185        self.packet[(1,2)]=["value"] 
     186        self.assertEqual(self.packet._PktEncodeAttributes(), 
     187                "\x1a\x0d\x00\x00\x00\x01\x02\x07value") 
     188 
     189        self.packet.clear() 
     190        self.packet[1]=["one", "two", "three"] 
     191        self.assertEqual(self.packet._PktEncodeAttributes(), 
     192                "\x01\x05one\x01\x05two\x01\x07three") 
     193 
     194        self.packet.clear() 
     195        self.packet[1]=["value"] 
     196        self.packet[(1,2)]=["value"] 
     197        self.assertEqual(self.packet._PktEncodeAttributes(), 
     198                "\x1a\x0d\x00\x00\x00\x01\x02\x07value\x01\x07value") 
     199 
     200 
     201    def testPktDecodeVendorAttribute(self): 
     202        decode=self.packet._PktDecodeVendorAttribute 
     203 
     204        # Non-RFC2865 recommended form 
     205        self.assertEqual(decode(""), (26, "")) 
     206        self.assertEqual(decode("12345"), (26, "12345")) 
     207 
     208        # Almost RFC2865 recommended form: bad length value 
     209        self.assertEqual(decode("\x00\x00\x00\x01\x02\x06value"), 
     210                (26, "\x00\x00\x00\x01\x02\x06value")) 
     211 
     212        # Proper RFC2865 recommended form 
     213        self.assertEqual(decode("\x00\x00\x00\x01\x02\x07value"), 
     214                ((1L,2), "value")) 
     215 
     216