def test_basic_functionality(self): kwargs = {'value': self.value, 'secret': self.secret} modern = flask_unsign.sign(**kwargs) legacy = flask_unsign.sign(**kwargs, legacy=True) self.assertNotEqual(modern, legacy) self.assertTrue(flask_unsign.verify(modern, self.secret)) self.assertTrue(flask_unsign.verify(legacy, self.secret, legacy=True)) self.assertFalse(flask_unsign.verify(modern, self.secret + 'x')) self.assertFalse( flask_unsign.verify(legacy, self.secret + 'x', legacy=True)) self.assertEqual(self.value, flask_unsign.decode(modern)) self.assertEqual(self.value, flask_unsign.decode(legacy)) with self.assertRaises(flask_unsign.DecodeError): flask_unsign.decode('Hello world!') with self.assertRaises(flask_unsign.DecodeError): flask_unsign.decode('') with wordlist(flask_unsign.DEFAULT_WORDLIST) as iterable: cracker = flask_unsign.Cracker(value=modern) cracker.crack(iterable) self.assertEqual(cracker.secret, self.secret) with wordlist(flask_unsign.DEFAULT_WORDLIST) as iterable: cracker = flask_unsign.Cracker(value=legacy, legacy=True) cracker.crack(iterable) self.assertEqual(cracker.secret, self.secret)
def test_sign(self): stdout, stderr = self.call('--sign', '--cookie', str(self.decoded), '--secret', self.secret) self.assertTrue( flask_unsign.verify(stdout.read().strip(), secret=self.secret)) stdout, stderr = self.call('--sign', '--cookie', str(self.decoded), '--secret', self.secret, '--output', self.output_file) self.assertEqual( stdout.read().strip(), '', ) with open(self.output_file) as out: self.assertTrue( flask_unsign.verify(out.read().strip(), secret=self.secret)) stdout, stderr = self.call('--sign', '--cookie', str(self.decoded), '--secret', '12345') self.assertNotEqual( stderr.read(), '', msg=('Expected an error when a non-string type is passed to sign')) stdout, stderr = self.call('--sign', '--cookie', str(self.decoded)) self.assertIn('--secret', stderr.read()) stdout, stderr = self.call('--sign', '--secret', self.secret) self.assertIn('--cookie', stderr.read())
def test_sign(self): stdout, stderr = self.call('--sign', '--cookie', str(self.decoded), '--secret', self.secret) self.assertTrue( flask_unsign.verify(stdout.read().strip(), secret=self.secret)) stdout, stderr = self.call('--sign', '--cookie', str(self.decoded)) self.assertIn('--secret', stderr.read()) stdout, stderr = self.call('--sign', '--secret', self.secret) self.assertIn('--cookie', stderr.read())
def test_verify(self): with self.assertRaises(FlaskUnsignException): flask_unsign.verify(value='', secret=[], legacy=False)