def testRotatingSecrets (self): sigmund = Sigmund() testData = {"blah": 'test'} sigmund.secret = ['a', 'b', 'c', 'd'] token = sigmund.generate(testData) self.assertTrue( sigmund.validate(token, testData), 'can validate a token against multiple secrets' )
def testValidatetokenFromGeneratedSecrets (self): self.__create_test_secrets_path() generatedSecrets = generate_secrets_to_file(self.tmpFile) sigmund = Sigmund() sigmund.secret = load_secrets_from_file(self.tmpFile); testData = {"hello": "world"} token = sigmund.generate(testData) self.assertTrue( sigmund.validate(token, testData), "Can validate a token with secrets loaded from file" ) self.__remove_test_secrets_path()
def testSimpleSecret (self): sigmund_no_secret = Sigmund() sigmund_secret = Sigmund() sigmund_secret.secret = "blahblah" testData = {"blah": 1234} token = sigmund_no_secret.generate(testData) token_secret = sigmund_secret.generate(testData) self.assertFalse( sigmund_no_secret.validate(token_secret, testData), 'cannot validate a token with a secret unless secret is provided' ) self.assertFalse( sigmund_secret.validate(token, testData), 'cannot validate a secretless token against an instance with secret provided' ) self.assertTrue( sigmund_secret.validate(token_secret, testData), 'can validate a token with a secret' )