Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #7 from alexlehm/master
[JENKINS-12582] CVS-Plugin: Password file "${user.home}/.cvspass" is ignored
  • Loading branch information
alexlehm committed Feb 14, 2012
2 parents a64d761 + cb3913e commit c80a279
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/hudson/scm/LegacyConvertor.java
Expand Up @@ -142,6 +142,10 @@ public String findPassword(String cvsRoot, File passFile) throws IOException {
password = line.substring(cvsRoot.length() + 5 + 1);
break;
}
if ((line.substring(0, portIndex) + ":" + line.substring(portIndex + 5)).startsWith(cvsRoot + " ")) {
password = line.substring(cvsRoot.length() + 4 + 1);
break;
}
}
}
} finally {
Expand Down
29 changes: 29 additions & 0 deletions src/test/java/hudson/scm/LegacyConvertorTest.java
@@ -0,0 +1,29 @@
package hudson.scm;

import java.io.File;
import java.net.URISyntaxException;

import org.junit.Test;
import org.jvnet.hudson.test.HudsonTestCase;

public class LegacyConvertorTest extends HudsonTestCase {

// borrowed from core/test/.../TestResultTest, this is probably too complicated
private String getDataFile(String name) throws URISyntaxException {
return new File(LegacyConvertorTest.class.getResource(name).toURI()).getAbsolutePath();
}

// check JENKINS-12582 CVS-Plugin: Password file "${user.home}/.cvspass" is ignored
@Test
public final void testGetPassword() throws URISyntaxException {
// FIXME: not sure if setting user.home is safe in all cases?
String home=System.getProperty("user.home");
System.setProperty("user.home", getDataFile(""));
LegacyConvertor instance = LegacyConvertor.getInstance();
assertEquals("password", instance.getPassword(":pserver:user@example.com/usr/local/cvsroot"));
assertEquals("password", instance.getPassword(":pserver:user@example.com:/usr/local/cvsroot"));

System.setProperty("user.home", home);
}

}
1 change: 1 addition & 0 deletions src/test/resources/hudson/scm/.cvspass
@@ -0,0 +1 @@
/1 :pserver:user@example.com:2401/usr/local/cvsroot A:yZZ30 e

0 comments on commit c80a279

Please sign in to comment.