use of com.thoughtworks.go.security.CryptoException in project gocd by gocd.
the class TfsMaterialConfigTest method shouldErrorOutIfDecryptionFails.
@Test
void shouldErrorOutIfDecryptionFails() throws CryptoException {
GoCipher mockGoCipher = mock(GoCipher.class);
String fakeCipherText = "fake cipher text";
when(mockGoCipher.decrypt(fakeCipherText)).thenThrow(new CryptoException("exception"));
TfsMaterialConfig materialConfig = tfs(mockGoCipher, new UrlArgument("http://10.4.4.101:8080/tfs/Sample"), "loser", "CORPORATE", "passwd", "walk_this_path");
ReflectionUtil.setField(materialConfig, "encryptedPassword", fakeCipherText);
try {
materialConfig.getPassword();
fail("Should have thrown up");
} catch (Exception e) {
assertThat(e.getMessage()).isEqualTo("Could not decrypt the password to get the real password");
}
}
use of com.thoughtworks.go.security.CryptoException in project gocd by gocd.
the class EnvironmentVariableRepresenter method fromJSON.
public static EnvironmentVariableConfig fromJSON(JsonReader jsonReader) {
String name = jsonReader.getString("name");
Boolean secure = jsonReader.optBoolean("secure").orElse(false);
Optional<String> optValue = jsonReader.optString("value");
Optional<String> optEncValue = jsonReader.optString("encrypted_value");
if (!optValue.isPresent() && !optEncValue.isPresent()) {
HaltApiResponses.haltBecauseOfReason("Environment variable must contain either 'value' or 'encrypted_value'");
}
String value = secure ? optValue.orElse(null) : jsonReader.getString("value");
String encryptedValue = optEncValue.orElse(null);
EnvironmentVariableConfig environmentVariableConfig = new EnvironmentVariableConfig();
try {
environmentVariableConfig.deserialize(name, value, secure, encryptedValue);
} catch (CryptoException e) {
environmentVariableConfig.addError(name, errorWhileEncryptingMessage());
}
return environmentVariableConfig;
}
Aggregations