public static TheoryData<KeyValuePair<string, string[]>> CreditCards()
        {
            var json = File.ReadAllText("Data\\ValidCards.json");
            var creditCards = JsonConvert.DeserializeObject<Dictionary<string, string[]>>(json);

            var data = new TheoryData<KeyValuePair<string, string[]>>();
            foreach (var item in creditCards)
            {
                data.Add(item);
            }

            return data;
        }
Пример #2
0
        private static void AddEncryptParameterCheckTheoryData(string testId, byte[] authenticatedData, byte[] plainText, TheoryData <AuthenticatedEncryptionTestParams> theoryData)
        {
            var provider = new AuthenticatedEncryptionProvider(Default.SymmetricEncryptionKey256, SecurityAlgorithms.Aes128CbcHmacSha256);

            theoryData.Add(new AuthenticatedEncryptionTestParams
            {
                AuthenticatedData = authenticatedData,
                EE = ExpectedException.ArgumentNullException(),
                EncryptionResults = new AuthenticatedEncryptionResult(Default.SymmetricEncryptionKey256, new byte[1], new byte[1], new byte[1]),
                Plaintext         = plainText,
                Provider          = provider,
                TestId            = testId
            });
        }
Пример #3
0
        public static TheoryData <AuthenticatedEncryptionTestParams> DecryptMismatchTheoryData()
        {
            var theoryData = new TheoryData <AuthenticatedEncryptionTestParams>();
            var keys128    = new List <SymmetricSecurityKey> {
                Default.SymmetricEncryptionKey256, Default.SymmetricEncryptionKey384, Default.SymmetricEncryptionKey512, Default.SymmetricEncryptionKey768, Default.SymmetricEncryptionKey1024
            };
            var keys256 = new List <SymmetricSecurityKey> {
                Default.SymmetricEncryptionKey512, Default.SymmetricEncryptionKey768, Default.SymmetricEncryptionKey1024
            };
            var keys128_256 = new List <SymmetricSecurityKey> {
                Default.SymmetricEncryptionKey512, Default.SymmetricEncryptionKey768, Default.SymmetricEncryptionKey1024, Default.SymmetricEncryptionKey256, Default.SymmetricEncryptionKey384
            };

            for (int i = 0; i < keys128.Count - 1; i++)
            {
                for (int j = i + 1; j < keys128.Count; j++)
                {
                    AddDecryptMismatchTheoryData(
                        "Test1-" + i.ToString() + "-" + j.ToString(),
                        keys128[i],
                        keys128[j],
                        SecurityAlgorithms.Aes128CbcHmacSha256,
                        SecurityAlgorithms.Aes128CbcHmacSha256,
                        ExpectedException.SecurityTokenDecryptionFailedException(),
                        theoryData);
                }
            }

            for (int i = keys128.Count - 1; i > 0; i--)
            {
                for (int j = i - 1; j > -1; j--)
                {
                    AddDecryptMismatchTheoryData(
                        "Test2-" + i.ToString() + "-" + j.ToString(),
                        keys128[i],
                        keys128[j],
                        SecurityAlgorithms.Aes128CbcHmacSha256,
                        SecurityAlgorithms.Aes128CbcHmacSha256,
                        ExpectedException.SecurityTokenDecryptionFailedException(),
                        theoryData);
                }
            }

            for (int i = 0; i < keys256.Count - 1; i++)
            {
                for (int j = i + 1; j < keys256.Count; j++)
                {
                    AddDecryptMismatchTheoryData(
                        "Test3-" + i.ToString() + "-" + j.ToString(),
                        keys256[i],
                        keys256[j],
                        SecurityAlgorithms.Aes256CbcHmacSha512,
                        SecurityAlgorithms.Aes256CbcHmacSha512,
                        ExpectedException.SecurityTokenDecryptionFailedException(),
                        theoryData);
                }
            }

            for (int i = keys256.Count - 1; i > 0; i--)
            {
                for (int j = i - 1; j > -1; j--)
                {
                    AddDecryptMismatchTheoryData(
                        "Test4-" + i.ToString() + "-" + j.ToString(),
                        keys256[i],
                        keys256[j],
                        SecurityAlgorithms.Aes256CbcHmacSha512,
                        SecurityAlgorithms.Aes256CbcHmacSha512,
                        ExpectedException.SecurityTokenDecryptionFailedException(),
                        theoryData);
                }
            }

            for (int i = 0; i < keys256.Count - 1; i++)
            {
                for (int j = 0; j < keys128.Count; j++)
                {
                    AddDecryptMismatchTheoryData(
                        "Test5-" + i.ToString() + "-" + j.ToString(),
                        keys128[j],
                        keys256[i],
                        SecurityAlgorithms.Aes128CbcHmacSha256,
                        SecurityAlgorithms.Aes256CbcHmacSha512,
                        ExpectedException.SecurityTokenDecryptionFailedException(),
                        theoryData);
                }
            }

            return(theoryData);
        }
Пример #4
0
        static EnumerableExtensionsTests()
        {
            IsEmptyExtensionTestCases =
                new TheoryData <UnaryComparisonOperationsTestCase>
            {
                new UnaryComparisonOperationsTestCase {
                    Source = null, Expected = true
                },
                new UnaryComparisonOperationsTestCase {
                    Source = Enumerable.Empty <int>(), Expected = true
                },
                new UnaryComparisonOperationsTestCase {
                    Source = Enumerable.Repeat(1, 2), Expected = false
                }
            };
            IsNotEmptyExtensionTestCases =
                new TheoryData <UnaryComparisonOperationsTestCase>
            {
                new UnaryComparisonOperationsTestCase {
                    Source = null, Expected = false
                },
                new UnaryComparisonOperationsTestCase {
                    Source = Enumerable.Empty <int>(), Expected = false
                },
                new UnaryComparisonOperationsTestCase {
                    Source = Enumerable.Repeat(1, 2), Expected = true
                }
            };

            var arrayForTesting = new[] { 1, 2, 3, 4, 5 };

            AsArrayExtensionTestCases =
                new TheoryData <AsArrayExtensionTestCase>
            {
                new AsArrayExtensionTestCase {
                    Source = null, Expected = new int[0]
                },
                new AsArrayExtensionTestCase {
                    Source = Enumerable.Range(1, 3), Expected = new[] { 1, 2, 3 }
                },
                new AsArrayExtensionTestCase {
                    Source = arrayForTesting, Expected = arrayForTesting
                }
            };

            IsEqualsExtensionTestCases =
                new TheoryData <BinaryComparisonOperationsTestCase>
            {
                new BinaryComparisonOperationsTestCase
                {
                    First = null, Second = null, Expected = true
                },
                new BinaryComparisonOperationsTestCase
                {
                    First = Enumerable.Empty <int>(), Second = Enumerable.Empty <int>(), Expected = true
                },
                new BinaryComparisonOperationsTestCase
                {
                    First = null, Second = Enumerable.Empty <int>(), Expected = false
                },
                new BinaryComparisonOperationsTestCase
                {
                    First = Enumerable.Empty <int>(), Second = null, Expected = false
                },
                new BinaryComparisonOperationsTestCase
                {
                    First = Enumerable.Empty <int>(), Second = Enumerable.Repeat(1, 2), Expected = false
                },
                new BinaryComparisonOperationsTestCase
                {
                    First = Enumerable.Repeat(1, 2), Second = Enumerable.Repeat(1, 2), Expected = true
                }
            };

            var array = new[] { 1, 2, 3 };

            IsSameExtensionTestCases =
                new TheoryData <BinaryComparisonOperationsTestCase>
            {
                new BinaryComparisonOperationsTestCase
                {
                    First = null, Second = null, Expected = true
                },
                new BinaryComparisonOperationsTestCase
                {
                    First = Enumerable.Empty <int>(), Second = Enumerable.Empty <int>(), Expected = true
                },
                new BinaryComparisonOperationsTestCase
                {
                    First = null, Second = Enumerable.Empty <int>(), Expected = false
                },
                new BinaryComparisonOperationsTestCase
                {
                    First = Enumerable.Empty <int>(), Second = null, Expected = false
                },
                new BinaryComparisonOperationsTestCase
                {
                    First = Enumerable.Empty <int>(), Second = Enumerable.Repeat(1, 2), Expected = false
                },
                new BinaryComparisonOperationsTestCase
                {
                    First = new[] { 1, 2 }, Second = new[] { 1, 2 }, Expected = true
                },
                new BinaryComparisonOperationsTestCase
                {
                    First = new[] { 2, 1 }, Second = new[] { 1, 2 }, Expected = true
                },
                new BinaryComparisonOperationsTestCase
                {
                    First = new[] { 1, 1 }, Second = new[] { 1, 2 }, Expected = false
                },
                new BinaryComparisonOperationsTestCase
                {
                    First = new[] { 1, 2 }, Second = new[] { 1, 1 }, Expected = false
                },
                new BinaryComparisonOperationsTestCase
                {
                    First = new[] { 1, 1 }, Second = new[] { 1, 1 }, Expected = true
                },
                new BinaryComparisonOperationsTestCase
                {
                    First = new[] { 1, 1 }, Second = new[] { 1, 1, 1 }, Expected = false
                },
                new BinaryComparisonOperationsTestCase
                {
                    First = new[] { 1, 1, 2, 2 }, Second = new[] { 1, 1, 1, 2 }, Expected = false
                },
                new BinaryComparisonOperationsTestCase
                {
                    First = new[] { 1, 1, 1, 2 }, Second = new[] { 1, 1, 2, 2 }, Expected = false
                },
                new BinaryComparisonOperationsTestCase
                {
                    First = array, Second = array, Expected = true
                }
            };
        }
Пример #5
0
        public static TheoryData <string, TimerInfo> GetRecordingName_Success_TestData()
        {
            var data = new TheoryData <string, TimerInfo>();

            data.Add(
                "The Incredibles 2020_04_20_21_06_00",
                new TimerInfo
            {
                Name      = "The Incredibles",
                StartDate = new DateTime(2020, 4, 20, 21, 6, 0, DateTimeKind.Local),
                IsMovie   = true
            });

            data.Add(
                "The Incredibles (2004)",
                new TimerInfo
            {
                Name           = "The Incredibles",
                IsMovie        = true,
                ProductionYear = 2004
            });
            data.Add(
                "The Big Bang Theory 2020_04_20_21_06_00",
                new TimerInfo
            {
                Name            = "The Big Bang Theory",
                StartDate       = new DateTime(2020, 4, 20, 21, 6, 0, DateTimeKind.Local),
                IsProgramSeries = true,
            });
            data.Add(
                "The Big Bang Theory S12E10",
                new TimerInfo
            {
                Name            = "The Big Bang Theory",
                IsProgramSeries = true,
                SeasonNumber    = 12,
                EpisodeNumber   = 10
            });
            data.Add(
                "The Big Bang Theory S12E10 The VCR Illumination",
                new TimerInfo
            {
                Name            = "The Big Bang Theory",
                IsProgramSeries = true,
                SeasonNumber    = 12,
                EpisodeNumber   = 10,
                EpisodeTitle    = "The VCR Illumination"
            });
            data.Add(
                "The Big Bang Theory 2018-12-06",
                new TimerInfo
            {
                Name            = "The Big Bang Theory",
                IsProgramSeries = true,
                OriginalAirDate = new DateTime(2018, 12, 6, 0, 0, 0, DateTimeKind.Local)
            });

            data.Add(
                "The Big Bang Theory 2018-12-06 - The VCR Illumination",
                new TimerInfo
            {
                Name            = "The Big Bang Theory",
                IsProgramSeries = true,
                OriginalAirDate = new DateTime(2018, 12, 6, 0, 0, 0, DateTimeKind.Local),
                EpisodeTitle    = "The VCR Illumination"
            });

            data.Add(
                "The Big Bang Theory 2018_12_06_21_06_00 - The VCR Illumination",
                new TimerInfo
            {
                Name            = "The Big Bang Theory",
                StartDate       = new DateTime(2018, 12, 6, 21, 6, 0, DateTimeKind.Local),
                IsProgramSeries = true,
                OriginalAirDate = new DateTime(2018, 12, 6),
                EpisodeTitle    = "The VCR Illumination"
            });

            data.Add(
                "Lorem ipsum dolor sit amet: consect 2018_12_06_21_06_00",
                new TimerInfo
            {
                Name            = "Lorem ipsum dolor sit amet: consect",
                IsProgramSeries = true,
                StartDate       = new DateTime(2018, 12, 6, 21, 6, 0, DateTimeKind.Local),
                OriginalAirDate = new DateTime(2018, 12, 6),
                EpisodeTitle    = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor"
            });

            return(data);
        }
        public static TheoryData <string, OpenIdConnectMessage, string> CreateAuthenticationRequestUrlTheoryData()
        {
            string customParameterName  = "Custom Parameter Name";
            string customParameterValue = "Custom Parameter Value";
            string nonce       = Guid.NewGuid().ToString();
            string redirectUri = "http://gotJwt.onmicrosoft.com/signedIn";
            string resource    = "location data";

            var theoryData = new TheoryData <string, OpenIdConnectMessage, string>();

            OpenIdConnectMessage.EnableTelemetryParametersByDefault = false;
            var message = new OpenIdConnectMessage();

            theoryData.Add("EmptyMessage", message, "");

            theoryData.Add(
                "Code",
                message = new OpenIdConnectMessage()
            {
                ResponseMode = OpenIdConnectResponseMode.FormPost,
                ResponseType = OpenIdConnectResponseType.Code,
                Scope        = OpenIdConnectScope.OpenIdProfile
            },
                string.Format(CultureInfo.InvariantCulture, @"?response_mode=form_post&response_type={0}&scope=openid%20profile", Uri.EscapeUriString(OpenIdConnectResponseType.Code))
                );

            theoryData.Add(
                "CodeIdToken",
                message = new OpenIdConnectMessage()
            {
                ResponseMode = OpenIdConnectResponseMode.FormPost,
                ResponseType = OpenIdConnectResponseType.CodeIdToken,
                Scope        = OpenIdConnectScope.OpenIdProfile
            },
                string.Format(CultureInfo.InvariantCulture, @"?response_mode=form_post&response_type={0}&scope=openid%20profile", Uri.EscapeUriString(OpenIdConnectResponseType.CodeIdToken))
                );

            theoryData.Add(
                "CodeIdTokenToken",
                message = new OpenIdConnectMessage()
            {
                ResponseMode = OpenIdConnectResponseMode.FormPost,
                ResponseType = OpenIdConnectResponseType.CodeIdTokenToken,
                Scope        = OpenIdConnectScope.OpenIdProfile
            },
                string.Format(CultureInfo.InvariantCulture, @"?response_mode=form_post&response_type={0}&scope=openid%20profile", Uri.EscapeUriString(OpenIdConnectResponseType.CodeIdTokenToken))
                );

            theoryData.Add(
                "CodeToken",
                message = new OpenIdConnectMessage()
            {
                ResponseMode = OpenIdConnectResponseMode.FormPost,
                ResponseType = OpenIdConnectResponseType.CodeToken,
                Scope        = OpenIdConnectScope.OpenIdProfile
            },
                string.Format(CultureInfo.InvariantCulture, @"?response_mode=form_post&response_type={0}&scope=openid%20profile", Uri.EscapeUriString(OpenIdConnectResponseType.CodeToken))
                );

            theoryData.Add(
                "IdToken",
                message = new OpenIdConnectMessage()
            {
                ResponseMode = OpenIdConnectResponseMode.FormPost,
                ResponseType = OpenIdConnectResponseType.IdToken,
                Scope        = OpenIdConnectScope.OpenIdProfile
            },
                string.Format(CultureInfo.InvariantCulture, @"?response_mode=form_post&response_type={0}&scope=openid%20profile", Uri.EscapeUriString(OpenIdConnectResponseType.IdToken))
                );

            theoryData.Add(
                "IdTokenToken",
                message = new OpenIdConnectMessage()
            {
                ResponseMode = OpenIdConnectResponseMode.FormPost,
                ResponseType = OpenIdConnectResponseType.IdTokenToken,
                Scope        = OpenIdConnectScope.OpenIdProfile
            },
                string.Format(CultureInfo.InvariantCulture, @"?response_mode=form_post&response_type={0}&scope=openid%20profile", Uri.EscapeUriString(OpenIdConnectResponseType.IdTokenToken))
                );

            theoryData.Add(
                "None",
                message = new OpenIdConnectMessage()
            {
                ResponseMode = OpenIdConnectResponseMode.FormPost,
                ResponseType = OpenIdConnectResponseType.None,
                Scope        = OpenIdConnectScope.OpenIdProfile
            },
                string.Format(CultureInfo.InvariantCulture, @"?response_mode=form_post&response_type={0}&scope=openid%20profile", Uri.EscapeUriString(OpenIdConnectResponseType.None))
                );

            theoryData.Add(
                "Token",
                message = new OpenIdConnectMessage()
            {
                ResponseMode = OpenIdConnectResponseMode.FormPost,
                ResponseType = OpenIdConnectResponseType.Token,
                Scope        = OpenIdConnectScope.OpenIdProfile
            },
                string.Format(CultureInfo.InvariantCulture, @"?response_mode=form_post&response_type={0}&scope=openid%20profile", Uri.EscapeUriString(OpenIdConnectResponseType.Token))
                );

            theoryData.Add(
                "Nonce",
                message = new OpenIdConnectMessage()
            {
                ResponseMode = OpenIdConnectResponseMode.FormPost,
                ResponseType = OpenIdConnectResponseType.CodeIdToken,
                Scope        = OpenIdConnectScope.OpenIdProfile,
                Nonce        = nonce
            },
                string.Format(CultureInfo.InvariantCulture, @"?response_mode=form_post&response_type=code%20id_token&scope=openid%20profile&nonce={0}", nonce)
                );

            theoryData.Add(
                "IssuerAddress",
                message = new OpenIdConnectMessage()
            {
                IssuerAddress = Default.Issuer,
                ResponseMode  = OpenIdConnectResponseMode.FormPost,
                ResponseType  = OpenIdConnectResponseType.CodeIdToken,
                Scope         = OpenIdConnectScope.OpenIdProfile,
                Nonce         = nonce
            },
                string.Format(CultureInfo.InvariantCulture, @"{0}?response_mode=form_post&response_type=code%20id_token&scope=openid%20profile&nonce={1}", Uri.EscapeUriString(Default.Issuer), nonce)
                );

            theoryData.Add(
                "IssuerAddress",
                message = new OpenIdConnectMessage()
            {
                IssuerAddress = Default.Issuer,
                ResponseMode  = OpenIdConnectResponseMode.FormPost,
                ResponseType  = OpenIdConnectResponseType.CodeIdToken,
                Scope         = OpenIdConnectScope.OpenIdProfile,
                Nonce         = nonce,
                RedirectUri   = redirectUri
            },
                string.Format(CultureInfo.InvariantCulture, @"{0}?response_mode=form_post&response_type=code%20id_token&scope=openid%20profile&nonce={1}&redirect_uri={2}", Uri.EscapeUriString(Default.Issuer), nonce, Uri.EscapeDataString(redirectUri))
                );

            theoryData.Add(
                "IssuerAddressEmpty",
                message = new OpenIdConnectMessage()
            {
                IssuerAddress = string.Empty,
                ResponseMode  = OpenIdConnectResponseMode.FormPost,
                ResponseType  = OpenIdConnectResponseType.CodeIdToken,
                Scope         = OpenIdConnectScope.OpenIdProfile,
                Nonce         = nonce,
                RedirectUri   = redirectUri
            },
                string.Format(CultureInfo.InvariantCulture, @"?response_mode=form_post&response_type=code%20id_token&scope=openid%20profile&nonce={0}&redirect_uri={1}", nonce, Uri.EscapeDataString(redirectUri))
                );

            theoryData.Add(
                "Resource",
                message = new OpenIdConnectMessage()
            {
                IssuerAddress = Default.Issuer,
                ResponseMode  = OpenIdConnectResponseMode.FormPost,
                ResponseType  = OpenIdConnectResponseType.CodeIdToken,
                Scope         = OpenIdConnectScope.OpenIdProfile,
                Nonce         = nonce,
                RedirectUri   = redirectUri,
                Resource      = resource
            },
                string.Format(CultureInfo.InvariantCulture, @"{0}?response_mode=form_post&response_type=code%20id_token&scope=openid%20profile&nonce={1}&redirect_uri={2}&resource={3}", Default.Issuer, nonce, Uri.EscapeDataString(redirectUri), Uri.EscapeDataString(resource))
                );

            message = new OpenIdConnectMessage()
            {
                IssuerAddress = Default.Issuer,
                ResponseMode  = OpenIdConnectResponseMode.FormPost,
                ResponseType  = OpenIdConnectResponseType.CodeIdToken,
                Scope         = OpenIdConnectScope.OpenIdProfile,
                Nonce         = nonce,
            };
            message.Parameters.Add(customParameterName, customParameterValue);
            message.RedirectUri = redirectUri;
            message.Resource    = resource;

            theoryData.Add(
                "CustomParam",
                message,
                string.Format(CultureInfo.InvariantCulture, @"{0}?response_mode=form_post&response_type=code%20id_token&scope=openid%20profile&nonce={1}&{2}={3}&redirect_uri={4}&resource={5}", Default.Issuer, nonce, Uri.EscapeDataString(customParameterName), Uri.EscapeDataString(customParameterValue), Uri.EscapeDataString(redirectUri), Uri.EscapeDataString(resource))
                );

            message = new OpenIdConnectMessage();
            theoryData.Add(
                "Resource",
                message = new OpenIdConnectMessage()
            {
                IssuerAddress = Default.Issuer,
                ResponseMode  = OpenIdConnectResponseMode.FormPost,
                ResponseType  = OpenIdConnectResponseType.CodeIdToken,
                Scope         = OpenIdConnectScope.OpenIdProfile,
                Nonce         = nonce,
                RedirectUri   = redirectUri,
                Resource      = resource
            },
                string.Format(CultureInfo.InvariantCulture, @"{0}?response_mode=form_post&response_type=code%20id_token&scope=openid%20profile&nonce={1}&redirect_uri={2}&resource={3}", Default.Issuer, nonce, Uri.EscapeDataString(redirectUri), Uri.EscapeDataString(resource))
                );

            OpenIdConnectMessage.EnableTelemetryParametersByDefault = true;
            message = new OpenIdConnectMessage();
            theoryData.Add(
                "Telemetry",
                message,
                string.Format(CultureInfo.InvariantCulture, $@"?x-client-SKU={message.SkuTelemetryValue}&x-client-ver={typeof(OpenIdConnectMessage).GetTypeInfo().Assembly.GetName().Version}")
                );

            // Telemetry turned off
            OpenIdConnectMessage.EnableTelemetryParametersByDefault = false;
            message = new OpenIdConnectMessage();
            message.EnableTelemetryParameters = true;
            theoryData.Add(
                "TelemetryStaticFalseInstanceTrue",
                message,
                string.Format(CultureInfo.InvariantCulture, $@"?x-client-SKU={message.SkuTelemetryValue}&x-client-ver={typeof(OpenIdConnectMessage).GetTypeInfo().Assembly.GetName().Version}")
                );

            // Telemetry turned off using static switch
            OpenIdConnectMessage.EnableTelemetryParametersByDefault = false;
            message = new OpenIdConnectMessage();
            theoryData.Add(
                "TelemetryStaticFalse",
                message,
                ""
                );

            // Telemetry turned off using static switch, but turned on on the instance
            OpenIdConnectMessage.EnableTelemetryParametersByDefault = true;
            message = new OpenIdConnectMessage();
            message.EnableTelemetryParameters = false;
            theoryData.Add(
                "TelemetryStaticTrueInstanceFalse",
                message,
                ""
                );

            OpenIdConnectMessage.EnableTelemetryParametersByDefault = true;

            return(theoryData);
        }
Пример #7
0
 private static void AddUnwrapMismatchTheoryData(string testId, SecurityKey encryptKey, SecurityKey decryptKey, string encryptAlg, string decryptAlg, ExpectedException ee, TheoryData <KeyWrapTestParams> theoryData)
 {
     theoryData.Add(new KeyWrapTestParams
     {
         EncryptAlgorithm = encryptAlg,
         EncryptKey       = encryptKey,
         DecryptAlgorithm = decryptAlg,
         DecryptKey       = decryptKey,
         EE     = ee,
         TestId = testId
     });
 }
Пример #8
0
 private static void AddWrapUnwrapTheoryData(string testId, string algorithm, SecurityKey key, TheoryData <KeyWrapTestParams> theoryData)
 {
     theoryData.Add(new KeyWrapTestParams
     {
         EncryptAlgorithm = algorithm,
         KeyToWrap        = Guid.NewGuid().ToByteArray(),
         EE         = ExpectedException.NoExceptionExpected,
         EncryptKey = key,
         TestId     = "AddWrapUnwrapTheoryData_" + testId
     });
 }
Пример #9
0
        public static TheoryData <string, PasswordHash> Parse_Valid_TestData()
        {
            var data = new TheoryData <string, PasswordHash>();

            // Id
            data.Add(
                "$PBKDF2",
                new PasswordHash("PBKDF2", Array.Empty <byte>()));

            // Id + parameter
            data.Add(
                "$PBKDF2$iterations=1000",
                new PasswordHash(
                    "PBKDF2",
                    Array.Empty <byte>(),
                    Array.Empty <byte>(),
                    new Dictionary <string, string>()
            {
                { "iterations", "1000" },
            }));

            // Id + parameters
            data.Add(
                "$PBKDF2$iterations=1000,m=120",
                new PasswordHash(
                    "PBKDF2",
                    Array.Empty <byte>(),
                    Array.Empty <byte>(),
                    new Dictionary <string, string>()
            {
                { "iterations", "1000" },
                { "m", "120" }
            }));

            // Id + hash
            data.Add(
                "$PBKDF2$62FBA410AFCA5B4475F35137AB2E8596B127E4D927BA23F6CC05C067E897042D",
                new PasswordHash(
                    "PBKDF2",
                    Convert.FromHexString("62FBA410AFCA5B4475F35137AB2E8596B127E4D927BA23F6CC05C067E897042D"),
                    Array.Empty <byte>(),
                    new Dictionary <string, string>()));

            // Id + salt + hash
            data.Add(
                "$PBKDF2$69F420$62FBA410AFCA5B4475F35137AB2E8596B127E4D927BA23F6CC05C067E897042D",
                new PasswordHash(
                    "PBKDF2",
                    Convert.FromHexString("62FBA410AFCA5B4475F35137AB2E8596B127E4D927BA23F6CC05C067E897042D"),
                    Convert.FromHexString("69F420"),
                    new Dictionary <string, string>()));

            // Id + parameter + hash
            data.Add(
                "$PBKDF2$iterations=1000$62FBA410AFCA5B4475F35137AB2E8596B127E4D927BA23F6CC05C067E897042D",
                new PasswordHash(
                    "PBKDF2",
                    Convert.FromHexString("62FBA410AFCA5B4475F35137AB2E8596B127E4D927BA23F6CC05C067E897042D"),
                    Array.Empty <byte>(),
                    new Dictionary <string, string>()
            {
                { "iterations", "1000" }
            }));
            // Id + parameters + hash
            data.Add(
                "$PBKDF2$iterations=1000,m=120$62FBA410AFCA5B4475F35137AB2E8596B127E4D927BA23F6CC05C067E897042D",
                new PasswordHash(
                    "PBKDF2",
                    Convert.FromHexString("62FBA410AFCA5B4475F35137AB2E8596B127E4D927BA23F6CC05C067E897042D"),
                    Array.Empty <byte>(),
                    new Dictionary <string, string>()
            {
                { "iterations", "1000" },
                { "m", "120" }
            }));
            // Id + parameters + salt + hash
            data.Add(
                "$PBKDF2$iterations=1000,m=120$69F420$62FBA410AFCA5B4475F35137AB2E8596B127E4D927BA23F6CC05C067E897042D",
                new PasswordHash(
                    "PBKDF2",
                    Convert.FromHexString("62FBA410AFCA5B4475F35137AB2E8596B127E4D927BA23F6CC05C067E897042D"),
                    Convert.FromHexString("69F420"),
                    new Dictionary <string, string>()
            {
                { "iterations", "1000" },
                { "m", "120" }
            }));
            return(data);
        }
Пример #10
0
        static PolynomialUnderPrimeOrderFieldTest()
        {
            Gf2 = new PrimeOrderField(2);
            Gf3 = new PrimeOrderField(3);

            DevideTestsData
                = new TheoryData <BinaryOperationTestCase>
                {
                new BinaryOperationTestCase
                {
                    Field = Gf2,
                    FirstOperandCoefficients   = new[] { 1 },
                    SecondOperandCoefficients  = new[] { 1, 1, 0, 1 },
                    ExpectedResultCoefficients = new[] { 0 }
                },
                new BinaryOperationTestCase
                {
                    Field = Gf2,
                    FirstOperandCoefficients   = new[] { 0, 1 },
                    SecondOperandCoefficients  = new[] { 1, 1, 0, 1 },
                    ExpectedResultCoefficients = new[] { 0 }
                },
                new BinaryOperationTestCase
                {
                    Field = Gf2,
                    FirstOperandCoefficients   = new[] { 0, 0, 0, 1 },
                    SecondOperandCoefficients  = new[] { 1, 1, 0, 1 },
                    ExpectedResultCoefficients = new[] { 1 }
                },
                new BinaryOperationTestCase
                {
                    Field = Gf2,
                    FirstOperandCoefficients   = new[] { 0, 0, 0, 0, 1 },
                    SecondOperandCoefficients  = new[] { 1, 1, 0, 1 },
                    ExpectedResultCoefficients = new[] { 0, 1 }
                },
                new BinaryOperationTestCase
                {
                    Field = Gf2,
                    FirstOperandCoefficients   = new[] { 0, 0, 0, 0, 0, 1 },
                    SecondOperandCoefficients  = new[] { 1, 1, 0, 1 },
                    ExpectedResultCoefficients = new[] { 1, 0, 1 }
                },
                new BinaryOperationTestCase
                {
                    Field = Gf2,
                    FirstOperandCoefficients   = new[] { 0, 0, 0, 0, 0, 0, 1 },
                    SecondOperandCoefficients  = new[] { 1, 1, 0, 1 },
                    ExpectedResultCoefficients = new[] { 1, 1, 0, 1 }
                },
                new BinaryOperationTestCase
                {
                    Field = Gf2,
                    FirstOperandCoefficients   = new[] { 0, 0, 0, 0, 0, 0, 0, 1 },
                    SecondOperandCoefficients  = new[] { 1, 1, 0, 1 },
                    ExpectedResultCoefficients = new[] { 1, 1, 1, 0, 1 }
                },
                new BinaryOperationTestCase
                {
                    Field = Gf3,
                    FirstOperandCoefficients   = new[] { 0, 0, 0, 1 },
                    SecondOperandCoefficients  = new[] { 1, 1 },
                    ExpectedResultCoefficients = new[] { 1, 2, 1 }
                }
                };

            ModuloTestsData
                = new TheoryData <BinaryOperationTestCase>
                {
                new BinaryOperationTestCase
                {
                    Field = Gf2,
                    FirstOperandCoefficients   = new[] { 1 },
                    SecondOperandCoefficients  = new[] { 1, 1, 0, 1 },
                    ExpectedResultCoefficients = new[] { 1 }
                },
                new BinaryOperationTestCase
                {
                    Field = Gf2,
                    FirstOperandCoefficients   = new[] { 0, 1 },
                    SecondOperandCoefficients  = new[] { 1, 1, 0, 1 },
                    ExpectedResultCoefficients = new[] { 0, 1 }
                },
                new BinaryOperationTestCase
                {
                    Field = Gf2,
                    FirstOperandCoefficients   = new[] { 0, 0, 0, 1 },
                    SecondOperandCoefficients  = new[] { 1, 1, 0, 1 },
                    ExpectedResultCoefficients = new[] { 1, 1 }
                },
                new BinaryOperationTestCase
                {
                    Field = Gf2,
                    FirstOperandCoefficients   = new[] { 0, 0, 0, 0, 1 },
                    SecondOperandCoefficients  = new[] { 1, 1, 0, 1 },
                    ExpectedResultCoefficients = new[] { 0, 1, 1 }
                },
                new BinaryOperationTestCase
                {
                    Field = Gf2,
                    FirstOperandCoefficients   = new[] { 0, 0, 0, 0, 0, 1 },
                    SecondOperandCoefficients  = new[] { 1, 1, 0, 1 },
                    ExpectedResultCoefficients = new[] { 1, 1, 1 }
                },
                new BinaryOperationTestCase
                {
                    Field = Gf2,
                    FirstOperandCoefficients   = new[] { 0, 0, 0, 0, 0, 0, 1 },
                    SecondOperandCoefficients  = new[] { 1, 1, 0, 1 },
                    ExpectedResultCoefficients = new[] { 1, 0, 1 }
                },
                new BinaryOperationTestCase
                {
                    Field = Gf2,
                    FirstOperandCoefficients   = new[] { 0, 0, 0, 0, 0, 0, 0, 1 },
                    SecondOperandCoefficients  = new[] { 1, 1, 0, 1 },
                    ExpectedResultCoefficients = new[] { 1 }
                },
                new BinaryOperationTestCase
                {
                    Field = Gf3,
                    FirstOperandCoefficients   = new[] { 0, 0, 0, 1 },
                    SecondOperandCoefficients  = new[] { 1, 1 },
                    ExpectedResultCoefficients = new[] { 2 }
                }
                };
        }
Пример #11
0
        public static TheoryData <Contact, Contact, IReadOnlyCollection <string> > LogsData()
        {
            var data = new TheoryData <Contact, Contact, IReadOnlyCollection <string> >
            {
                // Modified Name
                {
                    new Contact {
                        Id = "id", Name = "Name1", FirstName = "FirstName1", MiddleName = "MiddleName1", LastName = "LastName1", Salutation = "Salutation1", FullName = "FullName1", BirthDate = new DateTime(2001, 1, 10)
                    },
                    new Contact {
                        Id = "id", Name = "Name_New", FirstName = "FirstName_NEW", MiddleName = "MiddleName_NEW", LastName = "LastName_NEW", Salutation = "Salutation_NEW", FullName = "FullName_NEW", BirthDate = new DateTime(2001, 3, 10)
                    },
                    new[]
                    {
                        string.Format(MemberResources.MemberPropertyChanged, "Name", "Name1", "Name_New"),
                        string.Format(MemberResources.MemberPropertyChanged, "FirstName", "FirstName1", "FirstName_NEW"),
                        string.Format(MemberResources.MemberPropertyChanged, "MiddleName", "MiddleName1", "MiddleName_NEW"),
                        string.Format(MemberResources.MemberPropertyChanged, "LastName", "LastName1", "LastName_NEW"),
                        string.Format(MemberResources.MemberPropertyChanged, "Salutation", "Salutation1", "Salutation_NEW"),
                        string.Format(MemberResources.MemberPropertyChanged, "FullName", "FullName1", "FullName_NEW"),
                        string.Format(MemberResources.MemberPropertyChanged, "BirthDate", new DateTime(2001, 1, 10), new DateTime(2001, 3, 10)),
                    }
                },
                // Emails
                {
                    new Contact {
                        Id = "id", Emails = new List <string>()
                        {
                            "*****@*****.**", "*****@*****.**"
                        }
                    },
                    new Contact {
                        Id = "id", Emails = new List <string> {
                            "*****@*****.**", "*****@*****.**"
                        }
                    },
                    new[]
                    {
                        string.Format(MemberResources.EmailAdded, "*****@*****.**"),
                        string.Format(MemberResources.EmailDeleted, "*****@*****.**")
                    }
                },
                // Phones
                {
                    new Contact {
                        Id = "id", Phones = new List <string>()
                        {
                            "unchanged phone", "deleted phone"
                        }
                    },
                    new Contact {
                        Id = "id", Phones = new List <string> {
                            "unchanged phone", "added phone"
                        }
                    },
                    new[]
                    {
                        string.Format(MemberResources.PhoneAdded, "added phone"),
                        string.Format(MemberResources.PhoneDeleted, "deleted phone")
                    }
                },
                // Addresses
                {
                    new Contact {
                        Id = "id", Addresses = new List <Address>()
                        {
                            new Address {
                                Key = "1", City = "modified address"
                            }, new Address {
                                Key = "2", City = "deleted address"
                            }
                        }
                    },
                    new Contact {
                        Id = "id", Addresses = new List <Address> {
                            new Address {
                                City = "added address"
                            }, new Address {
                                Key = "1", City = "modified address2"
                            }
                        }
                    },
                    new[]
                    {
                        string.Format(MemberResources.AddressAdded, "added address"),
                        string.Format(MemberResources.AddressDeleted, "deleted address"),
                        string.Format(MemberResources.AddressModified, "modified address", "modified address2")
                    }
                },
                // Partial update (when null was passed for dependencies collections
                {
                    new Contact {
                        Id = "id", Phones = new List <string>()
                        {
                            "phone"
                        }, Emails = new List <string>()
                        {
                            "email"
                        }, Addresses = new List <Address>()
                        {
                            new Address {
                                Name = "address"
                            }
                        }
                    },
                    new Contact {
                        Id = "id"
                    },
                    Array.Empty <string>()
                },
                // No changes
                {
                    new Contact {
                        Id = "id", Name = "Name"
                    },
                    new Contact {
                        Id = "id", Name = "Name"
                    },
                    Array.Empty <string>()
                }
            };

            return(data);
        }
        private static void AddDecryptParameterCheckTheoryData(string testId, byte[] authenticatedData, byte[] authenticationTag, byte[] cipherText, byte[] iv, TheoryData <AuthenticatedEncryptionTheoryData> theoryData)
        {
            var provider = new AuthenticatedEncryptionProvider(Default.SymmetricEncryptionKey256, SecurityAlgorithms.Aes128CbcHmacSha256);

            theoryData.Add(new AuthenticatedEncryptionTheoryData
            {
                AuthenticatedData = authenticatedData,
                ExpectedException = ExpectedException.ArgumentNullException(),
                EncryptionResults = new AuthenticatedEncryptionResult(Default.SymmetricEncryptionKey256, cipherText, iv, authenticationTag),
                Provider          = provider,
                TestId            = testId
            });
        }
Пример #13
0
        public static TheoryData <string, MediaStream> Get_DisplayTitle_TestData()
        {
            var data = new TheoryData <string, MediaStream>();

            data.Add(
                "English - Und - ASS",
                new MediaStream
            {
                Type      = MediaStreamType.Subtitle,
                Title     = "English",
                Language  = string.Empty,
                IsForced  = false,
                IsDefault = false,
                Codec     = "ASS"
            });

            data.Add(
                "English - Und",
                new MediaStream
            {
                Type      = MediaStreamType.Subtitle,
                Title     = "English",
                Language  = string.Empty,
                IsForced  = false,
                IsDefault = false,
                Codec     = string.Empty
            });

            data.Add(
                "English",
                new MediaStream
            {
                Type      = MediaStreamType.Subtitle,
                Title     = "English",
                Language  = "EN",
                IsForced  = false,
                IsDefault = false,
                Codec     = string.Empty
            });

            data.Add(
                "English - Default - Forced - SRT",
                new MediaStream
            {
                Type      = MediaStreamType.Subtitle,
                Title     = "English",
                Language  = "EN",
                IsForced  = true,
                IsDefault = true,
                Codec     = "SRT"
            });

            data.Add(
                "Title - EN - Default - Forced - SRT - External",
                new MediaStream
            {
                Type       = MediaStreamType.Subtitle,
                Title      = "Title",
                Language   = "EN",
                IsForced   = true,
                IsDefault  = true,
                Codec      = "SRT",
                IsExternal = true
            });

            data.Add(
                "Und",
                new MediaStream
            {
                Type      = MediaStreamType.Subtitle,
                Title     = null,
                Language  = null,
                IsForced  = false,
                IsDefault = false,
                Codec     = null
            });

            data.Add(
                "Title - AAC - Default - External",
                new MediaStream
            {
                Type       = MediaStreamType.Audio,
                Title      = "Title",
                Language   = null,
                IsForced   = false,
                IsDefault  = true,
                Codec      = "AAC",
                IsExternal = true
            });

            return(data);
        }
        private static TheoryData<string, string[]> GetInvalidNameOrPrefixData(
            Func<string, string, string> onNameError,
            string whitespaceErrorString,
            Func<string, string> onDataError)
        {
            // name, expectedErrorMessages
            var data = new TheoryData<string, string[]>
            {
                { "!", new[] {  onNameError("!", "!") } },
                { "hello!", new[] { onNameError("hello!", "!") } },
                { "!hello", new[] { onNameError("!hello", "!") } },
                { "he!lo", new[] { onNameError("he!lo", "!") } },
                {
                    "!he!lo!",
                    new[]
                    {
                        onNameError("!he!lo!", "!"),
                        onNameError("!he!lo!", "!"),
                        onNameError("!he!lo!", "!"),
                    }
                },
                { "@", new[] { onNameError("@", "@") } },
                { "hello@", new[] { onNameError("hello@", "@") } },
                { "@hello", new[] { onNameError("@hello", "@") } },
                { "he@lo", new[] { onNameError("he@lo", "@") } },
                {
                    "@he@lo@",
                    new[]
                    {
                        onNameError("@he@lo@", "@"),
                        onNameError("@he@lo@", "@"),
                        onNameError("@he@lo@", "@"),
                    }
                },
                { "/", new[] { onNameError("/", "/") } },
                { "hello/", new[] { onNameError("hello/", "/") } },
                { "/hello", new[] { onNameError("/hello", "/") } },
                { "he/lo", new[] { onNameError("he/lo", "/") } },
                {
                    "/he/lo/",
                    new[]
                    {
                        onNameError("/he/lo/", "/"),
                        onNameError("/he/lo/", "/"),
                        onNameError("/he/lo/", "/"),
                    }
                },
                { "<", new[] { onNameError("<", "<") } },
                { "hello<", new[] { onNameError("hello<", "<") } },
                { "<hello", new[] { onNameError("<hello", "<") } },
                { "he<lo", new[] { onNameError("he<lo", "<") } },
                {
                    "<he<lo<",
                    new[]
                    {
                        onNameError("<he<lo<", "<"),
                        onNameError("<he<lo<", "<"),
                        onNameError("<he<lo<", "<"),
                    }
                },
                { "?", new[] { onNameError("?", "?") } },
                { "hello?", new[] { onNameError("hello?", "?") } },
                { "?hello", new[] { onNameError("?hello", "?") } },
                { "he?lo", new[] { onNameError("he?lo", "?") } },
                {
                    "?he?lo?",
                    new[]
                    {
                        onNameError("?he?lo?", "?"),
                        onNameError("?he?lo?", "?"),
                        onNameError("?he?lo?", "?"),
                    }
                },
                { "[", new[] { onNameError("[", "[") } },
                { "hello[", new[] { onNameError("hello[", "[") } },
                { "[hello", new[] { onNameError("[hello", "[") } },
                { "he[lo", new[] { onNameError("he[lo", "[") } },
                {
                    "[he[lo[",
                    new[]
                    {
                        onNameError("[he[lo[", "["),
                        onNameError("[he[lo[", "["),
                        onNameError("[he[lo[", "["),
                    }
                },
                { ">", new[] { onNameError(">", ">") } },
                { "hello>", new[] { onNameError("hello>", ">") } },
                { ">hello", new[] { onNameError(">hello", ">") } },
                { "he>lo", new[] { onNameError("he>lo", ">") } },
                {
                    ">he>lo>",
                    new[]
                    {
                        onNameError(">he>lo>", ">"),
                        onNameError(">he>lo>", ">"),
                        onNameError(">he>lo>", ">"),
                    }
                },
                { "]", new[] { onNameError("]", "]") } },
                { "hello]", new[] { onNameError("hello]", "]") } },
                { "]hello", new[] { onNameError("]hello", "]") } },
                { "he]lo", new[] { onNameError("he]lo", "]") } },
                {
                    "]he]lo]",
                    new[]
                    {
                        onNameError("]he]lo]", "]"),
                        onNameError("]he]lo]", "]"),
                        onNameError("]he]lo]", "]"),
                    }
                },
                { "=", new[] { onNameError("=", "=") } },
                { "hello=", new[] { onNameError("hello=", "=") } },
                { "=hello", new[] { onNameError("=hello", "=") } },
                { "he=lo", new[] { onNameError("he=lo", "=") } },
                {
                    "=he=lo=",
                    new[]
                    {
                        onNameError("=he=lo=", "="),
                        onNameError("=he=lo=", "="),
                        onNameError("=he=lo=", "="),
                    }
                },
                { "\"", new[] { onNameError("\"", "\"") } },
                { "hello\"", new[] { onNameError("hello\"", "\"") } },
                { "\"hello", new[] { onNameError("\"hello", "\"") } },
                { "he\"lo", new[] { onNameError("he\"lo", "\"") } },
                {
                    "\"he\"lo\"",
                    new[]
                    {
                        onNameError("\"he\"lo\"", "\""),
                        onNameError("\"he\"lo\"", "\""),
                        onNameError("\"he\"lo\"", "\""),
                    }
                },
                { "'", new[] { onNameError("'", "'") } },
                { "hello'", new[] { onNameError("hello'", "'") } },
                { "'hello", new[] { onNameError("'hello", "'") } },
                { "he'lo", new[] { onNameError("he'lo", "'") } },
                {
                    "'he'lo'",
                    new[]
                    {
                        onNameError("'he'lo'", "'"),
                        onNameError("'he'lo'", "'"),
                        onNameError("'he'lo'", "'"),
                    }
                },
                { "hello*", new[] { onNameError("hello*", "*") } },
                { "*hello", new[] { onNameError("*hello", "*") } },
                { "he*lo", new[] { onNameError("he*lo", "*") } },
                {
                    "*he*lo*",
                    new[]
                    {
                        onNameError("*he*lo*", "*"),
                        onNameError("*he*lo*", "*"),
                        onNameError("*he*lo*", "*"),
                    }
                },
                { Environment.NewLine, new[] { whitespaceErrorString } },
                { "\t", new[] { whitespaceErrorString } },
                { " \t ", new[] { whitespaceErrorString } },
                { " ", new[] { whitespaceErrorString } },
                { Environment.NewLine + " ", new[] { whitespaceErrorString } },
                {
                    "! \t\r\n@/<>?[]=\"'*",
                    new[]
                    {
                        onNameError("! \t\r\n@/<>?[]=\"'*", "!"),
                        onNameError("! \t\r\n@/<>?[]=\"'*", " "),
                        onNameError("! \t\r\n@/<>?[]=\"'*", "\t"),
                        onNameError("! \t\r\n@/<>?[]=\"'*", "\r"),
                        onNameError("! \t\r\n@/<>?[]=\"'*", "\n"),
                        onNameError("! \t\r\n@/<>?[]=\"'*", "@"),
                        onNameError("! \t\r\n@/<>?[]=\"'*", "/"),
                        onNameError("! \t\r\n@/<>?[]=\"'*", "<"),
                        onNameError("! \t\r\n@/<>?[]=\"'*", ">"),
                        onNameError("! \t\r\n@/<>?[]=\"'*", "?"),
                        onNameError("! \t\r\n@/<>?[]=\"'*", "["),
                        onNameError("! \t\r\n@/<>?[]=\"'*", "]"),
                        onNameError("! \t\r\n@/<>?[]=\"'*", "="),
                        onNameError("! \t\r\n@/<>?[]=\"'*", "\""),
                        onNameError("! \t\r\n@/<>?[]=\"'*", "'"),
                        onNameError("! \t\r\n@/<>?[]=\"'*", "*"),
                    }
                },
                {
                    "! \tv\ra\nl@i/d<>?[]=\"'*",
                    new[]
                    {
                        onNameError("! \tv\ra\nl@i/d<>?[]=\"'*", "!"),
                        onNameError("! \tv\ra\nl@i/d<>?[]=\"'*", " "),
                        onNameError("! \tv\ra\nl@i/d<>?[]=\"'*", "\t"),
                        onNameError("! \tv\ra\nl@i/d<>?[]=\"'*", "\r"),
                        onNameError("! \tv\ra\nl@i/d<>?[]=\"'*", "\n"),
                        onNameError("! \tv\ra\nl@i/d<>?[]=\"'*", "@"),
                        onNameError("! \tv\ra\nl@i/d<>?[]=\"'*", "/"),
                        onNameError("! \tv\ra\nl@i/d<>?[]=\"'*", "<"),
                        onNameError("! \tv\ra\nl@i/d<>?[]=\"'*", ">"),
                        onNameError("! \tv\ra\nl@i/d<>?[]=\"'*", "?"),
                        onNameError("! \tv\ra\nl@i/d<>?[]=\"'*", "["),
                        onNameError("! \tv\ra\nl@i/d<>?[]=\"'*", "]"),
                        onNameError("! \tv\ra\nl@i/d<>?[]=\"'*", "="),
                        onNameError("! \tv\ra\nl@i/d<>?[]=\"'*", "\""),
                        onNameError("! \tv\ra\nl@i/d<>?[]=\"'*", "'"),
                        onNameError("! \tv\ra\nl@i/d<>?[]=\"'*", "*"),
                    }
                },
            };

            if (onDataError != null)
            {
                data.Add("data-", new[] { onDataError("data-") });
                data.Add("data-something", new[] { onDataError("data-something") });
                data.Add("Data-Something", new[] { onDataError("Data-Something") });
                data.Add("DATA-SOMETHING", new[] { onDataError("DATA-SOMETHING") });
            }

            return data;
        }
Пример #15
0
        public static TheoryData <TOut1, TOut2, TOut3, TOut4, TOut5, TOut6, TOut7> Cast <TOut1, TOut2, TOut3, TOut4, TOut5, TOut6, TOut7, TIn1, TIn2, TIn3, TIn4, TIn5, TIn6, TIn7>(this TheoryData <TIn1, TIn2, TIn3, TIn4, TIn5, TIn6, TIn7> data)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            try
            {
                var outData = new TheoryData <TOut1, TOut2, TOut3, TOut4, TOut5, TOut6, TOut7>();
                foreach (var item in data)
                {
                    outData.Add(
                        (TOut1)Convert.ChangeType(item[0], typeof(TOut1)),
                        (TOut2)Convert.ChangeType(item[1], typeof(TOut2)),
                        (TOut3)Convert.ChangeType(item[2], typeof(TOut3)),
                        (TOut4)Convert.ChangeType(item[3], typeof(TOut4)),
                        (TOut5)Convert.ChangeType(item[4], typeof(TOut5)),
                        (TOut6)Convert.ChangeType(item[5], typeof(TOut6)),
                        (TOut7)Convert.ChangeType(item[6], typeof(TOut7)));
                }

                return(outData);
            }
            catch (Exception)
            {
                return(null);
            }
        }
        public static TheoryData<KeyValuePair<string, string[]>> CreditCards(CardIssuer cardIssuer)
        {
            var theoryData = new TheoryData<KeyValuePair<string, string[]>>();
            foreach (var creditCard in CreditCards()
                .SelectMany(item => item.Cast<KeyValuePair<string, string[]>>())
                .Where(x => x.Key.Equals(cardIssuer.ToString(), StringComparison.OrdinalIgnoreCase)))
            {
                theoryData.Add(creditCard);
            }

            return theoryData;
        }
Пример #17
0
        // helper method to generate data for the GetPreferredSizeCore test
        private static TheoryData <Button, Size, Size> GetPreferredSizeCoreTestData()
        {
            var data = new TheoryData <Button, Size, Size>();

            // first code path is FlatStyle != FlatStyle.System, AutoSizeMode = GrowAndShrink
            var b1 = new Button
            {
                FlatStyle    = FlatStyle.Flat,
                AutoSizeMode = AutoSizeMode.GrowAndShrink
            };
            var proposed1 = new Size(5, 5);
            var expected1 = new Size(8, 8);

            data.Add(b1, proposed1, expected1);

            // second code path is FlatStyle != FlatStyle.System, AutoSizeMode != GrowAndShrink
            var b2 = new Button
            {
                FlatStyle    = FlatStyle.Flat,
                AutoSizeMode = AutoSizeMode.GrowOnly
            };
            var proposed2 = new Size(5, 5);
            var expected2 = new Size(75, 23);

            data.Add(b2, proposed2, expected2);

            // third code path is FlatStyle == FlatStyle.System, button systemSize.Width is invalid
            // and AutoSizeMode = GrowAndShrink
            var b3 = new Button
            {
                // text and font need to be set since the code measures the size of the text
                Text         = "Hello World!",
                Font         = new Drawing.Font(Drawing.FontFamily.GenericMonospace, 1.5f),
                FlatStyle    = FlatStyle.System,
                AutoSizeMode = AutoSizeMode.GrowAndShrink
            };
            var proposed3 = new Size(100, 200);
            var expected3 = new Size(28, 12);

            data.Add(b3, proposed3, expected3);

            // fourth code path is FlatStyle == FlatStyle.System, button systemSize.Width is valid
            // and AutoSizeMode != GrowAndShrink
            var b4 = new Button
            {
                // text and font need to be set since the code measures the size of the text
                Text         = "Hello World!",
                Font         = new Drawing.Font(Drawing.FontFamily.GenericMonospace, 1.5f),
                FlatStyle    = FlatStyle.System,
                AutoSizeMode = AutoSizeMode.GrowOnly
            };
            var proposed4 = new Size(100, 200);

            // call getPreferredSizeCore once so the systemSize gets set
            b4.GetPreferredSizeCore(proposed4);
            var expected4 = new Size(75, 23);

            data.Add(b4, proposed4, expected4);

            return(data);
        }
Пример #18
0
        private static void AddUnwrapTamperedTheoryData(string testId, SecurityKey key, string algorithm, TheoryData <KeyWrapTestParams> theoryData)
        {
            var keyToWrap  = Guid.NewGuid().ToByteArray();
            var provider   = CryptoProviderFactory.Default.CreateKeyWrapProvider(key, algorithm);
            var wrappedKey = provider.WrapKey(keyToWrap);

            TestUtilities.XORBytes(wrappedKey);
            theoryData.Add(new KeyWrapTestParams
            {
                EncryptAlgorithm = algorithm,
                EncryptKey       = key,
                EE         = ExpectedException.KeyWrapException("IDX10659:"),
                Provider   = provider,
                WrappedKey = wrappedKey
            });
        }
Пример #19
0
 private static void AddWrapUnwrapTheoryData(string testId, string algorithm, SecurityKey key, TheoryData <KeyWrapTheoryData> theoryData)
 {
     theoryData.Add(new KeyWrapTheoryData
     {
         KeyToWrap     = Guid.NewGuid().ToByteArray(),
         WrapAlgorithm = algorithm,
         WrapKey       = key,
         TestId        = "AddWrapUnwrapTheoryData" + testId
     });
 }
Пример #20
0
 private static void AddUnwrapParameterCheckTheoryData(string testId, string algorithm, SecurityKey key, byte[] wrappedKey, ExpectedException ee, TheoryData <KeyWrapTestParams> theoryData)
 {
     theoryData.Add(new KeyWrapTestParams
     {
         EncryptAlgorithm = algorithm,
         EncryptKey       = key,
         WrappedKey       = wrappedKey,
         EE     = ee,
         TestId = testId
     });
 }
Пример #21
0
 private static void AddUnwrapMismatchTheoryData(string testId, SecurityKey encryptKey, SecurityKey decryptKey, string encryptAlg, string decryptAlg, ExpectedException ee, TheoryData <KeyWrapTheoryData> theoryData)
 {
     theoryData.Add(new KeyWrapTheoryData
     {
         ExpectedException = ee,
         TestId            = testId,
         UnwrapAlgorithm   = decryptAlg,
         UnwrapKey         = decryptKey,
         WrapAlgorithm     = encryptAlg,
         WrapKey           = encryptKey
     });
 }
Пример #22
0
        private static void AddWaSignInVariation(IList <Claim> claims, string variation, TheoryData <WsFederationSigninMessageTheoryData> theoryData)
        {
            var samlToken = CreateSamlToken(claims);
            var samlSecurityTokenHandler = new SamlSecurityTokenHandler();

            theoryData.Add(new WsFederationSigninMessageTheoryData
            {
                QueryString          = WsFederationTestUtilities.BuildWaSignInMessage(samlToken, samlSecurityTokenHandler, "saml1" + variation),
                SecurityToken        = samlToken,
                SecurityTokenHandler = samlSecurityTokenHandler,
                TestId = "Saml1WriteToken" + variation
            });

            theoryData.Add(new WsFederationSigninMessageTheoryData
            {
                QueryString          = WsFederationTestUtilities.BuildWaSignInMessage(samlSecurityTokenHandler.WriteToken(samlToken), "saml1" + variation),
                SecurityToken        = samlToken,
                SecurityTokenHandler = samlSecurityTokenHandler,
                TestId = "Saml1SetToken" + variation
            });

            // this results in %0D in the query string
            var saml = samlSecurityTokenHandler.WriteToken(samlToken).Replace("&#xD;", "\r");

            theoryData.Add(new WsFederationSigninMessageTheoryData
            {
                QueryString          = WsFederationTestUtilities.BuildWaSignInMessage(saml, "saml1" + variation),
                SecurityToken        = samlToken,
                SecurityTokenHandler = samlSecurityTokenHandler,
                TestId = "Saml1SetTokenReplace" + variation
            });

            var saml2Token = CreateSaml2Token(claims);
            var saml2SecurityTokenHandler = new Saml2SecurityTokenHandler();

            theoryData.Add(new WsFederationSigninMessageTheoryData
            {
                QueryString          = WsFederationTestUtilities.BuildWaSignInMessage(saml2Token, saml2SecurityTokenHandler, "saml2" + variation),
                SecurityToken        = saml2Token,
                SecurityTokenHandler = saml2SecurityTokenHandler,
                TestId = "Saml2WriteToken" + variation
            });

            theoryData.Add(new WsFederationSigninMessageTheoryData
            {
                QueryString          = WsFederationTestUtilities.BuildWaSignInMessage(saml2SecurityTokenHandler.WriteToken(saml2Token), "saml2" + variation),
                SecurityToken        = saml2Token,
                SecurityTokenHandler = saml2SecurityTokenHandler,
                TestId = "Saml2SetToken" + variation
            });

            // this results in %0D in the query string
            var saml2 = saml2SecurityTokenHandler.WriteToken(saml2Token).Replace("&#xD;", "\r");

            theoryData.Add(new WsFederationSigninMessageTheoryData
            {
                QueryString          = WsFederationTestUtilities.BuildWaSignInMessage(saml2, "saml2" + variation),
                SecurityToken        = saml2Token,
                SecurityTokenHandler = saml2SecurityTokenHandler,
                TestId = "Saml2SetTokenReplace" + variation
            });
        }
Пример #23
0
 private static void AddUnwrapParameterCheckTheoryData(string testId, string algorithm, SecurityKey key, byte[] wrappedKey, ExpectedException ee, TheoryData <KeyWrapTheoryData> theoryData)
 {
     theoryData.Add(new KeyWrapTheoryData
     {
         ExpectedException = ee,
         TestId            = testId,
         WrapAlgorithm     = algorithm,
         WrapKey           = key,
         WrappedKey        = wrappedKey
     });
 }
Пример #24
0
        public static TheoryData <CreateAndValidateParams> CreationParams()
        {
            var createParams       = new TheoryData <CreateAndValidateParams>();
            var expires            = DateTime.UtcNow + TimeSpan.FromDays(1);
            var handler            = new JwtSecurityTokenHandler();
            var nbf                = DateTime.UtcNow;
            var signingCredentials = new SigningCredentials(KeyingMaterial.X509SecurityKeySelfSigned2048_SHA256, SecurityAlgorithms.RsaSha256Signature);
            var verifyingKey       = KeyingMaterial.X509SecurityKeySelfSigned2048_SHA256_Public;

            createParams.Add(new CreateAndValidateParams
            {
                Case = "ClaimSets.NoClaims",
                SecurityTokenDescriptor   = IdentityUtilities.DefaultAsymmetricSecurityTokenDescriptor(null),
                TokenValidationParameters = IdentityUtilities.DefaultAsymmetricTokenValidationParameters,
            });

            createParams.Add(new CreateAndValidateParams
            {
                Case = "EmptyToken",
                SecurityTokenDescriptor   = new SecurityTokenDescriptor(),
                TokenValidationParameters = new TokenValidationParameters
                {
                    RequireSignedTokens = false,
                    ValidateAudience    = false,
                    ValidateLifetime    = false,
                    ValidateIssuer      = false,
                }
            });

            createParams.Add(new CreateAndValidateParams
            {
                Case                      = "ClaimSets.DuplicateTypes",
                ExceptionType             = null,
                SecurityTokenDescriptor   = IdentityUtilities.DefaultAsymmetricSecurityTokenDescriptor(ClaimSets.DuplicateTypes()),
                TokenValidationParameters = IdentityUtilities.DefaultAsymmetricTokenValidationParameters,
            });

            createParams.Add(new CreateAndValidateParams
            {
                Case                      = "ClaimSets.Simple_Asymmetric",
                ExceptionType             = null,
                SecurityTokenDescriptor   = IdentityUtilities.DefaultAsymmetricSecurityTokenDescriptor(ClaimSets.DefaultClaims),
                TokenValidationParameters = IdentityUtilities.DefaultAsymmetricTokenValidationParameters
            });

            createParams.Add(new CreateAndValidateParams
            {
                Case                      = "ClaimSets.Simple_Symmetric",
                ExceptionType             = null,
                SecurityTokenDescriptor   = IdentityUtilities.DefaultSymmetricSecurityTokenDescriptor(ClaimSets.DefaultClaims),
                TokenValidationParameters = IdentityUtilities.DefaultSymmetricTokenValidationParameters
            });

            createParams.Add(new CreateAndValidateParams
            {
                Case                      = "ClaimSets.RoleClaims",
                ExceptionType             = null,
                SecurityTokenDescriptor   = IdentityUtilities.DefaultSymmetricSecurityTokenDescriptor(ClaimSets.GetDefaultRoleClaims(handler)),
                TokenValidationParameters = IdentityUtilities.DefaultSymmetricTokenValidationParameters
            });

            return(createParams);
        }
        public static TheoryData <JwtTheoryData> InvalidRegExSegmentsData(string errorString, TheoryData <JwtTheoryData> theoryData)
        {
            var validRegEx   = "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9";
            var invalidRegEx = "eyJpc3MiOiJodHRwOi8vR290Snd0LmNvbSIsImF1Z CI6Imh0";

            theoryData.Add(new JwtTheoryData
            {
                CanRead           = false,
                TestId            = "'invalidRegEx: first position'",
                Token             = invalidRegEx + "." + validRegEx + "." + validRegEx + "." + validRegEx + "." + validRegEx,
                ExpectedException = ExpectedException.ArgumentException(errorString)
            });
            theoryData.Add(new JwtTheoryData
            {
                CanRead           = false,
                TestId            = "'invalidRegEx: second position'",
                Token             = validRegEx + "." + invalidRegEx + "." + validRegEx + "." + validRegEx + "." + validRegEx,
                ExpectedException = ExpectedException.ArgumentException(errorString)
            });
            theoryData.Add(new JwtTheoryData
            {
                CanRead           = false,
                TestId            = "'invalidRegEx: third position'",
                Token             = validRegEx + "." + validRegEx + "." + invalidRegEx + "." + validRegEx + "." + validRegEx,
                ExpectedException = ExpectedException.ArgumentException(errorString)
            });
            theoryData.Add(new JwtTheoryData
            {
                CanRead           = false,
                TestId            = "'invalidRegEx: fourth position'",
                Token             = validRegEx + "." + validRegEx + "." + validRegEx + "." + invalidRegEx + "." + validRegEx,
                ExpectedException = ExpectedException.ArgumentException(errorString)
            });
            theoryData.Add(new JwtTheoryData
            {
                CanRead           = false,
                TestId            = "'invalidRegEx: fifth position'",
                Token             = validRegEx + "." + validRegEx + "." + validRegEx + "." + validRegEx + "." + invalidRegEx,
                ExpectedException = ExpectedException.ArgumentException(errorString)
            });
            theoryData.Add(new JwtTheoryData
            {
                CanRead           = false,
                TestId            = "'invalidRegEx: first position (dir)'",
                Token             = invalidRegEx + ".." + validRegEx + "." + validRegEx + "." + validRegEx,
                ExpectedException = ExpectedException.ArgumentException(errorString)
            });
            theoryData.Add(new JwtTheoryData
            {
                CanRead           = false,
                TestId            = "'invalidRegEx: third position (dir)'",
                Token             = validRegEx + ".." + invalidRegEx + "." + validRegEx + "." + validRegEx,
                ExpectedException = ExpectedException.ArgumentException(errorString)
            });
            theoryData.Add(new JwtTheoryData
            {
                CanRead           = false,
                TestId            = "'invalidRegEx: fourth position (dir)'",
                Token             = invalidRegEx + ".." + validRegEx + "." + invalidRegEx + "." + validRegEx,
                ExpectedException = ExpectedException.ArgumentException(errorString)
            });
            theoryData.Add(new JwtTheoryData
            {
                CanRead           = false,
                TestId            = "'invalidRegEx: fifth position (dir)'",
                Token             = invalidRegEx + ".." + validRegEx + "." + validRegEx + "." + invalidRegEx,
                ExpectedException = ExpectedException.ArgumentException(errorString)
            });
            theoryData.Add(new JwtTheoryData
            {
                CanRead           = false,
                TestId            = "'invalidRegEx: first position (dir, Cipher text missing)'",
                Token             = invalidRegEx + "." + validRegEx + "." + validRegEx,
                ExpectedException = ExpectedException.ArgumentException(errorString)
            });
            theoryData.Add(new JwtTheoryData
            {
                CanRead           = false,
                TestId            = "'invalidRegEx: third position (dir, Cipher text missing)'",
                Token             = validRegEx + "." + invalidRegEx + "." + validRegEx,
                ExpectedException = ExpectedException.ArgumentException(errorString)
            });
            theoryData.Add(new JwtTheoryData
            {
                CanRead           = false,
                TestId            = "'invalidRegEx: third position (four parts)'",
                Token             = validRegEx + "." + invalidRegEx + ".",
                ExpectedException = ExpectedException.ArgumentException(errorString)
            });
            theoryData.Add(new JwtTheoryData
            {
                CanRead           = false,
                TestId            = "'invalidRegEx: fifth position (dir, Cipher text missing)'",
                Token             = validRegEx + "." + validRegEx + "." + invalidRegEx,
                ExpectedException = ExpectedException.ArgumentException(errorString)
            });
            theoryData.Add(new JwtTheoryData
            {
                CanRead           = false,
                TestId            = "'Encoding == SignedEncodedJwts.Asymmetric_LocalSts'",
                Token             = "SignedEncodedJwts.Asymmetric_LocalSts",
                ExpectedException = ExpectedException.ArgumentException(errorString)
            });

            return(theoryData);
        }
Пример #26
0
        private static void AddDecryptTamperedTheoryData(string testId, SymmetricSecurityKey key, string algorithm, TheoryData <AuthenticatedEncryptionTestParams> theoryData)
        {
            var authenticatedData = Guid.NewGuid().ToByteArray();
            var plainText         = Guid.NewGuid().ToByteArray();
            var provider          = new AuthenticatedEncryptionProvider(key, algorithm);
            var results           = provider.Encrypt(plainText, authenticatedData);

            theoryData.Add(new AuthenticatedEncryptionTestParams
            {
                AuthenticatedData = Guid.NewGuid().ToByteArray(),
                DecryptAlgorithm  = algorithm,
                DecryptKey        = key,
                EE = ExpectedException.SecurityTokenDecryptionFailedException("IDX10650:"),
                EncryptAlgorithm  = algorithm,
                EncryptKey        = key,
                EncryptionResults = results,
                Provider          = provider,
                TestId            = "AddDecryptTheoryData1_" + testId
            });

            results = provider.Encrypt(plainText, authenticatedData);
            TestUtilities.XORBytes(results.IV);
            theoryData.Add(new AuthenticatedEncryptionTestParams
            {
                AuthenticatedData = authenticatedData,
                DecryptAlgorithm  = algorithm,
                DecryptKey        = key,
                EE = ExpectedException.SecurityTokenDecryptionFailedException("IDX10650:"),
                EncryptAlgorithm  = algorithm,
                EncryptKey        = key,
                EncryptionResults = results,
                Provider          = provider,
                TestId            = "AddDecryptTheoryData2_" + testId
            });

            results = provider.Encrypt(plainText, authenticatedData);
            TestUtilities.XORBytes(results.AuthenticationTag);
            theoryData.Add(new AuthenticatedEncryptionTestParams
            {
                AuthenticatedData = authenticatedData,
                DecryptAlgorithm  = algorithm,
                DecryptKey        = key,
                EE = ExpectedException.SecurityTokenDecryptionFailedException("IDX10650:"),
                EncryptAlgorithm  = algorithm,
                EncryptKey        = key,
                EncryptionResults = results,
                Provider          = provider,
                TestId            = "AddDecryptTheoryData3_" + testId
            });

            results = provider.Encrypt(plainText, authenticatedData);
            TestUtilities.XORBytes(results.Ciphertext);
            theoryData.Add(new AuthenticatedEncryptionTestParams
            {
                AuthenticatedData = authenticatedData,
                DecryptAlgorithm  = algorithm,
                DecryptKey        = key,
                EE = ExpectedException.SecurityTokenDecryptionFailedException("IDX10650:"),
                EncryptAlgorithm  = algorithm,
                EncryptKey        = key,
                EncryptionResults = results,
                Provider          = provider,
                TestId            = "AddDecryptTheoryData4_" + testId
            });
        }
        public static TheoryData <JwtTheoryData> InvalidEncodedSegmentsData(string errorString, TheoryData <JwtTheoryData> theoryData)
        {
            theoryData.Add(new JwtTheoryData
            {
                CanRead           = true,
                TestId            = nameof(EncodedJwts.InvalidPayload),
                Token             = EncodedJwts.InvalidPayload,
                ExpectedException = ExpectedException.ArgumentException(substringExpected: "IDX12723:", inner: typeof(JsonReaderException))
            });

            return(theoryData);
        }
Пример #28
0
 private static void AddEncryptDecryptTheoryData(string testId, string algorithm, SymmetricSecurityKey key, TheoryData <AuthenticatedEncryptionTestParams> theoryData)
 {
     theoryData.Add(new AuthenticatedEncryptionTestParams
     {
         AuthenticatedData = Guid.NewGuid().ToByteArray(),
         DecryptAlgorithm  = algorithm,
         DecryptKey        = key,
         EE = ExpectedException.NoExceptionExpected,
         EncryptAlgorithm = algorithm,
         EncryptKey       = key,
         Plaintext        = Guid.NewGuid().ToByteArray(),
         TestId           = "AddEncryptDecryptTheoryData_" + testId
     });
 }
        public static TheoryData <JwtTheoryData> InvalidNumberOfSegmentsData(string errorString, TheoryData <JwtTheoryData> theoryData)
        {
            theoryData.Add(new JwtTheoryData
            {
                CanRead           = false,
                ExpectedException = ExpectedException.ArgumentNullException(),
                TestId            = "null"
            });

            theoryData.Add(new JwtTheoryData
            {
                CanRead           = false,
                ExpectedException = ExpectedException.ArgumentNullException(),
                TestId            = "emptystring",
                Token             = ""
            });
            theoryData.Add(new JwtTheoryData
            {
                CanRead           = false,
                ExpectedException = ExpectedException.ArgumentException(errorString),
                TestId            = "a",
                Token             = "a"
            });
            theoryData.Add(new JwtTheoryData
            {
                CanRead           = false,
                ExpectedException = ExpectedException.ArgumentException(errorString),
                TestId            = "a.b",
                Token             = "a.b"
            });
            theoryData.Add(new JwtTheoryData
            {
                CanRead           = false,
                ExpectedException = ExpectedException.ArgumentException(errorString),
                TestId            = "a.b.c.d",
                Token             = "a.b.c.d"
            });
            theoryData.Add(new JwtTheoryData
            {
                CanRead           = false,
                ExpectedException = ExpectedException.ArgumentException(errorString),
                TestId            = "a.b.c.d.e.f",
                Token             = "a.b.c.d.e.f"
            });

            return(theoryData);
        }
Пример #30
0
        private static void SetDataSet(List <Claim> claims, TheoryData <List <Claim>, JwtPayload, JwtPayload> dataset)
        {
            var payloadDirect = new JwtPayload();
            var jobj          = new JObject();

            foreach (var claim in claims)
            {
                object jsonValue = null;
                object existingValue;
                switch (claim.ValueType)
                {
                case ClaimValueTypes.String:
                    jsonValue = claim.Value;
                    break;

                case ClaimValueTypes.Boolean:
                    jsonValue = bool.Parse(claim.Value);
                    break;

                case ClaimValueTypes.Double:
                    jsonValue = double.Parse(claim.Value);
                    break;

                case ClaimValueTypes.Integer:
                case ClaimValueTypes.Integer32:
                    jsonValue = int.Parse(claim.Value);
                    break;

                case ClaimValueTypes.Integer64:
                    jsonValue = long.Parse(claim.Value);
                    break;

                case JsonClaimValueTypes.Json:
                    jsonValue = JObject.Parse(claim.Value);
                    break;

                case JsonClaimValueTypes.JsonArray:
                    jsonValue = JArray.Parse(claim.Value);
                    break;
                }

                JToken jtoken = null;
                if (jobj.TryGetValue(claim.Type, out jtoken))
                {
                    JArray jarray = jtoken as JArray;
                    if (jarray == null)
                    {
                        jarray = new JArray();
                        jarray.Add(jtoken);
                        jobj.Remove(claim.Type);
                        jobj.Add(claim.Type, jarray);
                    }

                    jarray.Add(JToken.FromObject(jsonValue));
                }
                else
                {
                    jobj.Add(claim.Type, JToken.FromObject(jsonValue));
                }

                if (payloadDirect.TryGetValue(claim.Type, out existingValue))
                {
                    IList <object> claimValues = existingValue as IList <object>;
                    if (claimValues == null)
                    {
                        claimValues = new List <object>();
                        claimValues.Add(existingValue);
                        payloadDirect[claim.Type] = claimValues;
                    }

                    claimValues.Add(jsonValue);
                }
                else
                {
                    payloadDirect[claim.Type] = jsonValue;
                }
            }

            var j = jobj.ToString(Formatting.None);
            var payloadDeserialized = JwtPayload.Deserialize(j);

            dataset.Add(claims, payloadDirect, payloadDeserialized);
        }
Пример #31
0
        public static TheoryData <string, SecurityTokenDescriptor, TokenValidationParameters, ExpectedException> RoundTripJWEParams()
        {
            var theoryData = new TheoryData <string, SecurityTokenDescriptor, TokenValidationParameters, ExpectedException>();

            theoryData.Add(
                "Test1",
                Default.SymmetricEncryptSignSecurityTokenDescriptor(),
                Default.SymmetricEncryptSignTokenValidationParameters,
                ExpectedException.NoExceptionExpected
                );

            theoryData.Add(
                "Test2",
                Default.SecurityTokenDescriptor(Default.SymmetricEncryptingCredentials, Default.SymmetricSigningCredentials, ClaimSets.DefaultClaims),
                Default.TokenValidationParameters(Default.SymmetricEncryptionKey256, Default.SymmetricSigningKey256),
                ExpectedException.NoExceptionExpected
                );

            var encryptingCredentials = new EncryptingCredentials(KeyingMaterial.RsaSecurityKey_2048, SecurityAlgorithms.RsaPKCS1, SecurityAlgorithms.Aes128CbcHmacSha256);

            theoryData.Add(
                "Test3",
                Default.SecurityTokenDescriptor(encryptingCredentials, Default.SymmetricSigningCredentials, ClaimSets.DefaultClaims),
                Default.TokenValidationParameters(KeyingMaterial.RsaSecurityKey_2048, Default.SymmetricSigningKey256),
                ExpectedException.NoExceptionExpected
                );

            encryptingCredentials = new EncryptingCredentials(KeyingMaterial.RsaSecurityKey_2048, SecurityAlgorithms.RsaPKCS1, SecurityAlgorithms.Aes192CbcHmacSha384);
            theoryData.Add(
                "RsaPKCS1-Aes192CbcHmacSha384",
                Default.SecurityTokenDescriptor(encryptingCredentials, Default.SymmetricSigningCredentials, ClaimSets.DefaultClaims),
                Default.TokenValidationParameters(KeyingMaterial.RsaSecurityKey_2048, Default.SymmetricSigningKey256),
                ExpectedException.NoExceptionExpected
                );

            encryptingCredentials = new EncryptingCredentials(KeyingMaterial.RsaSecurityKey_2048, SecurityAlgorithms.RsaPKCS1, SecurityAlgorithms.Aes256CbcHmacSha512);
            theoryData.Add(
                "RsaPKCS1-Aes256CbcHmacSha512",
                Default.SecurityTokenDescriptor(encryptingCredentials, Default.SymmetricSigningCredentials, ClaimSets.DefaultClaims),
                Default.TokenValidationParameters(KeyingMaterial.RsaSecurityKey_2048, Default.SymmetricSigningKey256),
                ExpectedException.NoExceptionExpected
                );

            encryptingCredentials = new EncryptingCredentials(KeyingMaterial.RsaSecurityKey_2048, SecurityAlgorithms.RsaOAEP, SecurityAlgorithms.Aes128CbcHmacSha256);
            theoryData.Add(
                "RsaOAEP-Aes128CbcHmacSha256",
                Default.SecurityTokenDescriptor(encryptingCredentials, Default.SymmetricSigningCredentials, ClaimSets.DefaultClaims),
                Default.TokenValidationParameters(KeyingMaterial.RsaSecurityKey_2048, Default.SymmetricSigningKey256),
                ExpectedException.NoExceptionExpected
                );

            encryptingCredentials = new EncryptingCredentials(KeyingMaterial.RsaSecurityKey_2048, SecurityAlgorithms.RsaOAEP, SecurityAlgorithms.Aes192CbcHmacSha384);
            theoryData.Add(
                "RsaOAEP-Aes192CbcHmacSha384",
                Default.SecurityTokenDescriptor(encryptingCredentials, Default.SymmetricSigningCredentials, ClaimSets.DefaultClaims),
                Default.TokenValidationParameters(KeyingMaterial.RsaSecurityKey_2048, Default.SymmetricSigningKey256),
                ExpectedException.NoExceptionExpected
                );

            encryptingCredentials = new EncryptingCredentials(KeyingMaterial.RsaSecurityKey_2048, SecurityAlgorithms.RsaOAEP, SecurityAlgorithms.Aes256CbcHmacSha512);
            theoryData.Add(
                "RsaOAEP-Aes256CbcHmacSha512",
                Default.SecurityTokenDescriptor(encryptingCredentials, Default.SymmetricSigningCredentials, ClaimSets.DefaultClaims),
                Default.TokenValidationParameters(KeyingMaterial.RsaSecurityKey_2048, Default.SymmetricSigningKey256),
                ExpectedException.NoExceptionExpected
                );

            encryptingCredentials = new EncryptingCredentials(KeyingMaterial.RsaSecurityKey_2048, SecurityAlgorithms.RsaOaepKeyWrap, SecurityAlgorithms.Aes128CbcHmacSha256);
            theoryData.Add(
                "RsaOaepKeyWrap-Aes128CbcHmacSha256",
                Default.SecurityTokenDescriptor(encryptingCredentials, Default.SymmetricSigningCredentials, ClaimSets.DefaultClaims),
                Default.TokenValidationParameters(KeyingMaterial.RsaSecurityKey_2048, Default.SymmetricSigningKey256),
                ExpectedException.NoExceptionExpected
                );

            encryptingCredentials = new EncryptingCredentials(KeyingMaterial.RsaSecurityKey_2048, SecurityAlgorithms.RsaOaepKeyWrap, SecurityAlgorithms.Aes192CbcHmacSha384);
            theoryData.Add(
                "RsaOaepKeyWrap-Aes192CbcHmacSha384",
                Default.SecurityTokenDescriptor(encryptingCredentials, Default.SymmetricSigningCredentials, ClaimSets.DefaultClaims),
                Default.TokenValidationParameters(KeyingMaterial.RsaSecurityKey_2048, Default.SymmetricSigningKey256),
                ExpectedException.NoExceptionExpected
                );

            encryptingCredentials = new EncryptingCredentials(KeyingMaterial.RsaSecurityKey_2048, SecurityAlgorithms.RsaOaepKeyWrap, SecurityAlgorithms.Aes256CbcHmacSha512);
            theoryData.Add(
                "RsaOaepKeyWrap-Aes256CbcHmacSha512",
                Default.SecurityTokenDescriptor(encryptingCredentials, Default.SymmetricSigningCredentials, ClaimSets.DefaultClaims),
                Default.TokenValidationParameters(KeyingMaterial.RsaSecurityKey_2048, Default.SymmetricSigningKey256),
                ExpectedException.NoExceptionExpected
                );

            // signing key not found
            theoryData.Add(
                "SigningKey-Not-Found",
                Default.SymmetricEncryptSignSecurityTokenDescriptor(),
                new TokenValidationParameters
            {
                IssuerSigningKey   = NotDefault.SymmetricSigningKey256,
                TokenDecryptionKey = Default.SymmetricEncryptionKey256,
            },
                ExpectedException.SecurityTokenSignatureKeyNotFoundException("IDX10501:")
                );

            // encryption key not found
            theoryData.Add(
                "EncryptionKey-Not-Found",
                Default.SymmetricEncryptSignSecurityTokenDescriptor(),
                new TokenValidationParameters
            {
                IssuerSigningKey   = Default.SymmetricSigningKey256,
                TokenDecryptionKey = NotDefault.SymmetricEncryptionKey,
            },
                ExpectedException.SecurityTokenDecryptionFailedException("IDX10603:")
                );

            // symmetric key wrap
            encryptingCredentials = new EncryptingCredentials(KeyingMaterial.SymmetricSecurityKey2_128, SecurityAlgorithms.Aes128KW, SecurityAlgorithms.Aes128CbcHmacSha256);
            theoryData.Add(
                "SymmetricSecurityKey2_128-Aes128KW-Aes128CbcHmacSha256",
                Default.SecurityTokenDescriptor(encryptingCredentials, Default.SymmetricSigningCredentials, ClaimSets.DefaultClaims),
                Default.TokenValidationParameters(KeyingMaterial.SymmetricSecurityKey2_128, Default.SymmetricSigningKey256),
                ExpectedException.NoExceptionExpected
                );

            encryptingCredentials = new EncryptingCredentials(Default.SymmetricEncryptionKey256, SecurityAlgorithms.Aes256KW, SecurityAlgorithms.Aes128CbcHmacSha256);
            theoryData.Add(
                "SymmetricEncryptionKey256-Aes256KW-Aes128CbcHmacSha256",
                Default.SecurityTokenDescriptor(encryptingCredentials, Default.SymmetricSigningCredentials, ClaimSets.DefaultClaims),
                Default.TokenValidationParameters(Default.SymmetricEncryptionKey256, Default.SymmetricSigningKey256),
                ExpectedException.NoExceptionExpected
                );

            encryptingCredentials = new EncryptingCredentials(KeyingMaterial.RsaSecurityKey_2048, SecurityAlgorithms.RsaOaepKeyWrap, SecurityAlgorithms.Aes192CbcHmacSha384);
            theoryData.Add(
                "RsaOaepKeyWrap-Aes192CbcHmacSha384",
                Default.SecurityTokenDescriptor(encryptingCredentials, Default.SymmetricSigningCredentials, ClaimSets.DefaultClaims),
                Default.TokenValidationParameters(KeyingMaterial.RsaSecurityKey_2048, Default.SymmetricSigningKey256),
                ExpectedException.NoExceptionExpected
                );

            return(theoryData);
        }
Пример #32
0
        public static void Add <T1, T2, T3, T4, T5, T6>(this TheoryData <T1, T2, T3, T4, T5, T6> data, TheoryData <T1, T2, T3, T4, T5, T6> dataToAdd)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }
            if (dataToAdd == null)
            {
                return;
            }

            foreach (var item in dataToAdd)
            {
                data.Add((T1)item[0], (T2)item[1], (T3)item[2], (T4)item[3], (T5)item[4], (T6)item[5]);
            }
        }
        static PrimePowerOrderFieldTests()
        {
            Gf8  = new PrimePowerOrderField(8, new Polynomial(new PrimeOrderField(2), 1, 1, 0, 1));
            Gf27 = new PrimePowerOrderField(27, new Polynomial(new PrimeOrderField(3), 2, 2, 0, 1));

            IncorrectFieldCreationTestsData
                = new TheoryData <IncorrectFieldCreationTestCase>
                {
                new IncorrectFieldCreationTestCase {
                    FieldOrder = 8
                },
                new IncorrectFieldCreationTestCase
                {
                    FieldOrder            = 8,
                    IrreduciblePolynomial = new Polynomial(new PrimeOrderField(3), 1)
                },
                new IncorrectFieldCreationTestCase
                {
                    FieldOrder            = 8,
                    IrreduciblePolynomial = new Polynomial(new PrimeOrderField(2), 1)
                },
                new IncorrectFieldCreationTestCase
                {
                    FieldOrder            = 8,
                    IrreduciblePolynomial = new Polynomial(new PrimeOrderField(2), 0, 0, 0, 1)
                }
                };

            SumTestsData
                = new TheoryData <BinaryOperationTestCase>
                {
                new BinaryOperationTestCase {
                    Field = Gf8, FirstOperand = 3, SecondOperand = 4, Expected = 7
                },
                new BinaryOperationTestCase {
                    Field = Gf8, FirstOperand = 1, SecondOperand = 3, Expected = 2
                },
                new BinaryOperationTestCase {
                    Field = Gf8, FirstOperand = 1, SecondOperand = 6, Expected = 7
                },
                new BinaryOperationTestCase {
                    Field = Gf8, FirstOperand = 5, SecondOperand = 6, Expected = 3
                },
                new BinaryOperationTestCase {
                    Field = Gf8, FirstOperand = 4, SecondOperand = 7, Expected = 3
                },
                new BinaryOperationTestCase {
                    Field = Gf8, FirstOperand = 5, SecondOperand = 5, Expected = 0
                },
                new BinaryOperationTestCase {
                    Field = Gf27, FirstOperand = 3, SecondOperand = 4, Expected = 7
                },
                new BinaryOperationTestCase {
                    Field = Gf27, FirstOperand = 10, SecondOperand = 12, Expected = 22
                },
                new BinaryOperationTestCase {
                    Field = Gf27, FirstOperand = 11, SecondOperand = 10, Expected = 18
                },
                new BinaryOperationTestCase {
                    Field = Gf27, FirstOperand = 18, SecondOperand = 9, Expected = 0
                },
                new BinaryOperationTestCase {
                    Field = Gf27, FirstOperand = 20, SecondOperand = 17, Expected = 7
                },
                new BinaryOperationTestCase {
                    Field = Gf27, FirstOperand = 9, SecondOperand = 21, Expected = 3
                }
                };
            SubtractTestsData
                = new TheoryData <BinaryOperationTestCase>
                {
                new BinaryOperationTestCase {
                    Field = Gf8, FirstOperand = 3, SecondOperand = 4, Expected = 7
                },
                new BinaryOperationTestCase {
                    Field = Gf8, FirstOperand = 1, SecondOperand = 3, Expected = 2
                },
                new BinaryOperationTestCase {
                    Field = Gf8, FirstOperand = 1, SecondOperand = 6, Expected = 7
                },
                new BinaryOperationTestCase {
                    Field = Gf8, FirstOperand = 5, SecondOperand = 6, Expected = 3
                },
                new BinaryOperationTestCase {
                    Field = Gf8, FirstOperand = 4, SecondOperand = 7, Expected = 3
                },
                new BinaryOperationTestCase {
                    Field = Gf8, FirstOperand = 5, SecondOperand = 5, Expected = 0
                },
                new BinaryOperationTestCase {
                    Field = Gf27, FirstOperand = 3, SecondOperand = 4, Expected = 2
                },
                new BinaryOperationTestCase {
                    Field = Gf27, FirstOperand = 10, SecondOperand = 12, Expected = 7
                },
                new BinaryOperationTestCase {
                    Field = Gf27, FirstOperand = 11, SecondOperand = 14, Expected = 6
                },
                new BinaryOperationTestCase {
                    Field = Gf27, FirstOperand = 18, SecondOperand = 9, Expected = 9
                },
                new BinaryOperationTestCase {
                    Field = Gf27, FirstOperand = 20, SecondOperand = 17, Expected = 12
                },
                new BinaryOperationTestCase {
                    Field = Gf27, FirstOperand = 9, SecondOperand = 21, Expected = 24
                }
                };
            MultiplyTestsData
                = new TheoryData <BinaryOperationTestCase>
                {
                new BinaryOperationTestCase {
                    Field = Gf8, FirstOperand = 0, SecondOperand = 4, Expected = 0
                },
                new BinaryOperationTestCase {
                    Field = Gf8, FirstOperand = 2, SecondOperand = 4, Expected = 3
                },
                new BinaryOperationTestCase {
                    Field = Gf8, FirstOperand = 3, SecondOperand = 4, Expected = 7
                },
                new BinaryOperationTestCase {
                    Field = Gf8, FirstOperand = 2, SecondOperand = 3, Expected = 6
                },
                new BinaryOperationTestCase {
                    Field = Gf8, FirstOperand = 6, SecondOperand = 7, Expected = 4
                },
                new BinaryOperationTestCase {
                    Field = Gf8, FirstOperand = 2, SecondOperand = 7, Expected = 5
                },
                new BinaryOperationTestCase {
                    Field = Gf27, FirstOperand = 0, SecondOperand = 4, Expected = 0
                },
                new BinaryOperationTestCase {
                    Field = Gf27, FirstOperand = 12, SecondOperand = 5, Expected = 1
                },
                new BinaryOperationTestCase {
                    Field = Gf27, FirstOperand = 3, SecondOperand = 4, Expected = 12
                },
                new BinaryOperationTestCase {
                    Field = Gf27, FirstOperand = 21, SecondOperand = 3, Expected = 17
                },
                new BinaryOperationTestCase {
                    Field = Gf27, FirstOperand = 20, SecondOperand = 21, Expected = 26
                },
                new BinaryOperationTestCase {
                    Field = Gf27, FirstOperand = 2, SecondOperand = 7, Expected = 5
                }
                };
            DivideTestsData
                = new TheoryData <BinaryOperationTestCase>
                {
                new BinaryOperationTestCase {
                    Field = Gf8, FirstOperand = 0, SecondOperand = 3, Expected = 0
                },
                new BinaryOperationTestCase {
                    Field = Gf8, FirstOperand = 4, SecondOperand = 3, Expected = 5
                },
                new BinaryOperationTestCase {
                    Field = Gf8, FirstOperand = 7, SecondOperand = 2, Expected = 6
                },
                new BinaryOperationTestCase {
                    Field = Gf8, FirstOperand = 2, SecondOperand = 7, Expected = 3
                },
                new BinaryOperationTestCase {
                    Field = Gf27, FirstOperand = 0, SecondOperand = 3, Expected = 0
                },
                new BinaryOperationTestCase {
                    Field = Gf27, FirstOperand = 15, SecondOperand = 7, Expected = 6
                },
                new BinaryOperationTestCase {
                    Field = Gf27, FirstOperand = 11, SecondOperand = 26, Expected = 14
                },
                new BinaryOperationTestCase {
                    Field = Gf27, FirstOperand = 10, SecondOperand = 17, Expected = 15
                },
                new BinaryOperationTestCase {
                    Field = Gf27, FirstOperand = 2, SecondOperand = 23, Expected = 25
                }
                };
        }