public void CreateAndVerifyUnicode() { var token = AntiCSRFToken.GenerateToken(unicode_username, unicode_key); Assert.IsNotNull(token, "Token should not be empty or null."); var isValid = AntiCSRFToken.ValidateToken(token, unicode_key, unicode_username); Assert.IsTrue(isValid, "isValid should be true."); }
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 CreateTokenAndChangeUser() { var token = AntiCSRFToken.GenerateToken(username, key); Assert.IsNotNull(token, "Token should not be empty or null."); var arr = username.ToCharArray(); Array.Reverse(arr); var emanresu = new string(arr); var isValid = AntiCSRFToken.ValidateToken(token, key, emanresu); Assert.IsFalse(isValid, "isValid should be false."); }
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."); }