Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 7444d4cb

Přidáno uživatelem Stanislav Král před asi 4 roky(ů)

Re #8472 - Changed access modifier of run_for_output method to private (was protected previously)

Zobrazit rozdíly:

proj/services/cryptography.py
38 38
        return "".join([f"/{key}={value}" for key, value in subj_dict.items()])
39 39

  
40 40
    @staticmethod
41
    def _run_for_output(args=None, proc_input=None, executable=OPENSSL_EXECUTABLE):
41
    def __run_for_output(args=None, proc_input=None, executable=OPENSSL_EXECUTABLE):
42 42
        """
43 43
        Launches a new process in which the given executable is run. STDIN and process arguments can be set.
44 44
        If the process ends with a non-zero then <CryptographyException> is raised.
......
81 81
        :return: string containing the generated private key in PEM format
82 82
        """
83 83
        if passphrase is None or len(passphrase) == 0:
84
            return self._run_for_output(["genrsa", "2048"]).decode()
84
            return self.__run_for_output(["genrsa", "2048"]).decode()
85 85
        else:
86
            return self._run_for_output(
86
            return self.__run_for_output(
87 87
                ["genrsa", PRIVATE_KEY_ENCRYPTION_METHOD, "-passout", f"pass:{passphrase}", "2048"]).decode()
88 88

  
89 89
    def create_sscrt(self, key, subject, config="", extensions="", key_pass=None):
......
119 119
            # waiting for the passphrase to be typed in
120 120
            args.extend(["-passin", f"pass:{key_pass}"])
121 121

  
122
            return self._run_for_output(args, proc_input=bytes(key, encoding="utf-8")).decode()
122
            return self.__run_for_output(args, proc_input=bytes(key, encoding="utf-8")).decode()
123 123

  
124 124
    def __create_csr(self, subject, subject_key, subject_key_pass=""):
125 125
        """
......
139 139
        # waiting for the passphrase to be typed in
140 140
        args.extend(["-passin", f"pass:{subject_key_pass}"])
141 141

  
142
        return self._run_for_output(args, proc_input=bytes(subject_key, encoding="utf-8")).decode()
142
        return self.__run_for_output(args, proc_input=bytes(subject_key, encoding="utf-8")).decode()
143 143

  
144 144
    def __sign_csr(self, csr, issuer_pem, issuer_key, issuer_key_pass=None, extensions="", days=30):
145 145
        """
......
172 172
            if len(extensions) > 0:
173 173
                params.extend(["-extfile", ext_path])
174 174

  
175
            return self._run_for_output(params, proc_input=(bytes(proc_input, encoding="utf-8"))).decode()
175
            return self.__run_for_output(params, proc_input=(bytes(proc_input, encoding="utf-8"))).decode()
176 176

  
177 177
    def create_crt(self, subject, subject_key, issuer_pem, issuer_key, subject_key_pass=None, issuer_key_pass=None,
178 178
                   extensions="",
proj/tests/services/cryptography/run_for_output_test.py
4 4

  
5 5

  
6 6
def test_simple_exec(service):
7
    out = service._run_for_output(["version"])
7
    out = service._CryptographyService__run_for_output(["version"])
8 8
    assert "OpenSSL" in out.decode()
9 9

  
10 10

  
11 11
def test_simple_exec_without_parameters(service):
12
    out = service._run_for_output()
12
    out = service._CryptographyService__run_for_output()
13 13
    assert "OpenSSL>" in out.decode()
14 14

  
15 15

  
16 16
def test_nonexistent_executable(service):
17 17
    with pytest.raises(CryptographyException) as e:
18
        service._run_for_output(executable="nonexistent_executable#")
18
        service._CryptographyService__run_for_output(executable="nonexistent_executable#")
19 19
    assert """"nonexistent_executable#" not found in the current PATH.""" in e.value.message
20 20

  
21 21

  
22 22
def test_exception_str(service):
23 23
    with pytest.raises(CryptographyException) as e:
24
        service._run_for_output(executable="nonexistent_executable")
24
        service._CryptographyService__run_for_output(executable="nonexistent_executable")
25 25
    assert """EXECUTABLE: nonexistent_executable
26 26
        ARGS: ('nonexistent_executable',)
27 27
        MESSAGE: "nonexistent_executable" not found in the current PATH.""" in e.value.__str__()

Také k dispozici: Unified diff