Fix: correct serializing of auth tokens for export
This commit is contained in:
parent
3af3484a00
commit
c5fddf8abe
@ -271,7 +271,6 @@ class Command(CryptMixin, BaseCommand):
|
|||||||
"social_accounts": SocialAccount.objects.all(),
|
"social_accounts": SocialAccount.objects.all(),
|
||||||
"social_apps": SocialApp.objects.all(),
|
"social_apps": SocialApp.objects.all(),
|
||||||
"social_tokens": SocialToken.objects.all(),
|
"social_tokens": SocialToken.objects.all(),
|
||||||
"auth_tokens": Token.objects.all(),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if settings.AUDIT_LOG_ENABLED:
|
if settings.AUDIT_LOG_ENABLED:
|
||||||
@ -286,6 +285,20 @@ class Command(CryptMixin, BaseCommand):
|
|||||||
serializers.serialize("json", manifest_key_to_object_query[key]),
|
serializers.serialize("json", manifest_key_to_object_query[key]),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Add the auth tokens to the manifest, serialized manually
|
||||||
|
manifest_dict["auth_tokens"] = [
|
||||||
|
{
|
||||||
|
"model": "authtoken.token",
|
||||||
|
"pk": t.pk,
|
||||||
|
"fields": {
|
||||||
|
"key": t.key,
|
||||||
|
"user": t.user_id,
|
||||||
|
"created": t.created.isoformat(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for t in Token.objects.all()
|
||||||
|
]
|
||||||
|
|
||||||
self.encrypt_secret_fields(manifest_dict)
|
self.encrypt_secret_fields(manifest_dict)
|
||||||
|
|
||||||
# These are treated specially and included in the per-document manifest
|
# These are treated specially and included in the per-document manifest
|
||||||
|
@ -20,6 +20,7 @@ from django.utils import timezone
|
|||||||
from guardian.models import GroupObjectPermission
|
from guardian.models import GroupObjectPermission
|
||||||
from guardian.models import UserObjectPermission
|
from guardian.models import UserObjectPermission
|
||||||
from guardian.shortcuts import assign_perm
|
from guardian.shortcuts import assign_perm
|
||||||
|
from rest_framework.authtoken.models import Token
|
||||||
|
|
||||||
from documents.management.commands import document_exporter
|
from documents.management.commands import document_exporter
|
||||||
from documents.models import Correspondent
|
from documents.models import Correspondent
|
||||||
@ -874,6 +875,8 @@ class TestCryptExportImport(
|
|||||||
password="mypassword",
|
password="mypassword",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Token.objects.create(user=User.objects.first())
|
||||||
|
|
||||||
call_command(
|
call_command(
|
||||||
"document_exporter",
|
"document_exporter",
|
||||||
"--no-progress-bar",
|
"--no-progress-bar",
|
||||||
@ -912,6 +915,10 @@ class TestCryptExportImport(
|
|||||||
self.assertIsNotNone(account)
|
self.assertIsNotNone(account)
|
||||||
self.assertEqual(account.password, "mypassword")
|
self.assertEqual(account.password, "mypassword")
|
||||||
|
|
||||||
|
token = Token.objects.first()
|
||||||
|
|
||||||
|
self.assertIsNotNone(token)
|
||||||
|
|
||||||
def test_import_crypt_no_passphrase(self):
|
def test_import_crypt_no_passphrase(self):
|
||||||
"""
|
"""
|
||||||
GIVEN:
|
GIVEN:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user