Skip to content

Commit

Permalink
test: resolve sonar issues
Browse files Browse the repository at this point in the history
  • Loading branch information
davdarras committed Jul 10, 2024
1 parent 287a7e5 commit 9bea53d
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ class GrantedAuthorityConverterTest {

private Map<String, Object> jwtHeaders;

private static final String jwtRoleInterviewer = "interviewer";
private static final String jwtRoleReviewer = "reviewer";
private static final String jwtRoleReviewerAlternative = "reviewerAlternative";
private static final String jwtRoleAdmin = "admin";
private static final String jwtRoleWebclient = "webclient";
private static final String jwtRoleSurveyUnit = "surveyUnit";
private static final String JWT_ROLE_INTERVIEWER = "interviewer";
private static final String JWT_ROLE_REVIEWER = "reviewer";
private static final String JWT_ROLE_REVIEWER_ALTERNATIVE = "reviewerAlternative";
private static final String JWT_ROLE_ADMIN = "admin";
private static final String JWT_ROLE_WEBCLIENT = "webclient";
private static final String JWT_ROLE_SURVEY_UNIT = "surveyUnit";

@BeforeEach
void init() {
Expand All @@ -43,7 +43,7 @@ void init() {
@Test
@DisplayName("Given a JWT, when converting null or empty JWT role, then converting ignore these roles")
void testConverter01() {
RoleProperties roleProperties = new RoleProperties("", null, jwtRoleAdmin, jwtRoleWebclient, jwtRoleReviewerAlternative, jwtRoleSurveyUnit);
RoleProperties roleProperties = new RoleProperties("", null, JWT_ROLE_ADMIN, JWT_ROLE_WEBCLIENT, JWT_ROLE_REVIEWER_ALTERNATIVE, JWT_ROLE_SURVEY_UNIT);
converter = new GrantedAuthorityConverter(oidcProperties, roleProperties);
Map<String, Object> claims = new HashMap<>();
List<String> tokenRoles = new ArrayList<>();
Expand All @@ -60,7 +60,7 @@ void testConverter01() {
@Test
@DisplayName("Given a JWT, when converting roles, then convert only JWT roles matching roles in role properties")
void testConverter02() {
RoleProperties roleProperties = new RoleProperties(jwtRoleInterviewer, jwtRoleReviewer, jwtRoleAdmin, jwtRoleWebclient, jwtRoleReviewerAlternative, jwtRoleSurveyUnit);
RoleProperties roleProperties = new RoleProperties(JWT_ROLE_INTERVIEWER, JWT_ROLE_REVIEWER, JWT_ROLE_ADMIN, JWT_ROLE_WEBCLIENT, JWT_ROLE_REVIEWER_ALTERNATIVE, JWT_ROLE_SURVEY_UNIT);
converter = new GrantedAuthorityConverter(oidcProperties, roleProperties);
Map<String, Object> claims = new HashMap<>();
List<String> tokenRoles = List.of("dummyRole1", roleProperties.reviewer(), "dummyRole2", roleProperties.interviewer(), "dummyRole3", roleProperties.surveyUnit());
Expand All @@ -80,7 +80,7 @@ void testConverter02() {
@MethodSource("provideJWTRoleWithAppRoleAssociated")
@DisplayName("Given a JWT, when converting roles, then assure each JWT role is converted to equivalent app role")
void testConverter03(String jwtRole, AuthorityRoleEnum appRole) {
RoleProperties roleProperties = new RoleProperties(jwtRoleInterviewer, jwtRoleReviewer, jwtRoleAdmin, jwtRoleWebclient, jwtRoleReviewerAlternative, jwtRoleSurveyUnit);
RoleProperties roleProperties = new RoleProperties(JWT_ROLE_INTERVIEWER, JWT_ROLE_REVIEWER, JWT_ROLE_ADMIN, JWT_ROLE_WEBCLIENT, JWT_ROLE_REVIEWER_ALTERNATIVE, JWT_ROLE_SURVEY_UNIT);
converter = new GrantedAuthorityConverter(oidcProperties, roleProperties);
Map<String, Object> claims = new HashMap<>();
List<String> tokenRoles = List.of(jwtRole);
Expand All @@ -97,11 +97,11 @@ void testConverter03(String jwtRole, AuthorityRoleEnum appRole) {
@DisplayName("Given a JWT, when no role claim is defined, then default role claim is used")
void testConverter04() {
oidcProperties = new OidcProperties(true, "host", "url", "realm", "principal-attribute", "", "client-id");
RoleProperties roleProperties = new RoleProperties(jwtRoleInterviewer, jwtRoleReviewer, jwtRoleAdmin, jwtRoleWebclient, jwtRoleReviewerAlternative, jwtRoleSurveyUnit);
RoleProperties roleProperties = new RoleProperties(JWT_ROLE_INTERVIEWER, JWT_ROLE_REVIEWER, JWT_ROLE_ADMIN, JWT_ROLE_WEBCLIENT, JWT_ROLE_REVIEWER_ALTERNATIVE, JWT_ROLE_SURVEY_UNIT);
converter = new GrantedAuthorityConverter(oidcProperties, roleProperties);
Map<String, Object> claims = new HashMap<>();
Map<String, Object> roleClaims = new HashMap<>();
List<String> tokenRoles = List.of(jwtRoleInterviewer, jwtRoleReviewer);
List<String> tokenRoles = List.of(JWT_ROLE_INTERVIEWER, JWT_ROLE_REVIEWER);
roleClaims.put(GrantedAuthorityConverter.ROLES, tokenRoles);
claims.put(GrantedAuthorityConverter.REALM_ACCESS, roleClaims);

Expand All @@ -115,11 +115,11 @@ void testConverter04() {

private static Stream<Arguments> provideJWTRoleWithAppRoleAssociated() {
return Stream.of(
Arguments.of(jwtRoleInterviewer, AuthorityRoleEnum.INTERVIEWER),
Arguments.of(jwtRoleReviewer, AuthorityRoleEnum.REVIEWER),
Arguments.of(jwtRoleReviewerAlternative, AuthorityRoleEnum.REVIEWER_ALTERNATIVE),
Arguments.of(jwtRoleAdmin, AuthorityRoleEnum.ADMIN),
Arguments.of(jwtRoleWebclient, AuthorityRoleEnum.WEBCLIENT),
Arguments.of(jwtRoleSurveyUnit, AuthorityRoleEnum.SURVEY_UNIT));
Arguments.of(JWT_ROLE_INTERVIEWER, AuthorityRoleEnum.INTERVIEWER),
Arguments.of(JWT_ROLE_REVIEWER, AuthorityRoleEnum.REVIEWER),
Arguments.of(JWT_ROLE_REVIEWER_ALTERNATIVE, AuthorityRoleEnum.REVIEWER_ALTERNATIVE),
Arguments.of(JWT_ROLE_ADMIN, AuthorityRoleEnum.ADMIN),
Arguments.of(JWT_ROLE_WEBCLIENT, AuthorityRoleEnum.WEBCLIENT),
Arguments.of(JWT_ROLE_SURVEY_UNIT, AuthorityRoleEnum.SURVEY_UNIT));
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public ObjectNode getData(String surveyUnitId) {

@Override
public void saveData(String surveyUnitId, ObjectNode dataValue) {

// not used for test at this moment
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,17 @@ public List<String> findAllSurveyUnitIds() {

@Override
public void updateSurveyUnit(SurveyUnit surveyUnit) {

// not used for test at this moment
}

@Override
public void updateSurveyUnit(String surveyUnitId, ObjectNode data, StateData stateData) {

// not used for test at this moment
}

@Override
public void createSurveyUnit(SurveyUnit surveyUnit) {

// not used for test at this moment
}

@Override
Expand All @@ -96,7 +96,7 @@ public List<SurveyUnitState> findWithStateByIds(List<String> surveyUnits) {

@Override
public void delete(String surveyUnitId) {

// not used for test at this moment
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,17 @@ public List<String> findAllSurveyUnitIds() {

@Override
public void updateSurveyUnit(SurveyUnit surveyUnit) {

// not used for test at this moment
}

@Override
public void updateSurveyUnit(String surveyUnitId, ObjectNode data, StateData stateData) {

// not used for test at this moment
}

@Override
public void createSurveyUnit(SurveyUnit surveyUnit) {

// not used for test at this moment
}

@Override
Expand All @@ -96,7 +96,7 @@ public List<SurveyUnitState> findWithStateByIds(List<String> surveyUnits) {

@Override
public void delete(String surveyUnitId) {

// not used for test at this moment
}

@Override
Expand Down

0 comments on commit 9bea53d

Please sign in to comment.