1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.server.operations.modify;
21
22
23 import org.apache.directory.server.core.integ.Level;
24 import org.apache.directory.server.core.integ.annotations.ApplyLdifs;
25 import org.apache.directory.server.core.integ.annotations.CleanupLevel;
26 import org.apache.directory.server.integ.SiRunner;
27 import static org.apache.directory.server.integ.ServerIntegrationUtils.getWiredConnection;
28
29 import org.apache.directory.server.ldap.LdapService;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import static org.junit.Assert.fail;
33 import static org.junit.Assert.assertEquals;
34
35 import netscape.ldap.LDAPAttribute;
36 import netscape.ldap.LDAPConnection;
37 import netscape.ldap.LDAPEntry;
38 import netscape.ldap.LDAPException;
39 import netscape.ldap.LDAPModification;
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63 @RunWith ( SiRunner.class )
64 @CleanupLevel ( Level.SUITE )
65 @ApplyLdifs( {
66
67 "dn: cn=Kate Bush,ou=system\n" +
68 "objectClass: person\n" +
69 "objectClass: top\n" +
70 "cn: Kate Bush\n" +
71 "sn: Bush\n\n"
72 }
73 )
74 public class IllegalModificationIT
75 {
76 private static final String DN = "cn=Kate Bush,ou=system";
77
78 public static LdapService ldapService;
79
80
81 @Test
82 public void testIllegalModification() throws Exception
83 {
84 LDAPConnection con = getWiredConnection( ldapService );
85 LDAPAttribute attr = new LDAPAttribute( "description" );
86 LDAPModification mod = new LDAPModification( LDAPModification.ADD, attr );
87
88 try
89 {
90 con.modify( "cn=Kate Bush,ou=system", mod );
91 fail( "error expected due to empty attribute value" );
92 }
93 catch ( LDAPException e )
94 {
95
96 }
97
98
99 LDAPEntry entry = con.read( DN );
100 assertEquals( "description exists?", null, entry.getAttribute( "description" ) );
101 }
102
103
104 @Test
105 public void testIllegalModification2() throws Exception
106 {
107 LDAPConnection con = getWiredConnection( ldapService );
108
109
110 LDAPAttribute attr = new LDAPAttribute( "description", "The description" );
111 LDAPModification mod = new LDAPModification( LDAPModification.ADD, attr );
112
113 attr = new LDAPAttribute( "displayName" );
114 LDAPModification mod2 = new LDAPModification( LDAPModification.ADD, attr );
115
116 try
117 {
118 con.modify( "cn=Kate Bush,ou=system", new LDAPModification[] { mod, mod2 } );
119 fail( "error expected due to empty attribute value" );
120 }
121 catch ( LDAPException e )
122 {
123
124 }
125
126
127 LDAPEntry entry = con.read( DN );
128 assertEquals( "displayName exists?", null, entry.getAttribute( "displayName" ) );
129 }
130 }