Skip to content

Commit c82f58c

Browse files
committed
Remove tests that mock final Cookie class
1 parent b819fad commit c82f58c

File tree

1 file changed

+5
-38
lines changed

1 file changed

+5
-38
lines changed

extensions-core/druid-pac4j/src/test/java/org/apache/druid/security/pac4j/Pac4jSessionStoreTest.java

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.pac4j.core.context.Cookie;
2727
import org.pac4j.core.context.WebContext;
2828
import org.pac4j.core.profile.CommonProfile;
29+
import org.pac4j.core.util.Pac4jConstants;
2930

3031
import java.util.Collections;
3132
import java.util.HashMap;
@@ -187,41 +188,7 @@ public void testGetWithNullCookies()
187188
EasyMock.verify(webContext);
188189
}
189190

190-
@Test
191-
public void testGetWithNullValue()
192-
{
193-
Pac4jSessionStore sessionStore = new Pac4jSessionStore(COOKIE_PASSPHRASE);
194-
195-
WebContext webContext = EasyMock.mock(WebContext.class);
196-
Cookie cookie = EasyMock.mock(Cookie.class);
197-
EasyMock.expect(cookie.getName()).andReturn("pac4j.session.key");
198-
EasyMock.expect(cookie.getValue()).andReturn(null);
199-
EasyMock.expect(webContext.getRequestCookies()).andReturn(Collections.singletonList(cookie));
200-
EasyMock.replay(webContext, cookie);
201-
202-
Optional<Object> result = sessionStore.get(webContext, "key");
203-
Assert.assertFalse(result.isPresent());
204-
205-
EasyMock.verify(webContext, cookie);
206-
}
207191

208-
@Test
209-
public void testGetWithEmptyValue()
210-
{
211-
Pac4jSessionStore sessionStore = new Pac4jSessionStore(COOKIE_PASSPHRASE);
212-
213-
WebContext webContext = EasyMock.mock(WebContext.class);
214-
Cookie cookie = EasyMock.mock(Cookie.class);
215-
EasyMock.expect(cookie.getName()).andReturn("pac4j.session.key");
216-
EasyMock.expect(cookie.getValue()).andReturn("");
217-
EasyMock.expect(webContext.getRequestCookies()).andReturn(Collections.singletonList(cookie));
218-
EasyMock.replay(webContext, cookie);
219-
220-
Optional<Object> result = sessionStore.get(webContext, "key");
221-
Assert.assertFalse(result.isPresent());
222-
223-
EasyMock.verify(webContext, cookie);
224-
}
225192

226193
@Test
227194
public void testSetAndGetClearUserProfile()
@@ -243,7 +210,7 @@ public void testSetAndGetClearUserProfile()
243210
profile.addAttribute("id_token", "id");
244211
profile.addAttribute("credentials", "creds");
245212

246-
sessionStore.set(webContext1, "pac4j.user.profiles", profile);
213+
sessionStore.set(webContext1, Pac4jConstants.USER_PROFILES, profile);
247214

248215
Cookie cookie = cookieCapture.getValue();
249216
Assert.assertTrue(cookie.isSecure());
@@ -254,7 +221,7 @@ public void testSetAndGetClearUserProfile()
254221
EasyMock.expect(webContext2.getRequestCookies()).andReturn(Collections.singletonList(cookie));
255222
EasyMock.replay(webContext2);
256223

257-
Optional<Object> value = sessionStore.get(webContext2, "pac4j.user.profiles");
224+
Optional<Object> value = sessionStore.get(webContext2, Pac4jConstants.USER_PROFILES);
258225
Assert.assertTrue(Objects.requireNonNull(value).isPresent());
259226
CommonProfile retrievedProfile = (CommonProfile) value.get();
260227
Assert.assertEquals("name", retrievedProfile.getAttribute("display_name"));
@@ -294,7 +261,7 @@ public void testSetAndGetClearUserMultipleProfile()
294261
profiles.put("profile1", profile1);
295262
profiles.put("profile2", profile2);
296263

297-
sessionStore.set(webContext1, "pac4j.user.profiles", profiles);
264+
sessionStore.set(webContext1, Pac4jConstants.USER_PROFILES, profiles);
298265

299266
Cookie cookie = cookieCapture.getValue();
300267
Assert.assertTrue(cookie.isSecure());
@@ -305,7 +272,7 @@ public void testSetAndGetClearUserMultipleProfile()
305272
EasyMock.expect(webContext2.getRequestCookies()).andReturn(Collections.singletonList(cookie));
306273
EasyMock.replay(webContext2);
307274

308-
Optional<Object> value = sessionStore.get(webContext2, "pac4j.user.profiles");
275+
Optional<Object> value = sessionStore.get(webContext2, Pac4jConstants.USER_PROFILES);
309276
Assert.assertTrue(Objects.requireNonNull(value).isPresent());
310277
@SuppressWarnings("unchecked")
311278
Map<String, CommonProfile> retrievedProfiles = (Map<String, CommonProfile>) value.get();

0 commit comments

Comments
 (0)