1 # Copyright (C) 2012-2014 by the Free Software Foundation, Inc.
3 # This file is part of GNU Mailman.
5 # GNU Mailman is free software: you can redistribute it and/or modify it under
6 # the terms of the GNU General Public License as published by the Free
7 # Software Foundation, either version 3 of the License, or (at your option)
10 # GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 # You should have received a copy of the GNU General Public License along with
16 # GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
18 """Testing the password utility."""
20 from __future__
import absolute_import
, print_function
, unicode_literals
31 from mailman
.config
import config
32 from mailman
.testing
.helpers
import configuration
33 from mailman
.testing
.layers
import ConfigLayer
37 class TestPasswords(unittest
.TestCase
):
40 def test_default_passlib(self
):
41 # By default, testing uses the roundup_plaintext hash algorithm, which
42 # is just plaintext with a prefix.
43 self
.assertEqual(config
.password_context
.encrypt('my password'),
44 '{plaintext}my password')
46 def test_passlib_from_file_path(self
):
47 # Set up this test to use a passlib configuration file specified with
48 # a file system path. We prove we're using the new configuration
49 # because a non-prefixed, i.e. non-roundup, plaintext hash algorithm
50 # will be used. When a file system path is used, the file can end in
52 config_file
= os
.path
.join(config
.VAR_DIR
, 'passlib.config')
53 with
open(config_file
, 'w') as fp
:
58 with
configuration('passwords', configuration
=config_file
):
59 self
.assertEqual(config
.password_context
.encrypt('my password'),