Exemplo n.º 1
0
        public void GenerateNonce_DefaultTimeout()
        {
            // Setup

            // Execution
            var nonce = NonceUtil.GenerateNonce("noncesecret");

            // Assertion
            Assert.IsFalse(String.IsNullOrEmpty(nonce));
        }
Exemplo n.º 2
0
        public void GenerateNonce_SpecificTimeout()
        {
            // Setup

            // Execution
            var nonce = NonceUtil.GenerateNonce("noncesecret", 900); // Timeout of 15 minutes

            // Assertion
            Assert.IsFalse(String.IsNullOrEmpty(nonce));
        }
Exemplo n.º 3
0
        public void CheckNonce_InvalidNonceStructure_ReturnsFalse()
        {
            // Setup - None

            // Execution
            var result = NonceUtil.CheckNonce("secret", "invalid,nonce"); // Pass an invalid nonce with only two sections (separated by comma), instead of three.

            // Assertion
            Assert.IsFalse(result);
        }
Exemplo n.º 4
0
        public void GenerateSalt_Single()
        {
            // Setup - None

            // Execution
            var salt = NonceUtil.GenerateSalt();

            // Assertion
            Assert.IsFalse(String.IsNullOrEmpty(salt));
            Assert.AreEqual(15, salt.Length); // Salt length is defined as a const = 15
        }
Exemplo n.º 5
0
        public void CheckNonce_InvalidNonce_ReturnsFalse()
        {
            // Setup
            var nonceSecret  = "noncesecret";
            var invalidNonce = "LpGobA3qy85Wlw8,1437406095.94737,4sAX+QAjE1HAaLKkBW2bPjGqHhMCA6hedDxDm0bIs9E="; // Pass an invalid nonce - the supplied salt does not match the hashed salt.

            // Execution
            var result = NonceUtil.CheckNonce(nonceSecret, invalidNonce);

            // Assertion
            Assert.IsFalse(result);
        }
Exemplo n.º 6
0
        public void CheckNonce_ValidNonce()
        {
            // Setup
            var nonceSecret = "noncesecret";
            var nonce       = NonceUtil.GenerateNonce(nonceSecret);

            // Execution
            var result = NonceUtil.CheckNonce(nonceSecret, nonce);

            // Assertion
            Assert.IsTrue(result);
        }
Exemplo n.º 7
0
        public void CheckNonce_NonceExceedsTimeout_ReturnsFalse()
        {
            // Setup
            var nonceSecret = "noncesecret";
            var nonce       = NonceUtil.GenerateNonce(nonceSecret, 1);

            Thread.Sleep(2000); // Introduce an artifical delay to ensure we go over the nonce expiry date/time.

            // Execution
            var result = NonceUtil.CheckNonce(nonceSecret, nonce);

            // Assertion
            Assert.IsFalse(result);
        }
Exemplo n.º 8
0
        public void GenerateSalt_Multiple()
        {
            // Setup
            var saltCount = 100;
            var saltList  = new List <string>();

            // Execution
            for (int i = 0; i < saltCount; i++)
            {
                var salt = NonceUtil.GenerateSalt();

                if (!saltList.Contains(salt))
                {
                    saltList.Add(salt);
                }
            }

            // Assertion
            Assert.AreEqual(saltCount, saltList.Count);
        }
Exemplo n.º 9
0
 public void GenerateNonce_SecretLessThanTenChars_ThrowsException()
 {
     NonceUtil.GenerateNonce("secret"); // Secret less than 10 chars
 }
Exemplo n.º 10
0
 public void GenerateNonce_EmptySecret_ThrowsException()
 {
     NonceUtil.GenerateNonce(String.Empty);
 }
Exemplo n.º 11
0
 public void GenerateNonce_SpecificTimeout_GreaterThanZero_ThrowsException()
 {
     NonceUtil.GenerateNonce("noncesecret", 0);
 }
Exemplo n.º 12
0
 public void CheckNonce_EmptySecretAndNonce_ThrowsException()
 {
     NonceUtil.CheckNonce(String.Empty, String.Empty);
 }
Exemplo n.º 13
0
 public void CheckNonce_EmptyNonce_ThrowsException()
 {
     NonceUtil.CheckNonce("secret", String.Empty);
 }
Exemplo n.º 14
0
 public void CheckNonce_EmptySecret_ThrowsException()
 {
     NonceUtil.CheckNonce(String.Empty, "nonce");
 }