Пример #1
0
    def test_access_wallet_with_bad_data_dir(self):
        '''
            Test accessing the wallet with a bad data directory.
        '''
        prefs = get_preferences()
        prefs.data_dir = '/bad/bitcoin/data/'
        prefs.bin_dir = '/tmp/bitcoin/bin/'
        prefs.backup_dir = '/tmp/bitcoin/data/backups/'
        save_preferences(prefs)

        request = self.factory.get('/bitcoin/access_wallet/')
        response = AccessWallet.as_view()(request)
        self.assertEqual(response.status_code, 200)
        self.assertTrue(
            b"<title>\nAccessing Bitcoin Core Wallet | Blockchain Backup\n</title>"
            in response.content)
        self.assertFalse(
            b'The Bitcoin binary directory is not valid.' in response.content)
        self.assertTrue(
            b'The Bitcoin data directory is not valid.' in response.content)
        self.assertFalse(
            b'The Bitcoin backup directory is not valid.' in response.content)
        self.assertTrue(
            b'Click <a class="btn btn-secondary" role="button" href="/bitcoin/preferences/" title="Click to change your preferences">Preferences</a> to set it.'
            in response.content)
Пример #2
0
    def test_update_with_bad_bin_dir(self):
        '''
            Test updating with a bad bin directory.
        '''
        prefs = get_preferences()
        prefs.data_dir = '/tmp/bitcoin/data/'
        prefs.bin_dir = '/bad/bitcoin/bin/'
        prefs.backup_dir = '/tmp/bitcoin/data/backups/'
        save_preferences(prefs)

        request = self.factory.get('/bitcoin/update/')
        response = Update.as_view()(request)
        self.assertEqual(response.status_code, 200)
        self.assertTrue(
            b"<title>\nUpdating Bitcoin's Blockchain | Blockchain Backup\n</title>"
            in response.content)
        self.assertTrue(
            b'The Bitcoin binary directory is not valid.' in response.content)
        self.assertFalse(
            b'The Bitcoin data directory is not valid.' in response.content)
        self.assertFalse(
            b'The Bitcoin backup directory is not valid.' in response.content)
        self.assertTrue(
            b'Click <a class="btn btn-secondary" role="button" href="/bitcoin/preferences/" title="Click to change your preferences">Preferences</a> to set it.'
            in response.content)

        self.assertTrue(get_backups_enabled())
Пример #3
0
    def test_restore_with_bad_backup(self):
        '''
            Test restore from a bad back up.
        '''
        MINUTE = 60
        MAX_SECONDS = 2 * MINUTE

        # change the data and backup dirs
        prefs = test_utils.get_preferences()
        prefs.data_dir = '/tmp/bitcoin/data-with-missing-file/testnet3/'
        prefs.backup_dir = '/tmp/bitcoin/data-with-missing-file/testnet3/backups/'
        preferences.save_preferences(prefs)

        __, preselected_date_dir = state.get_backup_dates_and_dirs()

        request = self.factory.get('/bitcoin/restore/')
        response = views.Restore.as_view()(request)
        self.assertEqual(response.status_code, 200)
        self.assertTrue(b"<title>\nAre you sure you want to restore the Bitcoin blockchain? | Blockchain Backup\n</title>" in response.content)
        self.assertTrue(b'Select backup to restore:' in response.content)
        self.assertTrue(b'<input type="submit" value="Yes, start restoring" name="yes-start-restoring-button" id="yes-start-restoring-id" alt="Yes, start restoring" class="btn btn-primary font-weight-bold " role="button"  title="Restore the blockchain now"/>' in response.content)
        self.assertTrue(b'<input type="submit" value="No, cancel restore" name="no-cancel-restore-button" id="no-cancel-restore-id" alt="No, cancel restore" class="btn btn-secondary font-weight-bold " role="button"  title="Do not restore the blockchain."/>' in response.content)

        client = Client()
        response = client.post('/bitcoin/restore/',
                               {'backup_dates_with_dirs': preselected_date_dir[0] })
        self.assertEqual(response.status_code, 200)
        self.assertTrue(b"<title>\nRestoring Bitcoin Blockchain | Blockchain Backup\n</title>" in response.content)
        self.assertTrue(b'WARNING: Do not shut down your computer until the restore finishes.' in response.content)
        self.assertTrue(b'Starting to restore the blockchain' in response.content)
        self.assertFalse(b'<input type="submit" value="Yes, start restoring" name="yes-start-restoring-button" id="yes-start-restoring-id" alt="Yes, start restoring" class="btn btn-primary font-weight-bold " role="button"  title="Restore the blockchain now"/>' in response.content)

        # wait until the restore finishes
        seconds = 0
        while not is_restore_running() and seconds < MAX_SECONDS:
            sleep(MINUTE)
            seconds += MINUTE

        self.assertFalse(is_bitcoind_running())
        self.assertFalse(state.get_backups_enabled())

        name = 'last-updated-2020-01-17 14:41'
        last_updated_file = os.path.join(prefs.backup_dir, 'level1', name)
        self.assertFalse(os.path.exists(last_updated_file))
Пример #4
0
    def test_restore_with_bad_data_dir(self):
        '''
            Test restoring with a bad data directory.
        '''
        prefs = preferences.get_preferences()
        prefs.data_dir = '/bad/bitcoin/data/'
        prefs.bin_dir = '/tmp/bitcoin/bin/'
        prefs.restore_dir = '/tmp/bitcoin/data/restores/'
        preferences.save_preferences(prefs)

        request = self.factory.get('/bitcoin/restore/')
        response = views.Restore.as_view()(request)

        self.assertEqual(response.status_code, 200)
        self.assertTrue(b"<title>\nUnable to Restore the Blockchain | Blockchain Backup\n</title>" in response.content)
        self.assertTrue(b"Unable to Restore the Blockchain" in response.content)
        self.assertTrue(b'The Bitcoin data directory is not valid. Click <a class="btn btn-secondary" role="button" href="/bitcoin/preferences/" title="Click to change your preferences">Preferences</a> to set it.' in response.content)
        self.assertFalse(b'Select backup to restore:' in response.content)
        self.assertFalse(b'<input type="submit" value="Yes, start restoring" name="yes-start-restoring-button" id="yes-start-restoring-id" alt="Yes, start restoring" class="btn btn-primary font-weight-bold " role="button"  title="Restore the blockchain now"/>' in response.content)
Пример #5
0
def set_new_preferences(new_preferences):
    '''
        Set the preferences.

        >>> set_new_preferences(None)
    '''
    if new_preferences is None:
        while True:
            try:
                prefs = preferences.get_preferences()
                prefs.delete()
            except:
                break
    else:
        prefs = get_preferences()
        prefs.data_dir = new_preferences.data_dir
        prefs.bin_dir = new_preferences.bin_dir
        prefs.backup_schedule = new_preferences.backup_schedule
        prefs.backup_levels = new_preferences.backup_levels
        prefs.backup_dir = new_preferences.backup_dir
        prefs.extra_args = new_preferences.extra_args
        preferences.save_preferences(prefs)
Пример #6
0
    def post_page(self, request):

        form = PreferencesForm(request.POST)
        if form.is_valid():

            data_dir = form.cleaned_data['data_dir']
            bin_dir = form.cleaned_data['bin_dir']
            backup_schedule = form.cleaned_data['backup_schedule']
            backup_levels = form.cleaned_data['backup_levels']
            backup_dir = form.cleaned_data['backup_dir']
            extra_args = form.cleaned_data['extra_args']

            prefs = preferences.get_preferences()
            prefs.data_dir = data_dir
            prefs.bin_dir = bin_dir
            prefs.backup_schedule = backup_schedule
            prefs.backup_levels = backup_levels
            prefs.backup_dir = backup_dir
            prefs.extra_args = extra_args
            preferences.save_preferences(prefs)
            log('Changed preferences.')
            messages.success(request, 'Changed preferences.')

            # send them back to the home page
            response = HttpResponseRedirect('/')

        else:
            log('form is not valid')
            log_bad_fields(form)
            messages.error(
                request,
                'Invalid preferences -- details about the errors appear below the fields.'
            )
            response = render(request, self.form_url, {
                'form': form,
            })

        return response