|
@@ -17,6 +17,8 @@
|
|
|
*/
|
|
|
package org.apache.hadoop.yarn.security;
|
|
|
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
+import java.io.DataOutputStream;
|
|
|
import java.io.IOException;
|
|
|
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
@@ -31,6 +33,7 @@ import org.apache.hadoop.yarn.api.records.NodeId;
|
|
|
import org.apache.hadoop.yarn.api.records.Priority;
|
|
|
import org.apache.hadoop.yarn.api.records.Resource;
|
|
|
import org.apache.hadoop.yarn.conf.YarnConfiguration;
|
|
|
+import org.apache.hadoop.yarn.proto.YarnSecurityTokenProtos.YARNDelegationTokenIdentifierProto;
|
|
|
import org.apache.hadoop.yarn.security.client.ClientToAMTokenIdentifier;
|
|
|
import org.apache.hadoop.yarn.security.client.RMDelegationTokenIdentifier;
|
|
|
import org.apache.hadoop.yarn.security.client.TimelineDelegationTokenIdentifier;
|
|
@@ -224,7 +227,7 @@ public class TestYARNTokenIdentifier {
|
|
|
DataInputBuffer dib = new DataInputBuffer();
|
|
|
dib.reset(tokenContent, tokenContent.length);
|
|
|
anotherToken.readFields(dib);
|
|
|
-
|
|
|
+ dib.close();
|
|
|
// verify the whole record equals with original record
|
|
|
Assert.assertEquals("Token is not the same after serialization " +
|
|
|
"and deserialization.", token, anotherToken);
|
|
@@ -249,6 +252,32 @@ public class TestYARNTokenIdentifier {
|
|
|
|
|
|
Assert.assertEquals("masterKeyId from proto is not the same with original token",
|
|
|
anotherToken.getMasterKeyId(), masterKeyId);
|
|
|
+
|
|
|
+ // Test getProto
|
|
|
+ RMDelegationTokenIdentifier token1 =
|
|
|
+ new RMDelegationTokenIdentifier(owner, renewer, realUser);
|
|
|
+ token1.setIssueDate(issueDate);
|
|
|
+ token1.setMaxDate(maxDate);
|
|
|
+ token1.setSequenceNumber(sequenceNumber);
|
|
|
+ token1.setMasterKeyId(masterKeyId);
|
|
|
+ YARNDelegationTokenIdentifierProto tokenProto = token1.getProto();
|
|
|
+ // Write token proto to stream
|
|
|
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
|
+ DataOutputStream out = new DataOutputStream(baos);
|
|
|
+ tokenProto.writeTo(out);
|
|
|
+
|
|
|
+ // Read token
|
|
|
+ byte[] tokenData = baos.toByteArray();
|
|
|
+ RMDelegationTokenIdentifier readToken = new RMDelegationTokenIdentifier();
|
|
|
+ DataInputBuffer db = new DataInputBuffer();
|
|
|
+ db.reset(tokenData, tokenData.length);
|
|
|
+ readToken.readFields(db);
|
|
|
+
|
|
|
+ // Verify if read token equals with original token
|
|
|
+ Assert.assertEquals("Token from getProto is not the same after " +
|
|
|
+ "serialization and deserialization.", token1, readToken);
|
|
|
+ db.close();
|
|
|
+ out.close();
|
|
|
}
|
|
|
|
|
|
@Test
|