-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MBL-18548][All] Images embedded in pages fail to load after 24h from…
… first logging into the app (#2799) refs: MBL-18548 affects: Student, Parent, Teacher release note: none * Added webview authentication in activities onResume. * Fixed Parent unit tests. * Removed try-catch to see where FlutterAppMigration tests are failing. * Add log and test with different timezone * More logs * More logs * Revert test changes.
- Loading branch information
1 parent
1e3aede
commit fe04336
Showing
10 changed files
with
128 additions
and
61 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
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
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
44 changes: 44 additions & 0 deletions
44
libs/pandautils/src/main/java/com/instructure/pandautils/utils/WebViewAuthenticator.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,44 @@ | ||
/* | ||
* Copyright (C) 2025 - present Instructure, Inc. | ||
* | ||
* 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 com.instructure.pandautils.utils | ||
|
||
import android.content.Context | ||
import com.instructure.canvasapi2.apis.OAuthAPI | ||
import com.instructure.canvasapi2.builders.RestParams | ||
import com.instructure.canvasapi2.utils.ApiPrefs | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.launch | ||
|
||
private const val HOUR_IN_MILLIS = 1000 * 60 * 60 | ||
|
||
class WebViewAuthenticator(private val oAuthApi: OAuthAPI.OAuthInterface, private val apiPrefs: ApiPrefs) { | ||
|
||
fun authenticateWebViews(coroutineScope: CoroutineScope, context: Context) { | ||
val currentTime = System.currentTimeMillis() | ||
val lastAuthenticated = apiPrefs.webViewAuthenticationTimestamp | ||
if (currentTime - lastAuthenticated > HOUR_IN_MILLIS) { | ||
coroutineScope.launch { | ||
oAuthApi.getAuthenticatedSession( | ||
apiPrefs.fullDomain, | ||
RestParams(isForceReadFromNetwork = true) | ||
).dataOrNull?.sessionUrl?.let { | ||
loadUrlIntoHeadlessWebView(context, it) | ||
apiPrefs.webViewAuthenticationTimestamp = currentTime | ||
} | ||
} | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
libs/pandautils/src/test/java/com/instructure/pandautils/utils/WebViewAuthenticatorTest.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,55 @@ | ||
/* | ||
* Copyright (C) 2025 - present Instructure, Inc. | ||
* | ||
* 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 com.instructure.pandautils.utils | ||
|
||
import com.instructure.canvasapi2.apis.OAuthAPI | ||
import com.instructure.canvasapi2.utils.ApiPrefs | ||
import com.instructure.canvasapi2.utils.DataResult | ||
import io.mockk.coEvery | ||
import io.mockk.coVerify | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.Test | ||
|
||
class WebViewAuthenticatorTest { | ||
|
||
private val oAuthApi: OAuthAPI.OAuthInterface = mockk(relaxed = true) | ||
private val apiPrefs: ApiPrefs = mockk(relaxed = true) | ||
|
||
private val webViewAuthenticator = WebViewAuthenticator(oAuthApi, apiPrefs) | ||
|
||
@Test | ||
fun `Authenticate webviews when timestamp is older than an hour`() = runTest { | ||
every { apiPrefs.webViewAuthenticationTimestamp } returns System.currentTimeMillis() - 1000 * 60 * 61 | ||
coEvery { oAuthApi.getAuthenticatedSession(any(), any()) } returns DataResult.Fail() | ||
|
||
webViewAuthenticator.authenticateWebViews(this, mockk()) | ||
this.testScheduler.advanceUntilIdle() | ||
|
||
coVerify { oAuthApi.getAuthenticatedSession(any(), any()) } | ||
} | ||
|
||
@Test | ||
fun `Do not authenticate webviews when timestamp is not older than an hour`() = runTest { | ||
every { apiPrefs.webViewAuthenticationTimestamp } returns System.currentTimeMillis() | ||
coEvery { oAuthApi.getAuthenticatedSession(any(), any()) } returns DataResult.Fail() | ||
|
||
webViewAuthenticator.authenticateWebViews(this, mockk()) | ||
|
||
coVerify(exactly = 0) { oAuthApi.getAuthenticatedSession(any(), any()) } | ||
} | ||
} |