mirror of
https://github.com/bitwarden/android.git
synced 2026-08-01 18:53:39 -05:00
PM-38998: Feat: Apply optional auth token to config endpoint (#7055)
This commit is contained in:
@@ -121,7 +121,7 @@ internal class BitwardenServiceClientImpl(
|
||||
|
||||
override val configService: ConfigService by lazy {
|
||||
ConfigServiceImpl(
|
||||
configApi = retrofits.unauthenticatedApiRetrofit.create(),
|
||||
configApi = retrofits.authenticatedApiRetrofit.create(),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ import java.time.Clock
|
||||
import java.time.Instant
|
||||
import java.time.temporal.ChronoUnit
|
||||
|
||||
private const val MISSING_TOKEN_MESSAGE: String = "Auth token is missing!"
|
||||
private const val MISSING_PROVIDER_MESSAGE: String = "Refresh token provider is missing!"
|
||||
private const val EXPIRATION_OFFSET_MINUTES: Long = 5L
|
||||
|
||||
@@ -83,8 +82,10 @@ internal class AuthTokenManager(
|
||||
|
||||
@Throws(IOException::class)
|
||||
override fun intercept(chain: Interceptor.Chain): Response {
|
||||
val token = getAccessToken()
|
||||
?: throw IOException(IllegalStateException(MISSING_TOKEN_MESSAGE))
|
||||
val token = getAccessToken() ?: run {
|
||||
Timber.w("Auth token is missing! Proceeding without token.")
|
||||
return chain.proceed(chain.request())
|
||||
}
|
||||
val request = chain
|
||||
.request()
|
||||
.newBuilder()
|
||||
|
||||
@@ -270,16 +270,19 @@ class AuthTokenManagerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `intercept should throw an exception when an auth token data is missing`() {
|
||||
val throwable = assertThrows(IOException::class.java) {
|
||||
authTokenManager.intercept(
|
||||
chain = FakeInterceptorChain(request = request),
|
||||
)
|
||||
fun `intercept should proceed without token when an auth token data is missing`() {
|
||||
val token = "token"
|
||||
authTokenManager.refreshTokenProvider = object : RefreshTokenProvider {
|
||||
override fun refreshAccessTokenSynchronously(
|
||||
userId: String,
|
||||
): Result<String> = token.asSuccess()
|
||||
}
|
||||
assertEquals(
|
||||
"Auth token is missing!",
|
||||
throwable.cause?.message,
|
||||
every { mockAuthTokenProvider.getAuthTokenDataOrNull() } returns null
|
||||
|
||||
val response = authTokenManager.intercept(
|
||||
chain = FakeInterceptorChain(request = request),
|
||||
)
|
||||
assertNull(response.request.header("Authorization"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user