Пример #1
0
    def request_token(self, uid):
        pw_user = pwd.getpwuid(uid)
        if pw_user == None:
            self.write_error("User not found")
            return

        polo_dir = os.path.join(pw_user.pw_dir, ".polo")

        if not os.path.exists(polo_dir):
            os.mkdir(polo_dir)
            os.chown(polo_dir, pw_user.pw_uid, pw_user.pw_gid)

        if not os.path.isfile(os.path.join(polo_dir, "token")):
            try:
                f = open(os.path.join(polo_dir, "token"), "wb")
                os.fchmod(f.fileno(), stat.S_IRUSR | stat.S_IWUSR | stat.S_IRUSR)
                os.fchown(f.fileno(), pw_user.pw_uid, pw_user.pw_gid)
                f.write(tokenprovider.create_token(uid, self.secret))
                f.close()
            except Exception as e:
                self.write_error(str(e))
                return
            self.write_ok(0)
        else:
            self.write_ok(1)
Пример #2
0
	def test_decrypt_token(self):
		secret = tokenprovider.generate_secret(32)
		value = 12323
		token = tokenprovider.create_token(value, secret)
		self.assertEqual(value, tokenprovider.decrypt_token(token, secret))
		
Пример #3
0
	def test_create_token(self):
		secret = tokenprovider.generate_secret(32)
		self.assertIsInstance(tokenprovider.create_token(1, secret), str)