Skip to content

Commit

Permalink
More unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
amontenegro committed Aug 1, 2024
1 parent 64e8c47 commit e30fbe1
Showing 1 changed file with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -289,14 +289,14 @@ public void grantDisabledTokenDoesntWorkTest() throws NoSuchAlgorithmException,
tokenGranter.grant(GRANT_TYPE, getTokenRequest(ACTIVE_CLIENT_ID, List.of("/read-limited")));
fail();
} catch (OrcidInvalidScopeException oise) {
assertEquals("The id_token is not associated with a valid scope", oise.getMessage());
assertEquals("The id_token is disabled and does not contain any valid scope", oise.getMessage());
} catch (Exception e) {
fail();
}
}

@Test
public void grantDisabledTokenWithActivitiesReadLimitedGenerateDeactivatedTokenTest()
public void grantUserDisabledTokenWithActivitiesReadLimitedGenerateDeactivatedTokenTest()
throws NoSuchAlgorithmException, IOException, ParseException, URISyntaxException, JOSEException {
OrcidOauth2TokenDetail token1 = getOrcidOauth2TokenDetail(true, "/activities/update", System.currentTimeMillis() + 60000, true);
token1.setRevokeReason(RevokeReason.USER_REVOKED.name());
Expand All @@ -309,6 +309,38 @@ public void grantDisabledTokenWithActivitiesReadLimitedGenerateDeactivatedTokenT
verify(tokenServicesMock, never()).createAccessToken(any());
}

@Test
public void grantClientDisabledTokenWithActivitiesReadLimitedThrowExceptionTest()
throws NoSuchAlgorithmException, IOException, ParseException, URISyntaxException, JOSEException {
OrcidOauth2TokenDetail token1 = getOrcidOauth2TokenDetail(true, "/activities/update", System.currentTimeMillis() + 60000, true);
token1.setRevokeReason(RevokeReason.CLIENT_REVOKED.name());

when(orcidOauthTokenDetailServiceMock.findByClientIdAndUserName(any(), any())).thenReturn(List.of(token1));
try {
tokenGranter.grant(GRANT_TYPE, getTokenRequest(ACTIVE_CLIENT_ID, List.of("/activities/update")));
} catch(OrcidInvalidScopeException e) {
assertEquals("The id_token is disabled and does not contain any valid scope", e.getMessage());
} catch(Exception e) {
fail("Unhandled exception:" + e.getMessage());
}
}

@Test
public void grantStaffDisabledTokenWithActivitiesReadLimitedThrowExceptionTest()
throws NoSuchAlgorithmException, IOException, ParseException, URISyntaxException, JOSEException {
OrcidOauth2TokenDetail token1 = getOrcidOauth2TokenDetail(true, "/activities/update", System.currentTimeMillis() + 60000, true);
token1.setRevokeReason(RevokeReason.STAFF_REVOKED.name());

when(orcidOauthTokenDetailServiceMock.findByClientIdAndUserName(any(), any())).thenReturn(List.of(token1));
try {
tokenGranter.grant(GRANT_TYPE, getTokenRequest(ACTIVE_CLIENT_ID, List.of("/activities/update")));
} catch(OrcidInvalidScopeException e) {
assertEquals("The id_token is disabled and does not contain any valid scope", e.getMessage());
} catch(Exception e) {
fail("Unhandled exception:" + e.getMessage());
}
}

@Test
public void grantDisabledTokenWithActivitiesUpdateAndOtherActiveTokenWithOtherScopesGenerateDeactivatedTokenTest()
throws NoSuchAlgorithmException, IOException, ParseException, URISyntaxException, JOSEException {
Expand Down

0 comments on commit e30fbe1

Please sign in to comment.