Skip to content

Commit

Permalink
Fix test that have dup key
Browse files Browse the repository at this point in the history
  • Loading branch information
amontenegro committed Jan 31, 2024
1 parent f8d80e7 commit a6cda29
Showing 1 changed file with 26 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ public class OrcidRefreshTokenTokenGranterTest extends DBUnitTest {
private static final String CLIENT_ID_2 = "APP-5555555555555556";
private static final String USER_ORCID = "0000-0000-0000-0001";

private Random random = new Random(System.currentTimeMillis());

@Resource
private OrcidOauth2TokenDetailService orcidOauth2TokenDetailService;

Expand Down Expand Up @@ -122,8 +120,8 @@ public void createRefreshTokenTest() {
// should be equal
long time = System.currentTimeMillis();
String scope = "/activities/update";
String tokenValue = "parent-token-" + random.nextLong();
String refreshTokenValue = "refresh-token-" + random.nextLong();
String tokenValue = "parent-token-" + getRandom();
String refreshTokenValue = "refresh-token-" + getRandom();
Boolean revokeOld = null;
Date parentTokenExpiration = new Date(time + 10000);
Long expireIn = null;
Expand Down Expand Up @@ -157,8 +155,8 @@ public void createRefreshTokenWithNarrowerScopesTest() {
long time = System.currentTimeMillis();
String parentScope = "/activities/update";
String refreshScope = "/orcid-works/create";
String tokenValue = "parent-token-" + random.nextLong();
String refreshTokenValue = "refresh-token-" + random.nextLong();
String tokenValue = "parent-token-" + getRandom();
String refreshTokenValue = "refresh-token-" + getRandom();
Boolean revokeOld = true;
Date parentTokenExpiration = new Date(time + 10000);
Long expireIn = null;
Expand Down Expand Up @@ -191,8 +189,8 @@ public void createRefreshTokenWithoutRevokeParent() {
// should be enabled, refresh should be enabled
long time = System.currentTimeMillis();
String parentScope = "/activities/update /read-limited";
String tokenValue = "parent-token-" + random.nextLong();
String refreshTokenValue = "refresh-token-" + random.nextLong();
String tokenValue = "parent-token-" + getRandom();
String refreshTokenValue = "refresh-token-" + getRandom();
Boolean revokeOld = false;
Date parentTokenExpiration = new Date(time + 10000);
Long expireIn = null;
Expand Down Expand Up @@ -231,8 +229,8 @@ public void createRefreshTokenWithoutRevokeParentAndWithNarrowerScopes() {
long time = System.currentTimeMillis();
String parentScope = "/person/read-limited";
String refreshScope = "/orcid-bio/read-limited";
String tokenValue = "parent-token-" + random.nextLong();
String refreshTokenValue = "refresh-token-" + random.nextLong();
String tokenValue = "parent-token-" + getRandom();
String refreshTokenValue = "refresh-token-" + getRandom();
Boolean revokeOld = false;
Date parentTokenExpiration = new Date(time + 10000);
Long expireIn = null;
Expand Down Expand Up @@ -265,8 +263,8 @@ public void createRefreshTokenWithExpirationOf10Secs() {
long time = System.currentTimeMillis();
String parentScope = "/person/read-limited";
String refreshScope = "/orcid-bio/read-limited";
String tokenValue = "parent-token-" + random.nextLong();
String refreshTokenValue = "refresh-token-" + random.nextLong();
String tokenValue = "parent-token-" + getRandom();
String refreshTokenValue = "refresh-token-" + getRandom();
Boolean revokeOld = false;
Date parentTokenExpiration = new Date(time + 10000);
Long expireIn = 5L;
Expand Down Expand Up @@ -302,8 +300,8 @@ public void tryToCreateRefreshTokenWithInvalidScopesTest() {
long time = System.currentTimeMillis();
String parentScope = "/person/update";
String refreshScope = "/orcid-works/read-limited";
String tokenValue = "parent-token-" + random.nextLong();
String refreshTokenValue = "refresh-token-" + random.nextLong();
String tokenValue = "parent-token-" + getRandom();
String refreshTokenValue = "refresh-token-" + getRandom();
Boolean revokeOld = true;
Date parentTokenExpiration = new Date(time + 10000);
Long expireIn = null;
Expand All @@ -325,8 +323,8 @@ public void tryToCreateRefreshTokenWithThatExpireAfterParentTokenTest() {
// token, fail
long time = System.currentTimeMillis();
String parentScope = "/person/update";
String tokenValue = "parent-token-" + random.nextLong();
String refreshTokenValue = "refresh-token-" + random.nextLong();
String tokenValue = "parent-token-" + getRandom();
String refreshTokenValue = "refresh-token-" + getRandom();
Boolean revokeOld = true;
Date parentTokenExpiration = new Date(time + 10000);
Long expireIn = time + (15000);
Expand All @@ -348,8 +346,8 @@ public void tryToCreateRefreshTokenWithInvalidClientTest() {
// client # 2, fail
long time = System.currentTimeMillis();
String parentScope = "/person/update";
String tokenValue = "parent-token-" + random.nextLong();
String refreshTokenValue = "refresh-token-" + random.nextLong();
String tokenValue = "parent-token-" + getRandom();
String refreshTokenValue = "refresh-token-" + getRandom();
Boolean revokeOld = true;
Date parentTokenExpiration = new Date(time + 10000);
Long expireIn = null;
Expand All @@ -370,8 +368,8 @@ public void tryToCreateRefreshTokenWithInvalidClientTest() {
public void tryToRefreshAnExpiredTokenTest() {
long time = System.currentTimeMillis();
String parentScope = "/person/update";
String tokenValue = "parent-token-" + random.nextLong();
String refreshTokenValue = "refresh-token-" + random.nextLong();
String tokenValue = "parent-token-" + getRandom();
String refreshTokenValue = "refresh-token-" + getRandom();
Boolean revokeOld = true;
Date parentTokenExpiration = new Date(time - 10000);
Long expireIn = null;
Expand All @@ -393,8 +391,8 @@ public void tryToCreateRefreshTokenWithInvalidRefreshTokenTest() {
// fail
long time = System.currentTimeMillis();
String parentScope = "/person/update";
String tokenValue = "parent-token-" + random.nextLong();
String refreshTokenValue = "refresh-token-" + random.nextLong();
String tokenValue = "parent-token-" + getRandom();
String refreshTokenValue = "refresh-token-" + getRandom();
Boolean revokeOld = true;
Date parentTokenExpiration = new Date(time + 10000);
Long expireIn = null;
Expand All @@ -418,8 +416,8 @@ public void tryToCreateRefreshTokenWithInvalidParentTokenValueTest() {
// value, fail
long time = System.currentTimeMillis();
String parentScope = "/person/update";
String tokenValue = "parent-token-" + random.nextLong();
String refreshTokenValue = "refresh-token-" + random.nextLong();
String tokenValue = "parent-token-" + getRandom();
String refreshTokenValue = "refresh-token-" + getRandom();
Boolean revokeOld = true;
Date parentTokenExpiration = new Date(time + 15000);
Long expireIn = null;
Expand All @@ -434,4 +432,8 @@ public void tryToCreateRefreshTokenWithInvalidParentTokenValueTest() {
assertNotNull(refreshedToken);
}

private long getRandom() {
Random random = new Random(System.currentTimeMillis());
return random.nextLong();
}
}

0 comments on commit a6cda29

Please sign in to comment.