コード例 #1
0
    def test_bad_storage_function(self):
        """
        Assigns a non-callable object to the storage callback function.
        """

        with self.assertRaises(TypeError):
            config = Config()
            config.storage_func = "test"
コード例 #2
0
    def test_compile_essid_regex_with_an_empty_regex(self):
        """
        Tests 'complile_essid_regex' with an empty regex.
        """

        config = Config()
        compiled_regex = config.complile_essid_regex()

        self.assertEqual(compiled_regex, None)
コード例 #3
0
    def test_default_frame_filter(self):
        """
        Tests the default frame filter.
        """

        config = Config()
        frame_filter = config.generate_frame_filter()

        self.assertEqual(frame_filter, "type mgt subtype probe-req")
コード例 #4
0
ファイル: test_config.py プロジェクト: SkypLabs/probequest
    def test_existing_interface(self):
        """
        Tests with an existing network interface.
        """

        # pylint: disable=no-self-use

        with patch("probequest.config.get_if_list", return_value=("wlan0",
                   "wlan0mon")):
            config = Config()
            config.interface = "wlan0"
コード例 #5
0
ファイル: test_config.py プロジェクト: SkypLabs/probequest
    def test_compiled_essid_regex_with_a_case_sensitive_regex(self):
        """
        Tests 'compiled_essid_regex' with a case-sensitive regex.
        """

        config = Config()
        config.essid_regex = "Free Wi-Fi"

        with self.assertLogs(self.logger, level=logging.DEBUG):
            compiled_regex = config.compiled_essid_regex

        self.assertEqual(compiled_regex, rcompile(config.essid_regex))
コード例 #6
0
ファイル: test_config.py プロジェクト: SkypLabs/probequest
    def test_non_existing_interface(self):
        """
        Tests if an exception is well raised when setting a non-existing
        network interface.
        """

        with patch("probequest.config.get_if_list", return_value=("wlan0",
                   "wlan0mon")):
            config = Config()

            with self.assertRaises(InterfaceDoesNotExistException):
                config.interface = "wlan1"
コード例 #7
0
    def test_compile_essid_regex_with_a_case_sensitive_regex(self):
        """
        Tests 'complile_essid_regex' with a case-sensitive regex.
        """

        from re import compile as rcompile

        config = Config()
        config.essid_regex = "Free Wi-Fi"
        compiled_regex = config.complile_essid_regex()

        self.assertEqual(compiled_regex, rcompile(config.essid_regex))
コード例 #8
0
    def test_frame_filter_with_mac_exclusion(self):
        """
        Tests the frame filter when some MAC addresses need to be excluded.
        """

        config = Config()
        config.mac_exclusions = ["a4:77:33:9a:73:5c", "b0:05:94:5d:5a:4d"]
        frame_filter = config.generate_frame_filter()

        self.assertEqual(
            frame_filter, "type mgt subtype probe-req" +
            " and not (ether src host a4:77:33:9a:73:5c" +
            "|| ether src host b0:05:94:5d:5a:4d)")
コード例 #9
0
    def test_compile_essid_regex_with_a_case_insensitive_regex(self):
        """
        Tests 'complile_essid_regex' with a case-insensitive regex.
        """

        from re import compile as rcompile, IGNORECASE

        config = Config()
        config.essid_regex = "Free Wi-Fi"
        config.ignore_case = True
        compiled_regex = config.complile_essid_regex()

        self.assertEqual(compiled_regex,
                         rcompile(config.essid_regex, IGNORECASE))
コード例 #10
0
ファイル: test_config.py プロジェクト: SkypLabs/probequest
    def test_frame_filter_with_mac_exclusion(self):
        """
        Tests the frame filter when some MAC addresses need to be excluded.
        """

        config = Config()
        config.mac_exclusions = ["a4:77:33:9a:73:5c", "b0:05:94:5d:5a:4d"]

        with self.assertLogs(self.logger, level=logging.DEBUG):
            self.assertEqual(
                config.frame_filter,
                "type mgt subtype probe-req" +
                " and not (ether src host a4:77:33:9a:73:5c" +
                "|| ether src host b0:05:94:5d:5a:4d)"
            )
コード例 #11
0
ファイル: test_config.py プロジェクト: SkypLabs/probequest
    def test_default_values(self):
        """
        Tests the default values.
        """

        config = Config()

        self.assertIsNone(config.interface)

        self.assertIsNone(config.essid_filters)
        self.assertIsNone(config.essid_regex)
        self.assertFalse(config.ignore_case)

        self.assertIsNone(config.mac_exclusions)
        self.assertIsNone(config.mac_filters)

        self.assertIsNone(config.output_file)

        self.assertFalse(config.fake)
        self.assertFalse(config.debug)

        with self.assertLogs(self.logger, level=logging.DEBUG):
            self.assertEqual(
                config.frame_filter,
                "type mgt subtype probe-req"
            )
コード例 #12
0
    def test_new_packet(self):
        """
        Tests the 'new_packet' method.
        """

        config = Config()
        new_packets = Queue()
        sniffer = PacketSniffer(config, new_packets)

        self.assertEqual(sniffer.new_packets.qsize(), 0)

        packet = RadioTap() \
            / Dot11(
                addr1="ff:ff:ff:ff:ff:ff",
                addr2="aa:bb:cc:11:22:33",
                addr3="dd:ee:ff:11:22:33"
            ) \
            / Dot11ProbeReq() \
            / Dot11Elt(
                info="Test"
            )

        sniffer.new_packet(packet)
        self.assertEqual(sniffer.new_packets.qsize(), 1)

        ProbeRequestParser.parse(sniffer.new_packets.get(timeout=1))
コード例 #13
0
    def test_create_sniffer(self):
        """
        Creates a 'ProbeRequestSniffer' object with the correct parameter.
        """

        # pylint: disable=no-self-use

        config = Config()
        sniffer = ProbeRequestSniffer(config)  # noqa: F841
コード例 #14
0
    def test_stop_before_start(self):
        """
        Creates a 'ProbeRequestSniffer' object and stops the sniffer before
        starting it.
        """

        # pylint: disable=no-self-use

        config = Config()
        sniffer = ProbeRequestSniffer(config)
        sniffer.stop()
コード例 #15
0
    def test_is_running_before_start(self):
        """
        Creates a 'PacketSniffer' object and runs 'is_running' before starting
        the sniffer.
        """

        config = Config()
        new_packets = Queue()
        sniffer = PacketSniffer(config, new_packets)

        self.assertFalse(sniffer.is_running())
コード例 #16
0
    def test_stop_before_start(self):
        """
        Creates a 'PacketSniffer' object and stops the sniffer before starting
        it.
        """

        config = Config()
        new_packets = Queue()
        sniffer = PacketSniffer(config, new_packets)

        with self.assertRaises(Scapy_Exception):
            sniffer.stop()
コード例 #17
0
    def test_stop_before_start_using_join(self):
        """
        Creates a 'FakePacketSniffer' object and stops the sniffer before
        starting it.
        """

        config = Config()
        new_packets = Queue()
        sniffer = FakePacketSniffer(config, new_packets)

        with self.assertRaises(RuntimeError):
            sniffer.join()
コード例 #18
0
    def test_new_packet(self):
        """
        Tests the 'new_packet' method.
        """

        config = Config()
        new_packets = Queue()
        sniffer = FakePacketSniffer(config, new_packets)

        self.assertEqual(sniffer.new_packets.qsize(), 0)

        sniffer.new_packet()
        self.assertEqual(sniffer.new_packets.qsize(), 1)
        sniffer.new_packet()
        self.assertEqual(sniffer.new_packets.qsize(), 2)
        sniffer.new_packet()
        self.assertEqual(sniffer.new_packets.qsize(), 3)

        ProbeRequestParser.parse(sniffer.new_packets.get(timeout=1))
        ProbeRequestParser.parse(sniffer.new_packets.get(timeout=1))
        ProbeRequestParser.parse(sniffer.new_packets.get(timeout=1))