示例#1
0
        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.");
        }
示例#2
0
        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.");
        }
示例#3
0
        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.");
        }
示例#4
0
        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.");
        }
示例#5
0
        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.");
        }