Search in sources :

Example 1 with DefaultCsrfToken

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);
}
Also used : DefaultCsrfToken(org.springframework.security.web.server.csrf.DefaultCsrfToken) Test(org.junit.jupiter.api.Test)

Example 2 with DefaultCsrfToken

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");
}
Also used : DefaultCsrfToken(org.springframework.security.web.server.csrf.DefaultCsrfToken) Test(org.junit.jupiter.api.Test)

Example 3 with DefaultCsrfToken

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);
}
Also used : HashMap(java.util.HashMap) DefaultCsrfToken(org.springframework.security.web.server.csrf.DefaultCsrfToken) DefaultCsrfToken(org.springframework.security.web.server.csrf.DefaultCsrfToken) CsrfToken(org.springframework.security.web.server.csrf.CsrfToken) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)3 DefaultCsrfToken (org.springframework.security.web.server.csrf.DefaultCsrfToken)3 HashMap (java.util.HashMap)1 CsrfToken (org.springframework.security.web.server.csrf.CsrfToken)1