/** * @deprecated used only in tests - we need to disentangle this */ public static SvnMaterial createSvnMaterialWithMock(Subversion svn) { return new SvnMaterial(svn); }
private SvnMaterial buildMockSvnMaterial(String url, String username, String password) { final SvnMaterial svnMaterial = mock(SvnMaterial.class); when(svnMaterial.getUrl()).thenReturn(url); when(svnMaterial.getUserName()).thenReturn(username); when(svnMaterial.getPassword()).thenReturn(password); return svnMaterial; } }
@Override public List<Modification> latestModification(SvnMaterial material, File baseDir, SubprocessExecutionContext execCtx) { return material.latestModification(baseDir, execCtx); }
private void addCredentials(ArrayList<String> argList) { String userName = material.getUserName(); if (!StringUtils.isBlank(userName)) { argList.add("--username"); argList.add(userName); if (!StringUtils.isBlank(material.getPassword())) { argList.add("--password"); argList.add(material.getPassword()); } } }
@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; } }
public void updateTo(ConsoleOutputStreamConsumer outputStreamConsumer, File baseDir, RevisionContext revisionContext, final SubprocessExecutionContext execCtx) { Revision revision = revisionContext.getLatestRevision(); File workingDir = execCtx.isServer() ? baseDir : workingdir(baseDir); LOGGER.debug("Updating to revision: {} in workingdirectory {}", revision, workingDir); outputStreamConsumer.stdOutput(format("[%s] Start updating %s at revision %s from %s", GoConstants.PRODUCT_NAME, updatingTarget(), revision.getRevision(), url)); boolean shouldDoFreshCheckout = !workingDir.isDirectory() || isRepositoryChanged(workingDir); if (shouldDoFreshCheckout) { freshCheckout(outputStreamConsumer, new SubversionRevision(revision), workingDir); } else { cleanupAndUpdate(outputStreamConsumer, new SubversionRevision(revision), workingDir); } LOGGER.debug("done with update"); outputStreamConsumer.stdOutput(format("[%s] Done.\n", GoConstants.PRODUCT_NAME)); }
@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 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")); }
public SvnMaterial externalMaterial() { SvnMaterial svnMaterial = new SvnMaterial(getSvnExternalCommand(externalRepositoryUrl(), true)); svnMaterial.setFolder(EXTERNAL_REPO_NAME); return svnMaterial; } }
private MaterialRevisions materialRevisions() throws IOException { MaterialRevision svnRevision = new MaterialRevision(this.svnMaterial, ModificationsMother.oneModifiedFile( svnRepoFixture.getHeadRevision(svnRepoFixture.getEnd2EndRepoUrl()))); SvnMaterial svnMaterialForExternal = SvnMaterial.createSvnMaterialWithMock(new SvnCommand(null, svnRepoFixture.getExternalRepoUrl())); String folder = this.svnMaterial.getFolder() == null ? "external" : this.svnMaterial.getFolder() + "/" + "external"; svnMaterialForExternal.setFolder(folder); MaterialRevision svnExternalRevision = new MaterialRevision(svnMaterialForExternal, ModificationsMother.oneModifiedFile( svnRepoFixture.getHeadRevision(svnRepoFixture.getExternalRepoUrl()))); MaterialRevision hgRevision = new MaterialRevision(hgMaterial, ModificationsMother.oneModifiedFile(hgTestRepo.latestModifications().get(0).getRevision())); MaterialRevision dependencyRevision1 = ModificationsMother.dependencyMaterialRevision(0, dependencyMaterial.getPipelineName() + "-label", 1, dependencyMaterial, new Date()); MaterialRevision dependencyRevisionWithName = ModificationsMother.dependencyMaterialRevision(0, dependencyMaterialWithName.getPipelineName() + "-label", 1, dependencyMaterialWithName, new Date()); return new MaterialRevisions(svnRevision, svnExternalRevision, hgRevision, dependencyRevision1, dependencyRevisionWithName); }
@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 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")); }
protected List<Modification> checkInOneFile(SvnMaterial svnMaterial, String filename, String message) throws IOException { final File workingCopy = temporaryFolder.newFolder(); tmpFolders.add(workingCopy); InMemoryStreamConsumer consumer = inMemoryConsumer(); Revision latestRevision = getLatestRevision(svnMaterial); svnMaterial.updateTo(consumer, workingCopy, new RevisionContext(latestRevision), new TestSubprocessExecutionContext()); File newFileToAdd = new File(workingCopy, filename); File directoryToAddTo = newFileToAdd.getParentFile(); boolean addedToExistingDir = directoryToAddTo.exists(); directoryToAddTo.mkdirs(); FileUtils.writeStringToFile(newFileToAdd, "", UTF_8); svnMaterial.add(consumer, addedToExistingDir ? newFileToAdd : directoryToAddTo); svnMaterial.commit(consumer, workingCopy, message); return svnMaterial.latestModification(workingCopy, new TestSubprocessExecutionContext()); }
@Test @RunIf(value = EnhancedOSChecker.class, arguments = {DO_NOT_RUN_ON, WINDOWS}) public void shouldRecogniseSvnAsTheSameIfURLContainsSpaces() throws Exception { File working = temporaryFolder.newFolder("shouldRecogniseSvnAsTheSameIfURLContainsSpaces"); SvnTestRepo repo = new SvnTestRepo(temporaryFolder, "a directory with spaces"); SvnMaterial material = repo.material(); assertThat(material.getUrl(), containsString("%20")); InMemoryStreamConsumer output = new InMemoryStreamConsumer(); material.freshCheckout(output, new SubversionRevision("3"), working); assertThat(output.getAllOutput(), containsString("Checked out revision 3")); InMemoryStreamConsumer output2 = new InMemoryStreamConsumer(); material.updateTo(output2, working, new RevisionContext(new SubversionRevision("4")), new TestSubprocessExecutionContext()); assertThat(output2.getAllOutput(), containsString("Updated to revision 4")); }
@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 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)); }
public void checkInOneFile(String fileName, SvnMaterial svnMaterial) throws Exception { final File baseDir = temporaryFolder.newFolder(); tmpFolders.add(baseDir); ProcessOutputStreamConsumer consumer = inMemoryConsumer(); Revision revision = latestRevision(svnMaterial, baseDir, new TestSubprocessExecutionContext()); svnMaterial.updateTo(consumer, baseDir, new RevisionContext(revision), new TestSubprocessExecutionContext()); File workingDir = new File(baseDir, svnMaterial.getFolder()); File newFileToAdd = new File(workingDir, fileName); newFileToAdd.getParentFile().mkdirs(); FileUtils.writeStringToFile(newFileToAdd, "", UTF_8); svnMaterial.add(consumer, newFileToAdd); svnMaterial.commit(consumer, workingDir, "adding file [" + svnMaterial.getFolder() + "/" + fileName + "]"); }
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; }
public BuildCommand updateTo(String baseDir, RevisionContext revisionContext) { Revision revision = revisionContext.getLatestRevision(); String workingDir = material.workingdir(new File(baseDir)).getPath(); UrlArgument url = material.getUrlArgument(); return compose( echoWithPrefix(format("Start updating %s at revision %s from %s", material.updatingTarget(), revision.getRevision(), url.forDisplay())), secret(url.forCommandline(), url.forDisplay()), secret(material.getPassword(), "*********************"), cleanupAndUpdate(workingDir, revision).setTest(shouldDoCleanupAndUpdate(workingDir)), freshCheckout(workingDir, revision).setTest(isNotRepository(workingDir)), freshCheckout(workingDir, revision).setTest(test("-nd", workingDir)), freshCheckout(workingDir, revision).setTest(repoUrlChanged(workingDir)), echoWithPrefix(format("Done.\n")) ); }