예제 #1
0
        public void CreateToken_BadExpiry()
        {
            var c = new AntiCSRFConfig {
                expiryInSeconds = -1
            };

            Assert.ThrowsException <ArgumentOutOfRangeException>(() => {
                AntiCSRFToken.GenerateToken(username, key, c);
            });
        }
예제 #2
0
        public void CreateToken_BadDataSize()
        {
            var c = new AntiCSRFConfig {
                dataSize = -1
            };

            Assert.ThrowsException <ArgumentOutOfRangeException>(() => {
                AntiCSRFToken.GenerateToken(username, key, c);
            });
        }
예제 #3
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.");
        }
예제 #4
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.");
        }
예제 #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.");
        }