@@ -19,7 +19,7 @@ def pytest_addoption(parser):
19
19
parser .addoption ("--globals" , default = "" )
20
20
21
21
22
- def self_signed_cert (test_dir , name ):
22
+ def self_signed_cert (name ):
23
23
k = crypto .PKey ()
24
24
k .generate_key (crypto .TYPE_RSA , 2048 )
25
25
cert = crypto .X509 ()
@@ -29,11 +29,9 @@ def self_signed_cert(test_dir, name):
29
29
cert .gmtime_adj_notAfter (365 * 86400 ) # 365 days
30
30
cert .set_pubkey (k )
31
31
cert .sign (k , "sha512" )
32
- (test_dir / f"{ name } .key" ).write_text (
33
- crypto .dump_privatekey (crypto .FILETYPE_PEM , k ).decode ("utf-8" )
34
- )
35
- (test_dir / f"{ name } .crt" ).write_text (
36
- crypto .dump_certificate (crypto .FILETYPE_PEM , cert ).decode ("utf-8" )
32
+ return (
33
+ crypto .dump_privatekey (crypto .FILETYPE_PEM , k ),
34
+ crypto .dump_certificate (crypto .FILETYPE_PEM , cert ),
37
35
)
38
36
39
37
@@ -66,7 +64,7 @@ def nginx_config(request, pytestconfig, testdir, logger):
66
64
67
65
68
66
@pytest .fixture (scope = "module" )
69
- def nginx (testdir , pytestconfig , nginx_config , certs , logger , otelcol ):
67
+ def nginx (testdir , pytestconfig , nginx_config , cert , logger , otelcol ):
70
68
(testdir / "nginx.conf" ).write_text (nginx_config )
71
69
logger .info ("Starting nginx..." )
72
70
proc = subprocess .Popen (
@@ -96,5 +94,8 @@ def nginx(testdir, pytestconfig, nginx_config, certs, logger, otelcol):
96
94
97
95
98
96
@pytest .fixture (scope = "module" )
99
- def certs (testdir ):
100
- self_signed_cert (testdir , "localhost" )
97
+ def cert (testdir ):
98
+ key , cert = self_signed_cert ("localhost" )
99
+ (testdir / "localhost.key" ).write_text (key .decode ("utf-8" ))
100
+ (testdir / "localhost.crt" ).write_text (cert .decode ("utf-8" ))
101
+ yield (key , cert )
0 commit comments