Override hostname used for EHLO command in tests
This commit is contained in:
parent
21d4ceb0d8
commit
e2f5719826
2 changed files with 23 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
|||
|
||||
package com.fsck.k9.mail.transport;
|
||||
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.util.Log;
|
||||
|
||||
import com.fsck.k9.mail.*;
|
||||
|
@ -241,7 +242,7 @@ public class SmtpTransport extends Transport {
|
|||
executeSimpleCommand(null);
|
||||
|
||||
InetAddress localAddress = mSocket.getLocalAddress();
|
||||
String localHost = localAddress.getCanonicalHostName();
|
||||
String localHost = getCanonicalHostName(localAddress);
|
||||
String ipAddr = localAddress.getHostAddress();
|
||||
|
||||
if (localHost.equals("") || localHost.equals(ipAddr) || localHost.contains("_")) {
|
||||
|
@ -761,6 +762,11 @@ public class SmtpTransport extends Transport {
|
|||
Base64.encode(username)), false);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
protected String getCanonicalHostName(InetAddress localAddress) {
|
||||
return localAddress.getCanonicalHostName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception that is thrown when the server sends a negative reply (reply codes 4xx or 5xx).
|
||||
*/
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.fsck.k9.mail.transport;
|
|||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
|
||||
import com.fsck.k9.mail.AuthType;
|
||||
import com.fsck.k9.mail.CertificateValidationException;
|
||||
|
@ -33,6 +34,7 @@ import static org.mockito.Mockito.when;
|
|||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(manifest = Config.NONE, sdk = 21)
|
||||
public class SmtpTransportTest {
|
||||
private static final String LOCALHOST_NAME = "localhost";
|
||||
private static final String USERNAME = "user";
|
||||
private static final String PASSWORD = "password";
|
||||
private static final String CLIENT_CERTIFICATE_ALIAS = null;
|
||||
|
@ -411,7 +413,7 @@ public class SmtpTransportTest {
|
|||
String uri = SmtpTransport.createUri(serverSettings);
|
||||
StoreConfig storeConfig = createStoreConfigWithTransportUri(uri);
|
||||
|
||||
return new SmtpTransport(storeConfig, socketFactory);
|
||||
return new TestSmtpTransport(storeConfig, socketFactory);
|
||||
}
|
||||
|
||||
private StoreConfig createStoreConfigWithTransportUri(String value) {
|
||||
|
@ -447,4 +449,17 @@ public class SmtpTransportTest {
|
|||
|
||||
return server;
|
||||
}
|
||||
|
||||
|
||||
static class TestSmtpTransport extends SmtpTransport {
|
||||
TestSmtpTransport(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory)
|
||||
throws MessagingException {
|
||||
super(storeConfig, trustedSocketFactory);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getCanonicalHostName(InetAddress localAddress) {
|
||||
return LOCALHOST_NAME;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue