Exemple #1
0
    def test_attach_volume_not_formatted(self, mock_execute):
        fake_key = uuid.uuid4().hex
        self.encryptor._get_key = mock.MagicMock()
        self.encryptor._get_key.return_value = test_cryptsetup.fake__get_key(
                                                                None, fake_key)

        mock_execute.side_effect = [
                processutils.ProcessExecutionError(exit_code=1),  # luksOpen
                processutils.ProcessExecutionError(exit_code=1),  # isLuks
                mock.DEFAULT,  # luksFormat
                mock.DEFAULT,  # luksOpen
                mock.DEFAULT,  # ln
        ]

        self.encryptor.attach_volume(None)

        mock_execute.assert_has_calls([
            mock.call('cryptsetup', 'luksOpen', '--key-file=-', self.dev_path,
                      self.dev_name, process_input=fake_key,
                      run_as_root=True, check_exit_code=True),
            mock.call('cryptsetup', 'isLuks', '--verbose', self.dev_path,
                      run_as_root=True, check_exit_code=True),
            mock.call('cryptsetup', '--batch-mode', 'luksFormat',
                      '--key-file=-', self.dev_path, process_input=fake_key,
                      run_as_root=True, check_exit_code=True, attempts=3),
            mock.call('cryptsetup', 'luksOpen', '--key-file=-', self.dev_path,
                      self.dev_name, process_input=fake_key,
                      run_as_root=True, check_exit_code=True),
            mock.call('ln', '--symbolic', '--force',
                      '/dev/mapper/%s' % self.dev_name, self.symlink_path,
                      run_as_root=True, check_exit_code=True),
        ], any_order=False)
        self.assertEqual(5, mock_execute.call_count)
Exemple #2
0
    def test_attach_volume_not_formatted(self, mock_execute):
        self.encryptor._get_key = mock.MagicMock()
        self.encryptor._get_key.return_value = \
                test_cryptsetup.fake__get_key(None)

        mock_execute.side_effect = [
                processutils.ProcessExecutionError(exit_code=1),  # luksOpen
                processutils.ProcessExecutionError(exit_code=1),  # isLuks
                mock.DEFAULT,  # luksFormat
                mock.DEFAULT,  # luksOpen
                mock.DEFAULT,  # ln
        ]

        self.encryptor.attach_volume(None)

        mock_execute.assert_has_calls([
            mock.call('cryptsetup', 'luksOpen', '--key-file=-', self.dev_path,
                      self.dev_name, process_input='0' * 32,
                      run_as_root=True, check_exit_code=True),
            mock.call('cryptsetup', 'isLuks', '--verbose', self.dev_path,
                      run_as_root=True, check_exit_code=True),
            mock.call('cryptsetup', '--batch-mode', 'luksFormat',
                      '--key-file=-', self.dev_path, process_input='0' * 32,
                      run_as_root=True, check_exit_code=True),
            mock.call('cryptsetup', 'luksOpen', '--key-file=-', self.dev_path,
                      self.dev_name, process_input='0' * 32,
                      run_as_root=True, check_exit_code=True),
            mock.call('ln', '--symbolic', '--force',
                      '/dev/mapper/%s' % self.dev_name, self.symlink_path,
                      run_as_root=True, check_exit_code=True),
        ], any_order=False)
        self.assertEqual(5, mock_execute.call_count)
Exemple #3
0
    def test_attach_volume_fail(self, mock_execute):
        fake_key = uuid.uuid4().hex
        self.encryptor._get_key = mock.MagicMock()
        self.encryptor._get_key.return_value = test_cryptsetup.fake__get_key(
            None, fake_key)

        mock_execute.side_effect = [
            processutils.ProcessExecutionError(exit_code=1),  # luksOpen
            mock.DEFAULT,  # isLuks
        ]

        self.assertRaises(processutils.ProcessExecutionError,
                          self.encryptor.attach_volume, None)

        mock_execute.assert_has_calls([
            mock.call('cryptsetup',
                      'luksOpen',
                      '--key-file=-',
                      self.dev_path,
                      self.dev_name,
                      process_input=fake_key,
                      run_as_root=True,
                      check_exit_code=True),
            mock.call('cryptsetup',
                      'isLuks',
                      '--verbose',
                      self.dev_path,
                      run_as_root=True,
                      check_exit_code=True),
        ],
                                      any_order=False)
        self.assertEqual(2, mock_execute.call_count)
Exemple #4
0
    def test_attach_volume(self, mock_execute):
        fake_key = uuid.uuid4().hex
        self.encryptor._get_key = mock.MagicMock()
        self.encryptor._get_key.return_value = test_cryptsetup.fake__get_key(
            None, fake_key)

        self.encryptor.attach_volume(None)

        mock_execute.assert_has_calls([
            mock.call('cryptsetup',
                      'luksOpen',
                      '--key-file=-',
                      self.dev_path,
                      self.dev_name,
                      process_input=fake_key,
                      run_as_root=True,
                      check_exit_code=True),
            mock.call('ln',
                      '--symbolic',
                      '--force',
                      '/dev/mapper/%s' % self.dev_name,
                      self.symlink_path,
                      run_as_root=True,
                      check_exit_code=True),
        ])
        self.assertEqual(2, mock_execute.call_count)
Exemple #5
0
    def test_attach_volume_unmangle_passphrase(self, mock_execute):
        fake_key = '0725230b'
        fake_key_mangled = '72523b'
        self.encryptor._get_key = mock.MagicMock(name='mock_execute')
        self.encryptor._get_key.return_value = \
            test_cryptsetup.fake__get_key(None, fake_key)

        mock_execute.side_effect = [
                processutils.ProcessExecutionError(exit_code=2),  # luksOpen
                mock.DEFAULT,  # luksOpen
                mock.DEFAULT,  # luksClose
                mock.DEFAULT,  # luksAddKey
                mock.DEFAULT,  # luksOpen
                mock.DEFAULT,  # luksClose
                mock.DEFAULT,  # luksRemoveKey
                mock.DEFAULT,  # luksOpen
                mock.DEFAULT,  # ln
        ]

        self.encryptor.attach_volume(None)

        mock_execute.assert_has_calls([
            mock.call('cryptsetup', 'luksOpen', '--key-file=-', self.dev_path,
                      self.dev_name, process_input=fake_key,
                      run_as_root=True, check_exit_code=True),
            mock.call('cryptsetup', 'luksOpen', '--key-file=-', self.dev_path,
                      self.dev_name, process_input=fake_key_mangled,
                      run_as_root=True, check_exit_code=True),
            mock.call('cryptsetup', 'luksClose', self.dev_name,
                      run_as_root=True, check_exit_code=True, attempts=3),
            mock.call('cryptsetup', 'luksAddKey', self.dev_path,
                      process_input=''.join([fake_key_mangled,
                                             '\n', fake_key,
                                             '\n', fake_key]),
                      run_as_root=True, check_exit_code=True),
            mock.call('cryptsetup', 'luksOpen', '--key-file=-', self.dev_path,
                      self.dev_name, process_input=fake_key,
                      run_as_root=True, check_exit_code=True),
            mock.call('cryptsetup', 'luksClose', self.dev_name,
                      run_as_root=True, check_exit_code=True, attempts=3),
            mock.call('cryptsetup', 'luksRemoveKey', self.dev_path,
                      process_input=fake_key_mangled, run_as_root=True,
                      check_exit_code=True),
            mock.call('cryptsetup', 'luksOpen', '--key-file=-', self.dev_path,
                      self.dev_name, process_input=fake_key,
                      run_as_root=True, check_exit_code=True),
            mock.call('ln', '--symbolic', '--force',
                      '/dev/mapper/%s' % self.dev_name, self.symlink_path,
                      run_as_root=True, check_exit_code=True),
        ], any_order=False)
        self.assertEqual(9, mock_execute.call_count)
Exemple #6
0
    def test_attach_volume(self, mock_execute):
        self.encryptor._get_key = mock.MagicMock()
        self.encryptor._get_key.return_value = \
                test_cryptsetup.fake__get_key(None)

        self.encryptor.attach_volume(None)

        mock_execute.assert_has_calls([
            mock.call('cryptsetup', 'luksOpen', '--key-file=-', self.dev_path,
                      self.dev_name, process_input='0' * 32,
                      run_as_root=True, check_exit_code=True),
            mock.call('ln', '--symbolic', '--force',
                      '/dev/mapper/%s' % self.dev_name, self.symlink_path,
                      run_as_root=True, check_exit_code=True),
        ])
        self.assertEqual(2, mock_execute.call_count)
Exemple #7
0
    def test_attach_volume_fail(self, mock_execute):
        self.encryptor._get_key = mock.MagicMock()
        self.encryptor._get_key.return_value = \
                test_cryptsetup.fake__get_key(None)

        mock_execute.side_effect = [
                processutils.ProcessExecutionError(exit_code=1),  # luksOpen
                mock.DEFAULT,  # isLuks
        ]

        self.assertRaises(processutils.ProcessExecutionError,
                          self.encryptor.attach_volume, None)

        mock_execute.assert_has_calls([
            mock.call('cryptsetup', 'luksOpen', '--key-file=-', self.dev_path,
                      self.dev_name, process_input='0' * 32,
                      run_as_root=True, check_exit_code=True),
            mock.call('cryptsetup', 'isLuks', '--verbose', self.dev_path,
                      run_as_root=True, check_exit_code=True),
        ], any_order=False)
        self.assertEqual(2, mock_execute.call_count)