Skip to content
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 @@ -47,7 +47,7 @@ import java.nio.charset.StandardCharsets
import java.security.{KeyPairGenerator, PrivateKey}
import java.time.Instant
import java.util.{Base64, UUID}
import scala.concurrent.duration.Duration
import scala.concurrent.duration.{Duration, DurationInt}
import scala.concurrent.{Await, ExecutionContext, Future}
import scala.util.{Failure, Random, Success}

Expand All @@ -69,13 +69,17 @@ class NihServiceUnitSpec extends AnyFlatSpec with Matchers with BeforeAndAfterEa
val userTcgaOnly = genSamUser();
val userTargetOnly = genSamUser();

// DateTimes must be modified in seconds instead of days to match implementation
val secondsIn30Days = 30.days.toSeconds.toInt

var userNoAllowlistsLinkedAccount =
LinkedEraAccount(userNoAllowlists.id.value, "nihUsername1", new DateTime().plusDays(30))
LinkedEraAccount(userNoAllowlists.id.value, "nihUsername1", new DateTime().plusSeconds(secondsIn30Days))
var userTcgaAndTargetLinkedAccount =
LinkedEraAccount(userTcgaAndTarget.id.value, "nihUsername2", new DateTime().plusDays(30))
var userTcgaOnlyLinkedAccount = LinkedEraAccount(userTcgaOnly.id.value, "nihUsername3", new DateTime().plusDays(30))
LinkedEraAccount(userTcgaAndTarget.id.value, "nihUsername2", new DateTime().plusSeconds(secondsIn30Days))
var userTcgaOnlyLinkedAccount =
LinkedEraAccount(userTcgaOnly.id.value, "nihUsername3", new DateTime().plusSeconds(secondsIn30Days))
var userTargetOnlyLinkedAccount =
LinkedEraAccount(userTargetOnly.id.value, "nihUsername4", new DateTime().plusDays(30))
LinkedEraAccount(userTargetOnly.id.value, "nihUsername4", new DateTime().plusSeconds(secondsIn30Days))

val samUsers = Seq(userNoLinkedAccount, userNoAllowlists, userTcgaAndTarget, userTcgaOnly, userTargetOnly)
val linkedAccounts = Seq(userNoAllowlistsLinkedAccount,
Expand Down Expand Up @@ -635,7 +639,8 @@ class NihServiceUnitSpec extends AnyFlatSpec with Matchers with BeforeAndAfterEa

private def jwtForUser(linkedEraAccount: LinkedEraAccount): JWTWrapper = {
val expiresInTheFuture: Long = linkedEraAccount.linkExpireTime.getMillis / 1000L
val issuedAt = Instant.ofEpochMilli(linkedEraAccount.linkExpireTime.minusDays(30).getMillis).getEpochSecond
val issuedAt =
Instant.ofEpochMilli(linkedEraAccount.linkExpireTime.minusSeconds(secondsIn30Days).getMillis).getEpochSecond
val validStr = Jwt.encode(
JwtClaim(s"""{"eraCommonsUsername": "${linkedEraAccount.linkedExternalId}"}""")
.issuedAt(issuedAt)
Expand Down
Loading