Skip to content
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 test that have dup key #6981

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
Loading