Skip to content

Commit d3baac8

Browse files
committed
Use tempdir for stunnel config
1 parent da2023b commit d3baac8

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ criterion = "0.3"
8484
partial-io = { version = "0.3", features = ["tokio", "quickcheck"] }
8585
quickcheck = "0.6"
8686
tokio = { version = "0.2", features = ["rt-core", "macros", "time"] }
87+
tempdir = "0.3"
8788

8889
[[test]]
8990
name = "test_async"

tests/support/mod.rs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ enum ServerType {
5050
pub struct RedisServer {
5151
pub process: process::Child,
5252
stunnel_process: Option<process::Child>,
53+
tempdir: Option<tempdir::TempDir>,
5354
addr: redis::ConnectionAddr,
5455
}
5556

@@ -115,6 +116,7 @@ impl RedisServer {
115116
redis_cmd
116117
.stdout(process::Stdio::null())
117118
.stderr(process::Stdio::null());
119+
let tempdir = tempdir::TempDir::new("redis").expect("failed to create tempdir");
118120
match addr {
119121
redis::ConnectionAddr::Tcp(ref bind, server_port) => {
120122
redis_cmd
@@ -126,6 +128,7 @@ impl RedisServer {
126128
RedisServer {
127129
process: spawner(&mut redis_cmd),
128130
stunnel_process: None,
131+
tempdir: None,
129132
addr,
130133
}
131134
}
@@ -135,43 +138,42 @@ impl RedisServer {
135138
.arg("--port")
136139
.arg("0")
137140
.arg("--unixsocket")
138-
.arg(&format!("/tmp/redis-rs-test-{}.sock", port));
141+
.arg(tempdir.path().join("redis.sock"));
139142

140143
// create a self-signed TLS server cert
141144
process::Command::new("openssl")
142-
.args(&[
143-
"req",
144-
"-nodes",
145-
"-new",
146-
"-x509",
147-
"-keyout",
148-
&format!("/tmp/redis-rs-test-{}.pem", port),
149-
"-out",
150-
&format!("/tmp/redis-rs-test-{}.crt", port),
151-
"-subj",
152-
"/C=XX/ST=crates/L=redis-rs/O=testing/CN=localhost",
153-
])
145+
.arg("req")
146+
.arg("-nodes")
147+
.arg("-new")
148+
.arg("-x509")
149+
.arg("-keyout")
150+
.arg(tempdir.path().join("key.pem"))
151+
.arg("-out")
152+
.arg(tempdir.path().join("cert.crt"))
153+
.arg("-subj")
154+
.arg("/C=XX/ST=crates/L=redis-rs/O=testing/CN=localhost")
154155
.stdout(process::Stdio::null())
155156
.stderr(process::Stdio::null())
156157
.spawn()
157158
.expect("failed to spawn openssl")
158159
.wait()
159160
.expect("failed to create self-signed TLS certificate");
160161

161-
let stunnel_config_path = format!("/tmp/redis-rs-stunnel-{}.conf", port);
162+
let stunnel_config_path = tempdir.path().join("stunnel.conf");
162163
let mut stunnel_config_file = fs::File::create(&stunnel_config_path).unwrap();
163164
stunnel_config_file
164165
.write_all(
165166
format!(
166167
r#"
167-
cert = /tmp/redis-rs-test-{stunnel_port}.crt
168-
key = /tmp/redis-rs-test-{stunnel_port}.pem
168+
cert = {tempdir}/cert.crt
169+
key = {tempdir}/key.pem
169170
verify = 0
170171
foreground = yes
171172
[redis]
172173
accept = {host}:{stunnel_port}
173-
connect = /tmp/redis-rs-test-{stunnel_port}.sock
174+
connect = {tempdir}/redis.sock
174175
"#,
176+
tempdir = tempdir.path().display(),
175177
host = host,
176178
stunnel_port = port,
177179
)
@@ -193,6 +195,7 @@ impl RedisServer {
193195
RedisServer {
194196
process: spawner(&mut redis_cmd),
195197
stunnel_process: Some(stunnel_cmd.spawn().expect("could not start stunnel")),
198+
tempdir: Some(tempdir),
196199
addr,
197200
}
198201
}
@@ -205,6 +208,7 @@ impl RedisServer {
205208
RedisServer {
206209
process: spawner(&mut redis_cmd),
207210
stunnel_process: None,
211+
tempdir: Some(tempdir),
208212
addr,
209213
}
210214
}

0 commit comments

Comments
 (0)