@@ -277,78 +277,63 @@ pub async fn retry_if_throttled<
277
277
278
278
#[ test_function]
279
279
pub async fn test_automatic_wireguard_rotation (
280
- ctx : TestContext ,
280
+ _ : TestContext ,
281
281
rpc : ServiceClient ,
282
282
mut mullvad_client : MullvadProxyClient ,
283
- ) -> Result < ( ) , Error > {
283
+ ) -> anyhow :: Result < ( ) > {
284
284
// Make note of current WG key
285
285
let old_key = mullvad_client
286
286
. get_device ( )
287
- . await
288
- . unwrap ( )
287
+ . await ?
289
288
. into_device ( )
290
- . expect ( "Could not get device" )
289
+ . context ( "Could not get device" ) ?
291
290
. device
292
291
. pubkey ;
293
292
294
293
log:: info!( "Old wireguard key: {old_key}" ) ;
295
294
296
- log:: info!( "Stopping daemon" ) ;
297
- rpc. stop_mullvad_daemon ( )
298
- . await
299
- . expect ( "Could not stop system service" ) ;
295
+ rpc. stop_mullvad_daemon ( ) . await ?;
300
296
301
297
log:: info!( "Changing created field of `device.json` to more than 7 days ago" ) ;
302
298
rpc. make_device_json_old ( )
303
299
. await
304
- . expect ( "Could not change device.json to have an old created timestamp" ) ;
305
-
306
- log:: info!( "Starting daemon" ) ;
307
- rpc. start_mullvad_daemon ( )
308
- . await
309
- . expect ( "Could not start system service" ) ;
300
+ . context ( "Could not change device.json to have an old created timestamp" ) ?;
310
301
311
- // NOTE: Need to create a new `mullvad_client` here after the restart otherwise we can't
312
- // communicate with the daemon
313
- log:: info!( "Reconnecting to daemon" ) ;
314
- drop ( mullvad_client) ;
315
- let mut mullvad_client = ctx. rpc_provider . new_client ( ) . await ;
316
-
317
- log:: info!( "Verifying that wireguard key has change" ) ;
302
+ rpc. start_mullvad_daemon ( ) . await ?;
318
303
319
304
// Check if the key rotation has already occurred when connected to the daemon, otherwise
320
305
// listen for device daemon events until we observe the change. We have to register the event
321
306
// listener before polling the current key to be sure we don't miss the change.
307
+ log:: info!( "Verifying that wireguard key has change" ) ;
322
308
let event_listener = mullvad_client. events_listen ( ) . await . unwrap ( ) ;
323
309
let new_key = mullvad_client
324
310
. get_device ( )
325
- . await
326
- . unwrap ( )
311
+ . await ?
327
312
. into_device ( )
328
- . expect ( "Could not get device" )
313
+ . context ( "Could not get device" ) ?
329
314
. device
330
315
. pubkey ;
331
316
332
317
// If key has not yet been updated, listen for changes to it
333
318
if new_key == old_key {
334
- log:: info!( "Listening for device daemon event" ) ;
335
319
// Verify rotation has happened within 100 seconds - if the key hasn't been rotated after
336
320
// that, the rotation probably won't happen anytime soon.
321
+ log:: info!( "Listening for device daemon event" ) ;
322
+ let device_event = |daemon_event| match daemon_event {
323
+ DaemonEvent :: Device ( device_event) => Some ( device_event) ,
324
+ _ => None ,
325
+ } ;
337
326
let device_event = tokio:: task:: spawn ( tokio:: time:: timeout (
338
327
Duration :: from_secs ( 100 ) ,
339
- helpers:: find_daemon_event ( event_listener, |daemon_event| match daemon_event {
340
- DaemonEvent :: Device ( device_event) => Some ( device_event) ,
341
- _ => None ,
342
- } ) ,
328
+ helpers:: find_daemon_event ( event_listener, device_event) ,
343
329
) )
344
- . await
345
- . unwrap ( )
346
- . map_err ( |_error| Error :: Daemon ( String :: from ( "Tunnel event listener timed out" ) ) ) ??;
330
+ . await ?
331
+ . context ( "Tunnel event listener timed out" ) ??;
347
332
348
333
let new_key = device_event
349
334
. new_state
350
335
. into_device ( )
351
- . expect ( "Could not get device" )
336
+ . context ( "Could not get device" ) ?
352
337
. device
353
338
. pubkey ;
354
339
0 commit comments