Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJens Baumgart2010-11-30 05:13:28 -0500
committerMatthias Sohn2010-11-30 09:35:45 -0500
commitcfb8c6e0d57e09fa6013c2c27bb679df12455bc8 (patch)
treed488eacddceb3a4031a51867d0ea7ba99cd549c6 /org.eclipse.egit.core.test
parente9f2af26088f25a43db8c890b4be8ea641ff546b (diff)
downloadegit-cfb8c6e0d57e09fa6013c2c27bb679df12455bc8.tar.gz
egit-cfb8c6e0d57e09fa6013c2c27bb679df12455bc8.tar.xz
egit-cfb8c6e0d57e09fa6013c2c27bb679df12455bc8.zip
Implement basic authentification
Implementation of basic authentification with user and password. User and password entered in the clone wizard are put in the Eclipse secure store. A credentials provider was implemented that fetches credentials from the secure store and asks the user if credentials are not available. Change-Id: I5239c6595e39d2a855318649fccc8fe8ac5e5fb8 Signed-off-by: Jens Baumgart <jens.baumgart@sap.com> Signed-off-by: Edwin Kempin <edwin.kempin@sap.com> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.egit.core.test')
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/securestorage/EGitSecureStoreTest.java150
1 files changed, 150 insertions, 0 deletions
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/securestorage/EGitSecureStoreTest.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/securestorage/EGitSecureStoreTest.java
new file mode 100644
index 000000000..337f519b5
--- /dev/null
+++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/securestorage/EGitSecureStoreTest.java
@@ -0,0 +1,150 @@
+/*******************************************************************************
+ * Copyright (C) 2010, Jens Baumgart <jens.baumgart@sap.com>
+ * Copyright (C) 2010, Edwin Kempin <edwin.kempin@sap.com>
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.egit.core.securestorage;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.HashMap;
+
+import javax.crypto.spec.PBEKeySpec;
+
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.egit.core.test.TestUtils;
+import org.eclipse.equinox.security.storage.EncodingUtils;
+import org.eclipse.equinox.security.storage.ISecurePreferences;
+import org.eclipse.equinox.security.storage.SecurePreferencesFactory;
+import org.eclipse.equinox.security.storage.provider.IProviderHints;
+import org.eclipse.jgit.transport.URIish;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class EGitSecureStoreTest {
+
+ ISecurePreferences secureStoreForTest;
+
+ TestUtils testUtils = new TestUtils();
+
+ EGitSecureStore store;
+
+ @Before
+ public void setUp() throws Exception {
+ setupNewSecureStore();
+ store = new EGitSecureStore(secureStoreForTest);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ secureStoreForTest.flush();
+ }
+
+ @Test
+ public void testPutUserAndPassword() throws Exception {
+ URIish uri = new URIish("http://testRepo.example.com/testrepo");
+ UserPasswordCredentials credentials = new UserPasswordCredentials(
+ "agitter", "letmein");
+ store.putCredentials(uri, credentials);
+
+ ISecurePreferences node = secureStoreForTest.node("/GIT/"
+ + EncodingUtils.encodeSlashes(uri.toString()));
+ assertEquals("agitter", node.get("user", null));
+ assertTrue(node.isEncrypted("password"));
+ assertEquals("letmein", node.get("password", null));
+ }
+
+ @Test
+ public void testGetUserAndPassword() throws Exception {
+ URIish uri = new URIish("http://testRepo.example.com/testrepo");
+ UserPasswordCredentials credentials = new UserPasswordCredentials(
+ "agitter", "letmein");
+ store.putCredentials(uri, credentials);
+
+ UserPasswordCredentials storedCredentials = store.getCredentials(uri);
+ assertEquals("agitter", storedCredentials.getUser());
+ assertEquals("letmein", storedCredentials.getPassword());
+ }
+
+ @Test
+ public void testGetUserAndPasswordUnknownURI() throws Exception {
+ URIish uri = new URIish("http://testRepo.example.com/testrepo");
+
+ UserPasswordCredentials storedCredentials = store.getCredentials(uri);
+ assertNull(storedCredentials);
+ }
+
+ @Test
+ public void testPutUserAndPasswordURIContainingUserAndPass()
+ throws Exception {
+ UserPasswordCredentials credentials = new UserPasswordCredentials(
+ "agitter", "letmein");
+ store.putCredentials(new URIish(
+ "http://user:pass@testRepo.example.com/testrepo"), credentials);
+
+ ISecurePreferences node = secureStoreForTest.node("/GIT/"
+ + EncodingUtils
+ .encodeSlashes("http://testRepo.example.com/testrepo"));
+ assertEquals("agitter", node.get("user", null));
+ assertTrue(node.isEncrypted("password"));
+ assertEquals("letmein", node.get("password", null));
+ }
+
+ @Test
+ public void testGetUserAndPasswordURIContainingUserAndPass()
+ throws Exception {
+ store.putCredentials(
+ new URIish("http://testRepo.example.com/testrepo"),
+ new UserPasswordCredentials("agitter", "letmein"));
+ UserPasswordCredentials credentials = store.getCredentials(new URIish(
+ "http://agitter:letmein@testRepo.example.com/testrepo"));
+ assertEquals("agitter", credentials.getUser());
+ assertEquals("letmein", credentials.getPassword());
+ }
+
+ @Test
+ public void testGetUserAndPasswordURIContainingOtherUserAndPass()
+ throws Exception {
+ store.putCredentials(
+ new URIish("http://testRepo.example.com/testrepo"),
+ new UserPasswordCredentials("agitter", "letmein"));
+ assertNull(store.getCredentials(new URIish(
+ "http://otheruser:otherpass@testRepo.example.com/testrepo")));
+ }
+
+ @Test
+ public void testClearCredentials() throws Exception {
+ URIish uri = new URIish("http://testRepo.example.com/testrepo");
+ UserPasswordCredentials credentials = new UserPasswordCredentials(
+ "agitter", "letmein");
+ store.putCredentials(uri, credentials);
+ store.clearCredentials(uri);
+ assertEquals(null, store.getCredentials(uri));
+ }
+
+ private void setupNewSecureStore() throws IOException,
+ MalformedURLException {
+ HashMap<String, Object> options = new HashMap<String, Object>();
+ options.put(IProviderHints.DEFAULT_PASSWORD, new PBEKeySpec(
+ "masterpass".toCharArray()));
+ String secureStorePath = ResourcesPlugin.getWorkspace().getRoot()
+ .getLocation().append("testSecureStore").toOSString();
+ File file = new File(secureStorePath);
+ testUtils.deleteRecursive(file);
+ URL url = file.toURI().toURL();
+ secureStoreForTest = SecurePreferencesFactory.open(url, options);
+ secureStoreForTest.node("/GIT").removeNode();
+ }
+
+}

Back to the top