You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by ff...@apache.org on 2014/04/15 09:42:06 UTC
git commit: [KARAF-2910]add a testcase
Repository: karaf
Updated Branches:
refs/heads/karaf-2.3.x a1b2aac03 -> 4ea848923
[KARAF-2910]add a testcase
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/4ea84892
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/4ea84892
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/4ea84892
Branch: refs/heads/karaf-2.3.x
Commit: 4ea8489232b69fd45ad93f4eab14e99dc6e60d80
Parents: a1b2aac
Author: Freeman Fang <fr...@gmail.com>
Authored: Tue Apr 15 15:41:48 2014 +0800
Committer: Freeman Fang <fr...@gmail.com>
Committed: Tue Apr 15 15:41:48 2014 +0800
----------------------------------------------------------------------
.../java/org/apache/karaf/itests/JaasTest.java | 51 ++++++++++++++++++++
1 file changed, 51 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/4ea84892/itests/src/test/java/org/apache/karaf/itests/JaasTest.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/JaasTest.java b/itests/src/test/java/org/apache/karaf/itests/JaasTest.java
index 032b888..980c10f 100644
--- a/itests/src/test/java/org/apache/karaf/itests/JaasTest.java
+++ b/itests/src/test/java/org/apache/karaf/itests/JaasTest.java
@@ -13,12 +13,25 @@
*/
package org.apache.karaf.itests;
+import java.io.IOException;
+import javax.inject.Inject;
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.callback.NameCallback;
+import javax.security.auth.callback.PasswordCallback;
+import javax.security.auth.callback.UnsupportedCallbackException;
+import javax.security.auth.login.LoginContext;
+import org.apache.felix.fileinstall.ArtifactInstaller;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.junit.ExamReactorStrategy;
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
import org.ops4j.pax.exam.spi.reactors.AllConfinedStagedReactorFactory;
+import org.osgi.framework.BundleContext;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@RunWith(JUnit4TestRunner.class)
@@ -33,4 +46,42 @@ public class JaasTest extends KarafTestSupport {
assertTrue(listRealmsOutput.contains("PublickeyLoginModule"));
}
+ @Ignore
+ //ignore it as this is too time consuming
+ public void testLoginNoLeak() throws Exception {
+ for (int i = 0; i<200000; i++) {
+ doLogin();
+ }
+ }
+
+ @Inject
+ protected BundleContext bundleContext;
+
+ @Test // shows the leak afaics
+ public void testLoginSingleReg() throws Exception {
+ for (int i=0; i<10; i++) {
+ doLogin();
+ }
+ assertEquals(3, bundleContext.getServiceReferences(ArtifactInstaller.class.getName(), null).length);
+ }
+
+ private void doLogin() throws Exception {
+ final String userPassRealm = "karaf";
+ LoginContext lc = new LoginContext(userPassRealm, new CallbackHandler() {
+ public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
+ for (int i = 0; i < callbacks.length; i++) {
+ Callback callback = callbacks[i];
+ if (callback instanceof PasswordCallback) {
+ PasswordCallback passwordCallback = (PasswordCallback)callback;
+ passwordCallback.setPassword(userPassRealm.toCharArray());
+ } else if (callback instanceof NameCallback) {
+ NameCallback nameCallback = (NameCallback)callback;
+ nameCallback.setName(userPassRealm);
+ }
+ }
+ }
+ });
+ lc.login();
+ assertNotNull(lc.getSubject());
+ }
}