Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e2f57198 authored by cketti's avatar cketti
Browse files

Override hostname used for EHLO command in tests

parent 21d4ceb0
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line

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).
     */
+16 −1
Original line number Diff line number Diff line
@@ -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;
        }
    }
}