@Test public void testGenerateRequestToken() { clock.setTime(0); byte[] key = "super secret password".getBytes(); String destination = "test"; long epoch = sessionUtil.getThirtySecondsStepsFromEpoch(); byte[] sessionToken = sessionUtil.generateSessionToken( key, Unpooled.wrappedBuffer(destination.getBytes()), epoch); int r1 = sessionUtil.generateRequestToken( sessionToken, Unpooled.wrappedBuffer("a new request".getBytes()), epoch); clock.setTime(40000); int r2 = sessionUtil.generateRequestToken( sessionToken, Unpooled.wrappedBuffer("a new request".getBytes()), epoch); Assert.assertEquals(r1, r2); clock.setTime(40000); int r3 = sessionUtil.generateRequestToken( sessionToken, Unpooled.wrappedBuffer("another request".getBytes()), epoch + 1); Assert.assertNotEquals(r1, r3); clock.setTime(60000); int r4 = sessionUtil.generateRequestToken( sessionToken, Unpooled.wrappedBuffer("a new request".getBytes()), epoch + 2); Assert.assertNotEquals(r1, r4); }
@Override public int generateRequestToken(byte[] sessionToken, ByteBuf message, long count) { byte[] bytes = generateSessionToken(sessionToken, message, count); ByteBuffer byteBuffer = LONG_BUFFER.get(); byteBuffer.clear(); byteBuffer.put(bytes, 0, 4); return ByteBuffer.wrap(bytes).getInt(); }
DefaultSessionUtil extends SessionUtil { @Override public int generateRequestToken(byte[] sessionToken, ByteBuf message, long count) { byte[] bytes = generateSessionToken(sessionToken, message, count); ByteBuffer byteBuffer = LONG_BUFFER.get(); byteBuffer.clear(); byteBuffer.put(bytes, 0, 4); return ByteBuffer.wrap(bytes).getInt(); } }
DefaultSessionUtil extends SessionUtil { @Override public int generateRequestToken(byte[] sessionToken, ByteBuf message, long count) { byte[] bytes = generateSessionToken(sessionToken, message, count); ByteBuffer byteBuffer = LONG_BUFFER.get(); byteBuffer.clear(); byteBuffer.put(bytes, 0, 4); return ByteBuffer.wrap(bytes).getInt(); } DefaultSessionUtil(Clock clock);   DefaultSessionUtil(); }
DefaultSessionUtil extends SessionUtil { @Override public int generateRequestToken(byte[] sessionToken, ByteBuf message, long count) { byte[] bytes = generateSessionToken(sessionToken, message, count); ByteBuffer byteBuffer = LONG_BUFFER.get(); byteBuffer.clear(); byteBuffer.put(bytes, 0, 4); return ByteBuffer.wrap(bytes).getInt(); } DefaultSessionUtil(Clock clock);   DefaultSessionUtil(); @Override byte[] generateSessionToken(byte[] key, ByteBuf data, long count); @Override int generateRequestToken(byte[] sessionToken, ByteBuf message, long count); @Override boolean validateMessage(
      byte[] sessionToken, ByteBuf message, int requestToken, long count); long getThirtySecondsStepsFromEpoch(); }
DefaultSessionUtil extends SessionUtil { @Override public int generateRequestToken(byte[] sessionToken, ByteBuf message, long count) { byte[] bytes = generateSessionToken(sessionToken, message, count); ByteBuffer byteBuffer = LONG_BUFFER.get(); byteBuffer.clear(); byteBuffer.put(bytes, 0, 4); return ByteBuffer.wrap(bytes).getInt(); } DefaultSessionUtil(Clock clock);   DefaultSessionUtil(); @Override byte[] generateSessionToken(byte[] key, ByteBuf data, long count); @Override int generateRequestToken(byte[] sessionToken, ByteBuf message, long count); @Override boolean validateMessage(
      byte[] sessionToken, ByteBuf message, int requestToken, long count); long getThirtySecondsStepsFromEpoch();  }