use of io.grpc.alts.internal.TsiTest.Handshakers in project grpc-java by grpc.
the class AltsTsiTest method verifyHandshakePeer.
@Test
public void verifyHandshakePeer() throws Exception {
Handshakers handshakers = newHandshakers();
TsiTest.performHandshake(TsiTest.getDefaultTransportBufferSize(), handshakers);
TsiPeer clientPeer = handshakers.getClient().extractPeer();
assertEquals(1, clientPeer.getProperties().size());
assertEquals(MockAltsHandshakerResp.getTestPeerAccount(), clientPeer.getProperty("service_account").getValue());
TsiPeer serverPeer = handshakers.getServer().extractPeer();
assertEquals(1, serverPeer.getProperties().size());
assertEquals(MockAltsHandshakerResp.getTestPeerAccount(), serverPeer.getProperty("service_account").getValue());
}
use of io.grpc.alts.internal.TsiTest.Handshakers in project grpc-java by grpc.
the class AltsTsiTest method newHandshakers.
private Handshakers newHandshakers() {
NoopChannelLogger channelLogger = new NoopChannelLogger();
TsiHandshaker clientHandshaker = new AltsTsiHandshaker(true, client, channelLogger);
TsiHandshaker serverHandshaker = new AltsTsiHandshaker(false, server, channelLogger);
return new Handshakers(clientHandshaker, serverHandshaker);
}
use of io.grpc.alts.internal.TsiTest.Handshakers in project grpc-java by grpc.
the class FakeTsiTest method handshakeStateOrderTest.
@Test
public void handshakeStateOrderTest() {
try {
Handshakers handshakers = newHandshakers();
TsiHandshaker clientHandshaker = handshakers.getClient();
TsiHandshaker serverHandshaker = handshakers.getServer();
byte[] transportBufferBytes = new byte[TsiTest.getDefaultTransportBufferSize()];
ByteBuffer transportBuffer = ByteBuffer.wrap(transportBufferBytes);
// Start off with an empty buffer
((Buffer) transportBuffer).limit(0);
((Buffer) transportBuffer).clear();
clientHandshaker.getBytesToSendToPeer(transportBuffer);
((Buffer) transportBuffer).flip();
assertEquals(FakeTsiHandshaker.State.CLIENT_INIT.toString().trim(), new String(transportBufferBytes, 4, transportBuffer.remaining(), UTF_8).trim());
serverHandshaker.processBytesFromPeer(transportBuffer);
assertFalse(transportBuffer.hasRemaining());
// client shouldn't offer any more bytes
((Buffer) transportBuffer).clear();
clientHandshaker.getBytesToSendToPeer(transportBuffer);
((Buffer) transportBuffer).flip();
assertFalse(transportBuffer.hasRemaining());
((Buffer) transportBuffer).clear();
serverHandshaker.getBytesToSendToPeer(transportBuffer);
((Buffer) transportBuffer).flip();
assertEquals(FakeTsiHandshaker.State.SERVER_INIT.toString().trim(), new String(transportBufferBytes, 4, transportBuffer.remaining(), UTF_8).trim());
clientHandshaker.processBytesFromPeer(transportBuffer);
assertFalse(transportBuffer.hasRemaining());
// server shouldn't offer any more bytes
((Buffer) transportBuffer).clear();
serverHandshaker.getBytesToSendToPeer(transportBuffer);
((Buffer) transportBuffer).flip();
assertFalse(transportBuffer.hasRemaining());
((Buffer) transportBuffer).clear();
clientHandshaker.getBytesToSendToPeer(transportBuffer);
((Buffer) transportBuffer).flip();
assertEquals(FakeTsiHandshaker.State.CLIENT_FINISHED.toString().trim(), new String(transportBufferBytes, 4, transportBuffer.remaining(), UTF_8).trim());
serverHandshaker.processBytesFromPeer(transportBuffer);
assertFalse(transportBuffer.hasRemaining());
// client shouldn't offer any more bytes
((Buffer) transportBuffer).clear();
clientHandshaker.getBytesToSendToPeer(transportBuffer);
((Buffer) transportBuffer).flip();
assertFalse(transportBuffer.hasRemaining());
((Buffer) transportBuffer).clear();
serverHandshaker.getBytesToSendToPeer(transportBuffer);
((Buffer) transportBuffer).flip();
assertEquals(FakeTsiHandshaker.State.SERVER_FINISHED.toString().trim(), new String(transportBufferBytes, 4, transportBuffer.remaining(), UTF_8).trim());
clientHandshaker.processBytesFromPeer(transportBuffer);
assertFalse(transportBuffer.hasRemaining());
// server shouldn't offer any more bytes
((Buffer) transportBuffer).clear();
serverHandshaker.getBytesToSendToPeer(transportBuffer);
((Buffer) transportBuffer).flip();
assertFalse(transportBuffer.hasRemaining());
} catch (GeneralSecurityException e) {
throw new AssertionError(e);
}
}
Aggregations