Upgrade to spring-javaformat 0.0.11

This commit is contained in:
Andy Wilkinson
2019-06-07 09:44:58 +01:00
parent d548c5ed31
commit 8f1be4cded
1940 changed files with 16814 additions and 28498 deletions

View File

@@ -62,8 +62,8 @@ public class SampleMethodSecurityApplicationTests {
public void testHome() throws Exception {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
ResponseEntity<String> entity = this.restTemplate.exchange("/", HttpMethod.GET,
new HttpEntity<Void>(headers), String.class);
ResponseEntity<String> entity = this.restTemplate.exchange("/", HttpMethod.GET, new HttpEntity<Void>(headers),
String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).contains("<title>Login");
}
@@ -76,13 +76,10 @@ public class SampleMethodSecurityApplicationTests {
form.set("username", "admin");
form.set("password", "admin");
getCsrf(form, headers);
ResponseEntity<String> entity = this.restTemplate.exchange("/login",
HttpMethod.POST,
new HttpEntity<MultiValueMap<String, String>>(form, headers),
String.class);
ResponseEntity<String> entity = this.restTemplate.exchange("/login", HttpMethod.POST,
new HttpEntity<MultiValueMap<String, String>>(form, headers), String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND);
assertThat(entity.getHeaders().getLocation().toString())
.isEqualTo("http://localhost:" + this.port + "/");
assertThat(entity.getHeaders().getLocation().toString()).isEqualTo("http://localhost:" + this.port + "/");
}
@Test
@@ -93,15 +90,12 @@ public class SampleMethodSecurityApplicationTests {
form.set("username", "user");
form.set("password", "user");
getCsrf(form, headers);
ResponseEntity<String> entity = this.restTemplate.exchange("/login",
HttpMethod.POST,
new HttpEntity<MultiValueMap<String, String>>(form, headers),
String.class);
ResponseEntity<String> entity = this.restTemplate.exchange("/login", HttpMethod.POST,
new HttpEntity<MultiValueMap<String, String>>(form, headers), String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND);
String cookie = entity.getHeaders().getFirst("Set-Cookie");
headers.set("Cookie", cookie);
ResponseEntity<String> page = this.restTemplate.exchange(
entity.getHeaders().getLocation(), HttpMethod.GET,
ResponseEntity<String> page = this.restTemplate.exchange(entity.getHeaders().getLocation(), HttpMethod.GET,
new HttpEntity<Void>(headers), String.class);
assertThat(page.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN);
assertThat(page.getBody()).contains("Access denied");
@@ -109,51 +103,42 @@ public class SampleMethodSecurityApplicationTests {
@Test
public void testManagementProtected() throws Exception {
ResponseEntity<String> entity = this.restTemplate.getForEntity("/beans",
String.class);
ResponseEntity<String> entity = this.restTemplate.getForEntity("/beans", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
}
@Test
public void testManagementAuthorizedAccess() throws Exception {
BasicAuthorizationInterceptor basicAuthInterceptor = new BasicAuthorizationInterceptor(
"admin", "admin");
BasicAuthorizationInterceptor basicAuthInterceptor = new BasicAuthorizationInterceptor("admin", "admin");
this.restTemplate.getRestTemplate().getInterceptors().add(basicAuthInterceptor);
try {
ResponseEntity<String> entity = this.restTemplate.getForEntity("/beans",
String.class);
ResponseEntity<String> entity = this.restTemplate.getForEntity("/beans", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
}
finally {
this.restTemplate.getRestTemplate().getInterceptors()
.remove(basicAuthInterceptor);
this.restTemplate.getRestTemplate().getInterceptors().remove(basicAuthInterceptor);
}
}
@Test
public void testManagementUnauthorizedAccess() throws Exception {
BasicAuthorizationInterceptor basicAuthInterceptor = new BasicAuthorizationInterceptor(
"user", "user");
BasicAuthorizationInterceptor basicAuthInterceptor = new BasicAuthorizationInterceptor("user", "user");
this.restTemplate.getRestTemplate().getInterceptors().add(basicAuthInterceptor);
try {
ResponseEntity<String> entity = this.restTemplate.getForEntity("/beans",
String.class);
ResponseEntity<String> entity = this.restTemplate.getForEntity("/beans", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN);
}
finally {
this.restTemplate.getRestTemplate().getInterceptors()
.remove(basicAuthInterceptor);
this.restTemplate.getRestTemplate().getInterceptors().remove(basicAuthInterceptor);
}
}
private void getCsrf(MultiValueMap<String, String> form, HttpHeaders headers) {
ResponseEntity<String> page = this.restTemplate.getForEntity("/login",
String.class);
ResponseEntity<String> page = this.restTemplate.getForEntity("/login", String.class);
String cookie = page.getHeaders().getFirst("Set-Cookie");
headers.set("Cookie", cookie);
String body = page.getBody();
Matcher matcher = Pattern.compile("(?s).*name=\"_csrf\".*?value=\"([^\"]+).*")
.matcher(body);
Matcher matcher = Pattern.compile("(?s).*name=\"_csrf\".*?value=\"([^\"]+).*").matcher(body);
matcher.find();
form.set("_csrf", matcher.group(1));
}