Fix tests

Some assumptions were being made in tests, e.g. about
there being an AuthenticationManager @Bean, which were
false with the new Security 3.2.1 updates from Rob.

Also parent-child contexts with the actuator were
problematic because they didn't exclude the web configuration
for the management security in the parent context.

Fixes gh-244
This commit is contained in:
Dave Syer
2014-02-26 18:15:05 +00:00
parent 6b0eba3759
commit b0b7bc0e7f
5 changed files with 45 additions and 51 deletions

View File

@@ -16,6 +16,8 @@
package sample.secure;
import static org.junit.Assert.assertEquals;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -28,6 +30,7 @@ import org.springframework.context.annotation.PropertySource;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.context.SecurityContextHolder;
@@ -35,8 +38,6 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import sample.secure.SampleSecureApplicationTests.TestConfiguration;
import static org.junit.Assert.assertEquals;
/**
* Basic integration tests for demo application.
*
@@ -58,7 +59,7 @@ public class SampleSecureApplicationTests {
@Before
public void init() {
AuthenticationManager authenticationManager = context
.getBean(AuthenticationManager.class);
.getBean(AuthenticationManagerBuilder.class).getOrBuild();
authentication = authenticationManager
.authenticate(new UsernamePasswordAuthenticationToken("user", "password"));
}
@@ -94,7 +95,6 @@ public class SampleSecureApplicationTests {
@PropertySource("classpath:test.properties")
@Configuration
protected static class TestConfiguration {
}
}