示例#1
0
    def test_it_should_assert_true_for_invalid_arguments(self):
        try:
            assertions.assertTrue(False)

            self.fail("did not identify that False is not True")
        except assertions.AssertionFailedError, e:
            self.assertEqual('expected False to be True', e.message)
示例#2
0
    def run(self):
        # This relies on SEND - Ping it so it sends an NS
        self.logger.info(
            "Sending an ICMPv6 Echo Request to the UUT, to trigger a Secure Neighbor Solicitation..."
        )
        self.node(1).send(
            IPv6(src=str(self.node(1).link_local_ip()),
                 dst=str(self.target(1).link_local_ip())) /
            ICMPv6EchoRequest(seq=self.next_seq()))

        self.logger.info("Checking for a signed CGA packet...")
        cga_packets = self.node(1).received(src=self.target(1).link_local_ip(),
                                            dst=self.node(1).link_local_ip(),
                                            type=ICMPv6NDOptCGA,
                                            timeout=120)
        assertGreaterThanOrEqualTo(
            1, len(cga_packets), "expect to receive one-or-more CGA packets")

        self.logger.info("Receive a CGA packet. Verifying it:")
        cga_layer = cga_packets[0][ICMPv6NDOptCGA]

        self.logger.info("Checking Collision count is in range...")
        assertTrue(cga_layer.collision in [0, 1, 2],
                   "expected Collision Count to be 0, 1 or 2")

        iface_identifier = inet_pton(socket.AF_INET6,
                                     IPAddress.identify(
                                         cga_packets[0].src).ip)[8:]
        prefix = IPAddress.identify(cga_packets[0].src).network()
        # check the CGA subnet prefix(mask) is equal to the subnet prefix
        self.logger.info("Checking the Subnet Prefix Mask...")
        assertEqual(str(Network(cga_layer.mask)), prefix,
                    "expected the CGA Prefix to match the Address Prefix")

        self.logger.info("Checking Hash One...")
        hash1 = self.hash_one(cga_layer)
        mask1 = '\x1c\xff\xff\xff\xff\xff\xff\xff'  # RFC3972, Section 2
        # Hash1 & Mask1 == Interface Identifier & Mask1, last 7 octets should match exactly
        assertEqual(self.and_byte_strings(hash1, mask1),
                    self.and_byte_strings(iface_identifier, mask1),
                    "expected hash1 to match the interface identifier")
        assertEqual(hash1[7:], iface_identifier[7:],
                    "expected hash1 to match the interface identifier")

        self.logger.info("Checking Hash Two...")
        hash2 = self.hash_two(cga_layer)
        sec = (ord(iface_identifier[0]) >> 5) & 0x07
        mask2 = '\xff\xff' * sec + '\x00\x00' * (
            7 - sec)  # 112bit mask as in RFC 3972, Section 2
        # Hash2 & Mask2  ==  0x0000000000000000000000000000
        assertEqual(self.and_byte_strings(hash2, mask2), '\x00\x00' * 7,
                    "expected hash2 & mask2 to be zero")
示例#3
0
    def run(self):
        # This relies on SEND - Ping it so it sends an NS
        self.logger.info("Sending an ICMPv6 Echo Request to the UUT, to trigger a Secure Neighbor Solicitation...")
        self.node(1).send(
            IPv6(src=str(self.node(1).link_local_ip()), dst=str(self.target(1).link_local_ip()))/
                ICMPv6EchoRequest(seq=self.next_seq()))

        self.logger.info("Checking for a signed CGA packet...")
        cga_packets = self.node(1).received(src=self.target(1).link_local_ip(), dst=self.node(1).link_local_ip(), type=ICMPv6NDOptCGA, timeout=120)
        assertGreaterThanOrEqualTo(1, len(cga_packets), "expect to receive one-or-more CGA packets")

        self.logger.info("Receive a CGA packet. Verifying it:")
        cga_layer = cga_packets[0][ICMPv6NDOptCGA]
        
        self.logger.info("Checking Collision count is in range...")
        assertTrue(cga_layer.collision in [0,1,2], "expected Collision Count to be 0, 1 or 2")
        
        iface_identifier = inet_pton(socket.AF_INET6, IPAddress.identify(cga_packets[0].src).ip)[8:]
        prefix           = IPAddress.identify(cga_packets[0].src).network()
        # check the CGA subnet prefix(mask) is equal to the subnet prefix
        self.logger.info("Checking the Subnet Prefix Mask...")
        assertEqual(str(Network(cga_layer.mask)), prefix, "expected the CGA Prefix to match the Address Prefix")

        self.logger.info("Checking Hash One...")
        hash1 = self.hash_one(cga_layer)
        mask1 = '\x1c\xff\xff\xff\xff\xff\xff\xff' # RFC3972, Section 2
        # Hash1 & Mask1 == Interface Identifier & Mask1, last 7 octets should match exactly
        assertEqual(self.and_byte_strings(hash1, mask1), self.and_byte_strings(iface_identifier, mask1), "expected hash1 to match the interface identifier")
        assertEqual(hash1[7:], iface_identifier[7:], "expected hash1 to match the interface identifier")

        self.logger.info("Checking Hash Two...")
        hash2 = self.hash_two(cga_layer)
        sec = (ord(iface_identifier[0]) >> 5) & 0x07
        mask2 = '\xff\xff'*sec + '\x00\x00'*(7-sec) # 112bit mask as in RFC 3972, Section 2
        # Hash2 & Mask2  ==  0x0000000000000000000000000000
        assertEqual(self.and_byte_strings(hash2, mask2), '\x00\x00'*7, "expected hash2 & mask2 to be zero")
示例#4
0
 def test_it_should_assert_true_for_valid_arguments(self):
     self.assertEqual(True, assertions.assertTrue(True),
                      'did not identify that True is True')
示例#5
0
 def test_it_should_assert_true(self):
     try:
         assertions.assertTrue(True)
     except assertions.AssertionFailedError, e:
         self.fail("did not identify that True was True")