Adds a warning if a user exports with mail accounts but no passphrase
This commit is contained in:
parent
3c22c4ea87
commit
89911453ad
@ -556,3 +556,11 @@ class Command(CryptMixin, BaseCommand):
|
|||||||
mail_account_record["fields"]["password"] = self.encrypt_string(
|
mail_account_record["fields"]["password"] = self.encrypt_string(
|
||||||
value=mail_account_record["fields"]["password"],
|
value=mail_account_record["fields"]["password"],
|
||||||
)
|
)
|
||||||
|
elif MailAccount.objects.count() > 0:
|
||||||
|
self.stdout.write(
|
||||||
|
self.style.NOTICE(
|
||||||
|
"You have configured mail accounts, "
|
||||||
|
"but have no passphrase was given. "
|
||||||
|
"Passwords will be in plaintext",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
@ -3,6 +3,7 @@ import json
|
|||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import tempfile
|
import tempfile
|
||||||
|
from io import StringIO
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
from zipfile import ZipFile
|
from zipfile import ZipFile
|
||||||
@ -857,6 +858,15 @@ class TestCryptExportImport(
|
|||||||
return super().tearDown()
|
return super().tearDown()
|
||||||
|
|
||||||
def test_export_passphrase(self):
|
def test_export_passphrase(self):
|
||||||
|
"""
|
||||||
|
GIVEN:
|
||||||
|
- A mail account exists
|
||||||
|
WHEN:
|
||||||
|
- Export command is called
|
||||||
|
- Passphrase is provided
|
||||||
|
THEN:
|
||||||
|
- Output password is not plaintext
|
||||||
|
"""
|
||||||
MailAccount.objects.create(
|
MailAccount.objects.create(
|
||||||
name="Test Account",
|
name="Test Account",
|
||||||
imap_server="test.imap.com",
|
imap_server="test.imap.com",
|
||||||
@ -903,6 +913,17 @@ class TestCryptExportImport(
|
|||||||
self.assertEqual(account.password, "mypassword")
|
self.assertEqual(account.password, "mypassword")
|
||||||
|
|
||||||
def test_import_crypt_no_passphrase(self):
|
def test_import_crypt_no_passphrase(self):
|
||||||
|
"""
|
||||||
|
GIVEN:
|
||||||
|
- A mail account exists
|
||||||
|
WHEN:
|
||||||
|
- Export command is called
|
||||||
|
- Passphrase is provided
|
||||||
|
- Import command is called
|
||||||
|
- No passphrase is given
|
||||||
|
THEN:
|
||||||
|
- An error is raised for the issue
|
||||||
|
"""
|
||||||
call_command(
|
call_command(
|
||||||
"document_exporter",
|
"document_exporter",
|
||||||
"--no-progress-bar",
|
"--no-progress-bar",
|
||||||
@ -921,3 +942,39 @@ class TestCryptExportImport(
|
|||||||
err.msg,
|
err.msg,
|
||||||
"No passphrase was given, but this export contains encrypted fields",
|
"No passphrase was given, but this export contains encrypted fields",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_export_warn_plaintext(self):
|
||||||
|
"""
|
||||||
|
GIVEN:
|
||||||
|
- A mail account exists
|
||||||
|
WHEN:
|
||||||
|
- Export command is called
|
||||||
|
- No passphrase is provided
|
||||||
|
THEN:
|
||||||
|
- Output password is plaintext
|
||||||
|
- Warning is output
|
||||||
|
"""
|
||||||
|
MailAccount.objects.create(
|
||||||
|
name="Test Account",
|
||||||
|
imap_server="test.imap.com",
|
||||||
|
username="myusername",
|
||||||
|
password="mypassword",
|
||||||
|
)
|
||||||
|
|
||||||
|
stdout = StringIO()
|
||||||
|
|
||||||
|
call_command(
|
||||||
|
"document_exporter",
|
||||||
|
"--no-progress-bar",
|
||||||
|
str(self.target),
|
||||||
|
stdout=stdout,
|
||||||
|
)
|
||||||
|
stdout.seek(0)
|
||||||
|
self.assertIn(
|
||||||
|
(
|
||||||
|
"You have configured mail accounts, "
|
||||||
|
"but have no passphrase was given. "
|
||||||
|
"Passwords will be in plaintext"
|
||||||
|
),
|
||||||
|
stdout.read(),
|
||||||
|
)
|
||||||
|
@ -241,7 +241,7 @@ class TestCommandImport(
|
|||||||
stdout.seek(0)
|
stdout.seek(0)
|
||||||
self.assertIn(
|
self.assertIn(
|
||||||
"Found existing user(s), this might indicate a non-empty installation",
|
"Found existing user(s), this might indicate a non-empty installation",
|
||||||
str(stdout.read()),
|
stdout.read(),
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_import_with_documents_exists(self):
|
def test_import_with_documents_exists(self):
|
||||||
@ -281,6 +281,14 @@ class TestCommandImport(
|
|||||||
)
|
)
|
||||||
|
|
||||||
def test_import_no_metadata_or_version_file(self):
|
def test_import_no_metadata_or_version_file(self):
|
||||||
|
"""
|
||||||
|
GIVEN:
|
||||||
|
- A source directory with a manifest file only
|
||||||
|
WHEN:
|
||||||
|
- An import is attempted
|
||||||
|
THEN:
|
||||||
|
- Warning about the missing files is output
|
||||||
|
"""
|
||||||
stdout = StringIO()
|
stdout = StringIO()
|
||||||
|
|
||||||
(self.dirs.scratch_dir / "manifest.json").touch()
|
(self.dirs.scratch_dir / "manifest.json").touch()
|
||||||
@ -299,6 +307,14 @@ class TestCommandImport(
|
|||||||
self.assertIn("No version.json or metadata.json file located", stdout_str)
|
self.assertIn("No version.json or metadata.json file located", stdout_str)
|
||||||
|
|
||||||
def test_import_version_file(self):
|
def test_import_version_file(self):
|
||||||
|
"""
|
||||||
|
GIVEN:
|
||||||
|
- A source directory with a manifest file and version file
|
||||||
|
WHEN:
|
||||||
|
- An import is attempted
|
||||||
|
THEN:
|
||||||
|
- Warning about the the version mismatch is output
|
||||||
|
"""
|
||||||
stdout = StringIO()
|
stdout = StringIO()
|
||||||
|
|
||||||
(self.dirs.scratch_dir / "manifest.json").touch()
|
(self.dirs.scratch_dir / "manifest.json").touch()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user