Move test security uname/pswd to constants.

parent 61513287
...@@ -22,7 +22,6 @@ import java.util.Map; ...@@ -22,7 +22,6 @@ import java.util.Map;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
...@@ -47,6 +46,8 @@ import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; ...@@ -47,6 +46,8 @@ import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.springframework.cloud.netflix.test.TestAutoConfiguration.PASSWORD;
import static org.springframework.cloud.netflix.test.TestAutoConfiguration.USER;
/** /**
* @author Spencer Gibb * @author Spencer Gibb
...@@ -60,12 +61,6 @@ public class HystrixOnlyTests { ...@@ -60,12 +61,6 @@ public class HystrixOnlyTests {
@LocalServerPort @LocalServerPort
private int port; private int port;
//FIXME: 2.0.0
private String username = "user";
//FIXME: 2.0.0
private String password = "password";
@Test @Test
public void testNormalExecution() { public void testNormalExecution() {
ResponseEntity<String> res = new TestRestTemplate() ResponseEntity<String> res = new TestRestTemplate()
...@@ -99,12 +94,10 @@ public class HystrixOnlyTests { ...@@ -99,12 +94,10 @@ public class HystrixOnlyTests {
map.containsKey("discovery")); map.containsKey("discovery"));
} }
private Map getHealth() { private Map getHealth() {
return new TestRestTemplate().exchange( return new TestRestTemplate().exchange(
"http://localhost:" + this.port + "/admin/health", HttpMethod.GET, "http://localhost:" + this.port + "/admin/health", HttpMethod.GET,
new HttpEntity<Void>(createBasicAuthHeader(username, password)), new HttpEntity<Void>(createBasicAuthHeader(USER, PASSWORD)),
Map.class).getBody(); Map.class).getBody();
} }
......
...@@ -38,6 +38,9 @@ import org.springframework.security.provisioning.InMemoryUserDetailsManager; ...@@ -38,6 +38,9 @@ import org.springframework.security.provisioning.InMemoryUserDetailsManager;
@AutoConfigureBefore(SecurityAutoConfiguration.class) @AutoConfigureBefore(SecurityAutoConfiguration.class)
public class TestAutoConfiguration { public class TestAutoConfiguration {
public static final String USER = "user";
public static final String PASSWORD = "password";
@Configuration @Configuration
@Order(Ordered.HIGHEST_PRECEDENCE) @Order(Ordered.HIGHEST_PRECEDENCE)
protected static class TestSecurityConfiguration extends WebSecurityConfigurerAdapter { protected static class TestSecurityConfiguration extends WebSecurityConfigurerAdapter {
...@@ -50,7 +53,7 @@ public class TestAutoConfiguration { ...@@ -50,7 +53,7 @@ public class TestAutoConfiguration {
@Bean @Bean
public UserDetailsService userDetailsService() { public UserDetailsService userDetailsService() {
InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager(); InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager();
manager.createUser(User.withUsername("user").password("password").roles("USER").build()); manager.createUser(User.withUsername(USER).password(PASSWORD).roles("USER").build());
return manager; return manager;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment