use of org.eclipse.ceylon.common.config.Authentication.UsernamePassword in project ceylon by eclipse.
the class AuthenticationTest method testRepoWithPrompt.
@Test
public void testRepoWithPrompt() {
mockPrompt.prompts.put("Password for bar at https://modules.ceylon-lang.org:", "repopassword");
Repository repository = repos.getRepository("repo-with-prompted");
Assert.assertNotNull(repository);
UsernamePassword up = Authentication.fromConfig(testConfig).getUsernameAndPassword(repository.getCredentials());
Assert.assertNotNull(up);
Assert.assertEquals("repopassword", new String(up.getPassword()));
mockPrompt.assertSeenOnlyGivenPrompts();
Assert.assertEquals(repository.getCredentials().getUser(), up.getUser());
}
use of org.eclipse.ceylon.common.config.Authentication.UsernamePassword in project ceylon by eclipse.
the class AuthenticationTest method testRepoWithFooAndKeystoreMissing.
@Test
public void testRepoWithFooAndKeystoreMissing() {
Authentication.setPasswordPrompt(mockPrompt);
Repository repository = repos.getRepository("repo-with-keystorefoo");
Assert.assertNull(repository.getCredentials().getPassword());
Assert.assertEquals("fooalias", repository.getCredentials().getAlias());
UsernamePassword up = Authentication.fromConfig(testConfig).getUsernameAndPassword(repository.getCredentials());
Assert.assertNotNull(up);
mockPrompt.assertSeenNoPrompts();
try {
up.getPassword();
Assert.fail();
} catch (RuntimeException e) {
if (!e.getMessage().contains("The default keystore (foofile) does not exist")) {
throw e;
}
}
mockPrompt.assertSeenNoPrompts();
Assert.assertEquals(repository.getCredentials().getUser(), up.getUser());
}
use of org.eclipse.ceylon.common.config.Authentication.UsernamePassword in project ceylon by eclipse.
the class AuthenticationTest method testRepoWithFoo.
@Test
public void testRepoWithFoo() 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 = "fooentrypass";
createStore(testConfig, keystoreSectionName, storeFilename, storeFile, repoPass, alias, storePass, storePass);
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.assertSeenNoPrompts();
Assert.assertEquals(repoPass, new String(up.getPassword()));
mockPrompt.assertSeenOnlyGivenPrompts();
Assert.assertEquals(repository.getCredentials().getUser(), up.getUser());
// Get the password again
up.getPassword();
// Check we're not prompted again
mockPrompt.assertSeenOnlyGivenPrompts();
}
use of org.eclipse.ceylon.common.config.Authentication.UsernamePassword 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());
}
use of org.eclipse.ceylon.common.config.Authentication.UsernamePassword 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());
}
Aggregations