added SecurityConfig

This commit is contained in:
Sjmillington 2019-11-23 13:06:06 +00:00
parent d2d9db6dda
commit 51e32cca92
2 changed files with 23 additions and 2 deletions

View File

@ -63,6 +63,10 @@
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>${spring-boot-admin-starter-client.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>

View File

@ -7,14 +7,17 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.context.annotation.Configuration;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import com.baeldung.web.log.app.Application;
import com.baeldung.web.log.data.TaxiRide;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = { Application.class}, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@SpringBootTest(classes = { Application.class, TaxiFareControllerIntegrationTest.SecurityConfig.class}, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class TaxiFareControllerIntegrationTest {
@LocalServerPort
@ -23,6 +26,7 @@ public class TaxiFareControllerIntegrationTest {
@Test
public void givenRequest_whenFetchTaxiFareRateCard_thanOK() {
System.out.println(port);
String URL = "http://localhost:" + port + "/spring-rest";
TestRestTemplate testRestTemplate = new TestRestTemplate();
TaxiRide taxiRide = new TaxiRide(true, 10l);
@ -30,6 +34,19 @@ public class TaxiFareControllerIntegrationTest {
URL + "/taxifare/calculate/",
taxiRide, String.class);
//assertThat(fare, equalTo("200"));
assertThat(fare, equalTo("200"));
}
@Configuration
static class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
System.out.println("security being set");
http
.authorizeRequests()
.anyRequest().permitAll()
.and()
.csrf().disable();
}
}
}