public void CreateToken_BadExpiry() { var c = new AntiCSRFConfig { expiryInSeconds = -1 }; Assert.ThrowsException <ArgumentOutOfRangeException>(() => { AntiCSRFToken.GenerateToken(username, key, c); }); }
public void CreateToken_BadDataSize() { var c = new AntiCSRFConfig { dataSize = -1 }; Assert.ThrowsException <ArgumentOutOfRangeException>(() => { AntiCSRFToken.GenerateToken(username, key, c); }); }
public void CreateAndVerifyToken_NoBase64() { var c = new AntiCSRFConfig { useBase64 = false }; var token = AntiCSRFToken.GenerateToken(username, key, c); Assert.IsNotNull(token, "Token should not be empty or null."); var isValid = AntiCSRFToken.ValidateToken(token, key, username, c); Assert.IsTrue(isValid, "isValid should be true."); }
public void CreateAndVerifyToken_HMACSHA512() { var c = new AntiCSRFConfig { hmac_alg = "SHA512" }; var token = AntiCSRFToken.GenerateToken(username, key, c); Assert.IsNotNull(token, "Token should not be empty or null."); var isValid = AntiCSRFToken.ValidateToken(token, key, username, c); Assert.IsTrue(isValid, "isValid should be true."); }
public void CreateAndExpireToken() { var c = new AntiCSRFConfig { expiryInSeconds = 1 }; var token = AntiCSRFToken.GenerateToken(username, key, c); Assert.IsNotNull(token, "Token should not be empty or null."); Thread.Sleep(1001); var isValid = AntiCSRFToken.ValidateToken(token, key, username, c); Assert.IsFalse(isValid, "isValid should be false."); }