You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by se...@apache.org on 2021/01/30 19:52:28 UTC

[directory-studio] branch master updated: DIRSTUDIO-996: Verify default schema is used if no schema is provided

This is an automated email from the ASF dual-hosted git repository.

seelmann pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/directory-studio.git


The following commit(s) were added to refs/heads/master by this push:
     new 67b96b4  DIRSTUDIO-996: Verify default schema is used if no schema is provided
67b96b4 is described below

commit 67b96b482bfcce1bb35c2166d97e4c9cb940c195
Author: Stefan Seelmann <ma...@stefan-seelmann.de>
AuthorDate: Sat Jan 30 20:44:14 2021 +0100

    DIRSTUDIO-996: Verify default schema is used if no schema is provided
---
 .../studio/test/integration/ui/OpenLdapTest.java   | 48 ++++++++++++++++++++++
 .../integration/ui/bots/ConnectionsViewBot.java    | 11 +++++
 .../studio/test/integration/ui/OpenLdapConfig.ldif | 25 +++++++++++
 3 files changed, 84 insertions(+)

diff --git a/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/OpenLdapTest.java b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/OpenLdapTest.java
index 0eae6d1..519e9b3 100644
--- a/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/OpenLdapTest.java
+++ b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/OpenLdapTest.java
@@ -35,6 +35,7 @@ import java.util.stream.Collectors;
 import java.util.stream.StreamSupport;
 
 import org.apache.commons.lang3.StringUtils;
+import org.apache.directory.api.ldap.model.entry.Modification;
 import org.apache.directory.api.ldap.model.exception.LdapAuthenticationException;
 import org.apache.directory.api.ldap.model.ldif.LdifEntry;
 import org.apache.directory.api.ldap.model.ldif.LdifReader;
@@ -44,12 +45,15 @@ import org.apache.directory.studio.connection.core.Connection;
 import org.apache.directory.studio.ldapbrowser.core.BrowserCorePlugin;
 import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
 import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection.ModifyMode;
+import org.apache.directory.studio.ldapbrowser.core.model.schema.Schema;
 import org.apache.directory.studio.test.integration.ui.bots.BrowserViewBot;
 import org.apache.directory.studio.test.integration.ui.bots.ConnectionsViewBot;
 import org.apache.directory.studio.test.integration.ui.bots.EntryEditorBot;
+import org.apache.directory.studio.test.integration.ui.bots.ErrorDialogBot;
 import org.apache.directory.studio.test.integration.ui.bots.ModificationLogsViewBot;
 import org.apache.directory.studio.test.integration.ui.bots.NewAttributeWizardBot;
 import org.apache.directory.studio.test.integration.ui.bots.NewConnectionWizardBot;
+import org.apache.directory.studio.test.integration.ui.bots.SchemaBrowserBot;
 import org.apache.directory.studio.test.integration.ui.bots.SearchDialogBot;
 import org.apache.directory.studio.test.integration.ui.bots.StudioBot;
 import org.apache.directory.studio.test.integration.ui.bots.utils.Assertions;
@@ -83,6 +87,8 @@ public class OpenLdapTest
     private static final int OPENLDAP_PORT = Integer.parseInt( getOrDefault( "OPENLDAP_PORT", "20389" ) );
     private static final String OPENLDAP_ADMIN_DN = getOrDefault( "OPENLDAP_ADMIN_DN", "cn=admin,dc=example,dc=org" );
     private static final String OPENLDAP_ADMIN_PASSWORD = getOrDefault( "OPENLDAP_ADMIN_PASSWORD", "admin" );
+    private static final String OPENLDAP_CONFIG_DN = getOrDefault( "OPENLDAP_CONFIG_DN", "cn=admin,cn=config" );
+    private static final String OPENLDAP_CONFIG_PASSWORD = getOrDefault( "OPENLDAP_CONFIG_PASSWORD", "config" );
 
     @BeforeClass
     public static void skipOpenLdapTestIfNotRunning() throws Exception
@@ -132,6 +138,19 @@ public class OpenLdapTest
                 connection.add( entry.getEntry() );
             }
         }
+
+        try ( LdapNetworkConnection connection = new LdapNetworkConnection( OPENLDAP_HOST, OPENLDAP_PORT );
+            LdifReader ldifReader = new LdifReader( OpenLdapTest.class.getResourceAsStream( "OpenLdapConfig.ldif" ) ) )
+        {
+            connection.bind( OPENLDAP_CONFIG_DN, OPENLDAP_CONFIG_PASSWORD );
+            for ( LdifEntry entry : ldifReader )
+            {
+                for ( Modification modification : entry.getModifications() )
+                {
+                    connection.modify( entry.getDn(), modification );
+                }
+            }
+        }
     }
 
 
@@ -426,4 +445,33 @@ public class OpenLdapTest
             StringUtils.countMatches( modificationLogsViewBot.getModificationLogsText(), "#!RESULT OK" ) );
     }
 
+
+    @Test
+    public void testNoPermissionToReadSchema() throws Exception
+    {
+        // Close connection and reset cached schema
+        connectionsViewBot.closeSelectedConnections();
+        IBrowserConnection browserConnection = BrowserCorePlugin.getDefault().getConnectionManager()
+            .getBrowserConnection( connection );
+        browserConnection.setSchema( Schema.DEFAULT_SCHEMA );
+
+        // Open connection as uid=user.1 which is not allowed to read cn=subschema
+        connection.setBindPrincipal( "uid=user.1,ou=users,dc=example,dc=org" );
+        connection.setBindPassword( "password" );
+        ErrorDialogBot errorDialog = connectionsViewBot.openSelectedConnectionExpectingNoSchemaProvidedErrorDialog();
+        assertThat( errorDialog.getErrorDetails(),
+            containsString( "No schema information returned by server, using default schema." ) );
+        errorDialog.clickOkButton();
+
+        // Verify default schema is used
+        SchemaBrowserBot schemaBrowser = connectionsViewBot.openSchemaBrowser();
+        schemaBrowser.selectObjectClass( "DEFAULTSCHEMA" );
+        String rawSchemaDefinition = schemaBrowser.getRawSchemaDefinition();
+        assertNotNull( rawSchemaDefinition );
+        assertTrue( rawSchemaDefinition.contains( "This is the Default Schema" ) );
+
+        // Verify browser
+        browserViewBot.selectEntry( "DIT", "Root DSE" );
+    }
+
 }
diff --git a/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/ConnectionsViewBot.java b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/ConnectionsViewBot.java
index bd7ca88..92687cc 100644
--- a/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/ConnectionsViewBot.java
+++ b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/ConnectionsViewBot.java
@@ -82,6 +82,17 @@ public class ConnectionsViewBot
     }
 
 
+    public ErrorDialogBot openSelectedConnectionExpectingNoSchemaProvidedErrorDialog()
+    {
+        String shellText = BotUtils.shell( () -> {
+            JobWatcher watcher = new JobWatcher( Messages.jobs__open_connections_name_1 );
+            getConnectionsTree().contextMenu( "Open Connection" ).click();
+            watcher.waitUntilDone();
+        }, "Problem Occurred" ).getText();
+        return new ErrorDialogBot( shellText );
+    }
+
+
     public void closeSelectedConnections()
     {
         JobWatcher watcher = new JobWatcher( Messages.jobs__close_connections_name_1 );
diff --git a/tests/test.integration.ui/src/main/resources/org/apache/directory/studio/test/integration/ui/OpenLdapConfig.ldif b/tests/test.integration.ui/src/main/resources/org/apache/directory/studio/test/integration/ui/OpenLdapConfig.ldif
new file mode 100644
index 0000000..f28f338
--- /dev/null
+++ b/tests/test.integration.ui/src/main/resources/org/apache/directory/studio/test/integration/ui/OpenLdapConfig.ldif
@@ -0,0 +1,25 @@
+#  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.
+#
+dn: olcDatabase={-1}frontend,cn=config
+changetype: modify
+replace: olcAccess
+olcAccess: {0}to * by dn.exact=gidNumber=0+uidNumber=0,cn=peercred,cn=external
+ ,cn=auth manage by * break
+olcAccess: {1}to dn.exact="" by * read
+olcAccess: {2}to dn.base="cn=Subschema" by dn.exact="uid=user.1,ou=users,dc=example,dc=org" none by * read
+-