### Question:
KeycloakCsrfRequestMatcher implements RequestMatcher { public boolean matches(HttpServletRequest request) { String uri = request.getRequestURI().replaceFirst(request.getContextPath(), ""); return !allowedEndpoints.matcher(uri).matches() && !allowedMethods.matcher(request.getMethod()).matches(); }  boolean matches(HttpServletRequest request);  }### Answer:
@Test public void testMatchesMethodGet() throws Exception { request.setMethod(HttpMethod.GET.name()); assertFalse(matcher.matches(request)); }
@Test public void testMatchesMethodPost() throws Exception { prepareRequest(HttpMethod.POST, ROOT_CONTEXT_PATH, "some/random/uri"); assertTrue(matcher.matches(request)); prepareRequest(HttpMethod.POST, SUB_CONTEXT_PATH, "some/random/uri"); assertTrue(matcher.matches(request)); }
@Test public void testMatchesKeycloakLogout() throws Exception { prepareRequest(HttpMethod.POST, ROOT_CONTEXT_PATH, AdapterConstants.K_LOGOUT); assertFalse(matcher.matches(request)); prepareRequest(HttpMethod.POST, SUB_CONTEXT_PATH, AdapterConstants.K_LOGOUT); assertFalse(matcher.matches(request)); }
@Test public void testMatchesKeycloakPushNotBefore() throws Exception { prepareRequest(HttpMethod.POST, ROOT_CONTEXT_PATH, AdapterConstants.K_PUSH_NOT_BEFORE); assertFalse(matcher.matches(request)); prepareRequest(HttpMethod.POST, SUB_CONTEXT_PATH, AdapterConstants.K_PUSH_NOT_BEFORE); assertFalse(matcher.matches(request)); }
@Test public void testMatchesKeycloakQueryBearerToken() throws Exception { prepareRequest(HttpMethod.POST, ROOT_CONTEXT_PATH, AdapterConstants.K_QUERY_BEARER_TOKEN); assertFalse(matcher.matches(request)); prepareRequest(HttpMethod.POST, SUB_CONTEXT_PATH, AdapterConstants.K_QUERY_BEARER_TOKEN); assertFalse(matcher.matches(request)); }
@Test public void testMatchesKeycloakTestAvailable() throws Exception { prepareRequest(HttpMethod.POST, ROOT_CONTEXT_PATH, AdapterConstants.K_TEST_AVAILABLE); assertFalse(matcher.matches(request)); prepareRequest(HttpMethod.POST, SUB_CONTEXT_PATH, AdapterConstants.K_TEST_AVAILABLE); assertFalse(matcher.matches(request)); }