-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
return DocumentExpired when a Deferred document has expired accessTok…
…en and/or refreshToken
- Loading branch information
1 parent
7106c70
commit 37d523e
Showing
4 changed files
with
161 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
...re/src/test/java/eu/europa/ec/eudi/wallet/issue/openid4vci/DeferredIssuanceContextTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
* Copyright (c) 2024 European Commission | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package eu.europa.ec.eudi.wallet.issue.openid4vci | ||
|
||
import eu.europa.ec.eudi.openid4vci.AccessToken | ||
import eu.europa.ec.eudi.openid4vci.DeferredIssuanceContext | ||
import eu.europa.ec.eudi.openid4vci.RefreshToken | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import org.junit.jupiter.api.Assertions.assertFalse | ||
import org.junit.jupiter.api.Assertions.assertTrue | ||
import org.junit.jupiter.api.Test | ||
import java.time.Instant | ||
|
||
class DeferredIssuanceContextTest { | ||
|
||
@Test | ||
fun `when accessToken has no expiration time DeferredIssuanceContextTest_hasExpired property is false`() { | ||
val deferredIssuanceContext: DeferredIssuanceContext = mockk { | ||
every { authorizedTransaction.authorizedRequest.timestamp } returns Instant.now().minusSeconds(3600) | ||
every { authorizedTransaction.authorizedRequest.accessToken } returns AccessToken( | ||
accessToken = "accessToken", | ||
expiresInSec = null, | ||
useDPoP = false | ||
) | ||
every { authorizedTransaction.authorizedRequest.refreshToken } returns null | ||
} | ||
|
||
assertFalse(deferredIssuanceContext.hasExpired) | ||
} | ||
|
||
@Test | ||
fun `when accessToken has expired DeferredIssuanceContextTest_hasExpired property is true`() { | ||
val deferredIssuanceContext: DeferredIssuanceContext = mockk { | ||
every { authorizedTransaction.authorizedRequest.timestamp } returns Instant.now().minusSeconds(3600) | ||
every { authorizedTransaction.authorizedRequest.accessToken } returns AccessToken( | ||
accessToken = "accessToken", | ||
expiresInSec = 60L, | ||
useDPoP = false | ||
) | ||
every { authorizedTransaction.authorizedRequest.refreshToken } returns null | ||
} | ||
|
||
assertTrue(deferredIssuanceContext.hasExpired) | ||
} | ||
|
||
@Test | ||
fun `when accessToken has not expired and there is no refreshToken DeferredIssuanceContextTest_hasExpired property is false`() { | ||
val deferredIssuanceContext: DeferredIssuanceContext = mockk { | ||
every { authorizedTransaction.authorizedRequest.timestamp } returns Instant.now().minusSeconds(3600) | ||
every { authorizedTransaction.authorizedRequest.accessToken } returns AccessToken( | ||
accessToken = "accessToken", | ||
expiresInSec = 6000L, | ||
useDPoP = false | ||
) | ||
every { authorizedTransaction.authorizedRequest.refreshToken } returns null | ||
} | ||
|
||
assertFalse(deferredIssuanceContext.hasExpired) | ||
} | ||
|
||
@Test | ||
fun `when accessToken has expired and there is refreshToken which has not expired DeferredIssuanceContextTest_hasExpired property is false`() { | ||
val deferredIssuanceContext: DeferredIssuanceContext = mockk { | ||
every { authorizedTransaction.authorizedRequest.timestamp } returns Instant.now().minusSeconds(3600) | ||
every { authorizedTransaction.authorizedRequest.accessToken } returns AccessToken( | ||
accessToken = "accessToken", | ||
expiresInSec = 10L, | ||
useDPoP = false | ||
) | ||
every { authorizedTransaction.authorizedRequest.refreshToken } returns RefreshToken( | ||
refreshToken = "refreshToken", | ||
expiresInSec = 6000L | ||
) | ||
} | ||
|
||
assertFalse(deferredIssuanceContext.hasExpired) | ||
} | ||
|
||
@Test | ||
fun `when accessToken has expired and there is refreshToken which has expired DeferredIssuanceContextTest_hasExpired property is true`() { | ||
val deferredIssuanceContext: DeferredIssuanceContext = mockk { | ||
every { authorizedTransaction.authorizedRequest.timestamp } returns Instant.now().minusSeconds(3600) | ||
every { authorizedTransaction.authorizedRequest.accessToken } returns AccessToken( | ||
accessToken = "accessToken", | ||
expiresInSec = 10L, | ||
useDPoP = false | ||
) | ||
every { authorizedTransaction.authorizedRequest.refreshToken } returns RefreshToken( | ||
refreshToken = "refreshToken", | ||
expiresInSec = 60L | ||
) | ||
} | ||
|
||
assertTrue(deferredIssuanceContext.hasExpired) | ||
} | ||
} |