@@ -16,10 +16,6 @@ use tokio::{
16
16
17
17
pub mod common;
18
18
19
- // An arbitrary but very long timeout.
20
- // No valid single IO operation should take anywhere near 10 minutes.
21
- pub const LONG_TIMEOUT : time:: Duration = time:: Duration :: from_secs ( 600 ) ;
22
-
23
19
async fn read_until_shutdown < S : AsyncRead + AsyncWrite + Unpin > (
24
20
stream : & mut TlsStream < S > ,
25
21
) -> Result < ( ) , std:: io:: Error > {
@@ -166,18 +162,6 @@ async fn shutdown_with_blinding() -> Result<(), Box<dyn std::error::Error>> {
166
162
let ( mut client, mut server) =
167
163
common:: run_negotiate ( & client, client_stream, & server, server_stream) . await ?;
168
164
169
- // Attempt to shutdown the client. This will eventually fail because the
170
- // server has not written the close_notify message yet, but it will at least
171
- // write the close_notify message that the server needs.
172
- //
173
- // Because this test begins paused and relies on auto-advancing, this does
174
- // not actually require waiting LONG_TIMEOUT. See the tokio `pause()` docs:
175
- // https://docs.rs/tokio/latest/tokio/time/fn.pause.html
176
- //
177
- // TODO: replace this with a half-close once the bindings support half-close.
178
- let timeout = time:: timeout ( LONG_TIMEOUT , client. shutdown ( ) ) . await ;
179
- assert ! ( timeout. is_err( ) ) ;
180
-
181
165
// Setup a bad record for the next read
182
166
overrides. next_read ( Some ( Box :: new ( |_, _, buf| {
183
167
// Parsing the header is one of the blinded operations
@@ -202,53 +186,9 @@ async fn shutdown_with_blinding() -> Result<(), Box<dyn std::error::Error>> {
202
186
// Server MUST eventually successfully shutdown
203
187
assert ! ( result. is_ok( ) ) ;
204
188
205
- // Shutdown MUST have sent the close_notify message needed by the peer
206
- // to also shutdown successfully.
207
- client. shutdown ( ) . await ?;
208
-
209
- Ok ( ( ) )
210
- }
211
-
212
- #[ tokio:: test( start_paused = true ) ]
213
- async fn shutdown_with_blinding_bad_close_record ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
214
- let clock = common:: TokioTime :: default ( ) ;
215
- let mut server_config = common:: server_config ( ) ?;
216
- server_config. set_monotonic_clock ( clock) ?;
217
-
218
- let client = TlsConnector :: new ( common:: client_config ( ) ?. build ( ) ?) ;
219
- let server = TlsAcceptor :: new ( server_config. build ( ) ?) ;
220
-
221
- let ( server_stream, client_stream) = common:: get_streams ( ) . await ?;
222
- let server_stream = common:: TestStream :: new ( server_stream) ;
223
- let overrides = server_stream. overrides ( ) ;
224
- let ( mut client, mut server) =
225
- common:: run_negotiate ( & client, client_stream, & server, server_stream) . await ?;
226
-
227
- // Setup a bad record for the next read
228
- overrides. next_read ( Some ( Box :: new ( |_, _, buf| {
229
- // Parsing the header is one of the blinded operations
230
- // in s2n_shutdown, so provide a malformed header.
231
- let zeroed_header = [ 23 , 0 , 0 , 0 , 0 ] ;
232
- buf. put_slice ( & zeroed_header) ;
233
- Ok ( ( ) ) . into ( )
234
- } ) ) ) ;
235
-
236
- let time_start = time:: Instant :: now ( ) ;
237
- let result = server. shutdown ( ) . await ;
238
- let time_elapsed = time_start. elapsed ( ) ;
239
-
240
- // Shutdown MUST NOT complete faster than minimal blinding time.
241
- assert ! ( time_elapsed > common:: MIN_BLINDING_SECS ) ;
242
-
243
- // Shutdown MUST eventually complete with the correct error after blinding.
244
- let io_error = result. unwrap_err ( ) ;
245
- let error: error:: Error = io_error. try_into ( ) ?;
246
- assert ! ( error. kind( ) == error:: ErrorType :: ProtocolError ) ;
247
- assert ! ( error. name( ) == "S2N_ERR_BAD_MESSAGE" ) ;
248
-
249
- // Shutdown MUST have sent the close_notify message needed by the peer
250
- // to also shutdown successfully.
251
- client. shutdown ( ) . await ?;
189
+ // Shutdown MUST have sent the close_notify message needed for EOF.
190
+ let mut received = [ 0 ; 1 ] ;
191
+ assert ! ( client. read( & mut received) . await ? == 0 ) ;
252
192
253
193
Ok ( ( ) )
254
194
}
@@ -295,7 +235,7 @@ async fn shutdown_with_poll_blinding() -> Result<(), Box<dyn std::error::Error>>
295
235
Ok ( ( ) )
296
236
}
297
237
298
- #[ tokio:: test( start_paused = true ) ]
238
+ #[ tokio:: test]
299
239
async fn shutdown_with_tcp_error ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
300
240
let client = TlsConnector :: new ( common:: client_config ( ) ?. build ( ) ?) ;
301
241
let server = TlsAcceptor :: new ( common:: server_config ( ) ?. build ( ) ?) ;
@@ -304,20 +244,9 @@ async fn shutdown_with_tcp_error() -> Result<(), Box<dyn std::error::Error>> {
304
244
let server_stream = common:: TestStream :: new ( server_stream) ;
305
245
let overrides = server_stream. overrides ( ) ;
306
246
307
- let ( mut client , mut server) =
247
+ let ( _ , mut server) =
308
248
common:: run_negotiate ( & client, client_stream, & server, server_stream) . await ?;
309
249
310
- // Attempt to shutdown the client. This will eventually fail because the
311
- // server has not written the close_notify message yet, but it will at least
312
- // write the close_notify message that the server needs.
313
- //
314
- // Because this test begins paused and relies on auto-advancing, this does
315
- // not actually require waiting LONG_TIMEOUT. See the tokio `pause()` docs:
316
- // https://docs.rs/tokio/latest/tokio/time/fn.pause.html
317
- //
318
- // TODO: replace this with a half-close once the bindings support half-close.
319
- _ = time:: timeout ( time:: Duration :: from_secs ( 600 ) , client. shutdown ( ) ) . await ;
320
-
321
250
// The underlying stream should return a unique error on shutdown
322
251
overrides. next_shutdown ( Some ( Box :: new ( |_, _| {
323
252
Ready ( Err ( io:: Error :: new ( io:: ErrorKind :: Other , common:: TEST_STR ) ) )
@@ -343,22 +272,22 @@ async fn shutdown_with_tls_error_and_tcp_error() -> Result<(), Box<dyn std::erro
343
272
let ( _, mut server) =
344
273
common:: run_negotiate ( & client, client_stream, & server, server_stream) . await ?;
345
274
346
- // Both s2n_shutdown and the underlying stream should error on shutdown
347
- overrides. next_read ( Some ( Box :: new ( |_, _, _| {
275
+ // Both s2n_shutdown_send and the underlying stream should error on shutdown
276
+ overrides. next_write ( Some ( Box :: new ( |_, _, _| {
348
277
Ready ( Err ( io:: Error :: from ( io:: ErrorKind :: Other ) ) )
349
278
} ) ) ) ;
350
279
overrides. next_shutdown ( Some ( Box :: new ( |_, _| {
351
280
Ready ( Err ( io:: Error :: new ( io:: ErrorKind :: Other , common:: TEST_STR ) ) )
352
281
} ) ) ) ;
353
282
354
- // Shutdown should complete with the correct error from s2n_shutdown
283
+ // Shutdown should complete with the correct error from s2n_shutdown_send
355
284
let result = server. shutdown ( ) . await ;
356
285
let io_error = result. unwrap_err ( ) ;
357
286
let error: error:: Error = io_error. try_into ( ) ?;
358
287
// Any non-blocking read error is translated as "IOError"
359
288
assert ! ( error. kind( ) == error:: ErrorType :: IOError ) ;
360
289
361
- // Even if s2n_shutdown fails, we need to close the underlying stream.
290
+ // Even if s2n_shutdown_send fails, we need to close the underlying stream.
362
291
// Make sure we called our mock shutdown, consuming it.
363
292
assert ! ( overrides. is_consumed( ) ) ;
364
293
@@ -374,14 +303,11 @@ async fn shutdown_with_tls_error_and_tcp_delay() -> Result<(), Box<dyn std::erro
374
303
let server_stream = common:: TestStream :: new ( server_stream) ;
375
304
let overrides = server_stream. overrides ( ) ;
376
305
377
- let ( _ , mut server) =
306
+ let ( mut client , mut server) =
378
307
common:: run_negotiate ( & client, client_stream, & server, server_stream) . await ?;
379
308
380
- // We want s2n_shutdown to fail on read in order to ensure that it is only
381
- // called once on failure.
382
- // If s2n_shutdown were called again, the second call would hang waiting
383
- // for nonexistent input from the peer.
384
- overrides. next_read ( Some ( Box :: new ( |_, _, _| {
309
+ // We want s2n_shutdown_send to produce an error on write
310
+ overrides. next_write ( Some ( Box :: new ( |_, _, _| {
385
311
Ready ( Err ( io:: Error :: from ( io:: ErrorKind :: Other ) ) )
386
312
} ) ) ) ;
387
313
@@ -391,16 +317,25 @@ async fn shutdown_with_tls_error_and_tcp_delay() -> Result<(), Box<dyn std::erro
391
317
Pending
392
318
} ) ) ) ;
393
319
394
- // Shutdown should complete with the correct error from s2n_shutdown
320
+ // Shutdown should complete with the correct error from s2n_shutdown_send
395
321
let result = server. shutdown ( ) . await ;
396
322
let io_error = result. unwrap_err ( ) ;
397
323
let error: error:: Error = io_error. try_into ( ) ?;
398
324
// Any non-blocking read error is translated as "IOError"
399
325
assert ! ( error. kind( ) == error:: ErrorType :: IOError ) ;
400
326
401
- // Even if s2n_shutdown fails, we need to close the underlying stream.
327
+ // Even if s2n_shutdown_send fails, we need to close the underlying stream.
402
328
// Make sure we at least called our mock shutdown, consuming it.
403
329
assert ! ( overrides. is_consumed( ) ) ;
404
330
331
+ // Since s2n_shutdown_send failed, we should NOT have sent a close_notify.
332
+ // Make sure the peer doesn't receive a close_notify.
333
+ // If this is not true, then we're incorrectly calling s2n_shutdown_send
334
+ // again after an error.
335
+ let mut received = [ 0 ; 1 ] ;
336
+ let io_error = client. read ( & mut received) . await . unwrap_err ( ) ;
337
+ let error: error:: Error = io_error. try_into ( ) ?;
338
+ assert ! ( error. kind( ) == error:: ErrorType :: ConnectionClosed ) ;
339
+
405
340
Ok ( ( ) )
406
341
}
0 commit comments