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

Commit df867f8f authored by Jesse Wilson's avatar Jesse Wilson
Browse files

Test that algorithm name is case-insensitive for digest auth.

Change-Id: I891a533ae3b16b838925fa488093c19dfeb32efa
http://code.google.com/p/android/issues/detail?id=16051
parent 40e44467
Loading
Loading
Loading
Loading
+44 −0
Original line number Diff line number Diff line
@@ -28,9 +28,17 @@ import java.io.Reader;
import java.io.StringWriter;
import junit.framework.TestCase;
import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthenticationException;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.auth.DigestScheme;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicHeader;

/**
 * Tests for various regressions and problems with DefaultHttpClient. This is
 * not a comprehensive test!
 */
public final class DefaultHttpClientTest extends TestCase {

    private MockWebServer server = new MockWebServer();
@@ -87,4 +95,40 @@ public final class DefaultHttpClientTest extends TestCase {
        reader.close();
        return writer.toString();
    }

    // http://code.google.com/p/android/issues/detail?id=16051
    public void testDigestSchemeAlgorithms() throws Exception {
        authenticateDigestAlgorithm("MD5");
        authenticateDigestAlgorithm("MD5-sess");
        authenticateDigestAlgorithm("md5");
        authenticateDigestAlgorithm("md5-sess");
        authenticateDigestAlgorithm("md5-SESS");
        authenticateDigestAlgorithm("MD5-SESS");
        try {
            authenticateDigestAlgorithm("MD5-");
        } catch (AuthenticationException expected) {
        }
        try {
            authenticateDigestAlgorithm("MD6");
        } catch (AuthenticationException expected) {
        }
        try {
            authenticateDigestAlgorithm("MD");
        } catch (AuthenticationException expected) {
        }
        try {
            authenticateDigestAlgorithm("");
        } catch (AuthenticationException expected) {
        }
    }

    private void authenticateDigestAlgorithm(String algorithm) throws Exception {
        String challenge = "Digest realm=\"protected area\", "
                + "nonce=\"dcd98b7102dd2f0e8b11d0f600bfb0c093\", "
                + "algorithm=" + algorithm;
        DigestScheme digestScheme = new DigestScheme();
        digestScheme.processChallenge(new BasicHeader("WWW-Authenticate", challenge));
        HttpGet get = new HttpGet();
        digestScheme.authenticate(new UsernamePasswordCredentials("username", "password"), get);
    }
}