Search

Marcelo Lecar

Category

Uncategorized

@WebMvcTest Spring Tests with CSRF

References:

To test your controllers without disabling CSRF, you can do the following:

1. First import statically the package bellow:

import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.*;

2. Then in your MockMvc request:

with(csrf())

3. And last:

this.mockMvc
            .perform(post("/users").with(csrf())
                    .content(objectMapper.writeValueAsString(createUserDto))
                    .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE))
            .andExpect(status().isCreated());

The recomendation from Spring, says the following:

When should you use CSRF protection? Our recommendation is to use CSRF protection for any request that could be processed by a browser by normal users. If you are only creating a service that is used by non-browser clients, you will likely want to disable CSRF protection.

Error: ENOSPC: System limit for number of file watchers reached

For everyone facing an issue like this one, starting a React application:

Error: ENOSPC: System limit for number of file watchers reached, watch

At first I wanted to disable this file watching, but I realized it was not an easy thing to do, so I followed this approach on https://confluence.jetbrains.com/display/IDEADEV/Inotify+Watches+Limit

More details can be found at https://unix.stackexchange.com/questions/13751/kernel-inotify-watch-limit-reached

As I am using linux, I did was the following:

  1. Add a new .conf file under /etc/sysctl.d and add the following line
fs.inotify.max_user_watches = 524288

2. Then you just need to execute the following command line:

sudo sysctl -p --system

Olá Mundo!

Olá! Seja bem vindo!
A idéia da criação de um blog surgiu da minha necessidade e satisfação em compartilhar a minha experiência ao longo dos anos desenvolvendo software.

Website Powered by WordPress.com.

Up ↑