Upgrade to spring-javaformat 0.0.11
This commit is contained in:
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user