public void ProfileReferences() { // Verify that [IProfileClient] integration works by starting a profile // server, injecting an [IProfileClient] implementation and then verifying // that secret passwords, secret values, and profile values can be // resolved. var pipeName = Guid.NewGuid().ToString("d"); var server = new ProfileServer(pipeName); server.GetProfileValueHandler = (request, name) => { if (name == "missing") { return(ProfileHandlerResult.CreateError(request, ProfileStatus.NotFound, $"[{name}] variable not found.")); } return(ProfileHandlerResult.Create($"{name}-profile")); }; server.GetSecretPasswordHandler = (request, name, vault, masterPassword) => { if (name == "missing") { return(ProfileHandlerResult.CreateError(request, ProfileStatus.NotFound, $"[{name}] variable not found.")); } if (vault == null) { return(ProfileHandlerResult.Create($"{name}-password")); } else { return(ProfileHandlerResult.Create($"{name}-password-{vault}")); } }; server.GetSecretValueHandler = (request, name, vault, masterPassword) => { if (name == "missing") { return(ProfileHandlerResult.CreateError(request, ProfileStatus.NotFound, $"[{name}] variable not found.")); } if (vault == null) { return(ProfileHandlerResult.Create($"{name}-secret")); } else { return(ProfileHandlerResult.Create($"{name}-secret-{vault}")); } }; server.Start(); try { var client = new ProfileClient(pipeName); NeonHelper.ServiceContainer.AddSingleton <IProfileClient>(client); //------------------------------------------------------------- // Verify secret passwords var source = "TEST = $<<<password:test>>>"; var output = new PreprocessReader(source).ReadToEnd().Trim(); Assert.Equal("TEST = test-password", output); source = "TEST = $<<<password:test:vault>>>"; output = new PreprocessReader(source).ReadToEnd().Trim(); Assert.Equal("TEST = test-password-vault", output); Assert.Throws <ProfileException>(() => new PreprocessReader("TEST = $<<<password:missing>>>").ReadToEnd()); //------------------------------------------------------------- // Verify secret values source = "TEST = $<<<secret:test>>>"; output = new PreprocessReader(source).ReadToEnd().Trim(); Assert.Equal("TEST = test-secret", output); source = "TEST = $<<<secret:test:vault>>>"; output = new PreprocessReader(source).ReadToEnd().Trim(); Assert.Equal("TEST = test-secret-vault", output); Assert.Throws <ProfileException>(() => new PreprocessReader("TEST = $<<<secret:missing>>>").ReadToEnd()); //------------------------------------------------------------- // Verify secret values targeting a specific property. source = "TEST = $<<<secret:test[field]>>>"; output = new PreprocessReader(source).ReadToEnd().Trim(); Assert.Equal("TEST = test[field]-secret", output); source = "TEST = $<<<secret:test[field]:vault>>>"; output = new PreprocessReader(source).ReadToEnd().Trim(); Assert.Equal("TEST = test[field]-secret-vault", output); Assert.Throws <ProfileException>(() => new PreprocessReader("TEST = $<<<secret:missing>>>").ReadToEnd()); //------------------------------------------------------------- // Verify profile values source = "TEST = $<<<profile:test>>>"; output = new PreprocessReader(source).ReadToEnd().Trim(); Assert.Equal("TEST = test-profile", output); Assert.Throws <ProfileException>(() => new PreprocessReader("TEST = $<<<profile:missing>>>").ReadToEnd()); } finally { NeonHelper.ServiceContainer.Remove(NeonHelper.ServiceContainer.Single(service => service.ServiceType == typeof(IProfileClient))); server.Dispose(); } }