mirror of
https://github.com/spring-projects/spring-security.git
synced 2026-03-25 03:21:18 +00:00
Add equals and hashCode to HttpMethodRequestMatcher
Closes gh-18911 Signed-off-by: Tran Ngoc Nhan <ngocnhan.tran1996@gmail.com>
This commit is contained in:
parent
9fed1ac8c3
commit
62f33d3fcf
@ -305,6 +305,19 @@ public final class PathPatternRequestMatcher implements RequestMatcher {
|
||||
return this.method.name().equals(request.getMethod());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof HttpMethodRequestMatcher that)) {
|
||||
return false;
|
||||
}
|
||||
return Objects.equals(this.method, that.method);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.method);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "HttpMethod [" + this.method + "]";
|
||||
|
||||
@ -145,6 +145,17 @@ public class PathPatternRequestMatcherTests {
|
||||
assertThat(matcher.matches(mock)).isTrue();
|
||||
}
|
||||
|
||||
// gh-18911
|
||||
@Test
|
||||
void testEqualsWithSameAndDifferentHttpMethod() {
|
||||
PathPatternRequestMatcher.Builder builder = PathPatternRequestMatcher.withDefaults();
|
||||
PathPatternRequestMatcher matcher1 = builder.matcher(HttpMethod.GET, "/foo");
|
||||
PathPatternRequestMatcher matcher2 = builder.matcher(HttpMethod.GET, "/foo");
|
||||
PathPatternRequestMatcher matcher3 = builder.matcher(HttpMethod.POST, "/foo");
|
||||
assertThat(matcher1).isEqualTo(matcher2);
|
||||
assertThat(matcher1).isNotEqualTo(matcher3);
|
||||
}
|
||||
|
||||
MockHttpServletRequest request(String uri) {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", uri);
|
||||
ServletRequestPathUtils.parseAndCache(request);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user