From f9564e833e38fa41312fdb8a30723ad8d0549350 Mon Sep 17 00:00:00 2001 From: Tamas Biro Date: Fri, 6 Sep 2024 17:51:24 +0200 Subject: [PATCH] LPD-33798 Using JSONUtil and JSONObject for the input value --- ...dConnectAuthenticationHandlerImplTest.java | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/modules/apps/portal-security-sso/portal-security-sso-openid-connect-impl/src/test/java/com/liferay/portal/security/sso/openid/connect/internal/OpenIdConnectAuthenticationHandlerImplTest.java b/modules/apps/portal-security-sso/portal-security-sso-openid-connect-impl/src/test/java/com/liferay/portal/security/sso/openid/connect/internal/OpenIdConnectAuthenticationHandlerImplTest.java index 6efe6f1207e291..5f66614fbbb5c4 100644 --- a/modules/apps/portal-security-sso/portal-security-sso-openid-connect-impl/src/test/java/com/liferay/portal/security/sso/openid/connect/internal/OpenIdConnectAuthenticationHandlerImplTest.java +++ b/modules/apps/portal-security-sso/portal-security-sso-openid-connect-impl/src/test/java/com/liferay/portal/security/sso/openid/connect/internal/OpenIdConnectAuthenticationHandlerImplTest.java @@ -6,6 +6,8 @@ package com.liferay.portal.security.sso.openid.connect.internal; import com.liferay.petra.function.UnsafeConsumer; +import com.liferay.portal.kernel.json.JSONObject; +import com.liferay.portal.kernel.json.JSONUtil; import com.liferay.portal.test.rule.LiferayUnitTestRule; import com.nimbusds.jwt.JWT; @@ -53,17 +55,28 @@ public void accept(Long aLong) { @Test public void testWhenEmailIsInJWTClaimSet() throws Exception { - Map claims = _processClaimSet( - "{\"sub\":\"subject\",\"name\": \"test_account\",\"email\": " + - "\"exists@test.com\"}"); + _jsonObject = JSONUtil.put( + "email", "exists@test.com" + ).put( + "name", "test_account" + ).put( + "sub", "subject" + ); + + Map claims = _processClaimSet(_jsonObject.toString()); Assert.assertEquals("exists@test.com", claims.get("email")); } @Test public void testWhenEmailIsNotInJWTClaimSet() throws Exception { - Map claims = _processClaimSet( - "{\"sub\":\"subject\",\"name\": \"test_account\"}"); + _jsonObject = JSONUtil.put( + "name", "test_account" + ).put( + "sub", "subject" + ); + + Map claims = _processClaimSet(_jsonObject.toString()); Assert.assertNull(claims.get("email")); } @@ -83,6 +96,7 @@ private Map _processClaimSet(String claimSetJSON) mockJWT); } + private JSONObject _jsonObject; private MockHttpServletRequest _mockHttpServletRequest; private MockHttpServletResponse _mockHttpServletResponse; private MockHttpSession _mockHttpSession;