use of org.springframework.security.web.util.matcher.MediaTypeRequestMatcher in project spring-security by spring-projects.
the class MediaTypeRequestMatcherTests method resolveTextPlainMatchesTextAll.
@Test
public void resolveTextPlainMatchesTextAll() throws HttpMediaTypeNotAcceptableException {
when(negotiationStrategy.resolveMediaTypes(any(NativeWebRequest.class))).thenReturn(Arrays.asList(MediaType.TEXT_PLAIN));
matcher = new MediaTypeRequestMatcher(negotiationStrategy, new MediaType("text", "*"));
assertThat(matcher.matches(request)).isTrue();
}
use of org.springframework.security.web.util.matcher.MediaTypeRequestMatcher in project spring-security by spring-projects.
the class MediaTypeRequestMatcherTests method useEqualsWithCustomMediaType.
@Test
public void useEqualsWithCustomMediaType() throws HttpMediaTypeNotAcceptableException {
when(negotiationStrategy.resolveMediaTypes(any(NativeWebRequest.class))).thenReturn(Arrays.asList(new MediaType("text", "unique")));
matcher = new MediaTypeRequestMatcher(negotiationStrategy, new MediaType("text", "unique"));
matcher.setUseEquals(true);
assertThat(matcher.matches(request)).isTrue();
}
use of org.springframework.security.web.util.matcher.MediaTypeRequestMatcher in project spring-security by spring-projects.
the class MediaTypeRequestMatcherTests method useEqualsResolveTextPlainMatchesTextAll.
@Test
public void useEqualsResolveTextPlainMatchesTextAll() throws HttpMediaTypeNotAcceptableException {
when(negotiationStrategy.resolveMediaTypes(any(NativeWebRequest.class))).thenReturn(Arrays.asList(MediaType.TEXT_PLAIN));
matcher = new MediaTypeRequestMatcher(negotiationStrategy, new MediaType("text", "*"));
matcher.setUseEquals(true);
assertThat(matcher.matches(request)).isFalse();
}
use of org.springframework.security.web.util.matcher.MediaTypeRequestMatcher in project spring-security by spring-projects.
the class MediaTypeRequestMatcherTests method useEqualsSame.
@Test
public void useEqualsSame() throws HttpMediaTypeNotAcceptableException {
when(negotiationStrategy.resolveMediaTypes(any(NativeWebRequest.class))).thenReturn(Arrays.asList(MediaType.TEXT_PLAIN));
matcher = new MediaTypeRequestMatcher(negotiationStrategy, MediaType.TEXT_PLAIN);
matcher.setUseEquals(true);
assertThat(matcher.matches(request)).isTrue();
}
use of org.springframework.security.web.util.matcher.MediaTypeRequestMatcher in project spring-security by spring-projects.
the class MediaTypeRequestMatcherTests method mediaAllQ08AndTextPlainIgnoreMediaTypeAll.
@Test
public void mediaAllQ08AndTextPlainIgnoreMediaTypeAll() throws HttpMediaTypeNotAcceptableException {
when(negotiationStrategy.resolveMediaTypes(any(NativeWebRequest.class))).thenReturn(Arrays.asList(MediaType.TEXT_PLAIN, MediaType.parseMediaType("*/*;q=0.8")));
matcher = new MediaTypeRequestMatcher(negotiationStrategy, MediaType.TEXT_HTML);
matcher.setIgnoredMediaTypes(Collections.singleton(MediaType.ALL));
assertThat(matcher.matches(request)).isFalse();
}
Aggregations