@@ -310,6 +310,45 @@ def test_configuration_crypttab_multiple_spaces(self):
310310 self .assertEqual (conf .value [0 ][1 ]['name' ], self .str_to_ay (self .vdevs [0 ]))
311311 self .assertEqual (conf .value [0 ][1 ]['device' ], self .str_to_ay ('UUID=%s' % uuid .value ))
312312
313+ @udiskstestcase .tag_test (udiskstestcase .TestTags .UNSAFE )
314+ def test_configuration_crypttab_no_keyfile (self ):
315+ # this test will change /etc/crypttab, we might want to revert the changes when it finishes
316+ crypttab = self .read_file ('/etc/crypttab' )
317+ self .addCleanup (self .write_file , '/etc/crypttab' , crypttab )
318+
319+ # format the disk
320+ disk1 = self .get_object ('/block_devices/' + os .path .basename (self .vdevs [0 ]))
321+ disk1 .Format ('xfs' , {'encrypt.passphrase' : 'test' }, dbus_interface = self .iface_prefix + '.Block' )
322+
323+ # cleanup -- close the luks and remove format
324+ self .addCleanup (self .wipe_fs , self .vdevs [0 ])
325+ self .addCleanup (self ._close_luks , disk1 )
326+
327+ # format the disk
328+ disk2 = self .get_object ('/block_devices/' + os .path .basename (self .vdevs [1 ]))
329+ disk2 .Format ('xfs' , {'encrypt.passphrase' : 'test' }, dbus_interface = self .iface_prefix + '.Block' )
330+
331+ # cleanup -- close the luks and remove format
332+ self .addCleanup (self .wipe_fs , self .vdevs [1 ])
333+ self .addCleanup (self ._close_luks , disk2 )
334+
335+ # write configuration to crypttab
336+ # both "none" and "-" should be accepted as an empty/non-existing key file
337+ uuid1 = self .get_property (disk1 , '.Block' , 'IdUUID' )
338+ uuid2 = self .get_property (disk2 , '.Block' , 'IdUUID' )
339+ self .write_file ('/etc/crypttab' , '%s UUID=%s\t none\n %s UUID=%s\t -\n ' % (self .vdevs [0 ], uuid1 .value ,
340+ self .vdevs [1 ], uuid2 .value ))
341+
342+ # get the secret configuration (passphrase)
343+ sec_conf = disk1 .GetSecretConfiguration (self .no_options , dbus_interface = self .iface_prefix + '.Block' )
344+ self .assertIsNotNone (sec_conf )
345+ self .assertEqual (sec_conf [0 ][1 ]['passphrase-path' ], self .str_to_ay ('' ))
346+
347+ # get the secret configuration (passphrase)
348+ sec_conf = disk2 .GetSecretConfiguration (self .no_options , dbus_interface = self .iface_prefix + '.Block' )
349+ self .assertIsNotNone (sec_conf )
350+ self .assertEqual (sec_conf [0 ][1 ]['passphrase-path' ], self .str_to_ay ('' ))
351+
313352 def test_rescan (self ):
314353
315354 disk = self .get_object ('/block_devices/' + os .path .basename (self .vdevs [0 ]))
0 commit comments