use of org.springframework.security.web.csrf.DefaultCsrfToken in project spring-security by spring-projects.
the class CsrfMetaTagsTagTests method handleTokenRendersTagsDifferentToken.
@Test
public void handleTokenRendersTagsDifferentToken() {
CsrfToken token = new DefaultCsrfToken("csrfHeader", "csrfParameter", "fooBarBazQux");
String value = this.tag.handleToken(token);
assertThat(value).as("The returned value should not be null.").isNotNull();
assertThat(value).withFailMessage("The output is not correct.").isEqualTo("<meta name=\"_csrf_parameter\" content=\"csrfParameter\" />" + "<meta name=\"_csrf_header\" content=\"csrfHeader\" />" + "<meta name=\"_csrf\" content=\"fooBarBazQux\" />");
}
use of org.springframework.security.web.csrf.DefaultCsrfToken in project spring-security by spring-projects.
the class CsrfRequestDataValueProcessorTests method createGetExtraHiddenFieldsHasCsrfToken.
@Test
public void createGetExtraHiddenFieldsHasCsrfToken() {
CsrfToken token = new DefaultCsrfToken("1", "a", "b");
this.request.setAttribute(CsrfToken.class.getName(), token);
Map<String, String> expected = new HashMap<>();
expected.put(token.getParameterName(), token.getToken());
RequestDataValueProcessor processor = new CsrfRequestDataValueProcessor();
assertThat(processor.getExtraHiddenFields(this.request)).isEqualTo(expected);
}
use of org.springframework.security.web.csrf.DefaultCsrfToken in project spring-security by spring-projects.
the class CsrfTokenArgumentResolverTests method setup.
@BeforeEach
public void setup() {
this.token = new DefaultCsrfToken("X-CSRF-TOKEN", "_csrf", "secret");
this.resolver = new CsrfTokenArgumentResolver();
this.request = new MockHttpServletRequest();
this.webRequest = new ServletWebRequest(this.request);
}
use of org.springframework.security.web.csrf.DefaultCsrfToken in project spring-security by spring-projects.
the class DefaultCsrfTokenMixinTests method defaultCsrfTokenSerializedTest.
// @formatter:on
@Test
public void defaultCsrfTokenSerializedTest() throws JsonProcessingException, JSONException {
DefaultCsrfToken token = new DefaultCsrfToken("csrf-header", "_csrf", "1");
String serializedJson = this.mapper.writeValueAsString(token);
JSONAssert.assertEquals(CSRF_JSON, serializedJson, true);
}
use of org.springframework.security.web.csrf.DefaultCsrfToken in project fastjson by alibaba.
the class DefaultSavedRequestTest method test_0.
public void test_0() throws Exception {
DefaultCsrfToken token = JSON.parseObject("{\"token\":\"xxx\",\"parameterName\":\"222\",\"headerName\":\"hhh\"}", DefaultCsrfToken.class);
assertEquals("hhh", token.getHeaderName());
assertEquals("222", token.getParameterName());
assertEquals("xxx", token.getToken());
assertEquals("{\"headerName\":\"hhh\",\"parameterName\":\"222\",\"token\":\"xxx\"}", JSON.toJSONString(token));
}
Aggregations