Skip to content

Commit a4216d0

Browse files
rwinchjgrandja
authored andcommitted
Additional HttpSessionOAuth2AuthorizationRequestRepository tests
Issue gh-5145
1 parent b8eee20 commit a4216d0

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

oauth2/oauth2-client/src/test/java/org/springframework/security/oauth2/client/web/HttpSessionOAuth2AuthorizationRequestRepositoryAllowMultipleAuthorizationRequestsTests.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,49 @@ public void loadAuthorizationRequestWhenMultipleSavedThenReturnMatchingAuthoriza
7373
assertThat(loadedAuthorizationRequest3).isEqualTo(authorizationRequest3);
7474
}
7575

76+
@Test
77+
public void loadAuthorizationRequestWhenSavedWithAllowMultipleAuthorizationRequests() {
78+
// save 2 requests with legacy (allowMultipleAuthorizationRequests=true) and load
79+
// with new
80+
HttpSessionOAuth2AuthorizationRequestRepository legacy = new HttpSessionOAuth2AuthorizationRequestRepository();
81+
legacy.setAllowMultipleAuthorizationRequests(true);
82+
MockHttpServletRequest request = new MockHttpServletRequest();
83+
MockHttpServletResponse response = new MockHttpServletResponse();
84+
String state1 = "state-1122";
85+
OAuth2AuthorizationRequest authorizationRequest1 = createAuthorizationRequest().state(state1).build();
86+
legacy.saveAuthorizationRequest(authorizationRequest1, request, response);
87+
String state2 = "state-3344";
88+
OAuth2AuthorizationRequest authorizationRequest2 = createAuthorizationRequest().state(state2).build();
89+
legacy.saveAuthorizationRequest(authorizationRequest2, request, response);
90+
91+
request.setParameter(OAuth2ParameterNames.STATE, state1);
92+
OAuth2AuthorizationRequest loaded = this.authorizationRequestRepository.loadAuthorizationRequest(request);
93+
94+
assertThat(loaded).isEqualTo(authorizationRequest1);
95+
}
96+
97+
@Test
98+
public void saveAuthorizationRequestWhenSavedWithAllowMultipleAuthorizationRequests() {
99+
// save 2 requests with legacy (allowMultipleAuthorizationRequests=true), save
100+
// with new, and load with new
101+
HttpSessionOAuth2AuthorizationRequestRepository legacy = new HttpSessionOAuth2AuthorizationRequestRepository();
102+
legacy.setAllowMultipleAuthorizationRequests(true);
103+
MockHttpServletRequest request = new MockHttpServletRequest();
104+
MockHttpServletResponse response = new MockHttpServletResponse();
105+
String state1 = "state-1122";
106+
OAuth2AuthorizationRequest authorizationRequest1 = createAuthorizationRequest().state(state1).build();
107+
legacy.saveAuthorizationRequest(authorizationRequest1, request, response);
108+
String state2 = "state-3344";
109+
OAuth2AuthorizationRequest authorizationRequest2 = createAuthorizationRequest().state(state2).build();
110+
legacy.saveAuthorizationRequest(authorizationRequest2, request, response);
111+
String state3 = "state-5566";
112+
OAuth2AuthorizationRequest authorizationRequest3 = createAuthorizationRequest().state(state3).build();
113+
114+
this.authorizationRequestRepository.saveAuthorizationRequest(authorizationRequest3, request, response);
115+
request.setParameter(OAuth2ParameterNames.STATE, state3);
116+
OAuth2AuthorizationRequest loaded = this.authorizationRequestRepository.loadAuthorizationRequest(request);
117+
118+
assertThat(loaded).isEqualTo(authorizationRequest3);
119+
}
120+
76121
}

0 commit comments

Comments
 (0)