public static void toJSON(OutputWriter jsonWriter, EnvironmentVariableConfig environmentVariableConfig) { if (!environmentVariableConfig.errors().isEmpty()) { jsonWriter.addChild("errors", errorWriter -> { HashMap<String, String> mapping = new HashMap<>(); mapping.put("encryptedValue", "encrypted_value"); new ErrorGetter(mapping).toJSON(jsonWriter, environmentVariableConfig); }); } jsonWriter.add("secure", environmentVariableConfig.isSecure()); jsonWriter.add("name", environmentVariableConfig.getName()); if (environmentVariableConfig.isPlain()) { jsonWriter.addIfNotNull("value", environmentVariableConfig.getValueForDisplay()); } if (environmentVariableConfig.isSecure()) { jsonWriter.addIfNotNull("encrypted_value", environmentVariableConfig.getValueForDisplay()); } }
public static void toJSON(OutputWriter jsonWriter, EnvironmentVariableConfig environmentVariableConfig) { if (!environmentVariableConfig.errors().isEmpty()) { jsonWriter.addChild("errors", errorWriter -> { HashMap<String, String> mapping = new HashMap<>(); mapping.put("encryptedValue", "encrypted_value"); new ErrorGetter(mapping).toJSON(jsonWriter, environmentVariableConfig); }); } jsonWriter.add("secure", environmentVariableConfig.isSecure()); jsonWriter.add("name", environmentVariableConfig.getName()); if (environmentVariableConfig.isPlain()) { jsonWriter.addIfNotNull("value", environmentVariableConfig.getValueForDisplay()); } if (environmentVariableConfig.isSecure()) { jsonWriter.addIfNotNull("encrypted_value", environmentVariableConfig.getValueForDisplay()); } }
@Test public void shouldReturnEncryptedValueForSecureVariables() throws CryptoException { when(goCipher.encrypt("bar")).thenReturn("encrypted"); when(goCipher.decrypt("encrypted")).thenReturn("bar"); EnvironmentVariableConfig environmentVariableConfig = new EnvironmentVariableConfig(goCipher, "foo", "bar", true); assertThat(environmentVariableConfig.getName(), is("foo")); assertThat(environmentVariableConfig.getValue(), is("bar")); assertThat(environmentVariableConfig.getValueForDisplay(), is(environmentVariableConfig.getEncryptedValue())); }
@Test public void shouldReturnValueForInSecureVariables() { EnvironmentVariableConfig environmentVariableConfig = new EnvironmentVariableConfig(goCipher, "foo", "bar", false); assertThat(environmentVariableConfig.getName(), is("foo")); assertThat(environmentVariableConfig.getValue(), is("bar")); assertThat(environmentVariableConfig.getValueForDisplay(), is("bar")); }