use of com.thoughtworks.go.util.command.UrlArgument in project gocd by gocd.
the class TfsMaterialConfigUpdateTest method shouldErrorOutIfEncryptionFails.
@Test
public void shouldErrorOutIfEncryptionFails() throws Exception {
GoCipher mockGoCipher = mock(GoCipher.class);
when(mockGoCipher.encrypt("password")).thenThrow(new InvalidCipherTextException("exception"));
try {
new TfsMaterialConfig(mockGoCipher, new UrlArgument("http://10.4.4.101:8080/tfs/Sample"), "loser", "CORPORATE", "password", "walk_this_path");
fail("Should have thrown up");
} catch (Exception e) {
assertThat(e.getMessage(), is("Password encryption failed. Please verify your cipher key."));
}
}
use of com.thoughtworks.go.util.command.UrlArgument in project gocd by gocd.
the class TfsMaterialConfigUpdateTest method shouldNotDecryptTfsPasswordIfPasswordIsNotNull.
@Test
public void shouldNotDecryptTfsPasswordIfPasswordIsNotNull() throws Exception {
GoCipher mockGoCipher = mock(GoCipher.class);
when(mockGoCipher.encrypt("password")).thenReturn("encrypted");
when(mockGoCipher.decrypt("encrypted")).thenReturn("password");
TfsMaterialConfig materialConfig = new TfsMaterialConfig(mockGoCipher, new UrlArgument("http://10.4.4.101:8080/tfs/Sample"), "loser", "CORPORATE", "password", "walk_this_path");
materialConfig.ensureEncrypted();
when(mockGoCipher.encrypt("new_password")).thenReturn("new_encrypted");
materialConfig.setPassword("new_password");
when(mockGoCipher.decrypt("new_encrypted")).thenReturn("new_password");
assertThat(materialConfig.getPassword(), is("new_password"));
}
use of com.thoughtworks.go.util.command.UrlArgument in project gocd by gocd.
the class TfsMaterialConfigUpdateTest method setConfigAttributes_shouldUpdatePasswordWhenPasswordChangedBooleanChanged.
@Test
public void setConfigAttributes_shouldUpdatePasswordWhenPasswordChangedBooleanChanged() throws Exception {
TfsMaterialConfig tfsMaterialConfig = new TfsMaterialConfig(new GoCipher(), new UrlArgument("http://10.4.4.101:8080/tfs/Sample"), "loser", "CORPORATE", "passwd", "walk_this_path");
Map<String, String> map = new HashMap<>();
map.put(TfsMaterialConfig.PASSWORD, "secret");
map.put(TfsMaterialConfig.PASSWORD_CHANGED, "1");
tfsMaterialConfig.setConfigAttributes(map);
tfsMaterialConfig.setConfigAttributes(map);
assertThat(ReflectionUtil.getField(tfsMaterialConfig, "password"), is(nullValue()));
assertThat(tfsMaterialConfig.getPassword(), is("secret"));
assertThat(tfsMaterialConfig.getEncryptedPassword(), is(new GoCipher().encrypt("secret")));
// Dont change
map.put(TfsMaterialConfig.PASSWORD, "Hehehe");
map.put(TfsMaterialConfig.PASSWORD_CHANGED, "0");
tfsMaterialConfig.setConfigAttributes(map);
assertThat(ReflectionUtil.getField(tfsMaterialConfig, "password"), is(nullValue()));
assertThat(tfsMaterialConfig.getPassword(), is("secret"));
assertThat(tfsMaterialConfig.getEncryptedPassword(), is(new GoCipher().encrypt("secret")));
map.put(TfsMaterialConfig.PASSWORD, "");
map.put(TfsMaterialConfig.PASSWORD_CHANGED, "1");
tfsMaterialConfig.setConfigAttributes(map);
assertThat(tfsMaterialConfig.getPassword(), is(nullValue()));
assertThat(tfsMaterialConfig.getEncryptedPassword(), is(nullValue()));
}
use of com.thoughtworks.go.util.command.UrlArgument in project gocd by gocd.
the class TfsMaterialTest method shouldGetAttributesWithoutSecureFields.
@Test
public void shouldGetAttributesWithoutSecureFields() {
TfsMaterial material = new TfsMaterial(new GoCipher(), new UrlArgument("http://username:password@tfsrepo.com"), "username", "domain", "password", "$project/path/");
Map<String, Object> attributes = material.getAttributes(false);
assertThat(attributes.get("type"), is("tfs"));
Map<String, Object> configuration = (Map<String, Object>) attributes.get("tfs-configuration");
assertThat(configuration.get("url"), is("http://username:******@tfsrepo.com"));
assertThat(configuration.get("domain"), is("domain"));
assertThat(configuration.get("username"), is("username"));
assertThat(configuration.get("password"), is(nullValue()));
assertThat(configuration.get("project-path"), is("$project/path/"));
}
use of com.thoughtworks.go.util.command.UrlArgument in project gocd by gocd.
the class TfsMaterialTest method shouldGetLongDescriptionForMaterial.
@Test
public void shouldGetLongDescriptionForMaterial() {
TfsMaterial material = new TfsMaterial(new GoCipher(), new UrlArgument("http://url/"), "user", "domain", "password", "$project/path/");
assertThat(material.getLongDescription(), is("URL: http://url/, Username: user, Domain: domain, ProjectPath: $project/path/"));
}
Aggregations