예제 #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 CreateToken_BadExpiry()
        {
            var c = new AntiCSRFConfig {
                expiryInSeconds = -1
            };

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

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