HTTPCLIENT-1649: serialization of auth schemes is broken

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1681016 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2015-05-22 07:24:01 +00:00
parent e4157e5d24
commit 8fc08b322e
3 changed files with 21 additions and 1 deletions

View File

@ -56,7 +56,7 @@ import org.apache.http.util.CharArrayBuffer;
@NotThreadSafe
public abstract class AuthSchemeBase implements ContextAwareAuthScheme {
private ChallengeState challengeState;
protected ChallengeState challengeState;
/**
* Creates an instance of {@code AuthSchemeBase} with the given challenge

View File

@ -158,6 +158,7 @@ public abstract class RFC2617Scheme extends AuthSchemeBase implements Serializab
private void writeObject(final ObjectOutputStream out) throws IOException {
out.defaultWriteObject();
out.writeUTF(this.credentialsCharset.name());
out.writeObject(this.challengeState);
}
@SuppressWarnings("unchecked")
@ -167,6 +168,7 @@ public abstract class RFC2617Scheme extends AuthSchemeBase implements Serializab
if (this.credentialsCharset == null) {
this.credentialsCharset = Consts.ASCII;
}
this.challengeState = (ChallengeState) in.readObject();
}
private void readObjectNoData() throws ObjectStreamException {

View File

@ -141,7 +141,25 @@ public class TestBasicScheme {
Assert.assertEquals(basicScheme.getSchemeName(), authScheme.getSchemeName());
Assert.assertEquals(basicScheme.getRealm(), authScheme.getRealm());
Assert.assertEquals(basicScheme.isComplete(), authScheme.isComplete());
Assert.assertEquals(true, basicScheme.isProxy());
}
@Test
public void testSerializationUnchallenged() throws Exception {
final BasicScheme basicScheme = new BasicScheme();
final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
final ObjectOutputStream out = new ObjectOutputStream(buffer);
out.writeObject(basicScheme);
out.flush();
final byte[] raw = buffer.toByteArray();
final ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(raw));
final BasicScheme authScheme = (BasicScheme) in.readObject();
Assert.assertEquals(basicScheme.getSchemeName(), authScheme.getSchemeName());
Assert.assertEquals(basicScheme.getRealm(), authScheme.getRealm());
Assert.assertEquals(basicScheme.isComplete(), authScheme.isComplete());
Assert.assertEquals(false, basicScheme.isProxy());
}
}