Search in sources :

Example 6 with Repository

use of org.eclipse.ceylon.common.config.Repositories.Repository in project ceylon by eclipse.

the class RepositoriesTest method testSetRepositoriesByType.

@Test
public void testSetRepositoriesByType() {
    CeylonConfig configCopy = testConfig.copy();
    Repositories testRepos = Repositories.withConfig(configCopy);
    Repository[] reps = testRepos.getRepositoriesByType(Repositories.REPO_TYPE_LOCAL_LOOKUP);
    reps = new Repositories.SimpleRepository[] { new Repositories.SimpleRepository("", "./mods", null) };
    testRepos.setRepositoriesByType(Repositories.REPO_TYPE_LOCAL_LOOKUP, reps);
    Repository[] lookup = testRepos.getLocalLookupRepositories();
    Assert.assertTrue(lookup.length == 1);
    assertRepository(lookup[0], "%lookup-1", "./mods", null, null);
}
Also used : Repositories(org.eclipse.ceylon.common.config.Repositories) Repository(org.eclipse.ceylon.common.config.Repositories.Repository) CeylonConfig(org.eclipse.ceylon.common.config.CeylonConfig) Test(org.junit.Test)

Example 7 with Repository

use of org.eclipse.ceylon.common.config.Repositories.Repository in project ceylon by eclipse.

the class RepositoriesTest method testGetDefaultGlobalLookupRepositories.

@Test
public void testGetDefaultGlobalLookupRepositories() {
    Repository[] lookup = defaultRepos.getGlobalLookupRepositories();
    Assert.assertTrue(lookup.length == 1);
    File userDir = defaultRepos.getUserRepoDir();
    assertRepository(lookup[0], "USER", userDir.getAbsolutePath(), null, null);
}
Also used : Repository(org.eclipse.ceylon.common.config.Repositories.Repository) File(java.io.File) Test(org.junit.Test)

Example 8 with Repository

use of org.eclipse.ceylon.common.config.Repositories.Repository in project ceylon by eclipse.

the class AuthenticationTest method testRepoWithFooAndBadStorePass.

@Test
public void testRepoWithFooAndBadStorePass() throws Exception {
    String keystoreSectionName = null;
    String storeFilename = "foofile";
    File storeFile = new File(testDir, storeFilename);
    String repoPass = "foopassword";
    String alias = "fooalias";
    String storePass = "foostorepass";
    createStore(testConfig, keystoreSectionName, storeFilename, storeFile, repoPass, alias, storePass, storePass);
    mockPrompt.prompts.put("Password for default keystore (foofile):", storePass + " whoops");
    Authentication.setPasswordPrompt(mockPrompt);
    Repository repository = repos.getRepository("repo-with-keystorefoo");
    Assert.assertNull(repository.getCredentials().getPassword());
    Assert.assertEquals(alias, repository.getCredentials().getAlias());
    UsernamePassword up = Authentication.fromConfig(testConfig).getUsernameAndPassword(repository.getCredentials());
    Assert.assertNotNull(up);
    mockPrompt.assertSeenNoPrompts();
    try {
        up.getPassword();
        Assert.fail();
    } catch (RuntimeException e) {
        // Annoyingly the Keystore provider (well the jecks one at least)
        // throws an IOException in this case
        Assert.assertTrue(e.getMessage(), e.getMessage().contains("Keystore was tampered with, or password was incorrect"));
    }
    mockPrompt.assertSeenOnlyGivenPrompts();
    Assert.assertEquals(repository.getCredentials().getUser(), up.getUser());
}
Also used : Repository(org.eclipse.ceylon.common.config.Repositories.Repository) File(java.io.File) UsernamePassword(org.eclipse.ceylon.common.config.Authentication.UsernamePassword) Test(org.junit.Test)

Example 9 with Repository

use of org.eclipse.ceylon.common.config.Repositories.Repository in project ceylon by eclipse.

the class AuthenticationTest method testRepoWithPlaintext.

@Test
public void testRepoWithPlaintext() {
    Repository repository = repos.getRepository("repo-with-plaintext");
    Assert.assertNotNull(repository);
    UsernamePassword up = Authentication.fromConfig(testConfig).getUsernameAndPassword(repository.getCredentials());
    Assert.assertNotNull(up);
    Assert.assertEquals("plaintext", new String(up.getPassword()));
    mockPrompt.assertSeenNoPrompts();
    Assert.assertEquals(repository.getCredentials().getUser(), up.getUser());
}
Also used : Repository(org.eclipse.ceylon.common.config.Repositories.Repository) UsernamePassword(org.eclipse.ceylon.common.config.Authentication.UsernamePassword) Test(org.junit.Test)

Example 10 with Repository

use of org.eclipse.ceylon.common.config.Repositories.Repository in project ceylon by eclipse.

the class AuthenticationTest method testRepoWithFooAndEntryStorePass.

@Test
public void testRepoWithFooAndEntryStorePass() throws Exception {
    String keystoreSectionName = null;
    String storeFilename = "foofile";
    File storeFile = new File(testDir, storeFilename);
    String repoPass = "foopassword";
    String alias = "fooalias";
    String storePass = "foostorepass";
    String entryPass = "fooentry";
    createStore(testConfig, keystoreSectionName, storeFilename, storeFile, repoPass, alias, storePass, entryPass);
    mockPrompt.prompts.put("Password for default keystore (foofile):", storePass);
    Authentication.setPasswordPrompt(mockPrompt);
    Repository repository = repos.getRepository("repo-with-keystorefoo");
    Assert.assertNull(repository.getCredentials().getPassword());
    Assert.assertEquals(alias, repository.getCredentials().getAlias());
    UsernamePassword up = Authentication.fromConfig(testConfig).getUsernameAndPassword(repository.getCredentials());
    Assert.assertNotNull(up);
    mockPrompt.assertSeenPrompts();
    try {
        up.getPassword();
        Assert.fail();
    } catch (RuntimeException e) {
        Assert.assertTrue(e.getMessage(), e.getMessage().contains("The given password cannot be used to access the alias fooalias in the default keystore (foofile)"));
    }
    mockPrompt.assertSeenPrompts("Password for default keystore (foofile):");
    Assert.assertEquals(repository.getCredentials().getUser(), up.getUser());
}
Also used : Repository(org.eclipse.ceylon.common.config.Repositories.Repository) File(java.io.File) UsernamePassword(org.eclipse.ceylon.common.config.Authentication.UsernamePassword) Test(org.junit.Test)

Aggregations

Repository (org.eclipse.ceylon.common.config.Repositories.Repository)10 Test (org.junit.Test)9 UsernamePassword (org.eclipse.ceylon.common.config.Authentication.UsernamePassword)6 File (java.io.File)4 CeylonConfig (org.eclipse.ceylon.common.config.CeylonConfig)3 Repositories (org.eclipse.ceylon.common.config.Repositories)3 BuildException (org.apache.tools.ant.BuildException)1 Credentials (org.eclipse.ceylon.common.config.Credentials)1