You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2018/09/13 06:36:53 UTC
svn commit: r1840781 - in
/felix/trunk/configadmin/src/test/java/org/apache/felix/cm/integration:
ConfigAdminSecurityTest.java helper/ConfigurationListenerTestActivator.java
helper/ManagedServiceFactoryTestActivator4.java
Author: cziegeler
Date: Thu Sep 13 06:36:53 2018
New Revision: 1840781
URL: http://svn.apache.org/viewvc?rev=1840781&view=rev
Log:
Add additional tests for FELIX-5010 contributed by Tim Ward
Added:
felix/trunk/configadmin/src/test/java/org/apache/felix/cm/integration/helper/ConfigurationListenerTestActivator.java (with props)
felix/trunk/configadmin/src/test/java/org/apache/felix/cm/integration/helper/ManagedServiceFactoryTestActivator4.java (with props)
Modified:
felix/trunk/configadmin/src/test/java/org/apache/felix/cm/integration/ConfigAdminSecurityTest.java
Modified: felix/trunk/configadmin/src/test/java/org/apache/felix/cm/integration/ConfigAdminSecurityTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/configadmin/src/test/java/org/apache/felix/cm/integration/ConfigAdminSecurityTest.java?rev=1840781&r1=1840780&r2=1840781&view=diff
==============================================================================
--- felix/trunk/configadmin/src/test/java/org/apache/felix/cm/integration/ConfigAdminSecurityTest.java (original)
+++ felix/trunk/configadmin/src/test/java/org/apache/felix/cm/integration/ConfigAdminSecurityTest.java Thu Sep 13 06:36:53 2018
@@ -34,7 +34,9 @@ import java.io.IOException;
import java.util.Dictionary;
import java.util.Hashtable;
+import org.apache.felix.cm.integration.helper.ConfigurationListenerTestActivator;
import org.apache.felix.cm.integration.helper.ManagedServiceFactoryTestActivator3;
+import org.apache.felix.cm.integration.helper.ManagedServiceFactoryTestActivator4;
import org.apache.felix.cm.integration.helper.NestedURLStreamHandler;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -161,4 +163,82 @@ public class ConfigAdminSecurityTest ext
TestCase.assertEquals( 1, tester.numManagedServiceFactoryUpdatedCalls );
TestCase.assertEquals( 1, tester.numManagedServiceFactoryDeleteCalls );
}
+
+ @Test
+ public void test_secure_configuration_client_has_perm_we_do_not() throws BundleException, IOException
+ {
+ final String factoryPid = "test_secure_configuration_client_has_perm_we_do_not";
+ bundle = installBundle( factoryPid, ManagedServiceFactoryTestActivator4.class );
+ bundle.start();
+ delay();
+
+ final Configuration config = createFactoryConfiguration( factoryPid, null, true );
+ final String pid = config.getPid();
+ delay();
+
+ // ==> configuration supplied to the service ms1
+ final ManagedServiceFactoryTestActivator4 tester = ManagedServiceFactoryTestActivator4.INSTANCE;
+ Dictionary<?, ?> props = tester.configs.get( pid );
+ TestCase.assertNotNull( props );
+ TestCase.assertEquals( pid, props.get( Constants.SERVICE_PID ) );
+ TestCase.assertEquals( factoryPid, props.get( ConfigurationAdmin.SERVICE_FACTORYPID ) );
+ TestCase.assertNull( props.get( ConfigurationAdmin.SERVICE_BUNDLELOCATION ) );
+ TestCase.assertEquals( PROP_NAME, props.get( PROP_NAME ) );
+ TestCase.assertTrue( props.get( "port" ) != null );
+ TestCase.assertTrue( ( (Integer) props.get( "port" ) ) > 0 );
+ TestCase.assertEquals( 0, tester.numManagedServiceUpdatedCalls );
+ TestCase.assertEquals( 1, tester.numManagedServiceFactoryUpdatedCalls );
+ TestCase.assertEquals( 0, tester.numManagedServiceFactoryDeleteCalls );
+
+ // delete
+ config.delete();
+ delay();
+
+ // ==> update with null
+ TestCase.assertNull( tester.configs.get( pid ) );
+ TestCase.assertEquals( 0, tester.numManagedServiceUpdatedCalls );
+ TestCase.assertEquals( 1, tester.numManagedServiceFactoryUpdatedCalls );
+ TestCase.assertEquals( 1, tester.numManagedServiceFactoryDeleteCalls );
+ }
+
+ @Test
+ public void test_secure_configuration_listener_has_perm_we_do_not() throws BundleException, IOException
+ {
+ final String pid = "test_secure_configuration_listener_has_perm_we_do_not";
+ bundle = installBundle( pid, ConfigurationListenerTestActivator.class );
+ bundle.start();
+ delay();
+
+ final Configuration config = configure( pid, null, true );
+ delay();
+
+ // ==> configuration supplied to the service ms1
+ final ConfigurationListenerTestActivator tester = ConfigurationListenerTestActivator.INSTANCE;
+ Dictionary<?, ?> props = tester.configs.get( pid );
+ TestCase.assertNotNull( props );
+ TestCase.assertEquals( pid, props.get( Constants.SERVICE_PID ) );
+ TestCase.assertNull( props.get( ConfigurationAdmin.SERVICE_BUNDLELOCATION ) );
+ TestCase.assertEquals( PROP_NAME, props.get( PROP_NAME ) );
+ TestCase.assertTrue( props.get( "port" ) != null );
+ TestCase.assertTrue( ( (Integer) props.get( "port" ) ) > 0 );
+ TestCase.assertEquals( 0, tester.numManagedServiceUpdatedCalls );
+ TestCase.assertEquals( 0, tester.numManagedServiceFactoryUpdatedCalls );
+ TestCase.assertEquals( 0, tester.numManagedServiceFactoryDeleteCalls );
+ TestCase.assertEquals( 1, tester.numListenerUpdatedCalls );
+ TestCase.assertEquals( 0, tester.numListenerDeleteCalls );
+ TestCase.assertEquals( 1, tester.numListenerLocationChangedCalls );
+
+ // delete
+ config.delete();
+ delay();
+
+ // ==> update with null
+ TestCase.assertNull( tester.configs.get( pid ) );
+ TestCase.assertEquals( 0, tester.numManagedServiceUpdatedCalls );
+ TestCase.assertEquals( 0, tester.numManagedServiceFactoryUpdatedCalls );
+ TestCase.assertEquals( 0, tester.numManagedServiceFactoryDeleteCalls );
+ TestCase.assertEquals( 1, tester.numListenerUpdatedCalls );
+ TestCase.assertEquals( 1, tester.numListenerDeleteCalls );
+ TestCase.assertEquals( 1, tester.numListenerLocationChangedCalls );
+ }
}
Added: felix/trunk/configadmin/src/test/java/org/apache/felix/cm/integration/helper/ConfigurationListenerTestActivator.java
URL: http://svn.apache.org/viewvc/felix/trunk/configadmin/src/test/java/org/apache/felix/cm/integration/helper/ConfigurationListenerTestActivator.java?rev=1840781&view=auto
==============================================================================
--- felix/trunk/configadmin/src/test/java/org/apache/felix/cm/integration/helper/ConfigurationListenerTestActivator.java (added)
+++ felix/trunk/configadmin/src/test/java/org/apache/felix/cm/integration/helper/ConfigurationListenerTestActivator.java Thu Sep 13 06:36:53 2018
@@ -0,0 +1,115 @@
+/*
+ * 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.felix.cm.integration.helper;
+
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.util.Dictionary;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.service.cm.ConfigurationEvent;
+import org.osgi.service.cm.ConfigurationListener;
+
+public class ConfigurationListenerTestActivator extends BaseTestActivator implements ConfigurationListener
+{
+ public static ConfigurationListenerTestActivator INSTANCE;
+
+ private BundleContext context;
+
+ public int numListenerUpdatedCalls = 0;
+ public int numListenerDeleteCalls = 0;
+ public int numListenerLocationChangedCalls = 0;
+
+ public void start( BundleContext context ) throws Exception
+ {
+ this.context = context;
+ context.registerService( ConfigurationListener.class.getName(), this, null );
+ INSTANCE = this;
+ }
+
+
+ public void stop( BundleContext arg0 ) throws Exception
+ {
+ INSTANCE = null;
+ }
+
+ @Override
+ public void configurationEvent(ConfigurationEvent event) {
+
+ String pid = event.getPid();
+
+ switch( event.getType() ) {
+ case ConfigurationEvent.CM_DELETED :
+ numListenerDeleteCalls++;
+ this.configs.remove( pid );
+ return;
+ case ConfigurationEvent.CM_LOCATION_CHANGED :
+ numListenerLocationChangedCalls++;
+ return;
+ case ConfigurationEvent.CM_UPDATED :
+ numListenerUpdatedCalls++;
+ // Deliberate fall through
+ }
+
+ try {
+ if( !pid.equals(getServiceProperties( context ).get( Constants.SERVICE_PID ))) {
+ return;
+ }
+ } catch ( Exception e1 ) {
+ e1.printStackTrace();
+ return;
+ }
+
+
+ Dictionary<String, Object> props;
+
+ try {
+ props = context.getService( event.getReference() )
+ .getConfiguration( pid ).getProperties();
+ } catch ( IOException ioe ) {
+ ioe.printStackTrace();
+ return;
+ }
+
+ this.configs.put( pid, props );
+
+ // Opening a socket is a secure action which Config Admin doesn't have permission to do
+
+ int port = 0;
+ ServerSocket ss = null;
+ try {
+ ss = new ServerSocket( 0 );
+ port = ss.getLocalPort();
+ } catch ( Exception e ) {
+ e.printStackTrace();
+ return;
+ } finally {
+ if (ss != null) {
+ try {
+ ss.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ props.put( "port", port );
+ }
+}
Propchange: felix/trunk/configadmin/src/test/java/org/apache/felix/cm/integration/helper/ConfigurationListenerTestActivator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: felix/trunk/configadmin/src/test/java/org/apache/felix/cm/integration/helper/ConfigurationListenerTestActivator.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Added: felix/trunk/configadmin/src/test/java/org/apache/felix/cm/integration/helper/ManagedServiceFactoryTestActivator4.java
URL: http://svn.apache.org/viewvc/felix/trunk/configadmin/src/test/java/org/apache/felix/cm/integration/helper/ManagedServiceFactoryTestActivator4.java?rev=1840781&view=auto
==============================================================================
--- felix/trunk/configadmin/src/test/java/org/apache/felix/cm/integration/helper/ManagedServiceFactoryTestActivator4.java (added)
+++ felix/trunk/configadmin/src/test/java/org/apache/felix/cm/integration/helper/ManagedServiceFactoryTestActivator4.java Thu Sep 13 06:36:53 2018
@@ -0,0 +1,72 @@
+/*
+ * 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.felix.cm.integration.helper;
+
+
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.util.Dictionary;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.service.cm.ManagedServiceFactory;
+
+
+public class ManagedServiceFactoryTestActivator4 extends BaseTestActivator
+{
+ public static ManagedServiceFactoryTestActivator4 INSTANCE;
+
+
+ public void start( BundleContext context ) throws Exception
+ {
+ context.registerService( ManagedServiceFactory.class.getName(), this, getServiceProperties( context ) );
+ INSTANCE = this;
+ }
+
+
+ public void stop( BundleContext arg0 ) throws Exception
+ {
+ INSTANCE = null;
+ }
+
+ public void updated( String pid, Dictionary props )
+ {
+ // Opening a socket is a secure action which Config Admin doesn't have permission to do
+
+ int port = 0;
+ ServerSocket ss = null;
+ try {
+ ss = new ServerSocket( 0 );
+ port = ss.getLocalPort();
+ } catch ( Exception e ) {
+ e.printStackTrace();
+ } finally {
+ if (ss != null) {
+ try {
+ ss.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ props.put( "port", port );
+
+ super.updated( pid, props );
+ }
+}
Propchange: felix/trunk/configadmin/src/test/java/org/apache/felix/cm/integration/helper/ManagedServiceFactoryTestActivator4.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: felix/trunk/configadmin/src/test/java/org/apache/felix/cm/integration/helper/ManagedServiceFactoryTestActivator4.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url