public static bool OneOrMoreExpiredKeysHaveNoKeyIdentifier(RijndaelEncryptionServiceConfig section) { return section .ExpiredKeys .Cast<RijndaelExpiredKey>() .Any(x => string.IsNullOrEmpty(x.KeyIdentifier)); }
public static bool ExpiredKeysHaveWhiteSpace(RijndaelEncryptionServiceConfig section) { return section .ExpiredKeys .Cast<RijndaelExpiredKey>() .Any(x => string.IsNullOrWhiteSpace(x.Key)); }
public static bool EncryptionKeyListedInExpiredKeys(RijndaelEncryptionServiceConfig section) { return section .ExpiredKeys .Cast<RijndaelExpiredKey>() .Any(x => x.Key == section.Key); }
public static bool ExpiredKeysHaveDuplicateKeys(RijndaelEncryptionServiceConfig section) { var items = section .ExpiredKeys .Cast<RijndaelExpiredKey>() .ToList(); return items.Count != items.Select(x => x.Key).Distinct().Count(); }
public void Should_be_true_when_encryption_key_in_expirede_keys() { var section = new RijndaelEncryptionServiceConfig { Key = "Key", ExpiredKeys = new RijndaelExpiredKeyCollection { new RijndaelExpiredKey{Key="Key"}, } }; Assert.IsTrue(RijndaelEncryptionServiceConfigValidations.EncryptionKeyListedInExpiredKeys(section)); }
public static bool ConfigurationHasDuplicateKeyIdentifiers(RijndaelEncryptionServiceConfig section) { // Combine all key identifier values, filter the empty ones, split them return section .ExpiredKeys .Cast<RijndaelExpiredKey>() .Select(x => x.KeyIdentifier) .Union(new[] { section.KeyIdentifier }) .Where(x => !string.IsNullOrEmpty(x)) .Select(x => x.Split(';')) .SelectMany(x => x) .GroupBy(x => x) .Any(x => x.Count() > 1); }
public void Should_be_true_when_duplicate_key_identifier_in_concat_expired_keys() { var section = new RijndaelEncryptionServiceConfig { KeyIdentifier = "2", ExpiredKeys = { new RijndaelExpiredKey{ Key="A", KeyIdentifier = "1;4" }, new RijndaelExpiredKey{ Key="B", KeyIdentifier = "3;4" } } }; Assert.IsTrue(RijndaelEncryptionServiceConfigValidations.ConfigurationHasDuplicateKeyIdentifiers(section)); }
public void Should_throw_when_expired_keys_has_duplicate_keys() { var section = new RijndaelEncryptionServiceConfig { ExpiredKeys = { new RijndaelExpiredKey{ Key = "Key" }, } }; Assert.Throws<ConfigurationErrorsException>(() => { section.ExpiredKeys.Add(new RijndaelExpiredKey { Key = "Key", KeyIdentifier = "ID" }); }, "The entry 'Key' has already been added."); }
public void Should_be_true_when_key_identifier_not_in_expired_keys() { var section = new RijndaelEncryptionServiceConfig { ExpiredKeys = { new RijndaelExpiredKey { Key = "Key" } } }; Assert.IsTrue(RijndaelEncryptionServiceConfigValidations.OneOrMoreExpiredKeysHaveNoKeyIdentifier(section)); }
public void Should_be_true_when_key_has_whitespace() { var section = new RijndaelEncryptionServiceConfig { ExpiredKeys = { new RijndaelExpiredKey{ Key = " " } } }; Assert.IsTrue(RijndaelEncryptionServiceConfigValidations.ExpiredKeysHaveWhiteSpace(section)); }