protected void SetupSecureSettingSource() { Configuration = Isolate.Fake.Instance<Configuration>(); Factory = new TestConfigurationFactory(Configuration); KeyManager = Isolate.Fake.Instance<SecretKeyManager>(); Key = "key"; Isolate.WhenCalled((() => KeyManager.GetKey())).WillReturn(Key); CryptoGraphy = Isolate.Fake.Instance<CryptoGraphy>(); Isolate.WhenCalled(() => CryptoGraphy.SetKey(Key)).IgnoreCall(); Name = "secret"; Encrypted = "[Secure]="; Isolate.WhenCalled((() => CryptoGraphy.Encrypt(Name))).WillReturn(Encrypted); Isolate.WhenCalled((() => CryptoGraphy.Decrypt(Encrypted))).WillReturn(Name); SecureSettingSource = new ConfigurationSettingSource(Factory); }
public void IsolateSecureSettingSource() { var testSource = new TestSource {Name = Value }; _fakeSetting = new TestSetting(testSource); _fakeSetting.Key = _fakeSetting.SecureMarker + Value; _fakeSetting.Value = _fakeSetting.SecureMarker + Value; Isolate.WhenCalled(() => _fakeSetting.Key = null).CallOriginal(); _secretKeyManager = new SecretKeyManager(); Isolate.WhenCalled(() => _secretKeyManager.GetKey()).WillReturn(Secret); _crypt = Isolate.Fake.Instance<CryptoGraphy>(); Isolate.WhenCalled(() => _crypt.SetKey(Secret)).IgnoreCall(); _secureSetting = new SecureSetting(_fakeSetting, _secretKeyManager, _crypt); Isolate.WhenCalled(() => _crypt.Encrypt(Value)).WillReturn(Value); var secureValue = _secureSetting.SecureMarker + Value; Isolate.WhenCalled(() => _crypt.Decrypt(secureValue)).WillReturn(Value); }
public SecureSetting(ISetting setting, SecretKeyManager manager, CryptoGraphy crypto) { _setting = setting; _manager = manager; _crypto = crypto; }