congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
MockHttpServletRequestBuilder.with
Code IndexAdd Tabnine to your IDE (free)

How to use
with
method
in
org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder

Best Java code snippets using org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder.with (Showing top 20 results out of 315)

origin: spring-projects/spring-framework

@Test  // SPR-12945
public void mergeInvokesDefaultRequestPostProcessorFirst() {
  final String ATTR = "ATTR";
  final String EXPECTED = "override";
  MockHttpServletRequestBuilder defaultBuilder =
      new MockHttpServletRequestBuilder(HttpMethod.GET, "/foo/bar")
          .with(requestAttr(ATTR).value("default"))
          .with(requestAttr(ATTR).value(EXPECTED));
  builder.merge(defaultBuilder);
  MockHttpServletRequest request = builder.buildRequest(servletContext);
  request = builder.postProcessRequest(request);
  assertEquals(EXPECTED, request.getAttribute(ATTR));
}
origin: spring-projects/spring-security

@Test
public void loginWhenUsingJaasApiProvisionThenJaasSubjectContainsUsername() throws Exception {
  this.spring.configLocations(xml("Jaas")).autowire();
  AuthorityGranter granter = this.spring.getContext().getBean(AuthorityGranter.class);
  when(granter.grant(any(Principal.class))).thenReturn(new HashSet<>(Arrays.asList("USER")));
  this.mvc.perform(get("/username")
      .with(httpBasic("user", "password")))
      .andExpect(content().string("user"));
}
origin: spring-projects/spring-security

/**
 * http/http-basic@authentication-details-source-ref equivalent
 */
@Test
public void basicAuthenticationWhenUsingAuthenticationDetailsSourceRefThenMatchesNamespace() throws Exception {
  this.spring.register(AuthenticationDetailsSourceHttpBasicConfig.class, UserConfig.class).autowire();
  AuthenticationDetailsSource<HttpServletRequest, ?> source =
      this.spring.getContext().getBean(AuthenticationDetailsSource.class);
  this.mvc.perform(get("/")
      .with(httpBasic("user", "password")));
  verify(source).buildDetails(any(HttpServletRequest.class));
}
origin: spring-projects/spring-security

@Test
public void requestWhenJwtAuthenticationConverterCustomizedAuthoritiesThenThoseAuthoritiesArePropagated()
    throws Exception {
  this.spring.register(JwtDecoderConfig.class, CustomAuthorityMappingConfig.class, BasicController.class)
      .autowire();
  JwtDecoder decoder = this.spring.getContext().getBean(JwtDecoder.class);
  when(decoder.decode(JWT_TOKEN)).thenReturn(JWT);
  this.mvc.perform(get("/requires-read-scope")
      .with(bearerToken(JWT_TOKEN)))
      .andExpect(status().isOk());
}
origin: spring-projects/spring-security

  private static RequestBuilder formLogin(MockHttpSession session) {
    return post("/login")
        .param("username", "user")
        .param("password", "password")
        .session(session)
        .with(csrf());
  }
}
origin: spring-projects/spring-framework

@Test
public void barHeader() throws Exception {
  this.mockMvc.perform(get("/").with(headers().bar("a=b"))).andExpect(content().string("Bar"));
}
origin: spring-projects/spring-framework

@Test
public void fooHeader() throws Exception {
  this.mockMvc.perform(get("/").with(headers().foo("a=b"))).andExpect(content().string("Foo"));
}
origin: spring-projects/spring-security

@Test
public void requestWhenCustomJwtDecoderExposedAsBeanThenUsed()
    throws Exception {
  this.spring.register(CustomJwtDecoderAsBean.class, BasicController.class).autowire();
  JwtDecoder decoder = this.spring.getContext().getBean(JwtDecoder.class);
  when(decoder.decode(anyString())).thenReturn(JWT);
  this.mvc.perform(get("/authenticated")
      .with(bearerToken(JWT_TOKEN)))
      .andExpect(status().isOk())
      .andExpect(content().string(JWT_SUBJECT));
}
origin: spring-projects/spring-security

@Test
public void requestWhenSessionManagementConfiguredThenUserConfigurationOverrides()
    throws Exception {
  this.spring.register(RestOperationsConfig.class, AlwaysSessionCreationConfig.class, BasicController.class).autowire();
  mockRestOperations(jwks("Default"));
  String token = this.token("ValidNoScopes");
  MvcResult result = this.mvc.perform(get("/")
      .with(bearerToken(token)))
      .andExpect(status().isOk())
      .andReturn();
  assertThat(result.getRequest().getSession(false)).isNotNull();
}
origin: spring-projects/spring-security

@Test
public void requestWhenUsingPublicKeyAlgorithmDoesNotMatchThenReturnsInvalidToken()
    throws Exception {
  this.spring.register(SingleKeyConfig.class).autowire();
  String token = this.token("WrongAlgorithm");
  this.mvc.perform(get("/")
      .with(bearerToken(token)))
      .andExpect(invalidTokenHeader("algorithm"));
}
origin: spring-projects/spring-security

@Test
public void requestWhenUsingPublicKeyAndSignatureFailsThenReturnsInvalidToken()
    throws Exception {
  this.spring.register(SingleKeyConfig.class).autowire();
  String token = this.token("WrongSignature");
  this.mvc.perform(get("/")
      .with(bearerToken(token)))
      .andExpect(invalidTokenHeader("signature"));
}
origin: spring-projects/spring-security

@Test
public void getWhenUsingCorsThenDoesSpringSecurityCorsHandshake()
  throws Exception {
  this.spring.configLocations(this.xml("WithCors")).autowire();
  this.mvc.perform(get("/").with(this.approved()))
      .andExpect(corsResponseHeaders())
      .andExpect((status().isIAmATeapot()));
  this.mvc.perform(options("/").with(this.preflight()))
      .andExpect(corsResponseHeaders())
      .andExpect(status().isOk());
}
origin: spring-projects/spring-security

@Test
public void configureWhenEnableWebMvcThenAuthenticationPrincipalResolvable() throws Exception {
  this.spring.register(AuthenticationPrincipalConfig.class).autowire();
  this.mockMvc.perform(get("/").with(authentication(new TestingAuthenticationToken("user1", "password"))))
    .andExpect(content().string("user1"));
}
origin: spring-projects/spring-security

@Test
public void requestWhenUsingPublicKeyAndValidTokenThenAuthenticates()
    throws Exception {
  this.spring.register(SingleKeyConfig.class, BasicController.class).autowire();
  String token = this.token("ValidNoScopes");
  this.mvc.perform(get("/")
      .with(bearerToken(token)))
      .andExpect(status().isOk());
}
origin: spring-projects/spring-security

/**
 * http@realm equivalent
 */
@Test
public void basicAuthenticationWhenUsingCustomRealmThenMatchesNamespace() throws Exception {
  this.spring.register(CustomHttpBasicConfig.class, UserConfig.class).autowire();
  this.mvc.perform(get("/")
      .with(httpBasic("user", "invalid")))
      .andExpect(status().isUnauthorized())
      .andExpect(header().string(HttpHeaders.WWW_AUTHENTICATE, "Basic realm=\"Custom Realm\""));
}
origin: spring-projects/spring-security

@Test
public void getWhenUsingDefaultsWithExpiredBearerTokenThenInvalidToken()
    throws Exception {
  this.spring.register(RestOperationsConfig.class, DefaultConfig.class, BasicController.class).autowire();
  mockRestOperations(jwks("Default"));
  String token = this.token("Expired");
  this.mvc.perform(get("/").with(bearerToken(token)))
      .andExpect(status().isUnauthorized())
      .andExpect(invalidTokenHeader("An error occurred while attempting to decode the Jwt"));
}
origin: spring-projects/spring-security

@Test
public void getWhenUsingMethodSecurityWithInsufficientScpThenInsufficientScopeError()
    throws Exception {
  this.spring.register(RestOperationsConfig.class, MethodSecurityConfig.class, BasicController.class).autowire();
  mockRestOperations(jwks("Default"));
  String token = this.token("ValidMessageWriteScp");
  this.mvc.perform(get("/ms-requires-read-scope")
      .with(bearerToken(token)))
      .andExpect(status().isForbidden())
      .andExpect(insufficientScopeHeader("message:write"));
}
origin: spring-projects/spring-security

@Test
public void postWhenUsingDefaultsWithExpiredBearerTokenAndNoCsrfThenInvalidToken()
    throws Exception {
  this.spring.register(RestOperationsConfig.class, DefaultConfig.class).autowire();
  mockRestOperations(jwks("Default"));
  String token = this.token("Expired");
  this.mvc.perform(post("/authenticated")
      .with(bearerToken(token)))
      .andExpect(status().isUnauthorized())
      .andExpect(invalidTokenHeader("An error occurred while attempting to decode the Jwt"));
}
origin: spring-projects/spring-security

@Test
public void getWhenUsingDefaultsWithSufficientlyScopedBearerTokenThenAcceptsRequest()
    throws Exception {
  this.spring.register(RestOperationsConfig.class, DefaultConfig.class, BasicController.class).autowire();
  mockRestOperations(jwks("Default"));
  String token = this.token("ValidMessageReadScope");
  this.mvc.perform(get("/requires-read-scope")
      .with(bearerToken(token)))
      .andExpect(status().isOk())
      .andExpect(content().string("SCOPE_message:read"));
}
origin: spring-projects/spring-security

@Test
public void getWhenUsingJwkSetUriThenAcceptsRequest() throws Exception {
  this.spring.register(WebServerConfig.class, JwkSetUriConfig.class, BasicController.class).autowire();
  mockWebServer(jwks("Default"));
  String token = this.token("ValidNoScopes");
  this.mvc.perform(get("/").with(bearerToken(token)))
      .andExpect(status().isOk())
      .andExpect(content().string("ok"));
}
org.springframework.test.web.servlet.requestMockHttpServletRequestBuilderwith

Javadoc

An extension point for further initialization of MockHttpServletRequestin ways not built directly into the MockHttpServletRequestBuilder. Implementation of this interface can have builder-style methods themselves and be made accessible through static factory methods.

Popular methods of MockHttpServletRequestBuilder

  • contentType
    Set the 'Content-Type' header of the request.
  • content
    Set the request body.
  • param
    Add a request parameter to the MockHttpServletRequest.If called more than once, new values get added
  • accept
    Set the 'Accept' header to the given media type(s).
  • header
    Add a header to the request. Values are always added.
  • requestAttr
    Set a request attribute.
  • buildRequest
    Build a MockHttpServletRequest.
  • contextPath
    Specify the portion of the requestURI that represents the context path. The context path, if specifi
  • principal
    Set the principal of the request.
  • flashAttr
    Set an "input" flash attribute.
  • headers
    Add all headers to the request. Values are always added.
  • session
    Set the HTTP session to use, possibly re-used across requests.Individual attributes provided via #se
  • headers,
  • session,
  • sessionAttr,
  • cookie,
  • params,
  • servletPath,
  • <init>,
  • characterEncoding,
  • locale

Popular in Java

  • Start an intent from android
  • onCreateOptionsMenu (Activity)
  • getSharedPreferences (Context)
  • runOnUiThread (Activity)
  • BufferedWriter (java.io)
    Wraps an existing Writer and buffers the output. Expensive interaction with the underlying reader is
  • FileWriter (java.io)
    A specialized Writer that writes to a file in the file system. All write requests made by calling me
  • InetAddress (java.net)
    An Internet Protocol (IP) address. This can be either an IPv4 address or an IPv6 address, and in pra
  • SQLException (java.sql)
    An exception that indicates a failed JDBC operation. It provides the following information about pro
  • TimeZone (java.util)
    TimeZone represents a time zone offset, and also figures out daylight savings. Typically, you get a
  • Vector (java.util)
    Vector is an implementation of List, backed by an array and synchronized. All optional operations in
  • Best IntelliJ plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now