Return-Path: X-Original-To: apmail-karaf-commits-archive@minotaur.apache.org Delivered-To: apmail-karaf-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id DACD98425 for ; Mon, 5 Sep 2011 11:08:25 +0000 (UTC) Received: (qmail 70239 invoked by uid 500); 5 Sep 2011 11:08:25 -0000 Delivered-To: apmail-karaf-commits-archive@karaf.apache.org Received: (qmail 70203 invoked by uid 500); 5 Sep 2011 11:08:24 -0000 Mailing-List: contact commits-help@karaf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@karaf.apache.org Delivered-To: mailing list commits@karaf.apache.org Received: (qmail 70195 invoked by uid 99); 5 Sep 2011 11:08:22 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 05 Sep 2011 11:08:22 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 05 Sep 2011 11:08:17 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 37EF523889E2 for ; Mon, 5 Sep 2011 11:07:56 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1165243 - in /karaf/sandbox/webconsole/trunk/core: ./ src/test/ src/test/java/ src/test/java/org/ src/test/java/org/apache/ src/test/java/org/apache/karaf/ src/test/java/org/apache/karaf/webconsole/ src/test/java/org/apache/karaf/webconsol... Date: Mon, 05 Sep 2011 11:07:55 -0000 To: commits@karaf.apache.org From: ldywicki@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110905110756.37EF523889E2@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: ldywicki Date: Mon Sep 5 11:07:55 2011 New Revision: 1165243 URL: http://svn.apache.org/viewvc?rev=1165243&view=rev Log: Login operation test. Works only from maven Added: karaf/sandbox/webconsole/trunk/core/src/test/ karaf/sandbox/webconsole/trunk/core/src/test/java/ karaf/sandbox/webconsole/trunk/core/src/test/java/org/ karaf/sandbox/webconsole/trunk/core/src/test/java/org/apache/ karaf/sandbox/webconsole/trunk/core/src/test/java/org/apache/karaf/ karaf/sandbox/webconsole/trunk/core/src/test/java/org/apache/karaf/webconsole/ karaf/sandbox/webconsole/trunk/core/src/test/java/org/apache/karaf/webconsole/core/ karaf/sandbox/webconsole/trunk/core/src/test/java/org/apache/karaf/webconsole/core/LoginTest.java karaf/sandbox/webconsole/trunk/core/src/test/java/org/apache/karaf/webconsole/core/TestInjector.java karaf/sandbox/webconsole/trunk/core/src/test/resources/ karaf/sandbox/webconsole/trunk/core/src/test/resources/jaas.conf karaf/sandbox/webconsole/trunk/core/src/test/resources/users.properties Modified: karaf/sandbox/webconsole/trunk/core/pom.xml Modified: karaf/sandbox/webconsole/trunk/core/pom.xml URL: http://svn.apache.org/viewvc/karaf/sandbox/webconsole/trunk/core/pom.xml?rev=1165243&r1=1165242&r2=1165243&view=diff ============================================================================== --- karaf/sandbox/webconsole/trunk/core/pom.xml (original) +++ karaf/sandbox/webconsole/trunk/core/pom.xml Mon Sep 5 11:07:55 2011 @@ -61,6 +61,26 @@ org.apache.karaf.jaas.modules ${karaf.version} + + + javax.servlet + servlet-api + 2.5 + provided + + + + junit + junit + 4.8.2 + test + + + org.slf4j + slf4j-log4j12 + ${slf4j.version} + test + @@ -105,6 +125,19 @@ + + org.apache.maven.plugins + maven-surefire-plugin + 2.9 + + + + java.security.auth.login.config + ${basedir}/src/test/resources/jaas.conf + + + + Added: karaf/sandbox/webconsole/trunk/core/src/test/java/org/apache/karaf/webconsole/core/LoginTest.java URL: http://svn.apache.org/viewvc/karaf/sandbox/webconsole/trunk/core/src/test/java/org/apache/karaf/webconsole/core/LoginTest.java?rev=1165243&view=auto ============================================================================== --- karaf/sandbox/webconsole/trunk/core/src/test/java/org/apache/karaf/webconsole/core/LoginTest.java (added) +++ karaf/sandbox/webconsole/trunk/core/src/test/java/org/apache/karaf/webconsole/core/LoginTest.java Mon Sep 5 11:07:55 2011 @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.karaf.webconsole.core; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.karaf.webconsole.core.brand.DefaultBrandProvider; +import org.apache.karaf.webconsole.core.dashboard.DashboardPage; +import org.apache.karaf.webconsole.core.internal.WebConsoleApplication; +import org.apache.karaf.webconsole.core.page.LoginPage; +import org.apache.wicket.authorization.UnauthorizedInstantiationException; +import org.apache.wicket.protocol.http.WebApplication; +import org.apache.wicket.util.tester.FormTester; +import org.apache.wicket.util.tester.WicketTester; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.BlockJUnit4ClassRunner; + +/** + * Test login operation and role verification. + */ +@RunWith(BlockJUnit4ClassRunner.class) +public class LoginTest { + + /** + * Application instance. + */ + private WebApplication application; + + @Before + public void setUp() { + application = new WebConsoleApplication(); + + final Map values = new HashMap(); + values.put("brandProvider", new DefaultBrandProvider()); + + application.addComponentInstantiationListener(new TestInjector(values)); + } + + @Test + public void testSuccessLogin() throws Exception { + WicketTester tester = new WicketTester(application); + tester.startPage(LoginPage.class); + //tester.debugComponentTrees(); + FormTester form = tester.newFormTester("signIn:signInForm"); + + form.setValue("username", "rootadmin"); + form.setValue("password", "admin"); + form.submit(); + + tester.assertNoErrorMessage(); + tester.assertRenderedPage(DashboardPage.class); + } + + @Test(expected = UnauthorizedInstantiationException.class) + public void testWrongRoleLogin() throws Exception { + WicketTester tester = new WicketTester(application); + tester.startPage(LoginPage.class); + + FormTester form = tester.newFormTester("signIn:signInForm"); + + form.setValue("username", "someuser"); + form.setValue("password", "user"); + form.submit(); + } + +} Added: karaf/sandbox/webconsole/trunk/core/src/test/java/org/apache/karaf/webconsole/core/TestInjector.java URL: http://svn.apache.org/viewvc/karaf/sandbox/webconsole/trunk/core/src/test/java/org/apache/karaf/webconsole/core/TestInjector.java?rev=1165243&view=auto ============================================================================== --- karaf/sandbox/webconsole/trunk/core/src/test/java/org/apache/karaf/webconsole/core/TestInjector.java (added) +++ karaf/sandbox/webconsole/trunk/core/src/test/java/org/apache/karaf/webconsole/core/TestInjector.java Mon Sep 5 11:07:55 2011 @@ -0,0 +1,96 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.karaf.webconsole.core; + +import java.io.Serializable; +import java.lang.reflect.Field; +import java.util.Map; + +import net.sf.cglib.proxy.Enhancer; + +import org.apache.wicket.Component; +import org.apache.wicket.application.IComponentInstantiationListener; +import org.ops4j.pax.wicket.api.PaxWicketBean; +import org.ops4j.pax.wicket.internal.injection.AbstractPaxWicketInjector; +import org.ops4j.pax.wicket.internal.injection.ComponentProxy; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * {@link IComponentInstantiationListener} which injects given values to fields + * annotated with {@link PaxWicketBean}. + */ +public class TestInjector extends AbstractPaxWicketInjector implements IComponentInstantiationListener { + + /** + * Logger. + */ + private Logger logger = LoggerFactory.getLogger(TestInjector.class); + + /** + * Values to inject. + */ + private final Map values; + + public TestInjector(Map values) { + this.values = values; + } + + /** + * {@inheritDoc} + */ + public void onInstantiation(Component component) { + + for (Field field : getFields(component.getClass())) { + // iterate over fields and check if there is values to inject + String name = field.getName(); + Class type = field.getType(); + + if (values.containsKey(name)) { + // we have value.. + Object value = values.get(name); + + // create instance proxy, just like pax-wicket does + if (type.isAssignableFrom(value.getClass())){ + Enhancer enhancer = new Enhancer(); + enhancer.setSuperclass(value.getClass()); + if (!(value instanceof Serializable)) { + logger.warn("Value for field {}.{} is not serializable. Adding Serializable interface for test, result in production may vary", + field.getDeclaringClass(), name); + enhancer.setInterfaces(new Class[] {Serializable.class}); + } + enhancer.setCallback(new ComponentProxy("test", null)); + setField(component, field, enhancer.create()); + } else { + logger.error("Type mismath for field {}.{}. Expected {} but {} given", new Object[] { + field.getDeclaringClass().getName(), name, field.getType().getName(), value.getClass().getName() + }); + System.err.println("Unknown type " + field.getType()); + } + } else { + logger.warn("No value provided for field {}.{}", field.getDeclaringClass().getName(), name); + } + } + } + + /** + * {@inheritDoc} + */ + public void inject(Object toInject, Class toHandle) { + throw new UnsupportedOperationException("inject operation should never be executed"); + } +} \ No newline at end of file Added: karaf/sandbox/webconsole/trunk/core/src/test/resources/jaas.conf URL: http://svn.apache.org/viewvc/karaf/sandbox/webconsole/trunk/core/src/test/resources/jaas.conf?rev=1165243&view=auto ============================================================================== --- karaf/sandbox/webconsole/trunk/core/src/test/resources/jaas.conf (added) +++ karaf/sandbox/webconsole/trunk/core/src/test/resources/jaas.conf Mon Sep 5 11:07:55 2011 @@ -0,0 +1,20 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +karaf { + org.apache.karaf.jaas.modules.properties.PropertiesLoginModule required + users="src/test/resources/users.properties"; +}; \ No newline at end of file Added: karaf/sandbox/webconsole/trunk/core/src/test/resources/users.properties URL: http://svn.apache.org/viewvc/karaf/sandbox/webconsole/trunk/core/src/test/resources/users.properties?rev=1165243&view=auto ============================================================================== --- karaf/sandbox/webconsole/trunk/core/src/test/resources/users.properties (added) +++ karaf/sandbox/webconsole/trunk/core/src/test/resources/users.properties Mon Sep 5 11:07:55 2011 @@ -0,0 +1,16 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +rootadmin=admin,admin +someuser=user,user \ No newline at end of file