~certify-web-dev/twisted/certify-staging

« back to all changes in this revision

Viewing changes to twisted/test/test_strcred.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2010-01-02 19:38:17 UTC
  • mfrom: (2.2.4 sid)
  • Revision ID: james.westby@ubuntu.com-20100102193817-jphp464ppwh7dulg
Tags: 9.0.0-1
* python-twisted: Depend on the python-twisted-* 9.0 packages.
* python-twisted: Depend on python-zope.interface only. Closes: #557781.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (c) 2007-2008 Twisted Matrix Laboratories.
 
1
# Copyright (c) 2007-2009 Twisted Matrix Laboratories.
2
2
# See LICENSE for details.
3
3
 
4
4
"""
5
 
Tests for L{strcred}.
 
5
Tests for L{twisted.cred.strcred}.
6
6
"""
7
7
 
8
8
import os
14
14
from twisted.plugins import cred_file, cred_anonymous
15
15
from twisted.python import usage
16
16
from twisted.python.filepath import FilePath
 
17
from twisted.python.fakepwd import UserDatabase
17
18
 
18
19
try:
19
20
    import crypt
174
175
        }
175
176
 
176
177
 
177
 
    def _pwd(self, username):
178
 
        return (username, crypt.crypt(self.users[username], 'F/'),
179
 
                1000, 1000, username, '/home/'+username, '/bin/sh')
180
 
 
181
 
 
182
178
    def _spwd(self, username):
183
179
        return (username, crypt.crypt(self.users[username], 'F/'),
184
180
                0, 0, 99999, 7, -1, -1, -1)
190
186
        self.badPass = credentials.UsernamePassword('alice', 'foobar')
191
187
        self.badUser = credentials.UsernamePassword('x', 'yz')
192
188
        self.checker = strcred.makeChecker('unix')
 
189
 
193
190
        # Hack around the pwd and spwd modules, since we can't really
194
191
        # go about reading your /etc/passwd or /etc/shadow files
195
192
        if pwd:
196
 
            self._pwd_getpwnam = pwd.getpwnam
197
 
            pwd.getpwnam = self._pwd
 
193
            database = UserDatabase()
 
194
            for username, password in self.users.items():
 
195
                database.addUser(
 
196
                    username, crypt.crypt(password, 'F/'),
 
197
                    1000, 1000, username, '/home/' + username, '/bin/sh')
 
198
            self.patch(pwd, 'getpwnam', database.getpwnam)
198
199
        if spwd:
199
200
            self._spwd_getspnam = spwd.getspnam
200
201
            spwd.getspnam = self._spwd
201
202
 
202
203
 
203
204
    def tearDown(self):
204
 
        if pwd:
205
 
            pwd.getpwnam = self._pwd_getpwnam
206
205
        if spwd:
207
206
            spwd.getspnam = self._spwd_getspnam
208
207