Beispiel #1
0
    def test_zipalign_valid_path(self):
        zipalign = Zipalign()
        assert os.path.isfile(zipalign.zipalign_path)

        with pytest.raises(subprocess.CalledProcessError) as e:
            subprocess.check_output(zipalign.zipalign_path, stderr=subprocess.STDOUT)
        assert "usage: zipalign" in e.value.output.decode().lower()
Beispiel #2
0
    def test_align_error_generic(self, tmp_demo_apk_v10_rebuild_path: str, monkeypatch):
        def mock(*args, **kwargs):
            raise Exception

        monkeypatch.setattr("subprocess.check_output", mock)

        with pytest.raises(Exception):
            Zipalign().align(tmp_demo_apk_v10_rebuild_path)
Beispiel #3
0
    def test_align_error_invalid_file(self, tmp_working_directory_path: str):
        invalid_file_path = os.path.join(tmp_working_directory_path, "invalid.apk")

        with open(invalid_file_path, "w") as invalid_file:
            invalid_file.write("This is not an apk file\n")

        with pytest.raises(subprocess.CalledProcessError):
            Zipalign().align(invalid_file_path)
Beispiel #4
0
def check_external_tool_dependencies():
    """
    Make sure all the external needed tools are available and ready to be used.
    """
    # APKTOOL_PATH, JARSIGNER_PATH and ZIPALIGN_PATH environment variables can be
    # used to specify the location of the external tools (make sure they have the
    # execute permission). If there is a problem with any of the executables below,
    # an exception will be thrown by the corresponding constructor.
    Apktool()
    Jarsigner()
    Zipalign()
Beispiel #5
0
    def align_obfuscated_apk(self) -> None:

        # This method must be called AFTER the obfuscated apk has been signed.

        # The obfuscated apk will be aligned with zipalign.
        zipalign: Zipalign = Zipalign()

        try:
            zipalign.align(self.obfuscated_apk_path)
        except Exception as e:
            self.logger.error("Error during apk alignment: {0}".format(e))
            raise
Beispiel #6
0
 def test_align_error_invalid_apk_path(self):
     with pytest.raises(FileNotFoundError):
         Zipalign().align("invalid.apk.path")
Beispiel #7
0
 def test_align_valid_apk(self, tmp_demo_apk_v10_rebuild_path: str):
     output = Zipalign().align(tmp_demo_apk_v10_rebuild_path)
     assert "verification succes" in output.lower()
Beispiel #8
0
 def test_zipalign_wrong_path(self, monkeypatch):
     monkeypatch.setenv("ZIPALIGN_PATH", "invalid.zipalign.path")
     with pytest.raises(RuntimeError):
         Zipalign()