| | 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 | |