Repository: karaf Updated Branches: refs/heads/master b220722c3 -> 70d14e6e1
[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/70d14e6e Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/70d14e6e Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/70d14e6e Branch: refs/heads/master Commit: 70d14e6e10560e5128a9637b3d135948aa42c1ce Parents: b220722 Author: Freeman Fang <[email protected]> Authored: Tue Apr 15 16:36:05 2014 +0800 Committer: Freeman Fang <[email protected]> Committed: Tue Apr 15 16:36:05 2014 +0800 ---------------------------------------------------------------------- .../java/org/apache/karaf/itests/JaasTest.java | 57 ++++++++++++++++++++ 1 file changed, 57 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/karaf/blob/70d14e6e/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 bb9bd19..27d3299 100644 --- a/itests/src/test/java/org/apache/karaf/itests/JaasTest.java +++ b/itests/src/test/java/org/apache/karaf/itests/JaasTest.java @@ -13,11 +13,28 @@ */ package org.apache.karaf.itests; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +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.PaxExam; import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy; import org.ops4j.pax.exam.spi.reactors.PerClass; +import org.ops4j.pax.exam.spi.reactors.PerMethod; + +import org.osgi.framework.BundleContext; @RunWith(PaxExam.class) @ExamReactorStrategy(PerClass.class) @@ -30,4 +47,44 @@ public class JaasTest extends KarafTestSupport { assertContains("PublickeyLoginModule", listRealmsOutput); } + @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()); + } + + }
