File tree Expand file tree Collapse file tree 2 files changed +54
-1
lines changed
integration-test/java/org/springframework/security/ldap/server
main/java/org/springframework/security/ldap/server Expand file tree Collapse file tree 2 files changed +54
-1
lines changed Original file line number Diff line number Diff line change @@ -141,4 +141,54 @@ void shutdown() {
141
141
this .container .stop ();
142
142
}
143
143
}
144
+
145
+ @ Test
146
+ public void unboundIdContainerWhenMissingLdifThenException () {
147
+ try {
148
+ appCtx = new AnnotationConfigApplicationContext (MissingLdifConfig .class );
149
+ failBecauseExceptionWasNotThrown (IllegalStateException .class );
150
+ } catch (Exception e ) {
151
+ assertThat (e .getCause ()).isInstanceOf (IllegalStateException .class );
152
+ assertThat (e .getMessage ()).contains ("Unable to load LDIF classpath:does-not-exist.ldif" );
153
+ }
154
+ }
155
+
156
+ @ Configuration
157
+ static class MissingLdifConfig {
158
+ private UnboundIdContainer container = new UnboundIdContainer ("dc=springframework,dc=org" ,
159
+ "classpath:does-not-exist.ldif" );
160
+
161
+ @ Bean
162
+ UnboundIdContainer ldapContainer () {
163
+ this .container .setPort (0 );
164
+ return this .container ;
165
+ }
166
+
167
+ @ PreDestroy
168
+ void shutdown () {
169
+ this .container .stop ();
170
+ }
171
+ }
172
+
173
+ @ Test
174
+ public void unboundIdContainerWhenWildcardLdifNotFoundThenProceeds () {
175
+ new AnnotationConfigApplicationContext (WildcardNoLdifConfig .class );
176
+ }
177
+
178
+ @ Configuration
179
+ static class WildcardNoLdifConfig {
180
+ private UnboundIdContainer container = new UnboundIdContainer ("dc=springframework,dc=org" ,
181
+ "classpath*:*.test.ldif" );
182
+
183
+ @ Bean
184
+ UnboundIdContainer ldapContainer () {
185
+ this .container .setPort (0 );
186
+ return this .container ;
187
+ }
188
+
189
+ @ PreDestroy
190
+ void shutdown () {
191
+ this .container .stop ();
192
+ }
193
+ }
144
194
}
Original file line number Diff line number Diff line change @@ -116,7 +116,10 @@ private void importLdif(InMemoryDirectoryServer directoryServer) {
116
116
if (StringUtils .hasText (this .ldif )) {
117
117
try {
118
118
Resource [] resources = this .context .getResources (this .ldif );
119
- if (resources .length > 0 && resources [0 ].exists ()) {
119
+ if (resources .length > 0 ) {
120
+ if (!resources [0 ].exists ()) {
121
+ throw new IllegalArgumentException ("Unable to find LDIF resource " + this .ldif );
122
+ }
120
123
try (InputStream inputStream = resources [0 ].getInputStream ()) {
121
124
directoryServer .importFromLDIF (false , new LDIFReader (inputStream ));
122
125
}
You can’t perform that action at this time.
0 commit comments