diff options
author | Stefan Seelmann <mail@stefan-seelmann.de> | 2021-04-06 00:44:38 +0300 |
---|---|---|
committer | Stefan Seelmann <mail@stefan-seelmann.de> | 2021-04-06 00:44:38 +0300 |
commit | 239d27fa50d60f387fff0031afe799284a554b57 (patch) | |
tree | 6d6b1ce29e21585be56a439691a255c153567696 | |
parent | 66fee764ce1a98e0cbcf65a4ec22d4c7cb4f16a0 (diff) |
DIRSTUDIO-1267: Fix handling of binary and other optionsDIRSTUDIO-1267-fix-binary-option
22 files changed, 726 insertions, 124 deletions
diff --git a/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/HexDialog.java b/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/HexDialog.java index d072388cb..d97864b23 100644 --- a/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/HexDialog.java +++ b/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/HexDialog.java @@ -35,7 +35,10 @@ import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.FileDialog; @@ -52,6 +55,8 @@ import org.eclipse.swt.widgets.Text; public class HexDialog extends Dialog { + public static final String LOAD_FILE_NAME_TOOLTIP = "LoadFileName"; + /** The default title. */ private static final String DIALOG_TITLE = Messages.getString( "HexDialog.HexEditor" ); //$NON-NLS-1$ @@ -64,6 +69,9 @@ public class HexDialog extends Dialog /** The button ID for the save button. */ private static final int SAVE_BUTTON_ID = 9999; + /** Hidden text to set the filename, used for UI tests. */ + private Text loadFilenameText; + /** The current data. */ private byte[] currentData; @@ -134,18 +142,7 @@ public class HexDialog extends Dialog String returnedFileName = fileDialog.open(); if ( returnedFileName != null ) { - try - { - File file = new File( returnedFileName ); - currentData = FileUtils.readFileToByteArray( file ); - hexText.setText( toFormattedHex( currentData ) ); - } - catch ( IOException e ) - { - ConnectionUIPlugin.getDefault().getExceptionHandler().handleException( - new Status( IStatus.ERROR, BrowserCommonConstants.PLUGIN_ID, IStatus.ERROR, Messages - .getString( "HexDialog.CantReadFile" ), e ) ); //$NON-NLS-1$ - } + loadFile( returnedFileName ); } } else @@ -157,6 +154,23 @@ public class HexDialog extends Dialog } + private void loadFile( String fileName ) + { + try + { + File file = new File( fileName ); + currentData = FileUtils.readFileToByteArray( file ); + hexText.setText( toFormattedHex( currentData ) ); + } + catch ( IOException e ) + { + ConnectionUIPlugin.getDefault().getExceptionHandler().handleException( + new Status( IStatus.ERROR, BrowserCommonConstants.PLUGIN_ID, IStatus.ERROR, Messages + .getString( "HexDialog.CantReadFile" ), e ) ); //$NON-NLS-1$ + } + } + + /** * Small helper. */ @@ -187,11 +201,23 @@ public class HexDialog extends Dialog */ protected void createButtonsForButtonBar( Composite parent ) { + ((GridLayout) parent.getLayout()).numColumns++; + loadFilenameText = new Text( parent, SWT.NONE ); + loadFilenameText.setToolTipText( LOAD_FILE_NAME_TOOLTIP ); + loadFilenameText.setBackground( parent.getBackground() ); + loadFilenameText.addModifyListener( new ModifyListener() + { + public void modifyText( ModifyEvent e ) + { + loadFile( loadFilenameText.getText() ); + } + } ); + if ( isEditable( currentData ) ) { createButton( parent, EDIT_AS_TEXT_BUTTON_ID, Messages.getString( "HexDialog.EditAsText" ), false ); //$NON-NLS-1$ } - + createButton( parent, LOAD_BUTTON_ID, Messages.getString( "HexDialog.LoadDataButton" ), false ); //$NON-NLS-1$ createButton( parent, SAVE_BUTTON_ID, Messages.getString( "HexDialog.SaveDataButton" ), false ); //$NON-NLS-1$ createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, false ); diff --git a/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/wizards/NewEntryAttributesWizardPage.java b/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/wizards/NewEntryAttributesWizardPage.java index b6409ea8d..ebba3c7c1 100644 --- a/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/wizards/NewEntryAttributesWizardPage.java +++ b/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/wizards/NewEntryAttributesWizardPage.java @@ -184,7 +184,7 @@ public class NewEntryAttributesWizardPage extends WizardPage implements EntryUpd // remove empty must attributes // necessary when navigating back, modifying object classes - // and Dn and navigation forward again. + // and Dn and navigating forward again. Collection<AttributeType> oldMusts = SchemaUtils.getMustAttributeTypeDescriptions( newEntry ); for ( AttributeType oldMust : oldMusts ) { diff --git a/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/IEntry.java b/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/IEntry.java index d7a942f85..b7741e3f7 100644 --- a/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/IEntry.java +++ b/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/IEntry.java @@ -24,18 +24,11 @@ package org.apache.directory.studio.ldapbrowser.core.model; import java.io.Serializable; import java.util.Collection; -import org.apache.directory.api.ldap.model.entry.Attribute; -import org.apache.directory.api.ldap.model.entry.DefaultAttribute; -import org.apache.directory.api.ldap.model.entry.DefaultEntry; -import org.apache.directory.api.ldap.model.entry.Entry; -import org.apache.directory.api.ldap.model.exception.LdapException; -import org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException; import org.apache.directory.api.ldap.model.name.Dn; import org.apache.directory.api.ldap.model.name.Rdn; import org.apache.directory.api.ldap.model.schema.ObjectClass; import org.apache.directory.api.ldap.model.url.LdapUrl; import org.apache.directory.studio.connection.core.ConnectionPropertyPageProvider; -import org.apache.directory.studio.connection.core.io.LdapRuntimeException; import org.apache.directory.studio.connection.core.jobs.StudioConnectionBulkRunnableWithProgress; import org.apache.directory.studio.ldapbrowser.core.propertypageproviders.EntryPropertyPageProvider; import org.eclipse.core.runtime.IAdaptable; @@ -471,38 +464,4 @@ public interface IEntry extends Serializable, IAdaptable, EntryPropertyPageProvi */ Collection<ObjectClass> getObjectClassDescriptions(); - - default Entry toEntry() - { - try - { - Entry entry = new DefaultEntry( getDn() ); - for ( IAttribute iAttribute : getAttributes() ) - { - Attribute attribute = new DefaultAttribute( iAttribute.getType() ); - for ( IValue iValue : iAttribute.getValues() ) - { - Object rawValue = iValue.getRawValue(); - if ( rawValue instanceof String ) - { - attribute.add( ( String ) rawValue ); - } - else if ( rawValue instanceof byte[] ) - { - attribute.add( ( byte[] ) rawValue ); - } - else - { - attribute.add( ( String ) null ); - } - } - entry.add( attribute ); - } - return entry; - } - catch ( LdapException e ) - { - throw new LdapRuntimeException( e ); - } - } } diff --git a/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/ModelConverter.java b/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/ModelConverter.java index 34e21637e..1ee7a314b 100644 --- a/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/ModelConverter.java +++ b/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/ModelConverter.java @@ -336,14 +336,14 @@ public class ModelConverter { for ( IValue value : iAttribute.getValues() ) { - String attributeType = value.getAttribute().getType(); + String attributeDescription = value.getAttribute().getDescription(); if ( value.isString() ) { - ldapApiEntry.add( attributeType, value.getStringValue() ); + ldapApiEntry.add( attributeDescription, value.getStringValue() ); } else { - ldapApiEntry.add( attributeType, value.getBinaryValue() ); + ldapApiEntry.add( attributeDescription, value.getBinaryValue() ); } } } diff --git a/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/certificate/CertificateDialog.java b/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/certificate/CertificateDialog.java index 99c501d18..c139d8aef 100644 --- a/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/certificate/CertificateDialog.java +++ b/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/certificate/CertificateDialog.java @@ -41,11 +41,15 @@ import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.FileDialog; import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; /** @@ -57,6 +61,8 @@ import org.eclipse.swt.widgets.Shell; public class CertificateDialog extends Dialog { + public static final String LOAD_FILE_NAME_TOOLTIP = "LoadFileName"; + /** The default title. */ private static final String DIALOG_TITLE = Messages.getString( "CertificateDialog.CertificateDialog" ); //$NON-NLS-1$ @@ -66,6 +72,9 @@ public class CertificateDialog extends Dialog /** The button ID for the save button. */ private static final int SAVE_BUTTON_ID = 9999; + /** Hidden text to set the filename, used for UI tests. */ + private Text loadFilenameText; + /** The current certificate binary data. */ private byte[] currentData; @@ -130,18 +139,7 @@ public class CertificateDialog extends Dialog String returnedFileName = fileDialog.open(); if ( returnedFileName != null ) { - try - { - File file = new File( returnedFileName ); - currentData = FileUtils.readFileToByteArray( file ); - updateInput(); - } - catch ( IOException e ) - { - ConnectionUIPlugin.getDefault().getExceptionHandler().handleException( - new Status( IStatus.ERROR, ValueEditorsConstants.PLUGIN_ID, IStatus.ERROR, Messages - .getString( "CertificateDialog.CantReadFile" ), e ) ); //$NON-NLS-1$ - } + loadFile( returnedFileName ); } } else @@ -153,6 +151,23 @@ public class CertificateDialog extends Dialog } + private void loadFile( String fileName ) + { + try + { + File file = new File( fileName ); + currentData = FileUtils.readFileToByteArray( file ); + updateInput(); + } + catch ( IOException e ) + { + ConnectionUIPlugin.getDefault().getExceptionHandler().handleException( + new Status( IStatus.ERROR, ValueEditorsConstants.PLUGIN_ID, IStatus.ERROR, Messages + .getString( "CertificateDialog.CantReadFile" ), e ) ); //$NON-NLS-1$ + } + } + + /** * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) */ @@ -169,6 +184,18 @@ public class CertificateDialog extends Dialog */ protected void createButtonsForButtonBar( Composite parent ) { + ((GridLayout) parent.getLayout()).numColumns++; + loadFilenameText = new Text( parent, SWT.NONE ); + loadFilenameText.setToolTipText( LOAD_FILE_NAME_TOOLTIP ); + loadFilenameText.setBackground( parent.getBackground() ); + loadFilenameText.addModifyListener( new ModifyListener() + { + public void modifyText( ModifyEvent e ) + { + loadFile( loadFilenameText.getText() ); + } + } ); + createButton( parent, LOAD_BUTTON_ID, Messages.getString( "CertificateDialog.LoadCertificateButton" ), false ); //$NON-NLS-1$ createButton( parent, SAVE_BUTTON_ID, Messages.getString( "CertificateDialog.SaveCertificateButton" ), false ); //$NON-NLS-1$ createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, false ); diff --git a/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/EntryEditorTest.java b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/EntryEditorTest.java index 04fcbeca6..756509956 100644 --- a/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/EntryEditorTest.java +++ b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/EntryEditorTest.java @@ -28,37 +28,25 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import java.io.File; -import java.io.InputStream; -import java.net.URL; -import java.security.KeyPair; -import java.security.KeyPairGenerator; -import java.security.cert.X509Certificate; - import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.StringUtils; import org.apache.directory.api.ldap.model.constants.AuthenticationLevel; import org.apache.directory.api.ldap.model.constants.LdapSecurityConstants; -import org.apache.directory.api.ldap.model.entry.DefaultModification; import org.apache.directory.api.ldap.model.entry.Entry; -import org.apache.directory.api.ldap.model.entry.ModificationOperation; import org.apache.directory.api.ldap.model.name.Dn; import org.apache.directory.api.ldap.model.password.PasswordUtil; -import org.apache.directory.api.util.FileUtils; -import org.apache.directory.api.util.IOUtils; import org.apache.directory.api.util.Strings; import org.apache.directory.server.annotations.CreateLdapServer; import org.apache.directory.server.annotations.CreateTransport; import org.apache.directory.server.core.annotations.ApplyLdifFiles; import org.apache.directory.server.core.integ.AbstractLdapTestUnit; -import org.apache.directory.server.core.security.CertificateUtil; import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages; import org.apache.directory.studio.ldifparser.LdifFormatParameters; import org.apache.directory.studio.ldifparser.LdifParserConstants; import org.apache.directory.studio.ldifparser.model.lines.LdifAttrValLine; import org.apache.directory.studio.test.integration.ui.bots.AciItemEditorDialogBot; -import org.apache.directory.studio.test.integration.ui.bots.BotUtils; import org.apache.directory.studio.test.integration.ui.bots.BrowserViewBot; +import org.apache.directory.studio.test.integration.ui.bots.CertificateEditorDialogBot; import org.apache.directory.studio.test.integration.ui.bots.ConnectionsViewBot; import org.apache.directory.studio.test.integration.ui.bots.DnEditorDialogBot; import org.apache.directory.studio.test.integration.ui.bots.EntryEditorBot; @@ -75,15 +63,12 @@ import org.apache.directory.studio.test.integration.ui.bots.utils.Assertions; import org.apache.directory.studio.test.integration.ui.bots.utils.Characters; import org.apache.directory.studio.test.integration.ui.bots.utils.FrameworkRunnerWithScreenshotCaptureListener; import org.apache.directory.studio.test.integration.ui.bots.utils.JobWatcher; -import org.eclipse.core.runtime.Platform; import org.eclipse.swtbot.swt.finder.utils.SWTUtils; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import sun.security.x509.X500Name; - /** * Tests the entry editor. @@ -523,29 +508,33 @@ public class EntryEditorTest extends AbstractLdapTestUnit /** - * DIRSTUDIO-1199, DIRSTUDIO-1204: Binary attributes + * DIRSTUDIO-1199, DIRSTUDIO-1204, DIRSTUDIO-1267: Binary attributes */ @Test public void testCertificateValueEditor() throws Exception { - X500Name issuer = new X500Name( "Foo", "Bar", "Baz", "US" ); - KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance( "EC" ); - keyPairGenerator.initialize( 256 ); - KeyPair keyPair = keyPairGenerator.generateKeyPair(); - X509Certificate certificate = CertificateUtil.generateSelfSignedCertificate( issuer, keyPair, 365, - "SHA256WithECDSA" ); - getService().getAdminSession().modify( new Dn( "cn=Barbara Jensen,ou=users,ou=system" ), - new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, "userCertificate", - certificate.getEncoded() ) ); + String certFile = ResourceUtils.prepareInputFile( "rfc5280_cert2.cer" ); browserViewBot.selectEntry( "DIT", "Root DSE", "ou=system", "ou=users", "cn=Barbara Jensen" ); EntryEditorBot entryEditorBot = studioBot.getEntryEditorBot( "cn=Barbara Jensen,ou=users,ou=system" ); entryEditorBot.activate(); - BotUtils.sleep( 1000 ); + NewAttributeWizardBot wizardBot = entryEditorBot.openNewAttributeWizard(); + assertTrue( wizardBot.isVisible() ); + wizardBot.typeAttributeType( "userCertificate" ); + wizardBot.clickNextButton(); + wizardBot.selectBinaryOption(); + CertificateEditorDialogBot certEditorBot = wizardBot.clickFinishButtonExpectingCertificateEditor(); + + assertTrue( certEditorBot.isVisible() ); + certEditorBot.typeFile( certFile ); + + certEditorBot.clickOkButton(); + + modificationLogsViewBot.waitForText( "add: userCertificate;binary\nuserCertificate;binary:: " ); assertTrue( entryEditorBot.getAttributeValues() - .contains( "userCertificate: X.509v3: CN=Foo,OU=Bar,O=Baz,C=US" ) ); + .contains( "userCertificate: X.509v3: CN=End Entity,DC=example,DC=com" ) ); } @@ -555,11 +544,7 @@ public class EntryEditorTest extends AbstractLdapTestUnit @Test public void testImageValueEditor() throws Exception { - URL url = Platform.getInstanceLocation().getURL(); - String destFile = url.getFile() + "studio_64x64.jpg"; - InputStream is = getClass().getResourceAsStream( "studio_64x64.jpg" ); - byte[] data = IOUtils.toByteArray( is, 2014 ); - FileUtils.writeByteArrayToFile( new File( destFile ), data ); + String imgFile = ResourceUtils.prepareInputFile( "studio_64x64.jpg" ); browserViewBot.selectEntry( "DIT", "Root DSE", "ou=system", "ou=users", "cn=Barbara Jensen" ); @@ -572,11 +557,11 @@ public class EntryEditorTest extends AbstractLdapTestUnit wizardBot.typeAttributeType( "jpegPhoto" ); ImageEditorDialogBot imageEditorBot = wizardBot.clickFinishButtonExpectingImageEditor(); assertTrue( imageEditorBot.isVisible() ); - imageEditorBot.typeFile( destFile ); + imageEditorBot.typeFile( imgFile ); imageEditorBot.clickOkButton(); // assert value after saved and reloaded from server - SWTUtils.sleep( 1000 ); + modificationLogsViewBot.waitForText( "add: jpegPhoto\njpegPhoto:: " ); assertTrue( entryEditorBot.getAttributeValues().contains( "jpegPhoto: JPEG-Image (64x64 Pixel, 2014 Bytes)" ) ); } @@ -780,7 +765,7 @@ public class EntryEditorTest extends AbstractLdapTestUnit /** - * Test for DIRSTUDIO-1249: userSMIMECertificate is a binary attribute. + * Test for DIRSTUDIO-1249, DIRSTUDIO-1267: userSMIMECertificate is a binary attribute. */ @Test public void testHexEditor() throws Exception @@ -789,7 +774,6 @@ public class EntryEditorTest extends AbstractLdapTestUnit EntryEditorBot entryEditorBot = studioBot.getEntryEditorBot( "uid=hnelson,ou=users,ou=system" ); entryEditorBot.activate(); - // SWTUtils.sleep( 10000 ); assertTrue( entryEditorBot.getAttributeValues().contains( "usersmimecertificate: Binary Data (255 Bytes)" ) ); assertTrue( entryEditorBot.getAttributeValues().contains( "usersmimecertificate: Binary Data (256 Bytes)" ) ); assertTrue( entryEditorBot.getAttributeValues().contains( "usersmimecertificate: Binary Data (257 Bytes)" ) ); @@ -801,7 +785,6 @@ public class EntryEditorTest extends AbstractLdapTestUnit assertTrue( hexText.contains( "70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f pqrstuvw xyz{|}~." ) ); assertTrue( hexText.contains( "80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f ........ ........" ) ); assertTrue( hexText.contains( "f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe ff ........ ........" ) ); - // SWTUtils.sleep( 10000 ); hexEditorDialogBot.clickCancelButton(); hexEditorDialogBot = entryEditorBot.editValueExpectingHexEditor( "usersmimecertificate", @@ -816,6 +799,25 @@ public class EntryEditorTest extends AbstractLdapTestUnit assertTrue( hexText.contains( "f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe ff ........ ........" ) ); assertTrue( hexText.contains( "00 ." ) ); hexEditorDialogBot.clickCancelButton(); + + String crtFile = ResourceUtils.prepareInputFile( "rfc5280_cert2.cer" ); + + entryEditorBot.activate(); + NewAttributeWizardBot wizardBot = entryEditorBot.openNewAttributeWizard(); + assertTrue( wizardBot.isVisible() ); + wizardBot.typeAttributeType( "userSMIMECertificate" ); + wizardBot.clickNextButton(); + wizardBot.selectBinaryOption(); + HexEditorDialogBot hexEditorBot = wizardBot.clickFinishButtonExpectingHexEditor(); + + assertTrue( hexEditorBot.isVisible() ); + hexEditorBot.typeFile( crtFile ); + + hexEditorBot.clickOkButton(); + + modificationLogsViewBot.waitForText( "add: userSMIMECertificate;binary\nuserSMIMECertificate;binary:: " ); + assertTrue( entryEditorBot.getAttributeValues() + .contains( "usersmimecertificate: Binary Data (629 Bytes)" ) ); } } diff --git a/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/ImportExportTest.java b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/ImportExportTest.java index 4cb5ee811..8c5e6529e 100644 --- a/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/ImportExportTest.java +++ b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/ImportExportTest.java @@ -30,18 +30,15 @@ import static org.junit.Assert.assertTrue; import java.io.File; import java.io.IOException; -import java.io.InputStream; import java.net.URL; import java.nio.charset.StandardCharsets; import java.util.List; -import java.util.UUID; import java.util.function.Supplier; import org.apache.directory.api.ldap.model.entry.DefaultEntry; import org.apache.directory.api.ldap.model.message.SearchScope; import org.apache.directory.api.ldap.model.name.Dn; import org.apache.directory.api.util.FileUtils; -import org.apache.directory.api.util.IOUtils; import org.apache.directory.server.annotations.CreateLdapServer; import org.apache.directory.server.annotations.CreateTransport; import org.apache.directory.server.core.annotations.ApplyLdifFiles; @@ -604,6 +601,11 @@ public class ImportExportTest extends AbstractLdapTestUnit assertTrue( entryEditorBot.getAttributeValues().contains( "roomNumber: 1234" ) ); assertTrue( entryEditorBot.getAttributeValues().contains( "roomNumber: 2345" ) ); assertTrue( entryEditorBot.getAttributeValues().contains( "roomNumber: 3456" ) ); + assertTrue( entryEditorBot.getAttributeValues() + .contains( "userCertificate: X.509v3: CN=End Entity,DC=example,DC=com" ) ); + modificationLogsViewBot.waitForText( "add: userCertificate;binary\nuserCertificate;binary:: " ); + modificationLogsViewBot.waitForText( "add: description;lang-en\ndescription;lang-en: " ); + modificationLogsViewBot.waitForText( "add: description;lang-de\ndescription;lang-de: " ); assertFalse( browserViewBot.existsEntry( "DIT", "Root DSE", "ou=system", "ou=users", "uid=user.2" ) ); @@ -684,12 +686,7 @@ public class ImportExportTest extends AbstractLdapTestUnit private String prepareInputFile( String inputFileName ) throws IOException { - URL url = Platform.getInstanceLocation().getURL(); - String destFile = url.getFile() + UUID.randomUUID().toString(); - InputStream is = getClass().getResourceAsStream( inputFileName ); - String ldifContent = IOUtils.toString( is, StandardCharsets.UTF_8 ); - FileUtils.writeStringToFile( new File( destFile ), ldifContent, StandardCharsets.UTF_8, false ); - return destFile; + return ResourceUtils.prepareInputFile( inputFileName ); } } diff --git a/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/NewEntryWizardTest.java b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/NewEntryWizardTest.java index 434aa5950..6fbaa3d2b 100644 --- a/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/NewEntryWizardTest.java +++ b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/NewEntryWizardTest.java @@ -42,14 +42,21 @@ import org.apache.directory.studio.connection.core.Connection.AliasDereferencing import org.apache.directory.studio.connection.core.Connection.ReferralHandlingMethod; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.test.integration.ui.bots.BrowserViewBot; +import org.apache.directory.studio.test.integration.ui.bots.CertificateEditorDialogBot; import org.apache.directory.studio.test.integration.ui.bots.ConnectionsViewBot; import org.apache.directory.studio.test.integration.ui.bots.DnEditorDialogBot; +import org.apache.directory.studio.test.integration.ui.bots.EditAttributeWizardBot; +import org.apache.directory.studio.test.integration.ui.bots.EntryEditorBot; +import org.apache.directory.studio.test.integration.ui.bots.HexEditorDialogBot; +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.NewEntryWizardBot; import org.apache.directory.studio.test.integration.ui.bots.ReferralDialogBot; import org.apache.directory.studio.test.integration.ui.bots.StudioBot; import org.apache.directory.studio.test.integration.ui.bots.SubtreeSpecificationEditorDialogBot; import org.apache.directory.studio.test.integration.ui.bots.utils.Assertions; import org.apache.directory.studio.test.integration.ui.bots.utils.FrameworkRunnerWithScreenshotCaptureListener; +import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException; import org.eclipse.swtbot.swt.finder.utils.SWTUtils; import org.junit.After; import org.junit.Before; @@ -71,10 +78,10 @@ public class NewEntryWizardTest extends AbstractLdapTestUnit private StudioBot studioBot; private ConnectionsViewBot connectionsViewBot; private BrowserViewBot browserViewBot; + private ModificationLogsViewBot modificationLogsViewBot; private Connection connection; - @Before public void setUp() throws Exception { @@ -95,6 +102,7 @@ public class NewEntryWizardTest extends AbstractLdapTestUnit connectionsViewBot = studioBot.getConnectionView(); connection = connectionsViewBot.createTestConnection( "NewEntryWizardTest", ldapServer.getPort() ); browserViewBot = studioBot.getBrowserView(); + modificationLogsViewBot = studioBot.getModificationLogsViewBot(); } @@ -570,4 +578,120 @@ public class NewEntryWizardTest extends AbstractLdapTestUnit browserViewBot.selectEntry( "DIT", "Root DSE", "ou=system", "l=eu+l=de+l=Berlin" ); } + + /** + * DIRSTUDIO-1267: Test creation of new entry with binary option and language tags. + */ + @Test + public void testCreateEntryWithBinaryOptionAndLanguageTags() throws Exception + { + String certFile = ResourceUtils.prepareInputFile( "rfc5280_cert1.cer" ); + String crlFile = ResourceUtils.prepareInputFile( "rfc5280_crl.crl" ); + + browserViewBot.selectEntry( "DIT", "Root DSE", "ou=system" ); + + NewEntryWizardBot wizardBot = browserViewBot.openNewEntryWizard(); + + wizardBot.selectCreateEntryFromScratch(); + wizardBot.clickNextButton(); + wizardBot.addObjectClasses( "organizationalRole" ); + wizardBot.addObjectClasses( "certificationAuthority" ); + wizardBot.clickNextButton(); + + wizardBot.setRdnType( 1, "cn" ); + wizardBot.setRdnValue( 1, "asdf" ); + wizardBot.clickNextButton(); + + // by default the hex or certificate editor is opened, close it + try + { + new HexEditorDialogBot().clickCancelButton(); + } + catch ( WidgetNotFoundException e ) + { + } + try + { + new CertificateEditorDialogBot().clickCancelButton(); + } + catch ( WidgetNotFoundException e ) + { + } + + wizardBot.activate(); + NewAttributeWizardBot newAttributeWizardBot = wizardBot.openNewAttributeWizard(); + assertTrue( newAttributeWizardBot.isVisible() ); + newAttributeWizardBot.typeAttributeType( "description" ); + newAttributeWizardBot.clickNextButton(); + newAttributeWizardBot.setLanguageTag( "en", "us" ); + newAttributeWizardBot.clickFinishButton(); + wizardBot.cancelEditValue(); + wizardBot.activate(); + wizardBot.editValue( "description;lang-en-us", null ); + SWTUtils.sleep( 1000 ); + wizardBot.typeValueAndFinish( "English description" ); + + wizardBot.activate(); + EditAttributeWizardBot editAttributeBot = wizardBot.editAttribute( "cACertificate", null ); + editAttributeBot.clickNextButton(); + editAttributeBot.selectBinaryOption(); + editAttributeBot.clickFinishButton(); + + wizardBot.activate(); + wizardBot.editValue( "cACertificate;binary", null ); + CertificateEditorDialogBot certEditorBot = new CertificateEditorDialogBot(); + assertTrue( certEditorBot.isVisible() ); + certEditorBot.typeFile( certFile ); + certEditorBot.clickOkButton(); + + wizardBot.activate(); + editAttributeBot = wizardBot.editAttribute( "certificateRevocationList", null ); + editAttributeBot.clickNextButton(); + editAttributeBot.selectBinaryOption(); + editAttributeBot.clickFinishButton(); + + wizardBot.activate(); + wizardBot.editValue( "certificateRevocationList;binary", null ); + HexEditorDialogBot hexEditorBot = new HexEditorDialogBot(); + assertTrue( hexEditorBot.isVisible() ); + hexEditorBot.typeFile( crlFile ); + hexEditorBot.clickOkButton(); + + wizardBot.activate(); + editAttributeBot = wizardBot.editAttribute( "authorityRevocationList", null ); + editAttributeBot.clickNextButton(); + editAttributeBot.selectBinaryOption(); + editAttributeBot.clickFinishButton(); + + wizardBot.activate(); + wizardBot.editValue( "authorityRevocationList;binary", null ); + assertTrue( hexEditorBot.isVisible() ); + hexEditorBot.typeFile( crlFile ); + hexEditorBot.clickOkButton(); + + wizardBot.activate(); + wizardBot.clickFinishButton(); + + assertTrue( browserViewBot.existsEntry( "DIT", "Root DSE", "ou=system", "cn=asdf" ) ); + browserViewBot.selectEntry( "DIT", "Root DSE", "ou=system", "cn=asdf" ); + + EntryEditorBot entryEditorBot = studioBot.getEntryEditorBot( "cn=asdf,ou=system" ); + entryEditorBot.activate(); + + modificationLogsViewBot.waitForText( "cACertificate;binary:: MIICPjCCAaeg" ); + assertTrue( entryEditorBot.getAttributeValues() + .contains( "cACertificate;binary: X.509v3: CN=Example CA,DC=example,DC=com" ) ); + + modificationLogsViewBot.waitForText( "certificateRevocationList;binary:: MIIBYDCBygIB" ); + assertTrue( entryEditorBot.getAttributeValues() + .contains( "certificateRevocationList;binary: Binary Data (356 Bytes)" ) ); + + modificationLogsViewBot.waitForText( "authorityRevocationList;binary:: MIIBYDCBygIB" ); + assertTrue( entryEditorBot.getAttributeValues() + .contains( "authorityRevocationList;binary: Binary Data (356 Bytes)" ) ); + + modificationLogsViewBot.waitForText( "description;lang-en-us: English description" ); + assertTrue( entryEditorBot.getAttributeValues() + .contains( "description;lang-en-us: English description" ) ); + } } 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 519e9b364..d5a6af00d 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 @@ -47,17 +47,24 @@ 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.CertificateEditorDialogBot; import org.apache.directory.studio.test.integration.ui.bots.ConnectionsViewBot; +import org.apache.directory.studio.test.integration.ui.bots.DeleteDialogBot; +import org.apache.directory.studio.test.integration.ui.bots.EditAttributeWizardBot; 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.HexEditorDialogBot; 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.NewEntryWizardBot; 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; import org.apache.directory.studio.test.integration.ui.bots.utils.FrameworkRunnerWithScreenshotCaptureListener; +import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException; +import org.eclipse.swtbot.swt.finder.utils.SWTUtils; import org.junit.After; import org.junit.Assume; import org.junit.Before; @@ -474,4 +481,223 @@ public class OpenLdapTest browserViewBot.selectEntry( "DIT", "Root DSE" ); } + + /** + * DIRSTUDIO-1267: Test creation of new entry with binary option and language tags. + */ + @Test + public void testCreateEntryWithBinaryOptionAndLanguageTags() throws Exception + { + String certFile = ResourceUtils.prepareInputFile( "rfc5280_cert1.cer" ); + String crlFile = ResourceUtils.prepareInputFile( "rfc5280_crl.crl" ); + + browserViewBot.selectEntry( "DIT", "Root DSE", "dc=example,dc=org", "ou=users" ); + + NewEntryWizardBot wizardBot = browserViewBot.openNewEntryWizard(); + + wizardBot.selectCreateEntryFromScratch(); + wizardBot.clickNextButton(); + wizardBot.addObjectClasses( "organizationalRole" ); + wizardBot.addObjectClasses( "certificationAuthority" ); + wizardBot.clickNextButton(); + + wizardBot.setRdnType( 1, "cn" ); + wizardBot.setRdnValue( 1, "asdf" ); + wizardBot.clickNextButton(); + + // by default the hex or certificate editor is opened, close it + try + { + new HexEditorDialogBot().clickCancelButton(); + } + catch ( WidgetNotFoundException e ) + { + } + try + { + new CertificateEditorDialogBot().clickCancelButton(); + } + catch ( WidgetNotFoundException e ) + { + } + + wizardBot.activate(); + NewAttributeWizardBot newAttributeWizardBot = wizardBot.openNewAttributeWizard(); + assertTrue( newAttributeWizardBot.isVisible() ); + newAttributeWizardBot.typeAttributeType( "description" ); + newAttributeWizardBot.clickNextButton(); + newAttributeWizardBot.setLanguageTag( "en", "us" ); + newAttributeWizardBot.clickFinishButton(); + wizardBot.cancelEditValue(); + wizardBot.activate(); + wizardBot.editValue( "description;lang-en-us", null ); + SWTUtils.sleep( 1000 ); + wizardBot.typeValueAndFinish( "English description" ); + + wizardBot.activate(); + EditAttributeWizardBot editAttributeBot = wizardBot.editAttribute( "cACertificate", null ); + editAttributeBot.clickNextButton(); + editAttributeBot.selectBinaryOption(); + editAttributeBot.clickFinishButton(); + + wizardBot.activate(); + wizardBot.editValue( "cACertificate;binary", null ); + CertificateEditorDialogBot certEditorBot = new CertificateEditorDialogBot(); + assertTrue( certEditorBot.isVisible() ); + certEditorBot.typeFile( certFile ); + certEditorBot.clickOkButton(); + + wizardBot.activate(); + editAttributeBot = wizardBot.editAttribute( "certificateRevocationList", null ); + editAttributeBot.clickNextButton(); + editAttributeBot.selectBinaryOption(); + editAttributeBot.clickFinishButton(); + + wizardBot.activate(); + wizardBot.editValue( "certificateRevocationList;binary", null ); + HexEditorDialogBot hexEditorBot = new HexEditorDialogBot(); + assertTrue( hexEditorBot.isVisible() ); + hexEditorBot.typeFile( crlFile ); + hexEditorBot.clickOkButton(); + + wizardBot.activate(); + editAttributeBot = wizardBot.editAttribute( "authorityRevocationList", null ); + editAttributeBot.clickNextButton(); + editAttributeBot.selectBinaryOption(); + editAttributeBot.clickFinishButton(); + + wizardBot.activate(); + wizardBot.editValue( "authorityRevocationList;binary", null ); + assertTrue( hexEditorBot.isVisible() ); + hexEditorBot.typeFile( crlFile ); + hexEditorBot.clickOkButton(); + + wizardBot.activate(); + wizardBot.clickFinishButton(); + + assertTrue( browserViewBot.existsEntry( "DIT", "Root DSE", "dc=example,dc=org", "ou=users", "cn=asdf" ) ); + browserViewBot.selectEntry( "DIT", "Root DSE", "dc=example,dc=org", "ou=users", "cn=asdf" ); + + EntryEditorBot entryEditorBot = studioBot.getEntryEditorBot( "cn=asdf,ou=users,dc=example,dc=org" ); + entryEditorBot.activate(); + + modificationLogsViewBot.waitForText( "cACertificate;binary:: MIICPjCCAaeg" ); + assertTrue( entryEditorBot.getAttributeValues() + .contains( "cACertificate;binary: X.509v3: CN=Example CA,DC=example,DC=com" ) ); + + modificationLogsViewBot.waitForText( "certificateRevocationList;binary:: MIIBYDCBygIB" ); + assertTrue( entryEditorBot.getAttributeValues() + .contains( "certificateRevocationList;binary: Binary Data (356 Bytes)" ) ); + + modificationLogsViewBot.waitForText( "authorityRevocationList;binary:: MIIBYDCBygIB" ); + assertTrue( entryEditorBot.getAttributeValues() + .contains( "authorityRevocationList;binary: Binary Data (356 Bytes)" ) ); + + modificationLogsViewBot.waitForText( "description;lang-en-us: English description" ); + assertTrue( entryEditorBot.getAttributeValues() + .contains( "description;lang-en-us: English description" ) ); + + browserViewBot.selectEntry( "DIT", "Root DSE", "dc=example,dc=org", "ou=users", "cn=asdf" ); + DeleteDialogBot deleteDialogBot = browserViewBot.openDeleteDialog(); + deleteDialogBot.clickOkButton(); + } + + + /** + * DIRSTUDIO-1267: Test adding, editing and deleting of attributes with binary option in the entry editor. + */ + @Test + public void testAddEditDeleteAttributeWithBinaryOption() throws Exception + { + String cert2File = ResourceUtils.prepareInputFile( "rfc5280_cert2.cer" ); + String cert3File = ResourceUtils.prepareInputFile( "rfc5280_cert3.cer" ); + + browserViewBot.selectEntry( "DIT", "Root DSE", "dc=example,dc=org", "ou=users", "uid=user.1" ); + + EntryEditorBot entryEditorBot = studioBot.getEntryEditorBot( "uid=user.1,ou=users,dc=example,dc=org" ); + entryEditorBot.activate(); + + // add userCertificate;binary + NewAttributeWizardBot wizardBot = entryEditorBot.openNewAttributeWizard(); + assertTrue( wizardBot.isVisible() ); + wizardBot.typeAttributeType( "userCertificate" ); + wizardBot.clickNextButton(); + wizardBot.selectBinaryOption(); + CertificateEditorDialogBot certEditorBot = wizardBot.clickFinishButtonExpectingCertificateEditor(); + assertTrue( certEditorBot.isVisible() ); + certEditorBot.typeFile( cert2File ); + certEditorBot.clickOkButton(); + modificationLogsViewBot.waitForText( "add: userCertificate;binary\nuserCertificate;binary:: MIICcTCCAdqg" ); + assertTrue( entryEditorBot.getAttributeValues() + .contains( "userCertificate;binary: X.509v3: CN=End Entity,DC=example,DC=com" ) ); + + // edit userCertificate;binary + certEditorBot = entryEditorBot.editValueExpectingCertificateEditor( "userCertificate;binary", + "X.509v3: CN=End Entity,DC=example,DC=com" ); + assertTrue( certEditorBot.isVisible() ); + certEditorBot.typeFile( cert3File ); + certEditorBot.clickOkButton(); + modificationLogsViewBot.waitForText( "delete: userCertificate;binary\nuserCertificate;binary:: MIICcTCCAdqg" ); + modificationLogsViewBot.waitForText( "add: userCertificate;binary\nuserCertificate;binary:: MIIDjjCCA06g" ); + assertFalse( entryEditorBot.getAttributeValues() + .contains( "userCertificate;binary: X.509v3: CN=End Entity,DC=example,DC=com" ) ); + assertTrue( entryEditorBot.getAttributeValues() + .contains( "userCertificate;binary: X.509v3: CN=DSA End Entity,DC=example,DC=com" ) ); + + // delete userCertificate;binary + entryEditorBot.deleteValue( "userCertificate;binary", "X.509v3: CN=DSA End Entity,DC=example,DC=com" ); + modificationLogsViewBot.waitForText( "delete: userCertificate;binary\nuserCertificate;binary:: MIIDjjCCA06g" ); + assertFalse( entryEditorBot.getAttributeValues() + .contains( "userCertificate;binary: X.509v3: CN=DSA End Entity,DC=example,DC=com" ) ); + + } + + + /** + * DIRSTUDIO-1267:Test adding, editing and deleting of attributes with language tag in the entry editor. + */ + @Test + public void testAddEditDeleteAttributeWithLanguageTag() throws Exception + { + browserViewBot.selectEntry( "DIT", "Root DSE", "dc=example,dc=org", "ou=users", "uid=user.1" ); + + EntryEditorBot entryEditorBot = studioBot.getEntryEditorBot( "uid=user.1,ou=users,dc=example,dc=org" ); + entryEditorBot.activate(); + + // add attribute description;lang-en + entryEditorBot.activate(); + NewAttributeWizardBot wizardBot = entryEditorBot.openNewAttributeWizard(); + assertTrue( wizardBot.isVisible() ); + wizardBot.typeAttributeType( "description" ); + wizardBot.clickNextButton(); + wizardBot.setLanguageTag( "en", "" ); + wizardBot.clickFinishButton(); + entryEditorBot.typeValueAndFinish( "English" ); + modificationLogsViewBot.waitForText( "add: description;lang-en\ndescription;lang-en: English\n-" ); + assertTrue( entryEditorBot.getAttributeValues().contains( "description;lang-en: English" ) ); + + // edit the attribute to description;lang-en + EditAttributeWizardBot editWizardBot = entryEditorBot.editAttribute( "description;lang-en", "English" ); + editWizardBot.clickNextButton(); + editWizardBot.setLanguageTag( "en", "us" ); + editWizardBot.clickFinishButton(); + modificationLogsViewBot.waitForText( "delete: description;lang-en\ndescription;lang-en: English\n-" ); + modificationLogsViewBot.waitForText( "add: description;lang-en-us\ndescription;lang-en-us: English\n-" ); + assertFalse( entryEditorBot.getAttributeValues().contains( "description;lang-en: English" ) ); + assertTrue( entryEditorBot.getAttributeValues().contains( "description;lang-en-us: English" ) ); + + // edit the value + entryEditorBot.editValue( "description;lang-en-us", "English" ); + entryEditorBot.typeValueAndFinish( "English US" ); + modificationLogsViewBot.waitForText( "delete: description;lang-en-us\ndescription;lang-en-us: English\n-" ); + modificationLogsViewBot.waitForText( "add: description;lang-en-us\ndescription;lang-en-us: English US\n-" ); + assertFalse( entryEditorBot.getAttributeValues().contains( "description;lang-en-us: English" ) ); + assertTrue( entryEditorBot.getAttributeValues().contains( "description;lang-en-us: English US" ) ); + + // delete the attribute + entryEditorBot.deleteValue( "description;lang-en-us", "English US" ); + modificationLogsViewBot.waitForText( "delete: description;lang-en-us\ndescription;lang-en-us: English US\n-" ); + assertFalse( entryEditorBot.getAttributeValues().contains( "description;lang-en-us: English US" ) ); + } + } diff --git a/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/ResourceUtils.java b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/ResourceUtils.java new file mode 100644 index 000000000..2fad2f3bc --- /dev/null +++ b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/ResourceUtils.java @@ -0,0 +1,50 @@ +/* + * 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.directory.studio.test.integration.ui; + + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.UUID; + +import org.apache.directory.api.util.IOUtils; +import org.eclipse.core.runtime.Platform; + + +public class ResourceUtils +{ + public static String prepareInputFile( String inputFileName ) throws IOException + { + URL url = Platform.getInstanceLocation().getURL(); + String destFile = url.getFile() + UUID.randomUUID().toString(); + + try ( InputStream is = ResourceUtils.class.getResourceAsStream( inputFileName ); + FileOutputStream fos = new FileOutputStream( new File( destFile ) ); ) + { + IOUtils.copy( is, fos ); + } + + return destFile; + } + +} diff --git a/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/CertificateEditorDialogBot.java b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/CertificateEditorDialogBot.java new file mode 100644 index 000000000..cdb02c844 --- /dev/null +++ b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/CertificateEditorDialogBot.java @@ -0,0 +1,40 @@ +/* + * 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.directory.studio.test.integration.ui.bots; + + +import org.apache.directory.studio.valueeditors.certificate.CertificateDialog; + + +public class CertificateEditorDialogBot extends DialogBot +{ + + public CertificateEditorDialogBot() + { + super( "Certificate Editor" ); + } + + + public void typeFile( String file ) + { + bot.textWithTooltip( CertificateDialog.LOAD_FILE_NAME_TOOLTIP ).setText( file ); + } + +} diff --git a/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/EditAttributeWizardBot.java b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/EditAttributeWizardBot.java new file mode 100644 index 000000000..cba11d24a --- /dev/null +++ b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/EditAttributeWizardBot.java @@ -0,0 +1,50 @@ +/* + * 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.directory.studio.test.integration.ui.bots; + + +public class EditAttributeWizardBot extends WizardBot +{ + + public EditAttributeWizardBot() + { + super( "Edit Attribute Description" ); + } + + + public void typeAttributeType( String text ) + { + bot.comboBox().setText( text ); + } + + + public void setLanguageTag( String lang, String country ) + { + bot.comboBox( 0 ).setText( lang ); + bot.comboBox( 1 ).setText( country ); + } + + + public void selectBinaryOption() + { + bot.checkBox().select(); + } + +} diff --git a/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/EntryEditorBot.java b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/EntryEditorBot.java index 1542c6edd..dcae169a4 100644 --- a/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/EntryEditorBot.java +++ b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/EntryEditorBot.java @@ -101,6 +101,12 @@ public class EntryEditorBot } + public EditAttributeWizardBot editAttribute( String attributeType, String value ) + { + return editorBot.editAttribute( attributeType, value ); + } + + public DnEditorDialogBot editValueExpectingDnEditor( String attributeType, String value ) { return editorBot.editValueExpectingDnEditor( attributeType, value ); @@ -119,12 +125,19 @@ public class EntryEditorBot } - public SubtreeSpecificationEditorDialogBot editValueExpectingSubtreeSpecificationEditor( String attributeType, String value ) + public SubtreeSpecificationEditorDialogBot editValueExpectingSubtreeSpecificationEditor( String attributeType, + String value ) { return editorBot.editValueExpectingSubtreeSpecificationEditor( attributeType, value ); } + public CertificateEditorDialogBot editValueExpectingCertificateEditor( String attributeType, String value ) + { + return editorBot.editValueExpectingCertificateEditor( attributeType, value ); + } + + public HexEditorDialogBot editValueExpectingHexEditor( String attributeType, String value ) { return editorBot.editValueExpectingHexEditor( attributeType, value ); diff --git a/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/EntryEditorWidgetBot.java b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/EntryEditorWidgetBot.java index 70bbecce1..a768b8ac3 100644 --- a/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/EntryEditorWidgetBot.java +++ b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/EntryEditorWidgetBot.java @@ -126,6 +126,16 @@ class EntryEditorWidgetBot } + EditAttributeWizardBot editAttribute( String attributeType, String value ) + { + cancelEditValue(); + SWTBotTreeItem treeItem = getTreeItem( attributeType, value ); + treeItem.select(); + ContextMenuHelper.clickContextMenu( bot.tree(), "Edit Attribute Description" ); + return new EditAttributeWizardBot(); + } + + void editValue( String attributeType, String value ) { cancelEditValue(); @@ -164,13 +174,21 @@ class EntryEditorWidgetBot } - SubtreeSpecificationEditorDialogBot editValueExpectingSubtreeSpecificationEditor( String attributeType, String value ) + SubtreeSpecificationEditorDialogBot editValueExpectingSubtreeSpecificationEditor( String attributeType, + String value ) { editValue( attributeType, value ); return new SubtreeSpecificationEditorDialogBot(); } + CertificateEditorDialogBot editValueExpectingCertificateEditor( String attributeType, String value ) + { + editValue( attributeType, value ); + return new CertificateEditorDialogBot(); + } + + HexEditorDialogBot editValueExpectingHexEditor( String attributeType, String value ) { editValue( attributeType, value ); diff --git a/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/HexEditorDialogBot.java b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/HexEditorDialogBot.java index 077c618b4..2d76811c3 100644 --- a/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/HexEditorDialogBot.java +++ b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/HexEditorDialogBot.java @@ -20,6 +20,9 @@ package org.apache.directory.studio.test.integration.ui.bots; +import org.apache.directory.studio.ldapbrowser.common.dialogs.HexDialog; + + public class HexEditorDialogBot extends DialogBot { @@ -29,6 +32,12 @@ public class HexEditorDialogBot extends DialogBot } + public void typeFile( String file ) + { + bot.textWithTooltip( HexDialog.LOAD_FILE_NAME_TOOLTIP ).setText( file ); + } + + public String getHexText() { return bot.text().getText(); diff --git a/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/NewAttributeWizardBot.java b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/NewAttributeWizardBot.java index 156229410..62877bd30 100644 --- a/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/NewAttributeWizardBot.java +++ b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/NewAttributeWizardBot.java @@ -35,6 +35,19 @@ public class NewAttributeWizardBot extends WizardBot } + public void setLanguageTag( String lang, String country ) + { + bot.comboBox( 0 ).setText( lang ); + bot.comboBox( 1 ).setText( country ); + } + + + public void selectBinaryOption() + { + bot.checkBox().select(); + } + + public DnEditorDialogBot clickFinishButtonExpectingDnEditor() { clickFinishButton(); @@ -55,4 +68,18 @@ public class NewAttributeWizardBot extends WizardBot return new ImageEditorDialogBot(); } + + public CertificateEditorDialogBot clickFinishButtonExpectingCertificateEditor() + { + clickFinishButton(); + return new CertificateEditorDialogBot(); + } + + + public HexEditorDialogBot clickFinishButtonExpectingHexEditor() + { + clickFinishButton(); + return new HexEditorDialogBot(); + } + } diff --git a/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/NewEntryWizardBot.java b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/NewEntryWizardBot.java index 3cf573b63..4de6704e1 100644 --- a/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/NewEntryWizardBot.java +++ b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/NewEntryWizardBot.java @@ -19,6 +19,7 @@ */ package org.apache.directory.studio.test.integration.ui.bots; + import org.apache.directory.api.ldap.model.name.Dn; import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages; import org.apache.directory.studio.test.integration.ui.bots.utils.JobWatcher; @@ -30,7 +31,6 @@ public class NewEntryWizardBot extends WizardBot private EntryEditorWidgetBot widgetBot; - public NewEntryWizardBot() { super( TITLE ); @@ -94,6 +94,20 @@ public class NewEntryWizardBot extends WizardBot } + public NewAttributeWizardBot openNewAttributeWizard() + { + widgetBot.isVisisble(); + return widgetBot.openNewAttributeWizard(); + } + + + public EditAttributeWizardBot editAttribute( String attributeType, String value ) + { + widgetBot.isVisisble(); + return widgetBot.editAttribute( attributeType, value ); + } + + public void editValue( String attributeType, String value ) { widgetBot.isVisisble(); @@ -113,7 +127,7 @@ public class NewEntryWizardBot extends WizardBot while ( true ) { String text = bot.text( 1 ).getText(); - + if ( Dn.isValid( text ) ) { return text; diff --git a/tests/test.integration.ui/src/main/resources/org/apache/directory/studio/test/integration/ui/ImportExportTest_Modifications.ldif b/tests/test.integration.ui/src/main/resources/org/apache/directory/studio/test/integration/ui/ImportExportTest_Modifications.ldif index c9672be20..5034e9cb3 100644 --- a/tests/test.integration.ui/src/main/resources/org/apache/directory/studio/test/integration/ui/ImportExportTest_Modifications.ldif +++ b/tests/test.integration.ui/src/main/resources/org/apache/directory/studio/test/integration/ui/ImportExportTest_Modifications.ldif @@ -103,6 +103,12 @@ delete: l add: description description:: QSDDqSDigqwg0K8gzrsg16kg2Lkg4ruhIA== - +add: description;lang-en +description;lang-en: English +- +add: description;lang-de +description;lang-de: Deutsch +- add: roomNumber roomNumber: 1234 roomNumber: 2345 @@ -114,8 +120,22 @@ replace: employeeType employeeType: Intern - replace: mail -mail: mail: user.1@example.com -mail: mail: Aaccf.Amar@example.com +mail: user.1@example.com +mail: Aaccf.Amar@example.com +- +add: userCertificate;binary +userCertificate;binary:: MIICcTCCAdqgAwIBAgIBEjANBgkqhkiG9w0BAQUFADBDMRMwEQYKCZImiZPy + LGQBGRYDY29tMRcwFQYKCZImiZPyLGQBGRYHZXhhbXBsZTETMBEGA1UEAxMKRXhhbXBsZSBDQTAeF + w0wNDA5MTUxMTQ4MjFaFw0wNTAzMTUxMTQ4MjFaMEMxEzARBgoJkiaJk/IsZAEZFgNjb20xFzAVBg + oJkiaJk/IsZAEZFgdleGFtcGxlMRMwEQYDVQQDEwpFbmQgRW50aXR5MIGfMA0GCSqGSIb3DQEBAQU + AA4GNADCBiQKBgQDhauQDMJcCPPQQ87UeTX8Ue/b10HjppIrwo3Xs7bZWln+ImYWa8j5od4frntGf + wLQX3KuJI6QdfhYjTE+oTfUxuHyq4xpJCfRLJtsnZzCCEgFK6Rq2wQxTi2z8L3pD7DM2fjKye9Wqz + wEUxhLsE/ItFHqLIVgUE0xGo5ryFpX/IwIDAQABo3UwczAhBgNVHREEGjAYgRZlbmQuZW50aXR5QG + V4YW1wbGUuY29tMB0GA1UdDgQWBBQXe5Iw/0TWZuGQECJsFk/AjkHdbTAfBgNVHSMEGDAWgBQIaK+ + FM8g5Snr4gpOOcGpKIIQsMjAOBgNVHQ8BAf8EBAMCBsAwDQYJKoZIhvcNAQEFBQADgYEAACAoNFto + MgG7CjYOrXHFlRrhBM+urcdiFKQbNjHA4gw92R7AANwQoLqFb0HLYnq3TGOBJl7SgEVeM+dwRTs5O + yZKnDvyJjZpCHm7+5ZDd0thi6GrkWTg8zdhPBqjpMmKsr9z1E3kWORi6rwgdJKGDs6EYHbpc7vHhd + ORRepiXc0= dn: uid=user.2,ou=users,ou=system diff --git a/tests/test.integration.ui/src/main/resources/org/apache/directory/studio/test/integration/ui/rfc5280_cert1.cer b/tests/test.integration.ui/src/main/resources/org/apache/directory/studio/test/integration/ui/rfc5280_cert1.cer Binary files differnew file mode 100644 index 000000000..bad00d025 --- /dev/null +++ b/tests/test.integration.ui/src/main/resources/org/apache/directory/studio/test/integration/ui/rfc5280_cert1.cer diff --git a/tests/test.integration.ui/src/main/resources/org/apache/directory/studio/test/integration/ui/rfc5280_cert2.cer b/tests/test.integration.ui/src/main/resources/org/apache/directory/studio/test/integration/ui/rfc5280_cert2.cer Binary files differnew file mode 100644 index 000000000..34af0109b --- /dev/null +++ b/tests/test.integration.ui/src/main/resources/org/apache/directory/studio/test/integration/ui/rfc5280_cert2.cer diff --git a/tests/test.integration.ui/src/main/resources/org/apache/directory/studio/test/integration/ui/rfc5280_cert3.cer b/tests/test.integration.ui/src/main/resources/org/apache/directory/studio/test/integration/ui/rfc5280_cert3.cer Binary files differnew file mode 100644 index 000000000..f9613dc34 --- /dev/null +++ b/tests/test.integration.ui/src/main/resources/org/apache/directory/studio/test/integration/ui/rfc5280_cert3.cer diff --git a/tests/test.integration.ui/src/main/resources/org/apache/directory/studio/test/integration/ui/rfc5280_crl.crl b/tests/test.integration.ui/src/main/resources/org/apache/directory/studio/test/integration/ui/rfc5280_crl.crl Binary files differnew file mode 100644 index 000000000..a4cc40574 --- /dev/null +++ b/tests/test.integration.ui/src/main/resources/org/apache/directory/studio/test/integration/ui/rfc5280_crl.crl |