Skip to content

Commit

Permalink
test: fixed clock tests in secure credential manager tests
Browse files Browse the repository at this point in the history
  • Loading branch information
desusai7 committed Jul 8, 2024
1 parent d1f3912 commit dfa566a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public class SecureCredentialsManager @VisibleForTesting(otherwise = VisibleForT
storage: Storage,
private val crypto: CryptoUtil,
jwtDecoder: JWTDecoder,
private val localAuthenticationManagerFactory: LocalAuthenticationManagerFactory,
private val serialExecutor: Executor,
private val localAuthenticationManagerFactory: LocalAuthenticationManagerFactory
) : SecuredCredentialsManager(apiClient, storage, jwtDecoder) {
private val gson: Gson = GsonProvider.gson

Expand All @@ -54,8 +54,8 @@ public class SecureCredentialsManager @VisibleForTesting(otherwise = VisibleForT
storage,
CryptoUtil(context, storage, KEY_ALIAS),
JWTDecoder(),
DefaultLocalAuthenticationManagerFactory(),
Executors.newSingleThreadExecutor(),
DefaultLocalAuthenticationManagerFactory()
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public class SecureCredentialsManagerTest {
.get()
)
val secureCredentialsManager =
SecureCredentialsManager(client, storage, crypto, jwtDecoder, serialExecutor, factory)
SecureCredentialsManager(client, storage, crypto, jwtDecoder, factory, serialExecutor)
manager = Mockito.spy(secureCredentialsManager)
Mockito.doReturn(CredentialsMock.CURRENT_TIME_MS).`when`(manager).currentTimeInMillis
gson = GsonProvider.gson
Expand Down Expand Up @@ -1688,7 +1688,7 @@ public class SecureCredentialsManagerTest {
*/
@Test
public fun shouldUseCustomClock() {
val manager = SecureCredentialsManager(client, storage, crypto, jwtDecoder, serialExecutor, factory) { }
val manager = SecureCredentialsManager(client, storage, crypto, jwtDecoder, factory) { }
val expirationTime = CredentialsMock.CURRENT_TIME_MS //Same as current time --> expired
Mockito.`when`(storage.retrieveLong("com.auth0.credentials_access_token_expires_at"))
.thenReturn(expirationTime)
Expand All @@ -1709,15 +1709,15 @@ public class SecureCredentialsManagerTest {

@Test(expected = java.lang.IllegalArgumentException::class)
public fun shouldUseCustomExecutorForGetCredentials() {
val manager = SecureCredentialsManager(apiClient = client, storage = storage, crypto = crypto, jwtDecoder = jwtDecoder) {
val manager = SecureCredentialsManager(client, storage, crypto, jwtDecoder, factory) {
throw java.lang.IllegalArgumentException("Proper Executor Set")
}
val expirationTime = CredentialsMock.ONE_HOUR_AHEAD_MS
Mockito.`when`(storage.retrieveLong("com.auth0.credentials_expires_at"))
.thenReturn(expirationTime)
Mockito.`when`(storage.retrieveString("com.auth0.credentials"))
.thenReturn("{\"access_token\":\"accessToken\"}")
manager.getCredentials(object : Callback<Credentials, CredentialsManagerException> {
manager.getCredentials(null, 0, emptyMap(), emptyMap(), false, object : Callback<Credentials, CredentialsManagerException> {
override fun onSuccess(result: Credentials) {}
override fun onFailure(error: CredentialsManagerException) {}
})
Expand Down

0 comments on commit dfa566a

Please sign in to comment.