コード例 #1
0
    def get(self):  # pragma: no cover
        """
        Execute the logic behind the meaning of ExpirationDate + return the matched status.
        """

        domain_validation = self.is_domain_valid()
        ip_validation = self.is_ip_valid()

        if domain_validation and not ip_validation or domain_validation:
            PyFunceble.CONFIGURATION.update(
                {"http_code": HTTPCode().get(), "referer": Referer().get()}
            )

            if PyFunceble.CONFIGURATION["referer"] in [
                PyFunceble.STATUS["official"]["up"],
                PyFunceble.STATUS["official"]["down"],
                PyFunceble.STATUS["official"]["invalid"],
            ]:
                return PyFunceble.CONFIGURATION["referer"]

            elif PyFunceble.CONFIGURATION["referer"]:
                return self._extract()

            self._whois_log()
            return Status(PyFunceble.STATUS["official"]["down"]).handle()

        elif ip_validation and not domain_validation or ip_validation:
            PyFunceble.CONFIGURATION["http_code"] = HTTPCode().get()

            self._whois_log()
            return Status(PyFunceble.STATUS["official"]["down"]).handle()

        self._whois_log()
        return Status(PyFunceble.STATUS["official"]["invalid"]).handle()
コード例 #2
0
    def get(self):  # pragma: no cover
        """
        Execute the logic behind the URL handling.
        """

        if self.is_url_valid():
            PyFunceble.CONFIGURATION.update(
                {"http_code": HTTPCode(full_url=True).get()})

            active_list = []
            active_list.extend(PyFunceble.HTTP_CODE["list"]["potentially_up"])
            active_list.extend(PyFunceble.HTTP_CODE["list"]["up"])

            inactive_list = []
            inactive_list.extend(
                PyFunceble.HTTP_CODE["list"]["potentially_down"])
            inactive_list.append("*" * 3)

            if PyFunceble.CONFIGURATION["http_code"] in active_list:
                return URLStatus(PyFunceble.STATUS["official"]["up"]).handle()

            elif PyFunceble.CONFIGURATION["http_code"] in inactive_list:
                return URLStatus(
                    PyFunceble.STATUS["official"]["down"]).handle()

        return URLStatus(PyFunceble.STATUS["official"]["invalid"]).handle()
コード例 #3
0
    def __init__(self,
                 subject,
                 subject_type="url",
                 filename=None,
                 inactive_db=None):
        # We share the subject.
        self.subject = subject
        # We share the subject type.
        self.subject_type = subject_type
        # We share the filename.
        self.filename = filename

        self.checker = PyFunceble.Check(self.subject)
        self.inactive_db = inactive_db

        # We initiate what we are going to return.
        self.output = {
            "domain_syntax_validation": None,
            "expiration_date": None,
            "ipv4_range_syntax_validation": None,
            "ipv4_syntax_validation": None,
            "subdomain_syntax_validation": None,
            "tested": self.subject,
            "url_syntax_validation": self.checker.is_url(),
            "whois_server": None,
            "http_status_code": HTTPCode(self.subject, "url").get(),
            "dns_lookup": None,
        }
コード例 #4
0
ファイル: url.py プロジェクト: smed79/PyFunceble
    def get(cls):  # pragma: no cover
        """
        Execute the logic behind the URL handling.

        :return: The status of the URL.
        :rtype: str
        """

        if Check().is_url_valid() or PyFunceble.CONFIGURATION["local"]:
            # * The url is valid.
            # or
            # * We are testing in/for a local or private network.

            if "current_test_data" in PyFunceble.INTERN:
                PyFunceble.INTERN["current_test_data"][
                    "url_syntax_validation"] = True

            # We initiate the HTTP status code.
            PyFunceble.INTERN.update({"http_code": HTTPCode().get()})

            # We initiate the list of active status code.
            active_list = []
            active_list.extend(PyFunceble.HTTP_CODE["list"]["potentially_up"])
            active_list.extend(PyFunceble.HTTP_CODE["list"]["up"])

            # We initiate the list of inactive status code.
            inactive_list = []
            inactive_list.extend(
                PyFunceble.HTTP_CODE["list"]["potentially_down"])
            inactive_list.append("*" * 3)

            if PyFunceble.INTERN["http_code"] in active_list:
                # The extracted HTTP status code is in the list of active list.

                # We handle and return the up status.
                return URLStatus(PyFunceble.STATUS["official"]["up"]).handle()

            if PyFunceble.INTERN["http_code"] in inactive_list:
                # The extracted HTTP status code is in the list of inactive list.

                # We handle and return the down status.
                return URLStatus(
                    PyFunceble.STATUS["official"]["down"]).handle()

        # The extracted HTTP status code is not in the list of active nor invalid list.

        if "current_test_data" in PyFunceble.INTERN:
            # The end-user want more information whith his test.

            # We update the url_syntax_validation index.
            PyFunceble.INTERN["current_test_data"][
                "url_syntax_validation"] = False

        # We handle and return the invalid down status.
        return URLStatus(PyFunceble.STATUS["official"]["invalid"]).handle()
コード例 #5
0
    def test_get_not_activated(self, _):
        """
        Test if HTTPCode().get() does not have a launch
        authorization.
        """

        PyFunceble.HTTP_CODE["active"] = False
        expected = None
        actual = HTTPCode().get()

        self.assertEqual(expected, actual)
コード例 #6
0
    def test_get_known_code(self, access):
        """
        Test of HTTPCode().get() for the case that
        it match a code which is in our list.
        """

        PyFunceble.HTTP_CODE["active"] = True

        access.return_value = 200
        expected = 200
        actual = HTTPCode().get()

        self.assertEqual(expected, actual)
コード例 #7
0
    def test_get_code_is_none(self, access):
        """
        Test of HTTPCode().get() for the case that
        it match a code which is not in our list.
        """

        PyFunceble.HTTP_CODE["active"] = True

        access.return_value = None
        expected = "***"
        actual = HTTPCode().get()

        self.assertEqual(expected, actual)
コード例 #8
0
ファイル: test_http_code.py プロジェクト: XorgX304/PyFunceble
    def test_get(self, access):
        """
        This method will test if HTTPCode().get() is filtering correctly.
        """

        PyFunceble.CONFIGURATION["domain"] = "google.com"

        # Test of the case that it returns None
        PyFunceble.HTTP_CODE["active"] = False
        expected = None
        actual = HTTPCode().get()

        self.assertEqual(expected, actual)
        PyFunceble.HTTP_CODE["active"] = True

        # Test of the case that it returns a code which is in our list
        access.return_value = 200
        expected = 200
        actual = HTTPCode().get()

        self.assertEqual(expected, actual)

        # Test of the case that it returns a code which is not in our list
        access.return_value = 859
        expected = "***"
        actual = HTTPCode().get()

        self.assertEqual(expected, actual)

        # Test of the case that it returns None
        access.return_value = None
        expected = "***"
        actual = HTTPCode().get()

        self.assertEqual(expected, actual)

        del PyFunceble.CONFIGURATION["domain"]
コード例 #9
0
ファイル: expiration_date.py プロジェクト: smed79/PyFunceble
    def get(self):  # pragma: no cover
        """
        Execute the logic behind the meaning of ExpirationDate + return the matched status.

        :return:
            The status of the tested domain.
            Can be one of the official status.
        :rtype: str
        """

        # We get the status of the domain validation.
        domain_validation = Check().is_domain_valid()
        # We get the status of the IPv4 validation.
        ip_validation = Check().is_ip_valid()

        if "current_test_data" in PyFunceble.INTERN:
            # The end-user want more information whith his test.

            # We update some index.
            PyFunceble.INTERN["current_test_data"].update({
                "domain_syntax_validation":
                domain_validation,
                "ip4_syntax_validation":
                ip_validation,
            })

        if (domain_validation and not ip_validation or domain_validation
                or PyFunceble.CONFIGURATION["local"]):
            # * The element is a valid domain.
            # and
            # * The element is not ahe valid IPv4.
            # or
            # * The element is a valid domain.

            # * We get the HTTP status code of the currently tested element.
            # and
            # * We try to get the element status from the IANA database.
            PyFunceble.INTERN.update({
                "http_code": HTTPCode().get(),
                "referer": Referer().get()
            })

            if PyFunceble.INTERN["referer"] in [
                    PyFunceble.STATUS["official"]["up"],
                    PyFunceble.STATUS["official"]["down"],
                    PyFunceble.STATUS["official"]["invalid"],
            ]:
                # The WHOIS record status is into our list of official status.

                # We consider that status as the status of the tested element.
                return PyFunceble.INTERN["referer"]

            # The WHOIS record status is not into our list of official status.

            if "current_test_data" in PyFunceble.INTERN:
                # The end-user want more information whith his test.

                # We update the whois_server index.
                PyFunceble.INTERN["current_test_data"][
                    "whois_server"] = PyFunceble.INTERN["referer"]

            if PyFunceble.INTERN["referer"] and not Check().is_subdomain():
                # * The iana database comparison status is not None.
                # and
                # * The domain we are testing is not a subdomain.

                # We try to extract the expiration date from the WHOIS record.
                # And we return the matched status.
                return self._extract()

            # The iana database comparison status is None.

            # We log our whois record if the debug mode is activated.
            Logs().whois(self.whois_record)

            # And we return and handle the official down status.
            return Status(PyFunceble.STATUS["official"]["down"]).handle()

        if (ip_validation and not domain_validation or ip_validation
                or PyFunceble.CONFIGURATION["local"]):
            # * The element is a valid IPv4.
            # and
            # * The element is not a valid domain.
            # or
            # * The element is a valid IPv4.

            # We get the HTTP status code.
            PyFunceble.INTERN["http_code"] = HTTPCode().get()

            # We log our whois record if the debug mode is activated.
            Logs().whois(self.whois_record)

            # And we return and handle the official down status.
            return Status(PyFunceble.STATUS["official"]["down"]).handle()

        # The validation was not passed.

        # We log our whois record if the debug mode is activated.
        Logs().whois(self.whois_record)

        # And we return and handle the official invalid status.
        return Status(PyFunceble.STATUS["official"]["invalid"],
                      "SYNTAX").handle()
コード例 #10
0
ファイル: expiration_date.py プロジェクト: mrijinm/PyFunceble
    def get(self):  # pragma: no cover
        """
        Execute the logic behind the meaning of ExpirationDate + return the matched status.

        :return:
            The status of the tested domain.
            Can be one of the official status.
        :rtype: str
        """

        # We get the status of the domain validation.
        domain_validation = self.checker.is_domain_valid()
        # We get the status of the IPv4 validation.
        ip_validation = self.checker.is_ip_valid()

        if "current_test_data" in PyFunceble.INTERN:
            # The end-user want more information whith his test.

            # We update some index.
            PyFunceble.INTERN["current_test_data"].update({
                "domain_syntax_validation":
                domain_validation,
                "ip4_syntax_validation":
                ip_validation,
            })

        if (domain_validation and not ip_validation or domain_validation
                or PyFunceble.CONFIGURATION["local"]):
            # * The element is a valid domain.
            # and
            # * The element is not ahe valid IPv4.
            # or
            # * The element is a valid domain.

            # * We get the HTTP status code of the currently tested element.
            # and
            # * We try to get the element status from the IANA database.
            PyFunceble.INTERN.update({
                "http_code": HTTPCode().get(),
                "referer": Referer().get()
            })

            if not PyFunceble.INTERN["referer"]:
                # We could not get the referer.

                # We parse the referer status into the upstream call.
                return PyFunceble.INTERN["referer"]

            # The WHOIS record status is not into our list of official status.

            if PyFunceble.INTERN["referer"] and not self.checker.is_subdomain(
            ):
                # * The iana database comparison status is not None.
                # and
                # * The domain we are testing is not a subdomain.

                # We try to extract the expiration date from the WHOIS record.
                # And we return the matched status.
                return self._extract()

            # The iana database comparison status is None.

            # We log our whois record if the debug mode is activated.
            Logs().whois(self.whois_record)

            # And we return None, we could not extract the expiration date.
            return None

        if (ip_validation and not domain_validation or ip_validation
                or PyFunceble.CONFIGURATION["local"]):
            # * The element is a valid IPv4.
            # and
            # * The element is not a valid domain.
            # or
            # * The element is a valid IPv4.

            # We get the HTTP status code.
            PyFunceble.INTERN["http_code"] = HTTPCode().get()

            # We log our whois record if the debug mode is activated.
            Logs().whois(self.whois_record)

            # And we return None, there is no expiration date to look for.
            return None

        # The validation was not passed.

        # We log our whois record if the debug mode is activated.
        Logs().whois(self.whois_record)

        # And we return False, the domain could not pass the IP and domains syntax validation.
        return False
コード例 #11
0
    def get(self):
        """
        Get the status while testing for an IP or domain.
        """

        if self.subject:
            self.output.update({
                "domain_syntax_validation":
                self.checker.is_domain(),
                "expiration_date":
                None,
                "http_status_code":
                "***",
                "ipv4_range_syntax_validation":
                self.checker.is_ipv4_range(),
                "ipv4_syntax_validation":
                self.checker.is_ipv4(),
                "subdomain_syntax_validation":
                self.checker.is_subdomain(),
                "tested":
                self.subject,
                "url_syntax_validation":
                self.checker.is_url(),
                "whois_server":
                Referer(self.subject).get(),
            })

            if PyFunceble.CONFIGURATION["local"] or (
                    self.output["domain_syntax_validation"]
                    or self.output["ipv4_syntax_validation"]):
                self.output["http_status_code"] = HTTPCode(
                    self.subject, self.subject_type).get()

                if not self.output["subdomain_syntax_validation"]:
                    self.output["expiration_date"], self.output[
                        "whois_record"] = ExpirationDate(
                            self.subject,
                            self.output["whois_server"],
                            whois_db=self.whois_db,
                        ).get()

                    if isinstance(self.output["expiration_date"], str):
                        self.output["_status_source"] = self.output[
                            "status_source"] = "WHOIS"
                        self.output["_status"] = self.output[
                            "status"] = PyFunceble.STATUS["official"]["up"]

                        Generate(
                            self.subject,
                            self.subject_type,
                            self.output["status"],
                            source=self.output["status_source"],
                            expiration_date=self.output["expiration_date"],
                            http_status_code=self.output["http_status_code"],
                            whois_server=self.output["whois_server"],
                            filename=self.filename,
                            ip_validation=self.
                            output["ipv4_syntax_validation"],
                        ).status_file()
                    else:
                        self.output["_status_source"] = "DNSLOOKUP"
                        self.handle(
                            status="inactive",
                            ip_validation_status=self.
                            output["ipv4_syntax_validation"],
                        )
                else:
                    self.output["_status_source"] = "DNSLOOKUP"
                    self.handle(
                        status="inactive",
                        ip_validation_status=self.
                        output["ipv4_syntax_validation"],
                    )
            else:
                self.output["_status_source"] = "SYNTAX"
                self.output["_status"] = PyFunceble.STATUS["official"][
                    "invalid"]

                self.handle(
                    status="invalid",
                    ip_validation_status=self.output["ipv4_syntax_validation"],
                )

            return self.output

        raise ValueError("Subject should be given.")