Search in sources :

Example 1 with UserPassword

use of com.google.copybara.git.GitCredential.UserPassword in project copybara by google.

the class GitOriginTest method testCredentials.

@Test
public void testCredentials() throws Exception {
    Path credentialsFile = Files.createTempFile("credentials", "test");
    Files.write(credentialsFile, "https://user:SECRET@somehost.com".getBytes(UTF_8));
    options.git.credentialHelperStorePath = credentialsFile.toString();
    GitRepository repository = origin().getRepository();
    UserPassword result = repository.credentialFill("https://somehost.com/foo/bar");
    assertThat(result.getUsername()).isEqualTo("user");
    assertThat(result.getPassword_BeCareful()).isEqualTo("SECRET");
}
Also used : Path(java.nio.file.Path) FileSubjects.assertThatPath(com.google.copybara.testing.FileSubjects.assertThatPath) UserPassword(com.google.copybara.git.GitCredential.UserPassword) Test(org.junit.Test)

Example 2 with UserPassword

use of com.google.copybara.git.GitCredential.UserPassword in project copybara by google.

the class GitCredentialTest method testSuccess.

@Test
public void testSuccess() throws Exception {
    Files.write(credentialsFile, "https://user:SECRET@somehost.com".getBytes(UTF_8));
    TestLogHandler handler = new TestLogHandler();
    Logger.getGlobal().getParent().addHandler(handler);
    UserPassword result;
    try {
        result = credential.fill(repoGitDir, "https://somehost.com/foo/bar");
    } finally {
        Logger.getGlobal().getParent().removeHandler(handler);
    }
    assertThat(result.getUsername()).isEqualTo("user");
    assertThat(result.getPassword_BeCareful()).isEqualTo("SECRET");
    assertThat(result.toString()).doesNotContain("SECRET");
    assertThat(Iterables.transform(handler.getStoredLogRecords(), LogRecord::getMessage)).doesNotContain("SECRET");
}
Also used : TestLogHandler(com.google.common.testing.TestLogHandler) LogRecord(java.util.logging.LogRecord) UserPassword(com.google.copybara.git.GitCredential.UserPassword) Test(org.junit.Test)

Example 3 with UserPassword

use of com.google.copybara.git.GitCredential.UserPassword in project copybara by google.

the class GitDestinationTest method checkCredentials.

private GitRepository checkCredentials() throws IOException, RepoException, ValidationException {
    Path credentialsFile = Files.createTempFile("credentials", "test");
    Files.write(credentialsFile, "https://user:SECRET@somehost.com".getBytes(UTF_8));
    options.git.credentialHelperStorePath = credentialsFile.toString();
    GitRepository repository = destinationFirstCommit().getLocalRepo().load(console);
    UserPassword result = repository.credentialFill("https://somehost.com/foo/bar");
    assertThat(result.getUsername()).isEqualTo("user");
    assertThat(result.getPassword_BeCareful()).isEqualTo("SECRET");
    return repository;
}
Also used : Path(java.nio.file.Path) UserPassword(com.google.copybara.git.GitCredential.UserPassword)

Example 4 with UserPassword

use of com.google.copybara.git.GitCredential.UserPassword in project copybara by google.

the class GitMirrorTest method testMirrorCredentials.

@Test
public void testMirrorCredentials() throws Exception {
    Path credentialsFile = Files.createTempFile("credentials", "test");
    Files.write(credentialsFile, "https://user:SECRET@somehost.com".getBytes(UTF_8));
    options.git.credentialHelperStorePath = credentialsFile.toString();
    String cfg = "" + "git.mirror(" + "    name = 'default'," + "    origin = 'file://" + originRepo.getGitDir().toAbsolutePath() + "'," + "    destination = 'file://" + destRepo.getGitDir().toAbsolutePath() + "'," + ")\n" + "";
    GitRepository repository = ((Mirror) loadMigration(cfg, "default")).getLocalRepo();
    UserPassword result = repository.credentialFill("https://somehost.com/foo/bar");
    assertThat(result.getUsername()).isEqualTo("user");
    assertThat(result.getPassword_BeCareful()).isEqualTo("SECRET");
}
Also used : Path(java.nio.file.Path) UserPassword(com.google.copybara.git.GitCredential.UserPassword) Test(org.junit.Test)

Aggregations

UserPassword (com.google.copybara.git.GitCredential.UserPassword)4 Path (java.nio.file.Path)3 Test (org.junit.Test)3 TestLogHandler (com.google.common.testing.TestLogHandler)1 FileSubjects.assertThatPath (com.google.copybara.testing.FileSubjects.assertThatPath)1 LogRecord (java.util.logging.LogRecord)1