@Test public void shouldReturnNullIfBothPasswordAndEncryptedPasswordAreNull() { SvnMaterialConfig svnMaterialConfig = new SvnMaterialConfig(); PasswordDeserializer passwordDeserializer = new PasswordDeserializer(); String encrypted = passwordDeserializer.deserialize(null, null, svnMaterialConfig); assertNull(encrypted); }
public static SvnMaterialConfig fromJSON(JsonReader jsonReader, ConfigHelperOptions options) { SvnMaterialConfig svnMaterialConfig = new SvnMaterialConfig(); ScmMaterialRepresenter.fromJSON(jsonReader, svnMaterialConfig); jsonReader.optBoolean("check_externals").ifPresent(svnMaterialConfig::setCheckExternals); jsonReader.readStringIfPresent("username", svnMaterialConfig::setUserName); String password = null, encryptedPassword = null; if (jsonReader.hasJsonObject("password")) { password = jsonReader.getString("password"); } if (jsonReader.hasJsonObject("encrypted_password")) { encryptedPassword = jsonReader.getString("encrypted_password"); } PasswordDeserializer passwordDeserializer = options.getPasswordDeserializer(); String encryptedPasswordValue = passwordDeserializer.deserialize(password, encryptedPassword, svnMaterialConfig); svnMaterialConfig.setEncryptedPassword(encryptedPasswordValue); return svnMaterialConfig; } }
public static SvnMaterialConfig fromJSON(JsonReader jsonReader, ConfigHelperOptions options) { SvnMaterialConfig svnMaterialConfig = new SvnMaterialConfig(); ScmMaterialRepresenter.fromJSON(jsonReader, svnMaterialConfig); jsonReader.optBoolean("check_externals").ifPresent(svnMaterialConfig::setCheckExternals); jsonReader.readStringIfPresent("username", svnMaterialConfig::setUserName); String password = null, encryptedPassword = null; if (jsonReader.hasJsonObject("password")) { password = jsonReader.getString("password"); } if (jsonReader.hasJsonObject("encrypted_password")) { encryptedPassword = jsonReader.getString("encrypted_password"); } PasswordDeserializer passwordDeserializer = options.getPasswordDeserializer(); String encryptedPasswordValue = passwordDeserializer.deserialize(password, encryptedPassword, svnMaterialConfig); svnMaterialConfig.setEncryptedPassword(encryptedPasswordValue); return svnMaterialConfig; } }
@Test public void shouldReturnNullIfBothPasswordAndEncryptedPasswordAreBlank() { SvnMaterialConfig svnMaterialConfig = new SvnMaterialConfig(); PasswordDeserializer passwordDeserializer = new PasswordDeserializer(); String encrypted = passwordDeserializer.deserialize("", "", svnMaterialConfig); assertNull(encrypted); }
static SvnMaterialConfig fromJSON(JsonReader json) { SvnMaterialConfig materialConfig = new SvnMaterialConfig(); json.readStringIfPresent("name", materialConfig::setName); json.readBooleanIfPresent("auto_update", materialConfig::setAutoUpdate); json.readStringIfPresent("url", materialConfig::setUrl); json.readBooleanIfPresent("check_externals", materialConfig::setCheckExternals); json.readStringIfPresent("username", materialConfig::setUserName); String password = json.getStringOrDefault("password", null); String encryptedPassword = json.getStringOrDefault("encrypted_password", null); materialConfig.setEncryptedPassword(PASSWORD_DESERIALIZER.deserialize(password, encryptedPassword, materialConfig)); return materialConfig; } }
@Test public void shouldNotValidateEncryptedPasswordIfBlank() { SvnMaterialConfig svnMaterialConfig = new SvnMaterialConfig(); PasswordDeserializer passwordDeserializer = new PasswordDeserializer(); String encrypted = passwordDeserializer.deserialize(null, "", svnMaterialConfig); assertNull(encrypted); }
public static P4MaterialConfig fromJSON(JsonReader jsonReader, ConfigHelperOptions options) { P4MaterialConfig p4MaterialConfig = new P4MaterialConfig(); ScmMaterialRepresenter.fromJSON(jsonReader, p4MaterialConfig); jsonReader.readStringIfPresent("port", p4MaterialConfig::setServerAndPort); jsonReader.readStringIfPresent("username", p4MaterialConfig::setUserName); jsonReader.optBoolean("use_tickets").ifPresent(p4MaterialConfig::setUseTickets); jsonReader.readStringIfPresent("view", p4MaterialConfig::setView); String password = null, encryptedPassword = null; if (jsonReader.hasJsonObject("password")) { password = jsonReader.getString("password"); } if (jsonReader.hasJsonObject("encrypted_password")) { encryptedPassword = jsonReader.getString("encrypted_password"); } PasswordDeserializer passwordDeserializer = options.getPasswordDeserializer(); String encryptedPasswordValue = passwordDeserializer.deserialize(password, encryptedPassword, p4MaterialConfig); p4MaterialConfig.setEncryptedPassword(encryptedPasswordValue); return p4MaterialConfig; } }
@Test public void shouldErrorOutWhenEncryptedPasswordIsInvalid() { SvnMaterialConfig svnMaterialConfig = new SvnMaterialConfig(); PasswordDeserializer passwordDeserializer = new PasswordDeserializer(); passwordDeserializer.deserialize(null, "invalidEncryptedPassword", svnMaterialConfig); assertThat(svnMaterialConfig.errors().getAllOn("encryptedPassword"), is(Arrays.asList("Encrypted value for password is invalid. This usually happens when the cipher text is invalid."))); }
public static P4MaterialConfig fromJSON(JsonReader json) { P4MaterialConfig materialConfig = new P4MaterialConfig(); json.readStringIfPresent("name", materialConfig::setName); json.readBooleanIfPresent("auto_update", materialConfig::setAutoUpdate); json.readStringIfPresent("port", materialConfig::setServerAndPort); json.readBooleanIfPresent("use_tickets", materialConfig::setUseTickets); json.readStringIfPresent("view", materialConfig::setView); json.readStringIfPresent("username", materialConfig::setUserName); String password = json.getStringOrDefault("password", null); String encryptedPassword = json.getStringOrDefault("encrypted_password", null); materialConfig.setEncryptedPassword(PASSWORD_DESERIALIZER.deserialize(password, encryptedPassword, materialConfig)); return materialConfig; } }
@Test public void shouldEncryptClearTextPasswordSentByUser() throws CryptoException { SvnMaterialConfig svnMaterialConfig = new SvnMaterialConfig(); PasswordDeserializer passwordDeserializer = new PasswordDeserializer(); String encrypted = passwordDeserializer.deserialize("password", null, svnMaterialConfig); assertThat(encrypted, is(new GoCipher().encrypt("password"))); }
public static P4MaterialConfig fromJSON(JsonReader jsonReader, ConfigHelperOptions options) { P4MaterialConfig p4MaterialConfig = new P4MaterialConfig(); ScmMaterialRepresenter.fromJSON(jsonReader, p4MaterialConfig); jsonReader.readStringIfPresent("port", p4MaterialConfig::setServerAndPort); jsonReader.readStringIfPresent("username", p4MaterialConfig::setUserName); jsonReader.optBoolean("use_tickets").ifPresent(p4MaterialConfig::setUseTickets); jsonReader.readStringIfPresent("view", p4MaterialConfig::setView); String password = null, encryptedPassword = null; if (jsonReader.hasJsonObject("password")) { password = jsonReader.getString("password"); } if (jsonReader.hasJsonObject("encrypted_password")) { encryptedPassword = jsonReader.getString("encrypted_password"); } PasswordDeserializer passwordDeserializer = options.getPasswordDeserializer(); String encryptedPasswordValue = passwordDeserializer.deserialize(password, encryptedPassword, p4MaterialConfig); p4MaterialConfig.setEncryptedPassword(encryptedPasswordValue); return p4MaterialConfig; } }
@Test public void shouldReturnTheEncryptedPasswordSentByUserIfValid() throws CryptoException { String encryptedPassword = new GoCipher().encrypt("password"); SvnMaterialConfig svnMaterialConfig = new SvnMaterialConfig(); PasswordDeserializer passwordDeserializer = new PasswordDeserializer(); String encrypted = passwordDeserializer.deserialize(null, encryptedPassword, svnMaterialConfig); assertThat(encrypted, is(encryptedPassword)); }
public static TfsMaterialConfig fromJSON(JsonReader json) { TfsMaterialConfig materialConfig = new TfsMaterialConfig(); json.readStringIfPresent("name", materialConfig::setName); json.readBooleanIfPresent("auto_update", materialConfig::setAutoUpdate); json.readStringIfPresent("url", materialConfig::setUrl); json.readStringIfPresent("project_path", materialConfig::setProjectPath); json.readStringIfPresent("domain", materialConfig::setDomain); json.readStringIfPresent("username", materialConfig::setUserName); String password = json.getStringOrDefault("password", null); String encryptedPassword = json.getStringOrDefault("encrypted_password", null); materialConfig.setEncryptedPassword(PASSWORD_DESERIALIZER.deserialize(password, encryptedPassword, materialConfig)); return materialConfig; } }
@Test public void shouldErrorOutWhenBothPasswordAndEncryptedPasswordAreGivenForDeserialization() throws CryptoException { SvnMaterialConfig svnMaterialConfig = new SvnMaterialConfig(); PasswordDeserializer passwordDeserializer = new PasswordDeserializer(); passwordDeserializer.deserialize("password", new GoCipher().encrypt("encryptedPassword"), svnMaterialConfig); assertThat(svnMaterialConfig.errors().getAllOn("password"), is(Arrays.asList("You may only specify `password` or `encrypted_password`, not both!"))); assertThat(svnMaterialConfig.errors().getAllOn("encryptedPassword"), is(Arrays.asList("You may only specify `password` or `encrypted_password`, not both!"))); }
public static TfsMaterialConfig fromJSON(JsonReader jsonReader, ConfigHelperOptions options) { TfsMaterialConfig tfsMaterialConfig = new TfsMaterialConfig(); ScmMaterialRepresenter.fromJSON(jsonReader, tfsMaterialConfig); jsonReader.readStringIfPresent("domain", tfsMaterialConfig::setDomain); jsonReader.readStringIfPresent("username", tfsMaterialConfig::setUserName); jsonReader.readStringIfPresent("project_path", tfsMaterialConfig::setProjectPath); String password = null, encryptedPassword = null; if (jsonReader.hasJsonObject("password")) { password = jsonReader.getString("password"); } if (jsonReader.hasJsonObject("encrypted_password")) { encryptedPassword = jsonReader.getString("encrypted_password"); } PasswordDeserializer passwordDeserializer = options.getPasswordDeserializer(); String encryptedPasswordValue = passwordDeserializer.deserialize(password, encryptedPassword, tfsMaterialConfig); tfsMaterialConfig.setEncryptedPassword(encryptedPasswordValue); return tfsMaterialConfig; } }
@Test public void shouldReEncryptedDESPasswords() throws IOException { resetCipher.setupAESCipherFile(); resetCipher.setupDESCipherFile(); SvnMaterialConfig svnMaterialConfig = new SvnMaterialConfig(); PasswordDeserializer passwordDeserializer = new PasswordDeserializer(); String encrypted = passwordDeserializer.deserialize(null, "mvcX9yrQsM4iPgm1tDxN1A==", svnMaterialConfig); assertThat(encrypted, startsWith("AES:")); }
public static TfsMaterialConfig fromJSON(JsonReader jsonReader, ConfigHelperOptions options) { TfsMaterialConfig tfsMaterialConfig = new TfsMaterialConfig(); ScmMaterialRepresenter.fromJSON(jsonReader, tfsMaterialConfig); jsonReader.readStringIfPresent("domain", tfsMaterialConfig::setDomain); jsonReader.readStringIfPresent("username", tfsMaterialConfig::setUserName); jsonReader.readStringIfPresent("project_path", tfsMaterialConfig::setProjectPath); String password = null, encryptedPassword = null; if (jsonReader.hasJsonObject("password")) { password = jsonReader.getString("password"); } if (jsonReader.hasJsonObject("encrypted_password")) { encryptedPassword = jsonReader.getString("encrypted_password"); } PasswordDeserializer passwordDeserializer = options.getPasswordDeserializer(); String encryptedPasswordValue = passwordDeserializer.deserialize(password, encryptedPassword, tfsMaterialConfig); tfsMaterialConfig.setEncryptedPassword(encryptedPasswordValue); return tfsMaterialConfig; } }