Skip to content

Commit af34aa8

Browse files
committed
Restart auto upload through the vault after re-authentication
After tapping "Tap to refresh authentication", the retried auto upload was sent to the cloud's backend instead of the vault and stored the photos unencrypted in the cloud's root folder. Fixes GHSA-5qmj-g47w-hx82
1 parent cc6c159 commit af34aa8

2 files changed

Lines changed: 55 additions & 4 deletions

File tree

‎presentation/src/main/java/org/cryptomator/presentation/presenter/AutoUploadRefreshTokenPresenter.kt‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.cryptomator.presentation.presenter
22

3-
import org.cryptomator.domain.Cloud
43
import org.cryptomator.domain.di.PerView
54
import org.cryptomator.domain.exception.authentication.AuthenticationException
65
import org.cryptomator.generator.Callback
@@ -21,15 +20,16 @@ class AutoUploadRefreshTokenPresenter @Inject constructor(
2120
authenticationExceptionHandler.handleAuthenticationException( //
2221
this@AutoUploadRefreshTokenPresenter, //
2322
authenticationException, //
24-
ActivityResultCallbacks.onAutoUploadCloudAuthenticated(authenticationException.cloud)
23+
ActivityResultCallbacks.onAutoUploadCloudAuthenticated()
2524
)
2625
}
2726

2827
@Callback(dispatchResultOkOnly = false)
29-
fun onAutoUploadCloudAuthenticated(result: ActivityResult, cloud: Cloud) {
28+
fun onAutoUploadCloudAuthenticated(result: ActivityResult) {
3029
if (result.isResultOk) {
3130
val cryptomatorApp = activity().application as CryptomatorApp
32-
cryptomatorApp.startAutoUpload(cloud)
31+
// the authenticated cloud is the vault's unencrypted backend, so the upload restarts through the vault
32+
cryptomatorApp.startAutoUpload()
3333
}
3434
finish()
3535
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package org.cryptomator.presentation.presenter
2+
3+
import android.app.Activity
4+
import org.cryptomator.presentation.CryptomatorApp
5+
import org.cryptomator.presentation.exception.ExceptionHandlers
6+
import org.cryptomator.presentation.ui.activity.view.AutoUploadRefreshTokenView
7+
import org.cryptomator.presentation.workflow.ActivityResult
8+
import org.cryptomator.presentation.workflow.AuthenticationExceptionHandler
9+
import org.junit.jupiter.api.BeforeEach
10+
import org.junit.jupiter.api.Test
11+
import org.mockito.kotlin.any
12+
import org.mockito.kotlin.mock
13+
import org.mockito.kotlin.never
14+
import org.mockito.kotlin.verify
15+
import org.mockito.kotlin.whenever
16+
17+
class AutoUploadRefreshTokenPresenterTest {
18+
19+
private val app = mock<CryptomatorApp>()
20+
private val view = mock<AutoUploadRefreshTokenView>()
21+
22+
private lateinit var inTest: AutoUploadRefreshTokenPresenter
23+
24+
@BeforeEach
25+
fun setup() {
26+
val activity = mock<Activity>()
27+
whenever(activity.application).thenReturn(app)
28+
whenever(view.activity()).thenReturn(activity)
29+
inTest = AutoUploadRefreshTokenPresenter(mock<ExceptionHandlers>(), mock<AuthenticationExceptionHandler>())
30+
inTest.view = view
31+
}
32+
33+
@Test
34+
fun testUploadRestartsThroughTheVaultAfterAuthentication() {
35+
inTest.onAutoUploadCloudAuthenticated(ActivityResult(null, null, true))
36+
37+
// uploading to the authenticated cloud directly would skip the vault's encryption
38+
verify(app).startAutoUpload()
39+
verify(app, never()).startAutoUpload(any())
40+
verify(view).finish()
41+
}
42+
43+
@Test
44+
fun testUploadDoesntRestartWithoutAuthentication() {
45+
inTest.onAutoUploadCloudAuthenticated(ActivityResult(null, null, false))
46+
47+
verify(app, never()).startAutoUpload()
48+
verify(app, never()).startAutoUpload(any())
49+
verify(view).finish()
50+
}
51+
}

0 commit comments

Comments
 (0)