From 16a9a91790084ab7b95d3093d1f472ce40124c5f Mon Sep 17 00:00:00 2001 From: Alex Prudencio Date: Mon, 23 Sep 2024 22:37:32 -0400 Subject: [PATCH] fix tests --- .../com/primefactorsolutions/config/SecurityConfig.java | 9 ++++++--- src/main/resources/application-test.properties | 2 ++ .../com/primefactorsolutions/views/AbstractAppTests.java | 6 ++---- 3 files changed, 10 insertions(+), 7 deletions(-) create mode 100644 src/main/resources/application-test.properties diff --git a/src/main/java/com/primefactorsolutions/config/SecurityConfig.java b/src/main/java/com/primefactorsolutions/config/SecurityConfig.java index f892d3f..f347ba3 100644 --- a/src/main/java/com/primefactorsolutions/config/SecurityConfig.java +++ b/src/main/java/com/primefactorsolutions/config/SecurityConfig.java @@ -4,6 +4,7 @@ import com.primefactorsolutions.model.Employee; import com.primefactorsolutions.service.EmployeeService; import com.primefactorsolutions.views.LoginView; import com.vaadin.flow.spring.security.VaadinWebSecurity; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpMethod; @@ -24,6 +25,8 @@ import java.util.Collection; @EnableWebSecurity @Configuration public class SecurityConfig extends VaadinWebSecurity { + @Value("${spring.ldap.url}") + private String ldapUrl; @Override protected void configure(final HttpSecurity http) throws Exception { @@ -47,10 +50,10 @@ public class SecurityConfig extends VaadinWebSecurity { @Bean public AuthenticationManager authenticationManager(final UserDetailsContextMapper userDetailsContextMapper) { - DefaultSpringSecurityContextSource contextSource = new DefaultSpringSecurityContextSource( - "ldap://localhost:8389/dc=primefactorsolutions,dc=com"); + final DefaultSpringSecurityContextSource contextSource = new DefaultSpringSecurityContextSource( + String.format("%s/dc=primefactorsolutions,dc=com", ldapUrl)); contextSource.setCacheEnvironmentProperties(false); - LdapBindAuthenticationManagerFactory factory = new LdapBindAuthenticationManagerFactory(contextSource); + final LdapBindAuthenticationManagerFactory factory = new LdapBindAuthenticationManagerFactory(contextSource); factory.setUserDnPatterns("uid={0},ou=users"); factory.setUserDetailsContextMapper(userDetailsContextMapper); diff --git a/src/main/resources/application-test.properties b/src/main/resources/application-test.properties new file mode 100644 index 0000000..fd2c3c7 --- /dev/null +++ b/src/main/resources/application-test.properties @@ -0,0 +1,2 @@ +spring.ldap.url=ldap://localhost:8391 +spring.ldap.embedded.port=8391 diff --git a/src/test/java/com/primefactorsolutions/views/AbstractAppTests.java b/src/test/java/com/primefactorsolutions/views/AbstractAppTests.java index f05c2ef..d51af1f 100644 --- a/src/test/java/com/primefactorsolutions/views/AbstractAppTests.java +++ b/src/test/java/com/primefactorsolutions/views/AbstractAppTests.java @@ -14,21 +14,19 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.ApplicationContext; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; -import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.context.SecurityContext; import org.springframework.security.core.context.SecurityContextHolder; -import com.github.mvysny.kaributesting.v10.MockVaadin; import com.github.mvysny.kaributesting.v10.Routes; import org.springframework.security.core.userdetails.User; -import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.test.context.ActiveProfiles; -import java.util.Collection; import java.util.List; import java.util.stream.Collectors; @SpringBootTest +@ActiveProfiles(value = "test") public class AbstractAppTests { private static final Routes routes = new Routes().autoDiscoverViews("com.primefactorsolutions");