Browse Source

Move test security uname/pswd to constants.

pull/6/head
Spencer Gibb 8 years ago
parent
commit
87e98edd61
No known key found for this signature in database
GPG Key ID: 7788A47380690861
  1. 13
      spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/hystrix/HystrixOnlyTests.java
  2. 5
      spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/test/TestAutoConfiguration.java

13
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/hystrix/HystrixOnlyTests.java

@ -22,7 +22,6 @@ import java.util.Map; @@ -22,7 +22,6 @@ import java.util.Map;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
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.junit.Assert.assertEquals;
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
@ -60,12 +61,6 @@ public class HystrixOnlyTests { @@ -60,12 +61,6 @@ public class HystrixOnlyTests {
@LocalServerPort
private int port;
//FIXME: 2.0.0
private String username = "user";
//FIXME: 2.0.0
private String password = "password";
@Test
public void testNormalExecution() {
ResponseEntity<String> res = new TestRestTemplate()
@ -99,12 +94,10 @@ public class HystrixOnlyTests { @@ -99,12 +94,10 @@ public class HystrixOnlyTests {
map.containsKey("discovery"));
}
private Map getHealth() {
return new TestRestTemplate().exchange(
"http://localhost:" + this.port + "/admin/health", HttpMethod.GET,
new HttpEntity<Void>(createBasicAuthHeader(username, password)),
new HttpEntity<Void>(createBasicAuthHeader(USER, PASSWORD)),
Map.class).getBody();
}

5
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/test/TestAutoConfiguration.java

@ -38,6 +38,9 @@ import org.springframework.security.provisioning.InMemoryUserDetailsManager; @@ -38,6 +38,9 @@ import org.springframework.security.provisioning.InMemoryUserDetailsManager;
@AutoConfigureBefore(SecurityAutoConfiguration.class)
public class TestAutoConfiguration {
public static final String USER = "user";
public static final String PASSWORD = "password";
@Configuration
@Order(Ordered.HIGHEST_PRECEDENCE)
protected static class TestSecurityConfiguration extends WebSecurityConfigurerAdapter {
@ -50,7 +53,7 @@ public class TestAutoConfiguration { @@ -50,7 +53,7 @@ public class TestAutoConfiguration {
@Bean
public UserDetailsService userDetailsService() {
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;
}

Loading…
Cancel
Save