-
Notifications
You must be signed in to change notification settings - Fork 151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: SCIM error message for invalid request values in V1 and V2 Roles Remove-Add-Replace operations (fixes #20334) #559
Merged
AnuradhaSK
merged 7 commits into
wso2-extensions:master
from
BimsaraBodaragama:bug/20344-scim2_error
Jul 5, 2024
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f8dc3cb
Fix SCIM error message for invalid request values in V1 and V2 Roles …
BimsaraBodaragama 04d7b00
Update the licenses of SCIMRoleManagerV1 with the new header format f…
BimsaraBodaragama b10c883
Fix invalidValue code and update to generic error message for group I…
BimsaraBodaragama 65b7b99
Test: Add testPatchRoleWithGroupDisplayNameInsteadOfGroupIdThrowingEr…
BimsaraBodaragama e15eeb8
refactor: instantiate SCIMRoleManagerV2 in tests
BimsaraBodaragama c8cf26b
refactor: remove SCIMRoleManagerV2 from @PrepareForTest
BimsaraBodaragama e97c090
fix: replace JUnit assertEquals with TestNG assertEquals
BimsaraBodaragama File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
...ommon/src/test/java/org/wso2/carbon/identity/scim2/common/impl/SCIMRoleManagerV2Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* | ||
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). | ||
* | ||
* WSO2 LLC. licenses this file to you under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.wso2.carbon.identity.scim2.common.impl; | ||
|
||
import org.mockito.Mock; | ||
import org.powermock.api.mockito.PowerMockito; | ||
import org.powermock.core.classloader.annotations.PrepareForTest; | ||
import org.powermock.modules.testng.PowerMockTestCase; | ||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.DataProvider; | ||
import org.testng.annotations.Test; | ||
import org.wso2.carbon.identity.core.util.IdentityUtil; | ||
import org.wso2.carbon.identity.role.v2.mgt.core.RoleManagementService; | ||
import org.wso2.carbon.identity.role.v2.mgt.core.exception.IdentityRoleManagementException; | ||
import org.wso2.charon3.core.exceptions.BadRequestException; | ||
import org.wso2.charon3.core.exceptions.CharonException; | ||
import org.wso2.charon3.core.exceptions.ConflictException; | ||
import org.wso2.charon3.core.exceptions.ForbiddenException; | ||
import org.wso2.charon3.core.exceptions.NotFoundException; | ||
import org.wso2.charon3.core.protocol.ResponseCodeConstants; | ||
import org.wso2.charon3.core.schema.SCIMConstants; | ||
import org.wso2.charon3.core.utils.codeutils.PatchOperation; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.mockito.Mockito.when; | ||
import static org.mockito.MockitoAnnotations.initMocks; | ||
import static org.testng.AssertJUnit.assertEquals; | ||
|
||
/** | ||
* Contains the unit test cases for SCIMRoleManagerV2. | ||
*/ | ||
@PrepareForTest({SCIMRoleManagerV2.class, IdentityUtil.class}) | ||
public class SCIMRoleManagerV2Test extends PowerMockTestCase { | ||
|
||
private static final String SAMPLE_TENANT_DOMAIN = "carbon.super"; | ||
private static final String SAMPLE_VALID_ROLE_ID = "595f5508-f286-446a-86c4-5071e07b98fc"; | ||
private static final String SAMPLE_GROUP_NAME = "testGroup"; | ||
private static final String SAMPLE_VALID_ROLE_NAME = "admin"; | ||
private static final int BAD_REQUEST = 400; | ||
|
||
@Mock | ||
private RoleManagementService roleManagementService; | ||
@Mock | ||
private SCIMRoleManagerV2 scimRoleManagerV2; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should not mock the class which the method we are testing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
@BeforeClass | ||
public void setUpClass() { | ||
|
||
initMocks(this); | ||
} | ||
|
||
@BeforeMethod | ||
public void setUpMethod() { | ||
|
||
scimRoleManagerV2 = PowerMockito.spy(new SCIMRoleManagerV2(roleManagementService, SAMPLE_TENANT_DOMAIN)); | ||
PowerMockito.mockStatic(IdentityUtil.class); | ||
} | ||
|
||
@DataProvider(name = "scimOperations") | ||
public Object[][] provideScimOperations() { | ||
|
||
return new Object[][]{ | ||
{SCIMConstants.OperationalConstants.ADD}, | ||
{SCIMConstants.OperationalConstants.REMOVE}, | ||
{SCIMConstants.OperationalConstants.REPLACE} | ||
}; | ||
} | ||
|
||
@Test(dataProvider = "scimOperations") | ||
public void testPatchRoleWithGroupDisplayNameInsteadOfGroupIdThrowingErrors(String operation) | ||
throws IdentityRoleManagementException, ForbiddenException, ConflictException, NotFoundException, | ||
CharonException { | ||
|
||
Map<String, List<PatchOperation>> patchOperations = new HashMap<>(); | ||
Map<String, String> valueMap = new HashMap<>(); | ||
valueMap.put(SCIMConstants.CommonSchemaConstants.DISPLAY, SAMPLE_GROUP_NAME); | ||
valueMap.put(SCIMConstants.CommonSchemaConstants.VALUE, null); | ||
|
||
PatchOperation patchOperation = new PatchOperation(); | ||
patchOperation.setOperation(operation); | ||
patchOperation.setAttributeName(SCIMConstants.RoleSchemaConstants.GROUPS); | ||
patchOperation.setValues(valueMap); | ||
patchOperations.put(SCIMConstants.RoleSchemaConstants.GROUPS, Collections.singletonList(patchOperation)); | ||
|
||
when(roleManagementService.getRoleNameByRoleId(SAMPLE_VALID_ROLE_ID, SAMPLE_TENANT_DOMAIN)) | ||
.thenReturn(SAMPLE_VALID_ROLE_NAME); | ||
|
||
try { | ||
scimRoleManagerV2.patchRole(SAMPLE_VALID_ROLE_ID, patchOperations); | ||
} catch (BadRequestException e) { | ||
assertEquals(BAD_REQUEST, e.getStatus()); | ||
assertEquals(ResponseCodeConstants.INVALID_VALUE, e.getScimType()); | ||
assertEquals("Group id is required to update group of the role.", e.getDetail()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's import org.testng.Assert and use its assertEquals
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed by e97c090