def testReadPasswordFile(self): passwdHash = poorHash('passwordsalt') data = dict(users={'John': { 'salt': 'salt', 'password': passwdHash }}, version=PasswordFile.version) jsonSave(data, open(self.filename, 'w')) pf = PasswordFile(filename=self.filename, hashMethod=poorHash) self.assertTrue(pf.validateUser('John', 'password'))
def save(self): if not isdir(self.directory): makedirs(self.directory) configFile = join(self.directory, CONFIG_FILENAME) tmpFile = '%s.tmp' % configFile jsonSave({ 'name': self.name, 'baseUrl': self.baseUrl, 'metadataPrefix': self.metadataPrefix, 'setSpec': self.setSpec, 'active': self.active, 'apiKey': self.apiKey, }, open(tmpFile, 'w')) rename(tmpFile, configFile) stateFile = join(self.directory, STATE_FILENAME) tmpFile = '%s.tmp' % stateFile jsonSave({ 'resumptionToken': self.resumptionToken, 'lastHarvest': self.lastHarvest }, open(tmpFile, 'w')) rename(tmpFile, stateFile)
def testReadPasswordFile(self): passwdHash = poorHash('password') userlist = {'John':passwdHash} jsonSave(userlist, open(self.filename, 'w')) pf = PasswordFile(filename=self.filename, hashPassword=poorHash) self.assertTrue(pf.validateUser('John', 'password'))