1{ stdenv
2, buildPythonPackage
3, fetchPypi
4, openssl
5, cryptography
6, pyasn1
7, idna
8, pytest
9, pretend
10, flaky
11, glibcLocales
12}:
13
14with stdenv.lib;
15
16
17let
18 # https://github.com/pyca/pyopenssl/issues/791
19 # These tests, we disable in the case that libressl is passed in as openssl.
20 failingLibresslTests = [
21 "test_op_no_compression"
22 "test_npn_advertise_error"
23 "test_npn_select_error"
24 "test_npn_client_fail"
25 "test_npn_success"
26 "test_use_certificate_chain_file_unicode"
27 "test_use_certificate_chain_file_bytes"
28 "test_add_extra_chain_cert"
29 "test_set_session_id_fail"
30 "test_verify_with_revoked"
31 "test_set_notAfter"
32 "test_set_notBefore"
33 ];
34
35 # these tests are extremely tightly wed to the exact output of the openssl cli tool,
36 # including exact punctuation.
37 failingOpenSSL_1_1Tests = [
38 "test_dump_certificate"
39 "test_dump_privatekey_text"
40 "test_dump_certificate_request"
41 "test_export_text"
42 ];
43
44 disabledTests = [
45 # https://github.com/pyca/pyopenssl/issues/692
46 # These tests, we disable always.
47 "test_set_default_verify_paths"
48 "test_fallback_default_verify_paths"
49 # https://github.com/pyca/pyopenssl/issues/768
50 "test_wantWriteError"
51 ] ++ (
52 optionals (hasPrefix "libressl" openssl.meta.name) failingLibresslTests
53 ) ++ (
54 optionals (versionAtLeast (getVersion openssl.name) "1.1") failingOpenSSL_1_1Tests
55 );
56
57 # Compose the final string expression, including the "-k" and the single quotes.
58 testExpression = optionalString (disabledTests != [])
59 "-k 'not ${concatStringsSep " and not " disabledTests}'";
60
61in
62
63
64buildPythonPackage rec {
65 pname = "pyOpenSSL";
66 version = "19.0.0";
67
68 src = fetchPypi {
69 inherit pname version;
70 sha256 = "aeca66338f6de19d1aa46ed634c3b9ae519a64b458f8468aec688e7e3c20f200";
71 };
72
73 outputs = [ "out" "dev" ];
74
75 checkPhase = ''
76 runHook preCheck
77 export LANG="en_US.UTF-8"
78 py.test tests ${testExpression}
79 runHook postCheck
80 '';
81
82 # Seems to fail unpredictably on Darwin. See http://hydra.nixos.org/build/49877419/nixlog/1
83 # for one example, but I've also seen ContextTests.test_set_verify_callback_exception fail.
84 doCheck = !stdenv.isDarwin;
85
86 nativeBuildInputs = [ openssl ];
87 propagatedBuildInputs = [ cryptography pyasn1 idna ];
88
89 checkInputs = [ pytest pretend flaky glibcLocales ];
90}