Skip to content

Commit f8f6fa5

Browse files
committed
Factor out common DirContext mocking
1 parent b1d6c1d commit f8f6fa5

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

ldap/src/test/java/org/springframework/security/ldap/authentication/ad/ActiveDirectoryLdapAuthenticationProviderTests.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -59,6 +59,7 @@
5959
/**
6060
* @author Luke Taylor
6161
* @author Rob Winch
62+
* @author Gengwu Zhao
6263
*/
6364
public class ActiveDirectoryLdapAuthenticationProviderTests {
6465

@@ -69,11 +70,14 @@ public class ActiveDirectoryLdapAuthenticationProviderTests {
6970
ActiveDirectoryLdapAuthenticationProvider provider;
7071

7172
UsernamePasswordAuthenticationToken joe = UsernamePasswordAuthenticationToken.unauthenticated("joe", "password");
73+
7274
DirContext ctx;
75+
7376
@BeforeEach
74-
public void setUp() {
77+
public void setUp() throws NamingException {
7578
this.provider = new ActiveDirectoryLdapAuthenticationProvider("mydomain.eu", "ldap://192.168.1.200/");
7679
ctx = mock(DirContext.class);
80+
given(ctx.getNameInNamespace()).willReturn("");
7781
}
7882

7983
@Test
@@ -196,6 +200,7 @@ public void duplicateUserSearchCausesError() throws Exception {
196200
assertThatExceptionOfType(IncorrectResultSizeDataAccessException.class)
197201
.isThrownBy(() -> this.provider.authenticate(this.joe));
198202
}
203+
199204
static final String msg = "[LDAP: error code 49 - 80858585: LdapErr: DSID-DECAFF0, comment: AcceptSecurityContext error, data ";
200205

201206
@Test

0 commit comments

Comments
 (0)