@Test(expected = CorruptedFrameException.class) public void testFailureDecodeBadRsa() throws Exception { // Decode our bad RSA key KeyFactory keyFactory = KeyFactory.getInstance("RSA"); X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(TestVotifierPlugin.r("/bad_public.key")); PublicKey badPublicKey = keyFactory.generatePublic(publicKeySpec); // Send the bad vote EmbeddedChannel channel = createChannel(); String voteString = "VOTE\nTest\ntest\ntest\ntest\n"; byte[] encrypted = RSA.encrypt(voteString.getBytes(StandardCharsets.UTF_8), badPublicKey); ByteBuf encryptedByteBuf = Unpooled.wrappedBuffer(encrypted); try { channel.writeInbound(encryptedByteBuf); } finally { channel.close(); } }