Search in sources :

Example 1 with CryptoException

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");
    }
}
Also used : UrlArgument(com.thoughtworks.go.util.command.UrlArgument) GoCipher(com.thoughtworks.go.security.GoCipher) CryptoException(com.thoughtworks.go.security.CryptoException) CryptoException(com.thoughtworks.go.security.CryptoException) Test(org.junit.jupiter.api.Test)

Example 2 with CryptoException

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;
}
Also used : EnvironmentVariableConfig(com.thoughtworks.go.config.EnvironmentVariableConfig) CryptoException(com.thoughtworks.go.security.CryptoException)

Aggregations

CryptoException (com.thoughtworks.go.security.CryptoException)2 EnvironmentVariableConfig (com.thoughtworks.go.config.EnvironmentVariableConfig)1 GoCipher (com.thoughtworks.go.security.GoCipher)1 UrlArgument (com.thoughtworks.go.util.command.UrlArgument)1 Test (org.junit.jupiter.api.Test)1