public void Should_throw_for_no_key_in_config() { var config = new RijndaelEncryptionServiceConfig(); var exception = Assert.Throws <Exception>(() => ConfigureRijndaelEncryptionService.ConvertConfigToRijndaelService(config)); Assert.AreEqual("The RijndaelEncryptionServiceConfig has an empty a 'Key' property.", exception.Message); }
public void Should_correctly_convert_ascii_key_when_no_value() { const string asciiKey = "0123456789123456"; var key = Encoding.ASCII.GetBytes("0123456789123456"); var section = new RijndaelEncryptionServiceConfig { Key = asciiKey, KeyIdentifier = "1", ExpiredKeys = { new RijndaelExpiredKey { KeyIdentifier = "2", Key = asciiKey } } }; var keys = ConfigureRijndaelEncryptionService.ExtractKeysFromConfigSection(section); Assert.AreEqual(key, keys["1"], "Key in configuration root incorrectly converted"); Assert.AreEqual(key, keys["2"], "Key in expired keys incorrectly converted"); }
public void Should_correctly_convert_base64_key() { byte[] key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F }; var base64 = Convert.ToBase64String(key); var section = new RijndaelEncryptionServiceConfig { Key = base64, KeyFormat = KeyFormat.Base64, KeyIdentifier = "1", ExpiredKeys = { new RijndaelExpiredKey { KeyIdentifier = "2", Key = base64, KeyFormat = KeyFormat.Base64 } } }; var keys = ConfigureRijndaelEncryptionService.ExtractKeysFromConfigSection(section); Assert.AreEqual(key, keys["1"], "Key in configuration root incorrectly converted"); Assert.AreEqual(key, keys["2"], "Key in expired keys incorrectly converted"); }
public void Should_correctly_parse_key_identifiers_containing_multiple_keys() { var section = new RijndaelEncryptionServiceConfig { KeyIdentifier = "1", ExpiredKeys = { new RijndaelExpiredKey { KeyIdentifier = "2", Key = "Key" } } }; var keys = ConfigureRijndaelEncryptionService.ExtractKeysFromConfigSection(section); ICollection <string> expected = new[] { "1", "2" }; Assert.AreEqual(expected, keys.Keys); }
public void Should_throw_for_whitespace_key() { var keys = new List <string> { "key1", "", "key2" }; var exception = Assert.Throws <ArgumentException>(() => ConfigureRijndaelEncryptionService.VerifyKeys(keys)); Assert.AreEqual("Empty encryption key detected in position 1.\r\nParameter name: expiredKeys", exception.Message); }
public void Should_throw_for_overlapping_keys() { var keys = new List <string> { "key1", "key2", "key1" }; var exception = Assert.Throws <ArgumentException>(() => ConfigureRijndaelEncryptionService.VerifyKeys(keys)); Assert.AreEqual("Overlapping keys defined. Please ensure that no keys overlap.\r\nParameter name: expiredKeys", exception.Message); }
public void Should_throw_for_null_keys_in_config() { var config = new RijndaelEncryptionServiceConfig { ExpiredKeys = new RijndaelExpiredKeyCollection { new RijndaelExpiredKey() } }; var exception = Assert.Throws <Exception>(() => ConfigureRijndaelEncryptionService.ExtractExpiredKeysFromConfigSection(config)); Assert.AreEqual("The RijndaelEncryptionServiceConfig has a 'ExpiredKeys' property defined however some keys have no data.", exception.Message); }
public void Should_throw_for_null_key() { var keys = new List <string> { "key1", null, "key2" }; var exception = Assert.Throws <ArgumentException>(() => ConfigureRijndaelEncryptionService.VerifyKeys(keys)); StringAssert.StartsWith("Empty encryption key detected in position 1.", exception.Message); Assert.AreEqual("expiredKeys", exception.ParamName); }
public void Should_for_duplicate_between_key_and_keys_in_config() { var config = new RijndaelEncryptionServiceConfig { Key = "a", ExpiredKeys = new RijndaelExpiredKeyCollection { new RijndaelExpiredKey { Key = "a" } } }; var exception = Assert.Throws <Exception>(() => ConfigureRijndaelEncryptionService.ExtractExpiredKeysFromConfigSection(config)); Assert.AreEqual("The RijndaelEncryptionServiceConfig has a 'Key' that is also defined inside the 'ExpiredKeys'.", exception.Message); }
public void Should_have_correct_number_of_extracted_keys_without_key_identifier() { var section = new RijndaelEncryptionServiceConfig { Key = "a", ExpiredKeys = { new RijndaelExpiredKey { Key = "b" } } }; var result = ConfigureRijndaelEncryptionService.ExtractDecryptionKeysFromConfigSection(section); Assert.AreEqual(2, result.Count, "Key count"); }
public void Duplicates_should_be_skipped() { var config = new RijndaelEncryptionServiceConfig { ExpiredKeys = new RijndaelExpiredKeyCollection { new RijndaelExpiredKey { Key = "a" }, new RijndaelExpiredKey { Key = "a" } } }; var keys = ConfigureRijndaelEncryptionService.ExtractExpiredKeysFromConfigSection(config); Assert.That(new[] { "a" }, Is.EquivalentTo(keys)); }
public void Should_not_throw_for_empty_keys() { ConfigureRijndaelEncryptionService.VerifyKeys(new List <string>()); }