DigestScheme extends RFC2617Scheme { @Override public void processChallenge( final Header header) throws MalformedChallengeException { super.processChallenge(header); if (getParameter("realm") == null) { throw new MalformedChallengeException("missing realm in challange"); } if (getParameter("nonce") == null) { throw new MalformedChallengeException("missing nonce in challange"); } boolean unsupportedQop = false; String qop = getParameter("qop"); if (qop != null) { StringTokenizer tok = new StringTokenizer(qop,","); while (tok.hasMoreTokens()) { String variant = tok.nextToken().trim(); if (variant.equals("auth")) { qopVariant = QOP_AUTH; break; } else if (variant.equals("auth-int")) { qopVariant = QOP_AUTH_INT; } else { unsupportedQop = true; } } } if (unsupportedQop && (qopVariant == QOP_MISSING)) { throw new MalformedChallengeException("None of the qop methods is supported"); } this.complete = true; } DigestScheme(); @Override void processChallenge(
            final Header header); boolean isComplete(); String getSchemeName(); boolean isConnectionBased(); void overrideParamter(final String name, final String value); Header authenticate(
            final Credentials credentials,
            final HttpRequest request); static String createCnonce();  }
@Test(expected=MalformedChallengeException.class) public void testDigestAuthenticationWithNoRealm() throws Exception { Header authChallenge = new BasicHeader(AUTH.WWW_AUTH, "Digest"); AuthScheme authscheme = new DigestScheme(); authscheme.processChallenge(authChallenge); }
@Test(expected=MalformedChallengeException.class) public void testDigestAuthenticationWithNoRealm2() throws Exception { Header authChallenge = new BasicHeader(AUTH.WWW_AUTH, "Digest "); AuthScheme authscheme = new DigestScheme(); authscheme.processChallenge(authChallenge); }
@Test(expected=MalformedChallengeException.class) public void testDigestAuthenticationMD5SessInvalidQop() throws Exception { String realm="realm"; String nonce="e273f1776275974f1a120d8b92c5b3cb"; String challenge="Digest realm=\"" + realm + "\", " + "nonce=\"" + nonce + "\", " + "opaque=\"SomeString\", " + "stale=false, " + "algorithm=MD5-sess, " + "qop=\"jakarta\""; Header authChallenge = new BasicHeader(AUTH.WWW_AUTH, challenge); AuthScheme authscheme = new DigestScheme(); authscheme.processChallenge(authChallenge); }