Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.GeneralSecurityException;

import org.slf4j.Logger;
Expand All @@ -55,6 +54,7 @@

import android.app.Dialog;
import android.content.Context;
import android.net.Uri;
import android.net.UrlQuerySanitizer;
import android.os.Bundle;
import android.text.Editable;
Expand Down Expand Up @@ -258,7 +258,7 @@ public void afterTextChanged(@NonNull Editable s) {

conName.setText(name);
try {
URL a = new URL(path);
Uri a = Uri.parse(path);
String userinfo = a.getUserInfo();
if (userinfo != null) {
String inf = decode(userinfo, Charsets.UTF_8.name());
Expand Down Expand Up @@ -296,8 +296,6 @@ public void afterTextChanged(@NonNull Editable s) {
}
} catch (UnsupportedEncodingException | IllegalArgumentException e) {
LOG.warn("failed to load smb dialog info for path {}", path, e);
} catch (MalformedURLException e) {
LOG.warn("failed to load smb dialog info", e);
}

} else if (path != null && path.length() > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import com.amaze.filemanager.utils.smb.SmbUtil
import io.mockk.confirmVerified
import io.mockk.spyk
import io.mockk.verify
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
import org.robolectric.shadows.ShadowDialog
Expand All @@ -45,6 +46,64 @@ import org.robolectric.shadows.ShadowLooper
* Tests [SmbConnectDialog].
*/
class SmbConnectDialogTest : AbstractMainActivityTestBase() {
/**
* Test editing an existing connection pre-fills all dialog fields.
* Regression test for https://github.com/TeamAmaze/AmazeFileManager/issues/4543
*/
@Test
fun testEditConnectionPreFillsAllFields() {
val listener = spyk<SmbConnectionListener>()
val encryptedPath =
SmbUtil.getSmbEncryptedPath(
AppConfig.getInstance(),
"smb://user:password@192.168.1.100/share",
)
doTestWithDialog(
listener = listener,
arguments =
Bundle().also {
it.putString(ARG_NAME, "My SMB Connection")
it.putString(ARG_PATH, encryptedPath)
it.putBoolean(ARG_EDIT, true)
},
withDialog = { dialog, _ ->
dialog.binding.run {
assertEquals("My SMB Connection", this.connectionET.text.toString())
assertEquals("192.168.1.100", this.ipET.text.toString())
assertEquals("share", this.shareET.text.toString())
assertEquals("user", this.usernameET.text.toString())
assertEquals("password", this.passwordET.text.toString())
}
},
)
}

/**
* Test editing an anonymous connection checks the anonymous checkbox.
* Regression test for https://github.com/TeamAmaze/AmazeFileManager/issues/4543
*/
@Test
fun testEditAnonymousConnectionSetsAnonymousCheckbox() {
val listener = spyk<SmbConnectionListener>()
doTestWithDialog(
listener = listener,
arguments =
Bundle().also {
it.putString(ARG_NAME, "Anonymous SMB")
it.putString(ARG_PATH, "smb://192.168.1.100/share")
it.putBoolean(ARG_EDIT, true)
},
withDialog = { dialog, _ ->
dialog.binding.run {
assertEquals("Anonymous SMB", this.connectionET.text.toString())
assertEquals("192.168.1.100", this.ipET.text.toString())
assertEquals("share", this.shareET.text.toString())
assertTrue(this.chkSmbAnonymous.isChecked)
}
},
)
}

/**
* Test call to [SmbConnectionListener.addConnection] is encrypted path.
*/
Expand Down
Loading