mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-25 15:52:35 -04:00 
			
		
		
		
	Add check for changed password
These tests are incomplete, but I have no idea how to write the other half.
This commit is contained in:
		
							parent
							
								
									c0ad6cd58a
								
							
						
					
					
						commit
						f72fa43e86
					
				| @ -0,0 +1 @@ | ||||
| from .checks import changed_password_check | ||||
							
								
								
									
										26
									
								
								src/documents/checks.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								src/documents/checks.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,26 @@ | ||||
| from django.core.checks import Warning, register | ||||
| 
 | ||||
| 
 | ||||
| @register() | ||||
| def changed_password_check(app_configs, **kwargs): | ||||
| 
 | ||||
|     from documents.models import Document | ||||
|     from paperless.db import GnuPG | ||||
| 
 | ||||
|     warning = ( | ||||
|         "At least one document:\n\n  {}\n\nin your data store was encrypted " | ||||
|         "with a password other than the one currently\nin use.  This means " | ||||
|         "that this file, and others encrypted with the other\npassword are no " | ||||
|         "longer acessible, which is probably not what you want.  If\nyou " | ||||
|         "intend to change your Paperless password, you must first export all " | ||||
|         "of\nthe old documents, start fresh with the new password and then " | ||||
|         "re-import them." | ||||
|     ) | ||||
| 
 | ||||
|     document = Document.objects.order_by("-pk").filter( | ||||
|         storage_type=Document.STORAGE_TYPE_GPG | ||||
|     ).first() | ||||
| 
 | ||||
|     if document and not GnuPG.decrypted(document.source_file): | ||||
|         return [Warning(warning.format(document))] | ||||
|     return [] | ||||
							
								
								
									
										25
									
								
								src/documents/tests/test_checks.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								src/documents/tests/test_checks.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,25 @@ | ||||
| import unittest | ||||
| 
 | ||||
| from django.test import TestCase | ||||
| 
 | ||||
| from ..checks import changed_password_check | ||||
| from ..models import Document | ||||
| from .factories import DocumentFactory | ||||
| 
 | ||||
| 
 | ||||
| class ChecksTestCase(TestCase): | ||||
| 
 | ||||
|     def test_changed_password_check_empty_db(self): | ||||
|         self.assertEqual(changed_password_check(None), []) | ||||
| 
 | ||||
|     def test_changed_password_check_no_encryption(self): | ||||
|         DocumentFactory.create(storage_type=Document.STORAGE_TYPE_UNENCRYPTED) | ||||
|         self.assertEqual(changed_password_check(None), []) | ||||
| 
 | ||||
|     @unittest.skip("I don't know how to test this") | ||||
|     def test_changed_password_check_gpg_encryption_with_good_password(self): | ||||
|         pass | ||||
| 
 | ||||
|     @unittest.skip("I don't know how to test this") | ||||
|     def test_changed_password_check_fail(self): | ||||
|         pass | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user