@Test public void testValidateProperWrappedComment() throws IOException, GeneralSecurityException { String comment = "This is another comment"; MessageId originalId = new MessageId(getRandomId()); MessageId oldId = new MessageId(getRandomId()); byte[] sigBytes = getRandomBytes(42); MessageId currentId = new MessageId(getRandomId()); BdfList m = BdfList.of(WRAPPED_COMMENT.getInt(), descriptor, message.getTimestamp(), comment, originalId, oldId, sigBytes, currentId); BdfList signed = BdfList.of(blog.getId(), message.getTimestamp(), comment, originalId, oldId); expectCrypto(blog, SIGNING_LABEL_COMMENT, signed, sigBytes); BdfList originalList = BdfList.of(COMMENT.getInt(), comment, originalId, oldId, sigBytes); byte[] originalBody = getRandomBytes(42); context.checking(new Expectations() {{ oneOf(groupFactory).createGroup(CLIENT_ID, MAJOR_VERSION, descriptor); will(returnValue(blog.getGroup())); oneOf(clientHelper).toByteArray(originalList); will(returnValue(originalBody)); oneOf(messageFactory) .createMessage(group.getId(), message.getTimestamp(), originalBody); will(returnValue(message)); }}); BdfDictionary result = validator.validateMessage(message, group, m).getDictionary(); assertEquals(comment, result.getString(KEY_COMMENT)); assertEquals(authorList, result.getList(KEY_AUTHOR)); assertEquals( message.getId().getBytes(), result.getRaw(KEY_ORIGINAL_MSG_ID)); assertEquals(currentId.getBytes(), result.getRaw(KEY_PARENT_MSG_ID)); context.assertIsSatisfied(); }
@Override protected BdfMessageContext validateMessage(Message m, Group g, BdfList body) throws InvalidMessageException, FormatException { BdfMessageContext c; int type = body.getLong(0).intValue(); body.remove(0); switch (MessageType.valueOf(type)) { case POST: c = validatePost(m, g, body); addMessageMetadata(c, m.getTimestamp()); break; case COMMENT: c = validateComment(m, g, body); addMessageMetadata(c, m.getTimestamp()); break; case WRAPPED_POST: c = validateWrappedPost(body); break; case WRAPPED_COMMENT: c = validateWrappedComment(body); break; default: throw new InvalidMessageException("Unknown Message Type"); } c.getDictionary().put(KEY_TYPE, type); return c; }
BlogPostValidator extends BdfMessageValidator { @Override protected BdfMessageContext validateMessage(Message m, Group g, BdfList body) throws InvalidMessageException, FormatException { BdfMessageContext c; int type = body.getLong(0).intValue(); body.remove(0); switch (MessageType.valueOf(type)) { case POST: c = validatePost(m, g, body); addMessageMetadata(c, m.getTimestamp()); break; case COMMENT: c = validateComment(m, g, body); addMessageMetadata(c, m.getTimestamp()); break; case WRAPPED_POST: c = validateWrappedPost(body); break; case WRAPPED_COMMENT: c = validateWrappedComment(body); break; default: throw new InvalidMessageException("Unknown Message Type"); } c.getDictionary().put(KEY_TYPE, type); return c; } }
BlogPostValidator extends BdfMessageValidator { @Override protected BdfMessageContext validateMessage(Message m, Group g, BdfList body) throws InvalidMessageException, FormatException { BdfMessageContext c; int type = body.getLong(0).intValue(); body.remove(0); switch (MessageType.valueOf(type)) { case POST: c = validatePost(m, g, body); addMessageMetadata(c, m.getTimestamp()); break; case COMMENT: c = validateComment(m, g, body); addMessageMetadata(c, m.getTimestamp()); break; case WRAPPED_POST: c = validateWrappedPost(body); break; case WRAPPED_COMMENT: c = validateWrappedComment(body); break; default: throw new InvalidMessageException("Unknown Message Type"); } c.getDictionary().put(KEY_TYPE, type); return c; } BlogPostValidator(GroupFactory groupFactory, MessageFactory messageFactory,
			BlogFactory blogFactory, ClientHelper clientHelper,
			MetadataEncoder metadataEncoder, Clock clock); }
BlogPostValidator extends BdfMessageValidator { @Override protected BdfMessageContext validateMessage(Message m, Group g, BdfList body) throws InvalidMessageException, FormatException { BdfMessageContext c; int type = body.getLong(0).intValue(); body.remove(0); switch (MessageType.valueOf(type)) { case POST: c = validatePost(m, g, body); addMessageMetadata(c, m.getTimestamp()); break; case COMMENT: c = validateComment(m, g, body); addMessageMetadata(c, m.getTimestamp()); break; case WRAPPED_POST: c = validateWrappedPost(body); break; case WRAPPED_COMMENT: c = validateWrappedComment(body); break; default: throw new InvalidMessageException("Unknown Message Type"); } c.getDictionary().put(KEY_TYPE, type); return c; } BlogPostValidator(GroupFactory groupFactory, MessageFactory messageFactory,
			BlogFactory blogFactory, ClientHelper clientHelper,
			MetadataEncoder metadataEncoder, Clock clock);  }
BlogPostValidator extends BdfMessageValidator { @Override protected BdfMessageContext validateMessage(Message m, Group g, BdfList body) throws InvalidMessageException, FormatException { BdfMessageContext c; int type = body.getLong(0).intValue(); body.remove(0); switch (MessageType.valueOf(type)) { case POST: c = validatePost(m, g, body); addMessageMetadata(c, m.getTimestamp()); break; case COMMENT: c = validateComment(m, g, body); addMessageMetadata(c, m.getTimestamp()); break; case WRAPPED_POST: c = validateWrappedPost(body); break; case WRAPPED_COMMENT: c = validateWrappedComment(body); break; default: throw new InvalidMessageException("Unknown Message Type"); } c.getDictionary().put(KEY_TYPE, type); return c; } BlogPostValidator(GroupFactory groupFactory, MessageFactory messageFactory,
			BlogFactory blogFactory, ClientHelper clientHelper,
			MetadataEncoder metadataEncoder, Clock clock);   }