/** * @deprecated used only in tests - we need to disentangle this */ public static SvnMaterial createSvnMaterialWithMock(Subversion svn) { return new SvnMaterial(svn); }
@Override public Material toOldMaterial(String name, String folder, String password) { SvnMaterial svn = new SvnMaterial(url, username, password, checkExternals, folder); setName(name, svn); svn.setId(id); return svn; } }
@Test public void shouldGenerateSqlCriteriaMapInSpecificOrder() throws Exception { SvnMaterial material = new SvnMaterial("url", "username", "password", true); Map<String, Object> map = material.getSqlCriteria(); assertThat(map.size(), is(4)); Iterator<Map.Entry<String, Object>> iter = map.entrySet().iterator(); assertThat(iter.next().getKey(), is("type")); assertThat(iter.next().getKey(), is("url")); assertThat(iter.next().getKey(), is("username")); assertThat(iter.next().getKey(), is("checkExternals")); }
@Test public void shouldNotDisplayPasswordInStringRepresentation() { SvnMaterial svn = new SvnMaterial("my-url", "user", "loser", false); assertThat(svn.toString(), not(containsString("loser"))); svn = new SvnMaterial("https://user:loser@foo.bar/baz?quux=bang", "user", "loser", false); assertThat(svn.toString(), not(containsString("loser"))); }
@Test public void shouldGetAttributesWithoutSecureFields() { SvnMaterial material = new SvnMaterial("http://username:password@svnrepo.com", "user", "password", true); Map<String, Object> attributes = material.getAttributes(false); assertThat(attributes.get("type"), is("svn")); Map<String, Object> configuration = (Map<String, Object>) attributes.get("svn-configuration"); assertThat(configuration.get("url"), is("http://username:******@svnrepo.com")); assertThat(configuration.get("username"), is("user")); assertThat(configuration.get("password"), is(nullValue())); assertThat(configuration.get("check-externals"), is(true)); } }
@Test public void shouldGetAttributesWithSecureFields() { SvnMaterial material = new SvnMaterial("http://username:password@svnrepo.com", "user", "password", true); Map<String, Object> attributes = material.getAttributes(true); assertThat(attributes.get("type"), is("svn")); Map<String, Object> configuration = (Map<String, Object>) attributes.get("svn-configuration"); assertThat(configuration.get("url"), is("http://username:password@svnrepo.com")); assertThat(configuration.get("username"), is("user")); assertThat(configuration.get("password"), is("password")); assertThat(configuration.get("check-externals"), is(true)); }
@Test public void shouldNotUsePasswordForEquality() { SvnMaterial svnBoozer = new SvnMaterial("foo.com", "loser", "boozer", true); SvnMaterial svnZooser = new SvnMaterial("foo.com", "loser", "zooser", true); assertThat(svnBoozer.hashCode(), is(svnZooser.hashCode())); assertThat(svnBoozer, is(svnZooser)); }
public List<Modification> checkInExternalFile(String fileName, String comment) throws IOException { SvnMaterial svnMaterial = new SvnMaterial(externalRepositoryUrl(), null, null, false); return checkInOneFile(svnMaterial, fileName, comment); }
@Test public void shouldErrorOutIfEncryptionFails() throws Exception { GoCipher mockGoCipher = mock(GoCipher.class); when(mockGoCipher.encrypt("password")).thenThrow(new CryptoException("exception")); try { new SvnMaterial("/foo", "username", "password", false, mockGoCipher); fail("Should have thrown up"); } catch (Exception e) { assertThat(e.getMessage(), is("Password encryption failed. Please verify your cipher key.")); } }
@Test public void shouldNotDecryptSvnPasswordIfPasswordIsNotNull() throws Exception { GoCipher mockGoCipher = mock(GoCipher.class); when(mockGoCipher.encrypt("password")).thenReturn("encrypted"); when(mockGoCipher.decrypt("encrypted")).thenReturn("password"); SvnMaterial material = new SvnMaterial("/foo", "username", "password", false, mockGoCipher); material.ensureEncrypted(); when(mockGoCipher.encrypt("new_password")).thenReturn("new_encrypted"); material.setPassword("new_password"); when(mockGoCipher.decrypt("new_encrypted")).thenReturn("new_password"); assertThat(material.getPassword(), is("new_password")); }
@Test public void shouldGetLongDescriptionForMaterial() { SvnMaterial material = new SvnMaterial("http://url/", "user", "password", true, "folder"); assertThat(material.getLongDescription(), is("URL: http://url/, Username: user, CheckExternals: true")); }
@Test public void shouldGeneratePipelineUniqueFingerprintBasedOnFingerprintAndDest() throws Exception { SvnMaterial one = new SvnMaterial("url", "username", "password", true, "folder1"); SvnMaterial two = new SvnMaterial("url", "username", "password", true, "folder2"); assertThat(one.getPipelineUniqueFingerprint(), is(Matchers.not(two.getFingerprint()))); assertThat(one.getPipelineUniqueFingerprint(), is(DigestUtils.sha256Hex("type=SvnMaterial<|>url=url<|>username=username<|>checkExternals=true<|>dest=folder1"))); }
@Test public void shouldEncryptSvnPasswordAndMarkPasswordAsNull() throws Exception { GoCipher mockGoCipher = mock(GoCipher.class); when(mockGoCipher.encrypt("password")).thenReturn("encrypted"); when(mockGoCipher.maybeReEncryptForPostConstructWithoutExceptions("encrypted")).thenReturn("encrypted"); SvnMaterial material = new SvnMaterial("/foo", "username", "password", false, mockGoCipher); material.ensureEncrypted(); assertThat(material.getPassword(), is(nullValue())); assertThat(material.getEncryptedPassword(), is("encrypted")); }
@Test public void shouldGenerateFingerprintBasedOnSqlCriteria() throws Exception { SvnMaterial one = new SvnMaterial("url", "username", "password", true); SvnMaterial two = new SvnMaterial("url", "username", "password", false); assertThat(one.getFingerprint(), is(Matchers.not(two.getFingerprint()))); assertThat(one.getFingerprint(), is(DigestUtils.sha256Hex("type=SvnMaterial<|>url=url<|>username=username<|>checkExternals=true"))); }
@Test public void shouldDecryptSvnPassword() throws Exception { GoCipher mockGoCipher = mock(GoCipher.class); when(mockGoCipher.decrypt("encrypted")).thenReturn("password"); when(mockGoCipher.maybeReEncryptForPostConstructWithoutExceptions("encrypted")).thenReturn("encrypted"); SvnMaterial material = new SvnMaterial("/foo", "username", null, false, mockGoCipher); ReflectionUtil.setField(material, "encryptedPassword", "encrypted"); material.ensureEncrypted(); assertThat(material.getPassword(), is("password")); }
@Test public void shouldCopyOverPasswordWhenConvertingToConfig() throws Exception { SvnMaterial material = new SvnMaterial("abc", "def", "ghi", false); SvnMaterialConfig config = (SvnMaterialConfig) material.config(); assertThat(config.getEncryptedPassword(), is(not(Matchers.nullValue()))); assertThat(config.getPassword(), is("ghi")); }
public SvnMaterial externalMaterial() { SvnMaterial svnMaterial = new SvnMaterial(getSvnExternalCommand(externalRepositoryUrl(), true)); svnMaterial.setFolder(EXTERNAL_REPO_NAME); return svnMaterial; } }
public static SvnMaterial svnMaterial(String svnUrl, String folder, String userName, String password, boolean checkExternals, String filterPattern) { SvnMaterial svnMaterial = new SvnMaterial(svnUrl, userName, password, checkExternals, folder); if (filterPattern != null) svnMaterial.setFilter(new Filter(new IgnoredFiles(filterPattern))); return svnMaterial; }
@Test public void shouldReturnExistingSvnMaterialFromMaterialsIfItContainsOne() { Materials materials = new Materials(); SvnMaterial existingMaterial = new SvnMaterial("foo", "bar", "blah", true); materials.add(existingMaterial); assertThat(materials.getSvnMaterial(), is(sameInstance(existingMaterial))); }
@Test public void shouldReturnTrueIfScmMaterialHasNoDestinationFolderSet() { Materials materials = new Materials(); SvnMaterial material1 = new SvnMaterial("url", "user", "pass", false); DependencyMaterial material2 = new DependencyMaterial(new CaseInsensitiveString("pipelineName"), new CaseInsensitiveString("stageName")); SvnMaterial material3 = new SvnMaterial("url", "user", "pass", false); material3.setFolder("foo"); materials.add(material1); materials.add(material2); assertThat(materials.scmMaterialsHaveDestination(), is(false)); }