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

@@ -66,54 +66,44 @@ public class SampleSecureOAuth2ApplicationTests {
@Before
public void setUp() {
this.mvc = MockMvcBuilders.webAppContextSetup(this.context)
.addFilters(this.filterChain).build();
this.mvc = MockMvcBuilders.webAppContextSetup(this.context).addFilters(this.filterChain).build();
SecurityContextHolder.clearContext();
}
@Test
public void everythingIsSecuredByDefault() throws Exception {
this.mvc.perform(get("/").accept(MediaTypes.HAL_JSON))
.andExpect(status().isUnauthorized()).andDo(print());
this.mvc.perform(get("/flights").accept(MediaTypes.HAL_JSON))
.andExpect(status().isUnauthorized()).andDo(print());
this.mvc.perform(get("/flights/1").accept(MediaTypes.HAL_JSON))
.andExpect(status().isUnauthorized()).andDo(print());
this.mvc.perform(get("/alps").accept(MediaTypes.HAL_JSON))
.andExpect(status().isUnauthorized()).andDo(print());
this.mvc.perform(get("/").accept(MediaTypes.HAL_JSON)).andExpect(status().isUnauthorized()).andDo(print());
this.mvc.perform(get("/flights").accept(MediaTypes.HAL_JSON)).andExpect(status().isUnauthorized())
.andDo(print());
this.mvc.perform(get("/flights/1").accept(MediaTypes.HAL_JSON)).andExpect(status().isUnauthorized())
.andDo(print());
this.mvc.perform(get("/alps").accept(MediaTypes.HAL_JSON)).andExpect(status().isUnauthorized()).andDo(print());
}
@Test
@Ignore
public void accessingRootUriPossibleWithUserAccount() throws Exception {
String header = "Basic " + new String(Base64.encode("greg:turnquist".getBytes()));
this.mvc.perform(
get("/").accept(MediaTypes.HAL_JSON).header("Authorization", header))
.andExpect(
header().string("Content-Type", MediaTypes.HAL_JSON.toString()))
.andExpect(status().isOk()).andDo(print());
this.mvc.perform(get("/").accept(MediaTypes.HAL_JSON).header("Authorization", header))
.andExpect(header().string("Content-Type", MediaTypes.HAL_JSON.toString())).andExpect(status().isOk())
.andDo(print());
}
@Test
public void useAppSecretsPlusUserAccountToGetBearerToken() throws Exception {
String header = "Basic " + new String(Base64.encode("foo:bar".getBytes()));
MvcResult result = this.mvc
.perform(post("/oauth/token").header("Authorization", header)
.param("grant_type", "password").param("scope", "read")
.param("username", "greg").param("password", "turnquist"))
.perform(post("/oauth/token").header("Authorization", header).param("grant_type", "password")
.param("scope", "read").param("username", "greg").param("password", "turnquist"))
.andExpect(status().isOk()).andDo(print()).andReturn();
Object accessToken = this.objectMapper
.readValue(result.getResponse().getContentAsString(), Map.class)
Object accessToken = this.objectMapper.readValue(result.getResponse().getContentAsString(), Map.class)
.get("access_token");
MvcResult flightsAction = this.mvc
.perform(get("/flights/1").accept(MediaTypes.HAL_JSON)
.header("Authorization", "Bearer " + accessToken))
.andExpect(header().string("Content-Type",
MediaTypes.HAL_JSON.toString() + ";charset=UTF-8"))
.perform(get("/flights/1").accept(MediaTypes.HAL_JSON).header("Authorization", "Bearer " + accessToken))
.andExpect(header().string("Content-Type", MediaTypes.HAL_JSON.toString() + ";charset=UTF-8"))
.andExpect(status().isOk()).andDo(print()).andReturn();
Flight flight = this.objectMapper.readValue(
flightsAction.getResponse().getContentAsString(), Flight.class);
Flight flight = this.objectMapper.readValue(flightsAction.getResponse().getContentAsString(), Flight.class);
assertThat(flight.getOrigin()).isEqualTo("Nashville");
assertThat(flight.getDestination()).isEqualTo("Dallas");