private void FactoryCreateFor(string testcase, SecurityKey key, string algorithm, SignatureProviderFactory factory, ExpectedException exceptionExpected)
        {
            Console.WriteLine(string.Format("Testcase: '{0}'", testcase));

            try
            {
                if (testcase.StartsWith("Siging"))
                {
                    factory.CreateForSigning(key, algorithm);
                }
                else
                {
                    factory.CreateForVerifying(key, algorithm);
                }

                Assert.IsFalse(exceptionExpected.Thrown != null, string.Format("Expected exception: '{0}'", exceptionExpected.Thrown));
            }
            catch (Exception ex)
            {
                ExpectedException.ProcessException(exceptionExpected, ex);
            }
        }
Exemple #2
0
        private void FactoryCreateFor(string testcase, SecurityKey key, string algorithm, SignatureProviderFactory factory, ExpectedException expectedException)
        {
            Console.WriteLine(string.Format("Testcase: '{0}'", testcase));

            try
            {
                if (testcase.StartsWith("Siging"))
                {
                    factory.CreateForSigning(key, algorithm);
                }
                else
                {
                    factory.CreateForVerifying(key, algorithm);
                }

                expectedException.ProcessNoException();
            }
            catch (Exception ex)
            {
                expectedException.ProcessException(ex);
            }
        }
Exemple #3
0
        private void RunCreationTests(SecurityTokenDescriptor tokenDescriptor, int iterations, bool display = true)
        {
            // Create jwts using wif
            // Create Saml2 tokens
            // Create Saml tokens

            DateTime started;
            string   written = "Created, signed and xmlWrite: '{0}', '{1}' Tokens. Time: '{2}'";
            string   created = "Created, signed: '{0}', '{1}' Tokens. Time: '{2}'";

            SignatureProviderFactory factory           = new SignatureProviderFactory();
            SignatureProvider        signatureProvider = factory.CreateForSigning(tokenDescriptor.SigningCredentials.SigningKey, tokenDescriptor.SigningCredentials.SignatureAlgorithm);

            started = DateTime.UtcNow;
            for (int i = 0; i < iterations; i++)
            {
                CreateJwts(tokenDescriptor, signatureProvider);
            }

            if (display)
            {
                Console.WriteLine(string.Format(created, "JwtHandler - signatureProvider != null", iterations, DateTime.UtcNow - started));
            }

            started = DateTime.UtcNow;
            for (int i = 0; i < iterations; i++)
            {
                CreateJwts(tokenDescriptor, null);
            }

            if (display)
            {
                Console.WriteLine(string.Format(created, "JwtHandler - signatureProvider == null", iterations, DateTime.UtcNow - started));
            }

            started = DateTime.UtcNow;
            for (int i = 0; i < iterations; i++)
            {
                CreateSaml2Tokens(tokenDescriptor);
            }

            if (display)
            {
                Console.WriteLine(string.Format(written, "Saml2", iterations, DateTime.UtcNow - started));
            }

            started = DateTime.UtcNow;
            for (int i = 0; i < iterations; i++)
            {
                CreateSamlTokens(tokenDescriptor);
            }

            if (display)
            {
                Console.WriteLine(string.Format(written, "Saml1", iterations, DateTime.UtcNow - started));
            }

            started = DateTime.UtcNow;
            for (int i = 0; i < iterations; i++)
            {
                WriteJwts(tokenDescriptor, signatureProvider);
            }

            if (display)
            {
                Console.WriteLine(string.Format(written, "JwtHandler", iterations, DateTime.UtcNow - started));
            }
        }