use of org.springframework.security.web.server.csrf.DefaultCsrfToken in project spring-security by spring-projects.
the class DefaultCsrfServerTokenMixinTests 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.server.csrf.DefaultCsrfToken in project spring-security by spring-projects.
the class DefaultCsrfServerTokenMixinTests method defaultCsrfTokenDeserializeTest.
@Test
public void defaultCsrfTokenDeserializeTest() throws IOException {
DefaultCsrfToken token = this.mapper.readValue(CSRF_JSON, DefaultCsrfToken.class);
assertThat(token).isNotNull();
assertThat(token.getHeaderName()).isEqualTo("csrf-header");
assertThat(token.getParameterName()).isEqualTo("_csrf");
assertThat(token.getToken()).isEqualTo("1");
}
use of org.springframework.security.web.server.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.exchange.getAttributes().put(CsrfRequestDataValueProcessor.DEFAULT_CSRF_ATTR_NAME, token);
Map<String, String> expected = new HashMap<>();
expected.put(token.getParameterName(), token.getToken());
CsrfRequestDataValueProcessor processor = new CsrfRequestDataValueProcessor();
assertThat(this.processor.getExtraHiddenFields(this.exchange)).isEqualTo(expected);
}
Aggregations