Exemplo n.º 1
0
class TestJCVersion:
    @pytest.mark.parametrize(
        "version,major,minor",
        [
            ("0000", 0, 0),
            ("0100", 1, 0),
            ("0202", 2, 2),
            ("0201", 2, 1),
            ("0300", 3, 0),
        ],
    )
    def test_from_str(self, version: str, major: int, minor: int):
        jcversion = JCVersion.from_str(version)

        assert jcversion.major == major
        assert jcversion.minor == minor

    @pytest.mark.parametrize(
        "version,string",
        [
            ("0000", "0.0"),
            ("0100", "1.0"),
            ("0202", "2.2"),
            ("0201", "2.1"),
            ("0300", "3.0"),
        ],
    )
    def test___str__(self, version: str, string: str):
        jcversion = JCVersion.from_str(version)
        assert str(jcversion) == string

    @pytest.mark.parametrize(
        "jcversion,exp_sdks",
        [
            ("0200", SDKVersion.from_list("jc202")),
            ("0300", SDKVersion.from_list("jc202,jc300,jc301,jc304")),
            ("0310", SDKVersion.from_list("jc202,jc300,jc301,jc304,jc310b43")),
        ],
    )
    def test_get_sdks(self, mocker, jcversion, exp_sdks):
        # mocking available SDKs
        mocker.patch.object(SDKVersion, "get_available_sdks")
        SDKVersion.get_available_sdks.return_value = SDKVersion.from_list(
            "jc202,jc300,jc301,jc304,jc310b43")

        jcversion = JCVersion.from_str(jcversion)
        sdks = jcversion.get_sdks()
        assert sdks == exp_sdks
Exemplo n.º 2
0
class TestSDKVersion:
    @pytest.mark.parametrize(
        "version,major,minor,patch,update,b_value",
        [
            ("jc211", 2, 1, 1, None, None),
            ("jc212", 2, 1, 2, None, None),
            ("jc222", 2, 2, 2, None, None),
            ("jc305u3", 3, 0, 5, 3, None),
            ("jc310b43", 3, 1, 0, None, 43),
        ],
    )
    def test_from_str(
        self,
        version: str,
        major: int,
        minor: int,
        patch: int,
        update: Optional[int],
        b_value: Optional[int],
    ):
        sdkversion = SDKVersion.from_str(version)
        assert sdkversion.major == major
        assert sdkversion.minor == minor
        assert sdkversion.patch == patch
        assert sdkversion.update == update
        assert sdkversion.b_value == b_value

    # FIXME this interacts with real data, but is not really a check
    def test_available_sdks(self):
        available = SDKVersion.get_available_sdks()
        assert SDKVersion.from_str("jc211") == available[0]

    @pytest.mark.parametrize(
        "raw_list,versions",
        [
            ("jc211", [SDKVersion.from_str("jc211")]),
            (
                "jc222,jc310b43",
                [
                    SDKVersion.from_str("jc222"),
                    SDKVersion.from_str("jc310b43")
                ],
            ),
        ],
    )
    def test_from_list(self, raw_list: str, versions: list):
        assert SDKVersion.from_list(raw_list) == versions
Exemplo n.º 3
0
 def possible_versions(self) -> List["SDKVersion"]:
     """
     Returns the intersection of SDKVersions the attack can be build for
     and the ones supported by the Card
     """
     attack_sdk_versions = SDKVersion.from_list(
         self.config["BUILD"]["versions"], sep=",")
     return list(set(attack_sdk_versions).intersection(set(self.card.sdks)))
Exemplo n.º 4
0
    def test_get_sdks(self, mocker, jcversion, exp_sdks):
        # mocking available SDKs
        mocker.patch.object(SDKVersion, "get_available_sdks")
        SDKVersion.get_available_sdks.return_value = SDKVersion.from_list(
            "jc202,jc300,jc301,jc304,jc310b43")

        jcversion = JCVersion.from_str(jcversion)
        sdks = jcversion.get_sdks()
        assert sdks == exp_sdks
Exemplo n.º 5
0
 def _determine_version(self) -> "SDKVersion":
     # determine the newest SDK version supported both by the card and the attack
     attack_versions = SDKVersion.from_list(
         self.config["BUILD"]["versions"])
     try:
         newest = list(
             set(attack_versions).intersection(set(self.card.sdks)))[-1]
     except IndexError:
         newest = attack_versions[0]
         log.warning("Could not determine SDK Version, defaulting to '%s'",
                     str(newest))
     return newest
Exemplo n.º 6
0
 def test_from_str(
     self,
     version: str,
     major: int,
     minor: int,
     patch: int,
     update: Optional[int],
     b_value: Optional[int],
 ):
     sdkversion = SDKVersion.from_str(version)
     assert sdkversion.major == major
     assert sdkversion.minor == minor
     assert sdkversion.patch == patch
     assert sdkversion.update == update
     assert sdkversion.b_value == b_value
Exemplo n.º 7
0
    def get_jcversion(self) -> "JCVersion":
        # TODO add better splitter, that handles spaces etc.
        self.config = configparser.ConfigParser()
        self.config.read(self.workdir / "config.ini")
        with cd(self.workdir):
            versions = self.config["BUILD"]["versions"].split(",")
        versions = load_versions(versions)

        for version in versions:
            # FIXME setting versions like so is quite a weird thing
            version = SDKVersion.from_str(version)
            report = self.execute(sdk_version=version)
            # FIXME after changing gppw the version cannot be read like this probably
            if report[1]["success"]:
                # TODO this is quite cumbersome
                version_str = report[1]["communication"]["8004000002"][
                    "payload"]
                return JCVersion.from_str(version_str)

        return JCVersion.from_str("")
Exemplo n.º 8
0
 def test_from_list(self, raw_list: str, versions: list):
     assert SDKVersion.from_list(raw_list) == versions
Exemplo n.º 9
0
 def test_available_sdks(self):
     available = SDKVersion.get_available_sdks()
     assert SDKVersion.from_str("jc211") == available[0]