Skip to content

Commit 6976cfb

Browse files
authored
Merge pull request #4598 from TranceLove/bugfix/4543
Fix edit SMB connection unable to populate value to dialog
2 parents ae50772 + 3200bfa commit 6976cfb

2 files changed

Lines changed: 61 additions & 4 deletions

File tree

app/src/main/java/com/amaze/filemanager/ui/dialogs/SmbConnectDialog.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import java.io.IOException;
3333
import java.io.UnsupportedEncodingException;
3434
import java.net.MalformedURLException;
35-
import java.net.URL;
3635
import java.security.GeneralSecurityException;
3736

3837
import org.slf4j.Logger;
@@ -55,6 +54,7 @@
5554

5655
import android.app.Dialog;
5756
import android.content.Context;
57+
import android.net.Uri;
5858
import android.net.UrlQuerySanitizer;
5959
import android.os.Bundle;
6060
import android.text.Editable;
@@ -258,7 +258,7 @@ public void afterTextChanged(@NonNull Editable s) {
258258

259259
conName.setText(name);
260260
try {
261-
URL a = new URL(path);
261+
Uri a = Uri.parse(path);
262262
String userinfo = a.getUserInfo();
263263
if (userinfo != null) {
264264
String inf = decode(userinfo, Charsets.UTF_8.name());
@@ -296,8 +296,6 @@ public void afterTextChanged(@NonNull Editable s) {
296296
}
297297
} catch (UnsupportedEncodingException | IllegalArgumentException e) {
298298
LOG.warn("failed to load smb dialog info for path {}", path, e);
299-
} catch (MalformedURLException e) {
300-
LOG.warn("failed to load smb dialog info", e);
301299
}
302300

303301
} else if (path != null && path.length() > 0) {

app/src/test/java/com/amaze/filemanager/ui/dialogs/SmbConnectDialogTest.kt

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import com.amaze.filemanager.utils.smb.SmbUtil
3636
import io.mockk.confirmVerified
3737
import io.mockk.spyk
3838
import io.mockk.verify
39+
import org.junit.Assert.assertEquals
3940
import org.junit.Assert.assertTrue
4041
import org.junit.Test
4142
import org.robolectric.shadows.ShadowDialog
@@ -45,6 +46,64 @@ import org.robolectric.shadows.ShadowLooper
4546
* Tests [SmbConnectDialog].
4647
*/
4748
class SmbConnectDialogTest : AbstractMainActivityTestBase() {
49+
/**
50+
* Test editing an existing connection pre-fills all dialog fields.
51+
* Regression test for https://github.com/TeamAmaze/AmazeFileManager/issues/4543
52+
*/
53+
@Test
54+
fun testEditConnectionPreFillsAllFields() {
55+
val listener = spyk<SmbConnectionListener>()
56+
val encryptedPath =
57+
SmbUtil.getSmbEncryptedPath(
58+
AppConfig.getInstance(),
59+
"smb://user:password@192.168.1.100/share",
60+
)
61+
doTestWithDialog(
62+
listener = listener,
63+
arguments =
64+
Bundle().also {
65+
it.putString(ARG_NAME, "My SMB Connection")
66+
it.putString(ARG_PATH, encryptedPath)
67+
it.putBoolean(ARG_EDIT, true)
68+
},
69+
withDialog = { dialog, _ ->
70+
dialog.binding.run {
71+
assertEquals("My SMB Connection", this.connectionET.text.toString())
72+
assertEquals("192.168.1.100", this.ipET.text.toString())
73+
assertEquals("share", this.shareET.text.toString())
74+
assertEquals("user", this.usernameET.text.toString())
75+
assertEquals("password", this.passwordET.text.toString())
76+
}
77+
},
78+
)
79+
}
80+
81+
/**
82+
* Test editing an anonymous connection checks the anonymous checkbox.
83+
* Regression test for https://github.com/TeamAmaze/AmazeFileManager/issues/4543
84+
*/
85+
@Test
86+
fun testEditAnonymousConnectionSetsAnonymousCheckbox() {
87+
val listener = spyk<SmbConnectionListener>()
88+
doTestWithDialog(
89+
listener = listener,
90+
arguments =
91+
Bundle().also {
92+
it.putString(ARG_NAME, "Anonymous SMB")
93+
it.putString(ARG_PATH, "smb://192.168.1.100/share")
94+
it.putBoolean(ARG_EDIT, true)
95+
},
96+
withDialog = { dialog, _ ->
97+
dialog.binding.run {
98+
assertEquals("Anonymous SMB", this.connectionET.text.toString())
99+
assertEquals("192.168.1.100", this.ipET.text.toString())
100+
assertEquals("share", this.shareET.text.toString())
101+
assertTrue(this.chkSmbAnonymous.isChecked)
102+
}
103+
},
104+
)
105+
}
106+
48107
/**
49108
* Test call to [SmbConnectionListener.addConnection] is encrypted path.
50109
*/

0 commit comments

Comments
 (0)