private static void ValidateConnection(RootConnection connection) { if (connection == null) { throw new ServiceException(ResponseCode.NotFound, "Connection for provided User can not be found."); } if (string.IsNullOrWhiteSpace(connection.EncryptedConnectionString)) { throw new ServiceException(ResponseCode.ValidationError, "Found Connection for provided User does not contain a Connection String."); } }
public void SetUp() { _rootRepoMock = new Mock <IRootRepository>(); _settingRepoMock = new Mock <ISettingRepository>(); _customerContextFactoryMock = new Mock <IDbCustomerDatabaseFactory>(); _mapperMock = new Mock <IMapper>(); _customerDatabaseMock = new Mock <dbCustomerDatabase>(); _userDbSetMock = new Mock <DbSet <User> >(); //Having to due all of this due to multi-tenency set up, I can't inject UserRepo var data = new List <User> { new User(Guid.NewGuid(), "Name", "Email", "Password") } .AsQueryable(); _userDbSetMock.As <IQueryable <User> >().Setup(m => m.Provider).Returns(data.Provider); _userDbSetMock.As <IQueryable <User> >().Setup(m => m.Expression).Returns(data.Expression); _userDbSetMock.As <IQueryable <User> >().Setup(m => m.ElementType).Returns(data.ElementType); _userDbSetMock.As <IQueryable <User> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator()); _customerDatabaseMock.Setup(c => c.Users).Returns(_userDbSetMock.Object); _authService = new AuthService( _rootRepoMock.Object, _settingRepoMock.Object, _customerContextFactoryMock.Object, _mapperMock.Object); _request = new ValidateUserRequest("Email", "Password"); var guid = Guid.NewGuid(); var connectionString = new Encryption( Key, Salt, guid.ToByteArray()) .EncryptString("Connection String"); _connection = new RootConnection(guid, connectionString); _userDto = new UserDto { UserGuid = Guid.NewGuid(), UserId = 1, Email = "Email Address", Name = "Name" }; }
public void SetUp() { _rootRepoMock = new Mock <IRootRepository>(); _settingRepoMock = new Mock <ISettingRepository>(); _customerContextFactoryMock = new Mock <IDbCustomerDatabaseFactory>(); _customerDatabaseMock = new Mock <dbCustomerDatabase>(); _userDbSetMock = new Mock <DbSet <User> >(); var user = new User(new Guid(UserGuid), "Name", "Email", "Password"); user.AddPasswordResetRequest(new ForgottenPassword(new Guid(UsedForgottenPasswordGuid)), 1); user.AddPasswordResetRequest(new ForgottenPassword(new Guid(ForgottenPasswordGuid)), 1); //Having to due all of this due to multi-tenency set up, I can't inject UserRepo var data = new List <User> { user } .AsQueryable(); _userDbSetMock.As <IQueryable <User> >().Setup(m => m.Provider).Returns(data.Provider); _userDbSetMock.As <IQueryable <User> >().Setup(m => m.Expression).Returns(data.Expression); _userDbSetMock.As <IQueryable <User> >().Setup(m => m.ElementType).Returns(data.ElementType); _userDbSetMock.As <IQueryable <User> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator()); _customerDatabaseMock.Setup(c => c.Users).Returns(_userDbSetMock.Object); _userService = new UserService( _rootRepoMock.Object, _settingRepoMock.Object, _customerContextFactoryMock.Object); _isValidKeyRequest = new IsValidKeyRequest(new Guid(ForgottenPasswordGuid), new Guid(UserGuid)); _requestPasswordResetRequest = new RequestPasswordResetRequest("Email"); _resetPasswordRequest = new ResetPasswordRequest(new Guid(ForgottenPasswordGuid), "Password2", new Guid(UserGuid)); var guid = Guid.NewGuid(); var connectionString = new Encryption( Key, Salt, guid.ToByteArray()) .EncryptString("Connection String"); _connection = new RootConnection(guid, connectionString); }
private string DecryptConnectionString(RootConnection connection) { var encryptionSaltSetting = _settingRepository.FindSettingAsString(SettingName.EncryptionSalt); var encryptionKeySetting = _settingRepository.FindSettingAsString(SettingName.EncryptionKey); if (string.IsNullOrWhiteSpace(encryptionSaltSetting)) { throw new ServiceException(ResponseCode.NotFound, "Encryption Salt can not be found."); } if (string.IsNullOrWhiteSpace(encryptionKeySetting)) { throw new ServiceException(ResponseCode.NotFound, "Encryption Key can not be found."); } var connectionString = new Encryption( encryptionKeySetting, encryptionSaltSetting, connection.ConnectionGuid.ToByteArray()) .DecryptString(connection.EncryptedConnectionString); return(connectionString); }