Skip to content

Commit

Permalink
LPD-33798 Using JSONUtil and JSONObject for the input value
Browse files Browse the repository at this point in the history
  • Loading branch information
tomibiro committed Sep 6, 2024
1 parent c8bab73 commit f9564e8
Showing 1 changed file with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -53,17 +55,28 @@ public void accept(Long aLong) {

@Test
public void testWhenEmailIsInJWTClaimSet() throws Exception {
Map<String, Object> claims = _processClaimSet(
"{\"sub\":\"subject\",\"name\": \"test_account\",\"email\": " +
"\"[email protected]\"}");
_jsonObject = JSONUtil.put(
"email", "[email protected]"
).put(
"name", "test_account"
).put(
"sub", "subject"
);

Map<String, Object> claims = _processClaimSet(_jsonObject.toString());

Assert.assertEquals("[email protected]", claims.get("email"));
}

@Test
public void testWhenEmailIsNotInJWTClaimSet() throws Exception {
Map<String, Object> claims = _processClaimSet(
"{\"sub\":\"subject\",\"name\": \"test_account\"}");
_jsonObject = JSONUtil.put(
"name", "test_account"
).put(
"sub", "subject"
);

Map<String, Object> claims = _processClaimSet(_jsonObject.toString());

Assert.assertNull(claims.get("email"));
}
Expand All @@ -83,6 +96,7 @@ private Map<String, Object> _processClaimSet(String claimSetJSON)
mockJWT);
}

private JSONObject _jsonObject;
private MockHttpServletRequest _mockHttpServletRequest;
private MockHttpServletResponse _mockHttpServletResponse;
private MockHttpSession _mockHttpSession;
Expand Down

0 comments on commit f9564e8

Please sign in to comment.