mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 12:19:54 +01:00
Use author encoding and parsing helpers everywhere.
This commit is contained in:
@@ -39,14 +39,10 @@ import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||
import static org.briarproject.bramble.util.StringUtils.getRandomString;
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_AUTHOR;
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_AUTHOR_ID;
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_AUTHOR_NAME;
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_COMMENT;
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_FORMAT_VERSION;
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_ORIGINAL_MSG_ID;
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_ORIGINAL_PARENT_MSG_ID;
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_PARENT_MSG_ID;
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_PUBLIC_KEY;
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_READ;
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_RSS_FEED;
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_TIMESTAMP;
|
||||
@@ -76,7 +72,7 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
context.mock(BlogPostFactory.class);
|
||||
|
||||
private final LocalAuthor localAuthor1, localAuthor2, rssLocalAuthor;
|
||||
private final BdfDictionary authorDict1, authorDict2, rssAuthorDict;
|
||||
private final BdfList authorList1, authorList2, rssAuthorList;
|
||||
private final Blog blog1, blog2, rssBlog;
|
||||
private final long timestamp, timeReceived;
|
||||
private final MessageId messageId, rssMessageId;
|
||||
@@ -91,9 +87,9 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
localAuthor1 = getLocalAuthor();
|
||||
localAuthor2 = getLocalAuthor();
|
||||
rssLocalAuthor = getLocalAuthor();
|
||||
authorDict1 = authorToBdfDictionary(localAuthor1);
|
||||
authorDict2 = authorToBdfDictionary(localAuthor2);
|
||||
rssAuthorDict = authorToBdfDictionary(rssLocalAuthor);
|
||||
authorList1 = authorToBdfList(localAuthor1);
|
||||
authorList2 = authorToBdfList(localAuthor2);
|
||||
rssAuthorList = authorToBdfList(rssLocalAuthor);
|
||||
blog1 = createBlog(localAuthor1, false);
|
||||
blog2 = createBlog(localAuthor2, false);
|
||||
rssBlog = createBlog(rssLocalAuthor, true);
|
||||
@@ -173,12 +169,14 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
new BdfEntry(KEY_TYPE, POST.getInt()),
|
||||
new BdfEntry(KEY_TIMESTAMP, timestamp),
|
||||
new BdfEntry(KEY_TIME_RECEIVED, timeReceived),
|
||||
new BdfEntry(KEY_AUTHOR, authorDict1),
|
||||
new BdfEntry(KEY_AUTHOR, authorList1),
|
||||
new BdfEntry(KEY_READ, false),
|
||||
new BdfEntry(KEY_RSS_FEED, false)
|
||||
);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(clientHelper).parseAndValidateAuthor(authorList1);
|
||||
will(returnValue(localAuthor1));
|
||||
oneOf(identityManager).getAuthorStatus(txn, localAuthor1.getId());
|
||||
will(returnValue(VERIFIED));
|
||||
}});
|
||||
@@ -212,11 +210,16 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
new BdfEntry(KEY_TYPE, POST.getInt()),
|
||||
new BdfEntry(KEY_TIMESTAMP, timestamp),
|
||||
new BdfEntry(KEY_TIME_RECEIVED, timeReceived),
|
||||
new BdfEntry(KEY_AUTHOR, rssAuthorDict),
|
||||
new BdfEntry(KEY_AUTHOR, rssAuthorList),
|
||||
new BdfEntry(KEY_READ, false),
|
||||
new BdfEntry(KEY_RSS_FEED, true)
|
||||
);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(clientHelper).parseAndValidateAuthor(rssAuthorList);
|
||||
will(returnValue(rssLocalAuthor));
|
||||
}});
|
||||
|
||||
blogManager.incomingMessage(txn, rssMessage, body, meta);
|
||||
context.assertIsSatisfied();
|
||||
|
||||
@@ -263,7 +266,7 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
BdfDictionary meta = BdfDictionary.of(
|
||||
new BdfEntry(KEY_TYPE, POST.getInt()),
|
||||
new BdfEntry(KEY_TIMESTAMP, timestamp),
|
||||
new BdfEntry(KEY_AUTHOR, authorDict1),
|
||||
new BdfEntry(KEY_AUTHOR, authorList1),
|
||||
new BdfEntry(KEY_READ, true),
|
||||
new BdfEntry(KEY_RSS_FEED, false)
|
||||
);
|
||||
@@ -275,7 +278,11 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
will(returnValue(blog1.getGroup()));
|
||||
oneOf(blogFactory).parseBlog(blog1.getGroup());
|
||||
will(returnValue(blog1));
|
||||
oneOf(clientHelper).toList(localAuthor1);
|
||||
will(returnValue(authorList1));
|
||||
oneOf(clientHelper).addLocalMessage(txn, message, meta, true);
|
||||
oneOf(clientHelper).parseAndValidateAuthor(authorList1);
|
||||
will(returnValue(localAuthor1));
|
||||
oneOf(identityManager).getAuthorStatus(txn, localAuthor1.getId());
|
||||
will(returnValue(OURSELVES));
|
||||
oneOf(db).commitTransaction(txn);
|
||||
@@ -309,7 +316,7 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
BdfDictionary meta = BdfDictionary.of(
|
||||
new BdfEntry(KEY_TYPE, POST.getInt()),
|
||||
new BdfEntry(KEY_TIMESTAMP, timestamp),
|
||||
new BdfEntry(KEY_AUTHOR, rssAuthorDict),
|
||||
new BdfEntry(KEY_AUTHOR, rssAuthorList),
|
||||
new BdfEntry(KEY_READ, true),
|
||||
new BdfEntry(KEY_RSS_FEED, true)
|
||||
);
|
||||
@@ -321,7 +328,11 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
will(returnValue(rssBlog.getGroup()));
|
||||
oneOf(blogFactory).parseBlog(rssBlog.getGroup());
|
||||
will(returnValue(rssBlog));
|
||||
oneOf(clientHelper).toList(rssLocalAuthor);
|
||||
will(returnValue(rssAuthorList));
|
||||
oneOf(clientHelper).addLocalMessage(txn, rssMessage, meta, true);
|
||||
oneOf(clientHelper).parseAndValidateAuthor(rssAuthorList);
|
||||
will(returnValue(rssLocalAuthor));
|
||||
oneOf(db).commitTransaction(txn);
|
||||
oneOf(db).endTransaction(txn);
|
||||
}});
|
||||
@@ -356,7 +367,7 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
new BdfEntry(KEY_TYPE, POST.getInt()),
|
||||
new BdfEntry(KEY_RSS_FEED, false),
|
||||
new BdfEntry(KEY_ORIGINAL_MSG_ID, messageId),
|
||||
new BdfEntry(KEY_AUTHOR, authorDict1),
|
||||
new BdfEntry(KEY_AUTHOR, authorList1),
|
||||
new BdfEntry(KEY_TIMESTAMP, timestamp),
|
||||
new BdfEntry(KEY_TIME_RECEIVED, timeReceived)
|
||||
);
|
||||
@@ -370,7 +381,7 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
new BdfEntry(KEY_ORIGINAL_MSG_ID, commentId),
|
||||
new BdfEntry(KEY_ORIGINAL_PARENT_MSG_ID, messageId),
|
||||
new BdfEntry(KEY_PARENT_MSG_ID, messageId),
|
||||
new BdfEntry(KEY_AUTHOR, authorDict1)
|
||||
new BdfEntry(KEY_AUTHOR, authorList1)
|
||||
);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
@@ -380,14 +391,20 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
oneOf(blogPostFactory).createBlogComment(blog1.getId(),
|
||||
localAuthor1, comment, messageId, messageId);
|
||||
will(returnValue(commentMsg));
|
||||
oneOf(clientHelper).toList(localAuthor1);
|
||||
will(returnValue(authorList1));
|
||||
// Store the comment
|
||||
oneOf(clientHelper).addLocalMessage(txn, commentMsg, commentMeta,
|
||||
true);
|
||||
// Create the headers for the comment and its parent
|
||||
oneOf(clientHelper).parseAndValidateAuthor(authorList1);
|
||||
will(returnValue(localAuthor1));
|
||||
oneOf(identityManager).getAuthorStatus(txn, localAuthor1.getId());
|
||||
will(returnValue(OURSELVES));
|
||||
oneOf(clientHelper).getMessageMetadataAsDictionary(txn, messageId);
|
||||
will(returnValue(postMeta));
|
||||
oneOf(clientHelper).parseAndValidateAuthor(authorList1);
|
||||
will(returnValue(localAuthor1));
|
||||
oneOf(identityManager).getAuthorStatus(txn, localAuthor1.getId());
|
||||
will(returnValue(OURSELVES));
|
||||
oneOf(db).commitTransaction(txn);
|
||||
@@ -446,7 +463,7 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
new BdfEntry(KEY_TYPE, WRAPPED_POST.getInt()),
|
||||
new BdfEntry(KEY_RSS_FEED, false),
|
||||
new BdfEntry(KEY_ORIGINAL_MSG_ID, messageId),
|
||||
new BdfEntry(KEY_AUTHOR, authorDict1),
|
||||
new BdfEntry(KEY_AUTHOR, authorList1),
|
||||
new BdfEntry(KEY_TIMESTAMP, timestamp),
|
||||
new BdfEntry(KEY_TIME_RECEIVED, timeReceived)
|
||||
);
|
||||
@@ -460,7 +477,7 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
new BdfEntry(KEY_ORIGINAL_MSG_ID, commentId),
|
||||
new BdfEntry(KEY_ORIGINAL_PARENT_MSG_ID, messageId),
|
||||
new BdfEntry(KEY_PARENT_MSG_ID, wrappedPostId),
|
||||
new BdfEntry(KEY_AUTHOR, authorDict2)
|
||||
new BdfEntry(KEY_AUTHOR, authorList2)
|
||||
);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
@@ -475,6 +492,8 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
blog1.getGroup().getDescriptor(), timestamp,
|
||||
originalPostBody);
|
||||
will(returnValue(wrappedPostMsg));
|
||||
oneOf(clientHelper).toList(localAuthor1);
|
||||
will(returnValue(authorList1));
|
||||
// Store the wrapped post
|
||||
oneOf(clientHelper).addLocalMessage(txn, wrappedPostMsg,
|
||||
wrappedPostMeta, true);
|
||||
@@ -482,15 +501,21 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
oneOf(blogPostFactory).createBlogComment(blog2.getId(),
|
||||
localAuthor2, comment, messageId, wrappedPostId);
|
||||
will(returnValue(commentMsg));
|
||||
oneOf(clientHelper).toList(localAuthor2);
|
||||
will(returnValue(authorList2));
|
||||
// Store the comment
|
||||
oneOf(clientHelper).addLocalMessage(txn, commentMsg, commentMeta,
|
||||
true);
|
||||
// Create the headers for the comment and the wrapped post
|
||||
oneOf(clientHelper).parseAndValidateAuthor(authorList2);
|
||||
will(returnValue(localAuthor2));
|
||||
oneOf(identityManager).getAuthorStatus(txn, localAuthor2.getId());
|
||||
will(returnValue(OURSELVES));
|
||||
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
||||
wrappedPostId);
|
||||
will(returnValue(wrappedPostMeta));
|
||||
oneOf(clientHelper).parseAndValidateAuthor(authorList1);
|
||||
will(returnValue(localAuthor1));
|
||||
oneOf(identityManager).getAuthorStatus(txn, localAuthor1.getId());
|
||||
will(returnValue(VERIFIED));
|
||||
oneOf(db).commitTransaction(txn);
|
||||
@@ -549,7 +574,7 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
new BdfEntry(KEY_TYPE, WRAPPED_POST.getInt()),
|
||||
new BdfEntry(KEY_RSS_FEED, true),
|
||||
new BdfEntry(KEY_ORIGINAL_MSG_ID, rssMessageId),
|
||||
new BdfEntry(KEY_AUTHOR, rssAuthorDict),
|
||||
new BdfEntry(KEY_AUTHOR, rssAuthorList),
|
||||
new BdfEntry(KEY_TIMESTAMP, timestamp),
|
||||
new BdfEntry(KEY_TIME_RECEIVED, timeReceived)
|
||||
);
|
||||
@@ -563,7 +588,7 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
new BdfEntry(KEY_ORIGINAL_MSG_ID, commentId),
|
||||
new BdfEntry(KEY_ORIGINAL_PARENT_MSG_ID, rssMessageId),
|
||||
new BdfEntry(KEY_PARENT_MSG_ID, wrappedPostId),
|
||||
new BdfEntry(KEY_AUTHOR, authorDict1)
|
||||
new BdfEntry(KEY_AUTHOR, authorList1)
|
||||
);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
@@ -578,6 +603,8 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
rssBlog.getGroup().getDescriptor(), timestamp,
|
||||
originalPostBody);
|
||||
will(returnValue(wrappedPostMsg));
|
||||
oneOf(clientHelper).toList(rssLocalAuthor);
|
||||
will(returnValue(rssAuthorList));
|
||||
// Store the wrapped post
|
||||
oneOf(clientHelper).addLocalMessage(txn, wrappedPostMsg,
|
||||
wrappedPostMeta, true);
|
||||
@@ -585,15 +612,21 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
oneOf(blogPostFactory).createBlogComment(blog1.getId(),
|
||||
localAuthor1, comment, rssMessageId, wrappedPostId);
|
||||
will(returnValue(commentMsg));
|
||||
oneOf(clientHelper).toList(localAuthor1);
|
||||
will(returnValue(authorList1));
|
||||
// Store the comment
|
||||
oneOf(clientHelper).addLocalMessage(txn, commentMsg, commentMeta,
|
||||
true);
|
||||
// Create the headers for the comment and the wrapped post
|
||||
oneOf(clientHelper).parseAndValidateAuthor(authorList1);
|
||||
will(returnValue(localAuthor1));
|
||||
oneOf(identityManager).getAuthorStatus(txn, localAuthor1.getId());
|
||||
will(returnValue(OURSELVES));
|
||||
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
||||
wrappedPostId);
|
||||
will(returnValue(wrappedPostMeta));
|
||||
oneOf(clientHelper).parseAndValidateAuthor(rssAuthorList);
|
||||
will(returnValue(rssLocalAuthor));
|
||||
oneOf(db).commitTransaction(txn);
|
||||
oneOf(db).endTransaction(txn);
|
||||
}});
|
||||
@@ -654,7 +687,7 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
new BdfEntry(KEY_TYPE, WRAPPED_POST.getInt()),
|
||||
new BdfEntry(KEY_RSS_FEED, true),
|
||||
new BdfEntry(KEY_ORIGINAL_MSG_ID, messageId),
|
||||
new BdfEntry(KEY_AUTHOR, rssAuthorDict),
|
||||
new BdfEntry(KEY_AUTHOR, rssAuthorList),
|
||||
new BdfEntry(KEY_TIMESTAMP, timestamp),
|
||||
new BdfEntry(KEY_TIME_RECEIVED, timeReceived)
|
||||
);
|
||||
@@ -666,7 +699,7 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
new BdfEntry(KEY_COMMENT, comment),
|
||||
new BdfEntry(KEY_PARENT_MSG_ID, rewrappedPostId),
|
||||
new BdfEntry(KEY_ORIGINAL_MSG_ID, originalCommentId),
|
||||
new BdfEntry(KEY_AUTHOR, authorDict1),
|
||||
new BdfEntry(KEY_AUTHOR, authorList1),
|
||||
new BdfEntry(KEY_TIMESTAMP, timestamp),
|
||||
new BdfEntry(KEY_TIME_RECEIVED, timeReceived)
|
||||
);
|
||||
@@ -681,7 +714,7 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
new BdfEntry(KEY_ORIGINAL_MSG_ID, localCommentId),
|
||||
new BdfEntry(KEY_ORIGINAL_PARENT_MSG_ID, originalCommentId),
|
||||
new BdfEntry(KEY_PARENT_MSG_ID, wrappedCommentId),
|
||||
new BdfEntry(KEY_AUTHOR, authorDict2)
|
||||
new BdfEntry(KEY_AUTHOR, authorList2)
|
||||
);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
@@ -693,6 +726,8 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
oneOf(blogPostFactory).rewrapWrappedPost(blog2.getId(),
|
||||
wrappedPostBody);
|
||||
will(returnValue(rewrappedPostMsg));
|
||||
oneOf(clientHelper).toList(rssLocalAuthor);
|
||||
will(returnValue(rssAuthorList));
|
||||
// Store the rewrapped post
|
||||
oneOf(clientHelper).addLocalMessage(txn, rewrappedPostMsg,
|
||||
rewrappedPostMeta, true);
|
||||
@@ -708,6 +743,8 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
blog1.getGroup().getDescriptor(), timestamp,
|
||||
originalCommentBody, rewrappedPostId);
|
||||
will(returnValue(wrappedCommentMsg));
|
||||
oneOf(clientHelper).toList(localAuthor1);
|
||||
will(returnValue(authorList1));
|
||||
// Store the wrapped comment
|
||||
oneOf(clientHelper).addLocalMessage(txn, wrappedCommentMsg,
|
||||
wrappedCommentMeta, true);
|
||||
@@ -716,21 +753,29 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
localAuthor2, localComment, originalCommentId,
|
||||
wrappedCommentId);
|
||||
will(returnValue(localCommentMsg));
|
||||
oneOf(clientHelper).toList(localAuthor2);
|
||||
will(returnValue(authorList2));
|
||||
// Store the new comment
|
||||
oneOf(clientHelper).addLocalMessage(txn, localCommentMsg,
|
||||
localCommentMeta, true);
|
||||
// Create the headers for the new comment, the wrapped comment and
|
||||
// the rewrapped post
|
||||
oneOf(clientHelper).parseAndValidateAuthor(authorList2);
|
||||
will(returnValue(localAuthor2));
|
||||
oneOf(identityManager).getAuthorStatus(txn, localAuthor2.getId());
|
||||
will(returnValue(OURSELVES));
|
||||
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
||||
wrappedCommentId);
|
||||
will(returnValue(wrappedCommentMeta));
|
||||
oneOf(clientHelper).parseAndValidateAuthor(authorList1);
|
||||
will(returnValue(localAuthor1));
|
||||
oneOf(identityManager).getAuthorStatus(txn, localAuthor1.getId());
|
||||
will(returnValue(VERIFIED));
|
||||
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
||||
rewrappedPostId);
|
||||
will(returnValue(rewrappedPostMeta));
|
||||
oneOf(clientHelper).parseAndValidateAuthor(rssAuthorList);
|
||||
will(returnValue(rssLocalAuthor));
|
||||
oneOf(db).commitTransaction(txn);
|
||||
oneOf(db).endTransaction(txn);
|
||||
}});
|
||||
@@ -827,13 +872,8 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
return new Blog(group, localAuthor, rssFeed);
|
||||
}
|
||||
|
||||
private BdfDictionary authorToBdfDictionary(Author a) {
|
||||
return BdfDictionary.of(
|
||||
new BdfEntry(KEY_AUTHOR_ID, a.getId()),
|
||||
new BdfEntry(KEY_FORMAT_VERSION, a.getFormatVersion()),
|
||||
new BdfEntry(KEY_AUTHOR_NAME, a.getName()),
|
||||
new BdfEntry(KEY_PUBLIC_KEY, a.getPublicKey())
|
||||
);
|
||||
private BdfList authorToBdfList(Author a) {
|
||||
return BdfList.of(a.getFormatVersion(), a.getName(), a.getPublicKey());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package org.briarproject.briar.blog;
|
||||
import org.briarproject.bramble.api.FormatException;
|
||||
import org.briarproject.bramble.api.client.ClientHelper;
|
||||
import org.briarproject.bramble.api.data.BdfDictionary;
|
||||
import org.briarproject.bramble.api.data.BdfEntry;
|
||||
import org.briarproject.bramble.api.data.BdfList;
|
||||
import org.briarproject.bramble.api.data.MetadataEncoder;
|
||||
import org.briarproject.bramble.api.identity.Author;
|
||||
@@ -30,14 +29,10 @@ import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||
import static org.briarproject.bramble.util.StringUtils.getRandomString;
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_AUTHOR;
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_AUTHOR_ID;
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_AUTHOR_NAME;
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_COMMENT;
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_FORMAT_VERSION;
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_ORIGINAL_MSG_ID;
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_ORIGINAL_PARENT_MSG_ID;
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_PARENT_MSG_ID;
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_PUBLIC_KEY;
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_READ;
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_RSS_FEED;
|
||||
import static org.briarproject.briar.api.blog.BlogManager.CLIENT_ID;
|
||||
@@ -55,7 +50,7 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
||||
|
||||
private final Mockery context = new Mockery();
|
||||
private final Blog blog, rssBlog;
|
||||
private final BdfDictionary authorDict;
|
||||
private final BdfList authorList;
|
||||
private final byte[] descriptor;
|
||||
private final Group group;
|
||||
private final Message message;
|
||||
@@ -73,11 +68,10 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
||||
descriptor = getRandomBytes(42);
|
||||
group = new Group(groupId, CLIENT_ID, descriptor);
|
||||
author = getAuthor();
|
||||
authorDict = BdfDictionary.of(
|
||||
new BdfEntry(KEY_AUTHOR_ID, author.getId()),
|
||||
new BdfEntry(KEY_FORMAT_VERSION, author.getFormatVersion()),
|
||||
new BdfEntry(KEY_AUTHOR_NAME, author.getName()),
|
||||
new BdfEntry(KEY_PUBLIC_KEY, author.getPublicKey())
|
||||
authorList = BdfList.of(
|
||||
author.getFormatVersion(),
|
||||
author.getName(),
|
||||
author.getPublicKey()
|
||||
);
|
||||
blog = new Blog(group, author, false);
|
||||
rssBlog = new Blog(group, author, true);
|
||||
@@ -117,7 +111,7 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
||||
BdfDictionary result =
|
||||
validator.validateMessage(message, group, m).getDictionary();
|
||||
|
||||
assertEquals(authorDict, result.getDictionary(KEY_AUTHOR));
|
||||
assertEquals(authorList, result.getList(KEY_AUTHOR));
|
||||
assertFalse(result.getBoolean(KEY_READ));
|
||||
assertEquals(rssFeed, result.getBoolean(KEY_RSS_FEED));
|
||||
context.assertIsSatisfied();
|
||||
@@ -129,7 +123,7 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
||||
BdfList content = BdfList.of(null, null, body);
|
||||
BdfList m = BdfList.of(POST.getInt(), content, null);
|
||||
|
||||
validator.validateMessage(message, group, m).getDictionary();
|
||||
validator.validateMessage(message, group, m);
|
||||
}
|
||||
|
||||
@Test(expected = FormatException.class)
|
||||
@@ -138,7 +132,7 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
||||
BdfList content = BdfList.of(null, null, body, null);
|
||||
BdfList m = BdfList.of(POST.getInt(), content, null);
|
||||
|
||||
validator.validateMessage(message, group, m).getDictionary();
|
||||
validator.validateMessage(message, group, m);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -159,7 +153,7 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
||||
validator.validateMessage(message, group, m).getDictionary();
|
||||
|
||||
assertEquals(comment, result.getString(KEY_COMMENT));
|
||||
assertEquals(authorDict, result.getDictionary(KEY_AUTHOR));
|
||||
assertEquals(authorList, result.getList(KEY_AUTHOR));
|
||||
assertEquals(pOriginalId.getBytes(),
|
||||
result.getRaw(KEY_ORIGINAL_PARENT_MSG_ID));
|
||||
assertEquals(currentId.getBytes(), result.getRaw(KEY_PARENT_MSG_ID));
|
||||
@@ -229,7 +223,7 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
||||
BdfDictionary result =
|
||||
validator.validateMessage(message, group, m).getDictionary();
|
||||
|
||||
assertEquals(authorDict, result.getDictionary(KEY_AUTHOR));
|
||||
assertEquals(authorList, result.getList(KEY_AUTHOR));
|
||||
assertEquals(rssFeed, result.getBoolean(KEY_RSS_FEED));
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
@@ -272,7 +266,7 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
||||
validator.validateMessage(message, group, m).getDictionary();
|
||||
|
||||
assertEquals(comment, result.getString(KEY_COMMENT));
|
||||
assertEquals(authorDict, result.getDictionary(KEY_AUTHOR));
|
||||
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));
|
||||
@@ -284,6 +278,8 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(blogFactory).parseBlog(group);
|
||||
will(returnValue(b));
|
||||
oneOf(clientHelper).toList(b.getAuthor());
|
||||
will(returnValue(authorList));
|
||||
oneOf(clientHelper)
|
||||
.verifySignature(label, sig, author.getPublicKey(), signed);
|
||||
}});
|
||||
|
||||
@@ -22,11 +22,7 @@ import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||
import static org.briarproject.bramble.util.StringUtils.getRandomString;
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_READ;
|
||||
import static org.briarproject.briar.api.forum.ForumConstants.KEY_AUTHOR;
|
||||
import static org.briarproject.briar.api.forum.ForumConstants.KEY_FORMAT_VERSION;
|
||||
import static org.briarproject.briar.api.forum.ForumConstants.KEY_ID;
|
||||
import static org.briarproject.briar.api.forum.ForumConstants.KEY_NAME;
|
||||
import static org.briarproject.briar.api.forum.ForumConstants.KEY_PARENT;
|
||||
import static org.briarproject.briar.api.forum.ForumConstants.KEY_PUBLIC_KEY;
|
||||
import static org.briarproject.briar.api.forum.ForumConstants.KEY_TIMESTAMP;
|
||||
import static org.briarproject.briar.api.forum.ForumConstants.MAX_FORUM_POST_BODY_LENGTH;
|
||||
import static org.briarproject.briar.api.forum.ForumPostFactory.SIGNING_LABEL_POST;
|
||||
@@ -74,7 +70,7 @@ public class ForumPostValidatorTest extends ValidatorTestCase {
|
||||
|
||||
BdfMessageContext messageContext = v.validateMessage(message, group,
|
||||
BdfList.of(null, authorList, content, signature));
|
||||
assertExpectedContext(messageContext, false, authorName);
|
||||
assertExpectedContext(messageContext, false);
|
||||
}
|
||||
|
||||
@Test(expected = FormatException.class)
|
||||
@@ -149,7 +145,7 @@ public class ForumPostValidatorTest extends ValidatorTestCase {
|
||||
|
||||
BdfMessageContext messageContext = v.validateMessage(message, group,
|
||||
BdfList.of(parentId, authorList, shortContent, signature));
|
||||
assertExpectedContext(messageContext, true, authorName);
|
||||
assertExpectedContext(messageContext, true);
|
||||
}
|
||||
|
||||
@Test(expected = FormatException.class)
|
||||
@@ -224,7 +220,7 @@ public class ForumPostValidatorTest extends ValidatorTestCase {
|
||||
}
|
||||
|
||||
private void assertExpectedContext(BdfMessageContext messageContext,
|
||||
boolean hasParent, String authorName) throws FormatException {
|
||||
boolean hasParent) throws FormatException {
|
||||
BdfDictionary meta = messageContext.getDictionary();
|
||||
Collection<MessageId> dependencies = messageContext.getDependencies();
|
||||
if (hasParent) {
|
||||
@@ -238,12 +234,6 @@ public class ForumPostValidatorTest extends ValidatorTestCase {
|
||||
}
|
||||
assertEquals(timestamp, meta.getLong(KEY_TIMESTAMP).longValue());
|
||||
assertFalse(meta.getBoolean(KEY_READ));
|
||||
BdfDictionary authorMeta = meta.getDictionary(KEY_AUTHOR);
|
||||
assertEquals(4, authorMeta.size());
|
||||
assertArrayEquals(author.getId().getBytes(), authorMeta.getRaw(KEY_ID));
|
||||
assertEquals(author.getFormatVersion(),
|
||||
authorMeta.getLong(KEY_FORMAT_VERSION).intValue());
|
||||
assertEquals(authorName, authorMeta.getString(KEY_NAME));
|
||||
assertArrayEquals(authorPublicKey, authorMeta.getRaw(KEY_PUBLIC_KEY));
|
||||
assertEquals(authorList, meta.getList(KEY_AUTHOR));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,10 +34,7 @@ import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_
|
||||
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_GROUP_POST_BODY_LENGTH;
|
||||
import static org.briarproject.briar.api.privategroup.invitation.GroupInvitationFactory.SIGNING_LABEL_INVITE;
|
||||
import static org.briarproject.briar.privategroup.GroupConstants.KEY_INITIAL_JOIN_MSG;
|
||||
import static org.briarproject.briar.privategroup.GroupConstants.KEY_MEMBER_FORMAT_VERSION;
|
||||
import static org.briarproject.briar.privategroup.GroupConstants.KEY_MEMBER_ID;
|
||||
import static org.briarproject.briar.privategroup.GroupConstants.KEY_MEMBER_NAME;
|
||||
import static org.briarproject.briar.privategroup.GroupConstants.KEY_MEMBER_PUBLIC_KEY;
|
||||
import static org.briarproject.briar.privategroup.GroupConstants.KEY_MEMBER;
|
||||
import static org.briarproject.briar.privategroup.GroupConstants.KEY_PARENT_MSG_ID;
|
||||
import static org.briarproject.briar.privategroup.GroupConstants.KEY_PREVIOUS_MSG_ID;
|
||||
import static org.briarproject.briar.privategroup.GroupConstants.KEY_READ;
|
||||
@@ -180,7 +177,7 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
|
||||
memberSignature);
|
||||
BdfMessageContext messageContext =
|
||||
validator.validateMessage(message, group, body);
|
||||
assertExpectedMessageContext(messageContext, JOIN, creator,
|
||||
assertExpectedMessageContext(messageContext, JOIN, creatorList,
|
||||
Collections.emptyList());
|
||||
assertTrue(messageContext.getDictionary()
|
||||
.getBoolean(KEY_INITIAL_JOIN_MSG));
|
||||
@@ -365,7 +362,7 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
|
||||
memberSignature);
|
||||
BdfMessageContext messageContext =
|
||||
validator.validateMessage(message, group, body);
|
||||
assertExpectedMessageContext(messageContext, JOIN, member,
|
||||
assertExpectedMessageContext(messageContext, JOIN, memberList,
|
||||
Collections.emptyList());
|
||||
assertFalse(messageContext.getDictionary()
|
||||
.getBoolean(KEY_INITIAL_JOIN_MSG));
|
||||
@@ -616,7 +613,7 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
|
||||
expectPostMessage(parentId, true);
|
||||
BdfMessageContext messageContext =
|
||||
validator.validateMessage(message, group, body);
|
||||
assertExpectedMessageContext(messageContext, POST, member,
|
||||
assertExpectedMessageContext(messageContext, POST, memberList,
|
||||
Arrays.asList(parentId, previousMsgId));
|
||||
assertArrayEquals(previousMsgId.getBytes(),
|
||||
messageContext.getDictionary().getRaw(KEY_PREVIOUS_MSG_ID));
|
||||
@@ -631,7 +628,7 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
|
||||
expectPostMessage(null, true);
|
||||
BdfMessageContext messageContext =
|
||||
validator.validateMessage(message, group, body);
|
||||
assertExpectedMessageContext(messageContext, POST, member,
|
||||
assertExpectedMessageContext(messageContext, POST, memberList,
|
||||
Collections.singletonList(previousMsgId));
|
||||
assertArrayEquals(previousMsgId.getBytes(),
|
||||
messageContext.getDictionary().getRaw(KEY_PREVIOUS_MSG_ID));
|
||||
@@ -659,18 +656,14 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
|
||||
}
|
||||
|
||||
private void assertExpectedMessageContext(BdfMessageContext c,
|
||||
MessageType type, Author member,
|
||||
MessageType type, BdfList member,
|
||||
Collection<MessageId> dependencies) throws FormatException {
|
||||
BdfDictionary d = c.getDictionary();
|
||||
assertEquals(type.getInt(), d.getLong(KEY_TYPE).intValue());
|
||||
assertEquals(message.getTimestamp(),
|
||||
d.getLong(KEY_TIMESTAMP).longValue());
|
||||
assertFalse(d.getBoolean(KEY_READ));
|
||||
assertEquals(member.getId().getBytes(), d.getRaw(KEY_MEMBER_ID));
|
||||
assertEquals(member.getFormatVersion(),
|
||||
d.getLong(KEY_MEMBER_FORMAT_VERSION).intValue());
|
||||
assertEquals(member.getName(), d.getString(KEY_MEMBER_NAME));
|
||||
assertEquals(member.getPublicKey(), d.getRaw(KEY_MEMBER_PUBLIC_KEY));
|
||||
assertEquals(member, d.getList(KEY_MEMBER));
|
||||
assertEquals(dependencies, c.getDependencies());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user