AuthMetadataCodec { public static ByteBuf encodeMetadataWithCompression( ByteBufAllocator allocator, String authType, ByteBuf metadata) { WellKnownAuthType wkn = WellKnownAuthType.fromString(authType); if (wkn == WellKnownAuthType.UNPARSEABLE_AUTH_TYPE) { return AuthMetadataCodec.encodeMetadata(allocator, authType, metadata); } else { return AuthMetadataCodec.encodeMetadata(allocator, wkn, metadata); } } private  AuthMetadataCodec(); static ByteBuf encodeMetadata(
      ByteBufAllocator allocator, String customAuthType, ByteBuf metadata); static ByteBuf encodeMetadata(
      ByteBufAllocator allocator, WellKnownAuthType authType, ByteBuf metadata); static ByteBuf encodeSimpleMetadata(
      ByteBufAllocator allocator, char[] username, char[] password); static ByteBuf encodeBearerMetadata(ByteBufAllocator allocator, char[] token); static ByteBuf encodeMetadataWithCompression(
      ByteBufAllocator allocator, String authType, ByteBuf metadata); static boolean isWellKnownAuthType(ByteBuf metadata); static WellKnownAuthType readWellKnownAuthType(ByteBuf metadata); static CharSequence readCustomAuthType(ByteBuf metadata); static ByteBuf readPayload(ByteBuf metadata); static ByteBuf readUsername(ByteBuf simpleAuthMetadata); static ByteBuf readPassword(ByteBuf simpleAuthMetadata); static char[] readUsernameAsCharArray(ByteBuf simpleAuthMetadata); static char[] readPasswordAsCharArray(ByteBuf simpleAuthMetadata); static char[] readBearerTokenAsCharArray(ByteBuf bearerAuthMetadata);  }
@Test void shouldCompressMetadata1() { ByteBuf byteBuf = AuthMetadataCodec.encodeMetadataWithCompression( ByteBufAllocator.DEFAULT, "bearer", Unpooled.copiedBuffer(TEST_BEARER_TOKEN, CharsetUtil.UTF_8)); byteBuf.markReaderIndex(); checkBearerAuthMetadataEncoding(TEST_BEARER_TOKEN, byteBuf); byteBuf.resetReaderIndex(); checkBearerAuthMetadataEncodingUsingDecoders(TEST_BEARER_TOKEN, byteBuf); }
@Test void shouldNotCompressMetadata() { ByteBuf testMetadataPayload = Unpooled.wrappedBuffer(TEST_BEARER_TOKEN.getBytes(CharsetUtil.UTF_8)); String customAuthType = "testauthtype"; ByteBuf byteBuf = AuthMetadataCodec.encodeMetadataWithCompression( ByteBufAllocator.DEFAULT, customAuthType, testMetadataPayload); checkCustomAuthMetadataEncoding(testMetadataPayload, customAuthType, byteBuf); }
@Test void shouldReadSimpleWellKnownAuthType() { ByteBuf metadata = AuthMetadataCodec.encodeMetadataWithCompression( ByteBufAllocator.DEFAULT, "simple", Unpooled.EMPTY_BUFFER); WellKnownAuthType expectedType = WellKnownAuthType.SIMPLE; checkDecodeWellKnowAuthTypeCorrectly(metadata, expectedType); }
@Test void shouldReadSimpleWellKnownAuthType1() { ByteBuf metadata = AuthMetadataCodec.encodeMetadataWithCompression( ByteBufAllocator.DEFAULT, "bearer", Unpooled.EMPTY_BUFFER); WellKnownAuthType expectedType = WellKnownAuthType.BEARER; checkDecodeWellKnowAuthTypeCorrectly(metadata, expectedType); }
@Test void shouldCompressMetadata() { ByteBuf byteBuf = AuthMetadataCodec.encodeMetadataWithCompression( ByteBufAllocator.DEFAULT, "simple", ByteBufAllocator.DEFAULT.buffer().writeShort(1).writeByte('u').writeByte('p')); checkSimpleAuthMetadataEncoding("u", "p", 1, 1, byteBuf); }