HDFS-13485. DataNode WebHDFS endpoint throws NPE. Contributed by Siyao Meng.
This commit is contained in:
parent
121865c3f9
commit
d215357718
|
@ -23,6 +23,7 @@ import com.google.protobuf.ByteString;
|
|||
import com.google.common.primitives.Bytes;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.hadoop.HadoopIllegalArgumentException;
|
||||
import org.apache.hadoop.classification.InterfaceAudience;
|
||||
import org.apache.hadoop.classification.InterfaceStability;
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
|
@ -358,6 +359,10 @@ public class Token<T extends TokenIdentifier> implements Writable {
|
|||
*/
|
||||
private static void decodeWritable(Writable obj,
|
||||
String newValue) throws IOException {
|
||||
if (newValue == null) {
|
||||
throw new HadoopIllegalArgumentException(
|
||||
"Invalid argument, newValue is null");
|
||||
}
|
||||
Base64 decoder = new Base64(0, null, true);
|
||||
DataInputBuffer buf = new DataInputBuffer();
|
||||
byte[] decoded = decoder.decode(newValue);
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.apache.hadoop.security.token;
|
|||
import java.io.*;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apache.hadoop.HadoopIllegalArgumentException;
|
||||
import org.apache.hadoop.io.*;
|
||||
import org.apache.hadoop.security.token.delegation.AbstractDelegationTokenIdentifier;
|
||||
import org.apache.hadoop.security.token.delegation.TestDelegationToken.TestDelegationTokenIdentifier;
|
||||
|
@ -100,6 +101,23 @@ public class TestToken {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Test decodeWritable() with null newValue string argument,
|
||||
* should throw HadoopIllegalArgumentException.
|
||||
*/
|
||||
@Test
|
||||
public void testDecodeWritableArgSanityCheck() throws Exception {
|
||||
Token<AbstractDelegationTokenIdentifier> token =
|
||||
new Token<AbstractDelegationTokenIdentifier>();
|
||||
try {
|
||||
token.decodeFromUrlString(null);
|
||||
fail("Should have thrown HadoopIllegalArgumentException");
|
||||
}
|
||||
catch (HadoopIllegalArgumentException e) {
|
||||
Token.LOG.info("Test decodeWritable() sanity check success.");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeIdentifier() throws IOException {
|
||||
TestDelegationTokenSecretManager secretManager =
|
||||
|
|
Loading…
Reference in New Issue