mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 02:39:05 +01:00
Merge branch '941-reblogged-rss-post-has-wrong-icon' into 'master'
Store RSS flag for wrapped blog posts Closes #941 See merge request !524
This commit is contained in:
@@ -63,7 +63,7 @@ class BlogFactoryImpl implements BlogFactory {
|
||||
@Override
|
||||
public Blog parseBlog(Group group) throws FormatException {
|
||||
byte[] descriptor = group.getDescriptor();
|
||||
// Author Name, Public Key
|
||||
// Author name, public key, RSS feed
|
||||
BdfList blog = clientHelper.toList(descriptor);
|
||||
String name = blog.getString(0);
|
||||
if (name.length() > MAX_AUTHOR_NAME_LENGTH)
|
||||
@@ -72,8 +72,7 @@ class BlogFactoryImpl implements BlogFactory {
|
||||
if (publicKey.length > MAX_PUBLIC_KEY_LENGTH)
|
||||
throw new IllegalArgumentException();
|
||||
|
||||
Author author =
|
||||
authorFactory.createAuthor(name, publicKey);
|
||||
Author author = authorFactory.createAuthor(name, publicKey);
|
||||
boolean rssFeed = blog.getBoolean(2);
|
||||
return new Blog(group, author, rssFeed);
|
||||
}
|
||||
|
||||
@@ -373,6 +373,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
||||
// Re-wrap wrapped post without adding another wrapping layer
|
||||
wMessage = blogPostFactory.rewrapWrappedPost(groupId, body);
|
||||
meta.put(KEY_TYPE, WRAPPED_POST.getInt());
|
||||
meta.put(KEY_RSS_FEED, pOriginalHeader.isRssFeed());
|
||||
} else if (type == WRAPPED_COMMENT) {
|
||||
BlogCommentHeader wComment = (BlogCommentHeader) pOriginalHeader;
|
||||
MessageId wrappedId =
|
||||
|
||||
@@ -201,6 +201,7 @@ class BlogPostValidator extends BdfMessageValidator {
|
||||
// Get and Validate the Wrapped Message
|
||||
Group wGroup = groupFactory
|
||||
.createGroup(BlogManagerImpl.CLIENT_ID, descriptor);
|
||||
Blog wBlog = blogFactory.parseBlog(wGroup);
|
||||
BdfList wBodyList = BdfList.of(POST.getInt(), content, signature);
|
||||
byte[] wBody = clientHelper.toByteArray(wBodyList);
|
||||
Message wMessage =
|
||||
@@ -213,6 +214,7 @@ class BlogPostValidator extends BdfMessageValidator {
|
||||
meta.put(KEY_ORIGINAL_MSG_ID, wMessage.getId());
|
||||
meta.put(KEY_TIMESTAMP, wTimestamp);
|
||||
meta.put(KEY_AUTHOR, c.getDictionary().getDictionary(KEY_AUTHOR));
|
||||
meta.put(KEY_RSS_FEED, wBlog.isRssFeed());
|
||||
return new BdfMessageContext(meta);
|
||||
}
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@ 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_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;
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_TIME_RECEIVED;
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_TYPE;
|
||||
@@ -198,12 +199,17 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
new BdfEntry(KEY_TYPE, POST.getInt()),
|
||||
new BdfEntry(KEY_TIMESTAMP, message.getTimestamp()),
|
||||
new BdfEntry(KEY_AUTHOR, authorMeta),
|
||||
new BdfEntry(KEY_READ, true)
|
||||
new BdfEntry(KEY_READ, true),
|
||||
new BdfEntry(KEY_RSS_FEED, false)
|
||||
);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).startTransaction(false);
|
||||
will(returnValue(txn));
|
||||
oneOf(db).getGroup(txn, blog1.getId());
|
||||
will(returnValue(blog1.getGroup()));
|
||||
oneOf(blogFactory).parseBlog(blog1.getGroup());
|
||||
will(returnValue(blog1));
|
||||
oneOf(clientHelper)
|
||||
.addLocalMessage(txn, message, meta, true);
|
||||
oneOf(identityManager)
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.briarproject.briar.blog;
|
||||
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.bramble.test.TestDatabaseModule;
|
||||
import org.briarproject.briar.api.blog.Blog;
|
||||
@@ -22,6 +23,9 @@ import java.util.Iterator;
|
||||
|
||||
import static junit.framework.Assert.assertFalse;
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
|
||||
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomString;
|
||||
import static org.briarproject.briar.api.blog.MessageType.COMMENT;
|
||||
import static org.briarproject.briar.api.blog.MessageType.POST;
|
||||
@@ -35,6 +39,7 @@ public class BlogManagerIntegrationTest
|
||||
|
||||
private BlogManager blogManager0, blogManager1;
|
||||
private Blog blog0, blog1, rssBlog;
|
||||
private LocalAuthor rssAuthor;
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
@@ -46,6 +51,10 @@ public class BlogManagerIntegrationTest
|
||||
|
||||
author0 = identityManager0.getLocalAuthor();
|
||||
author1 = identityManager1.getLocalAuthor();
|
||||
rssAuthor = c0.getAuthorFactory().createLocalAuthor(
|
||||
getRandomString(MAX_AUTHOR_NAME_LENGTH),
|
||||
getRandomBytes(MAX_PUBLIC_KEY_LENGTH),
|
||||
getRandomBytes(123));
|
||||
|
||||
blogManager0 = c0.getBlogManager();
|
||||
blogManager1 = c1.getBlogManager();
|
||||
@@ -53,7 +62,7 @@ public class BlogManagerIntegrationTest
|
||||
blog0 = blogFactory.createBlog(author0);
|
||||
blog1 = blogFactory.createBlog(author1);
|
||||
|
||||
rssBlog = blogFactory.createFeedBlog(author0);
|
||||
rssBlog = blogFactory.createFeedBlog(rssAuthor);
|
||||
Transaction txn = db0.startTransaction(false);
|
||||
blogManager0.addBlog(txn, rssBlog);
|
||||
db0.commitTransaction(txn);
|
||||
@@ -82,11 +91,12 @@ public class BlogManagerIntegrationTest
|
||||
@Test
|
||||
public void testPersonalBlogInitialisation() throws Exception {
|
||||
Collection<Blog> blogs0 = blogManager0.getBlogs();
|
||||
assertEquals(3, blogs0.size());
|
||||
assertEquals(4, blogs0.size());
|
||||
Iterator<Blog> i0 = blogs0.iterator();
|
||||
assertEquals(author0, i0.next().getAuthor());
|
||||
assertEquals(author1, i0.next().getAuthor());
|
||||
assertEquals(author2, i0.next().getAuthor());
|
||||
assertEquals(rssAuthor, i0.next().getAuthor());
|
||||
|
||||
Collection<Blog> blogs1 = blogManager1.getBlogs();
|
||||
assertEquals(2, blogs1.size());
|
||||
@@ -103,11 +113,14 @@ public class BlogManagerIntegrationTest
|
||||
assertEquals(blog0, blogManager1.getBlog(blog0.getId()));
|
||||
assertEquals(blog1, blogManager0.getBlog(blog1.getId()));
|
||||
assertEquals(blog1, blogManager1.getBlog(blog1.getId()));
|
||||
assertEquals(rssBlog, blogManager0.getBlog(rssBlog.getId()));
|
||||
|
||||
assertEquals(1, blogManager0.getBlogs(author0).size());
|
||||
assertEquals(1, blogManager1.getBlogs(author0).size());
|
||||
assertEquals(1, blogManager0.getBlogs(author1).size());
|
||||
assertEquals(1, blogManager1.getBlogs(author1).size());
|
||||
assertEquals(1, blogManager0.getBlogs(rssAuthor).size());
|
||||
assertEquals(0, blogManager1.getBlogs(rssAuthor).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -287,9 +300,8 @@ public class BlogManagerIntegrationTest
|
||||
assertEquals(POST, headers1.iterator().next().getType());
|
||||
|
||||
// 1 reblogs that blog post
|
||||
blogManager1
|
||||
.addLocalComment(author1, blog1.getId(), null,
|
||||
headers1.iterator().next());
|
||||
blogManager1.addLocalComment(author1, blog1.getId(), null,
|
||||
headers1.iterator().next());
|
||||
|
||||
// sync comment over
|
||||
sync1To0(2, true);
|
||||
@@ -312,8 +324,7 @@ public class BlogManagerIntegrationTest
|
||||
sync0To1(3, true);
|
||||
|
||||
// check that comment arrived
|
||||
headers1 =
|
||||
blogManager1.getPostHeaders(blog0.getId());
|
||||
headers1 = blogManager1.getPostHeaders(blog0.getId());
|
||||
assertEquals(2, headers1.size());
|
||||
|
||||
// get header of comment
|
||||
@@ -453,7 +464,7 @@ public class BlogManagerIntegrationTest
|
||||
// make sure it got saved as an RSS feed post
|
||||
headers = blogManager0.getPostHeaders(blog0.getId());
|
||||
assertEquals(2, headers.size());
|
||||
for (BlogPostHeader h: headers) {
|
||||
for (BlogPostHeader h : headers) {
|
||||
assertTrue(h instanceof BlogCommentHeader);
|
||||
assertEquals(COMMENT, h.getType());
|
||||
assertTrue(((BlogCommentHeader) h).getRootPost().isRssFeed());
|
||||
|
||||
@@ -38,6 +38,7 @@ import static org.briarproject.briar.api.blog.BlogConstants.KEY_ORIGINAL_PARENT_
|
||||
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.BlogPostFactory.SIGNING_LABEL_COMMENT;
|
||||
import static org.briarproject.briar.api.blog.BlogPostFactory.SIGNING_LABEL_POST;
|
||||
import static org.briarproject.briar.api.blog.MessageType.COMMENT;
|
||||
@@ -50,7 +51,7 @@ import static org.junit.Assert.assertFalse;
|
||||
public class BlogPostValidatorTest extends BriarTestCase {
|
||||
|
||||
private final Mockery context = new Mockery();
|
||||
private final Blog blog;
|
||||
private final Blog blog, rssBlog;
|
||||
private final BdfDictionary authorDict;
|
||||
private final ClientId clientId;
|
||||
private final byte[] descriptor;
|
||||
@@ -80,6 +81,7 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
||||
new BdfEntry(KEY_PUBLIC_KEY, author.getPublicKey())
|
||||
);
|
||||
blog = new Blog(group, author, false);
|
||||
rssBlog = new Blog(group, author, true);
|
||||
|
||||
MessageId messageId = new MessageId(TestUtils.getRandomId());
|
||||
long timestamp = System.currentTimeMillis();
|
||||
@@ -97,17 +99,28 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
||||
@Test
|
||||
public void testValidateProperBlogPost()
|
||||
throws IOException, GeneralSecurityException {
|
||||
testValidateProperBlogPost(blog, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateProperRssBlogPost()
|
||||
throws IOException, GeneralSecurityException {
|
||||
testValidateProperBlogPost(rssBlog, true);
|
||||
}
|
||||
|
||||
private void testValidateProperBlogPost(Blog b, boolean rssFeed)
|
||||
throws IOException, GeneralSecurityException {
|
||||
final byte[] sigBytes = TestUtils.getRandomBytes(42);
|
||||
BdfList m = BdfList.of(POST.getInt(), body, sigBytes);
|
||||
|
||||
BdfList signed =
|
||||
BdfList.of(blog.getId(), message.getTimestamp(), body);
|
||||
expectCrypto(SIGNING_LABEL_POST, signed, sigBytes);
|
||||
BdfList signed = BdfList.of(b.getId(), message.getTimestamp(), body);
|
||||
expectCrypto(b, SIGNING_LABEL_POST, signed, sigBytes);
|
||||
final BdfDictionary result =
|
||||
validator.validateMessage(message, group, m).getDictionary();
|
||||
|
||||
assertEquals(authorDict, result.getDictionary(KEY_AUTHOR));
|
||||
assertFalse(result.getBoolean(KEY_READ));
|
||||
assertEquals(rssFeed, result.getBoolean(KEY_RSS_FEED));
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
|
||||
@@ -137,14 +150,12 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
||||
MessageId pOriginalId = new MessageId(TestUtils.getRandomId());
|
||||
MessageId currentId = new MessageId(TestUtils.getRandomId());
|
||||
final byte[] sigBytes = TestUtils.getRandomBytes(42);
|
||||
BdfList m =
|
||||
BdfList.of(COMMENT.getInt(), comment, pOriginalId, currentId,
|
||||
sigBytes);
|
||||
BdfList m = BdfList.of(COMMENT.getInt(), comment, pOriginalId,
|
||||
currentId, sigBytes);
|
||||
|
||||
BdfList signed =
|
||||
BdfList.of(blog.getId(), message.getTimestamp(), comment,
|
||||
pOriginalId, currentId);
|
||||
expectCrypto(SIGNING_LABEL_COMMENT, signed, sigBytes);
|
||||
BdfList signed = BdfList.of(blog.getId(), message.getTimestamp(),
|
||||
comment, pOriginalId, currentId);
|
||||
expectCrypto(blog, SIGNING_LABEL_COMMENT, signed, sigBytes);
|
||||
final BdfDictionary result =
|
||||
validator.validateMessage(message, group, m).getDictionary();
|
||||
|
||||
@@ -164,14 +175,12 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
||||
MessageId originalId = new MessageId(TestUtils.getRandomId());
|
||||
MessageId currentId = new MessageId(TestUtils.getRandomId());
|
||||
final byte[] sigBytes = TestUtils.getRandomBytes(42);
|
||||
BdfList m =
|
||||
BdfList.of(COMMENT.getInt(), null, originalId, currentId,
|
||||
sigBytes);
|
||||
BdfList m = BdfList.of(COMMENT.getInt(), null, originalId, currentId,
|
||||
sigBytes);
|
||||
|
||||
BdfList signed =
|
||||
BdfList.of(blog.getId(), message.getTimestamp(), null,
|
||||
originalId, currentId);
|
||||
expectCrypto(SIGNING_LABEL_COMMENT, signed, sigBytes);
|
||||
BdfList signed = BdfList.of(blog.getId(), message.getTimestamp(), null,
|
||||
originalId, currentId);
|
||||
expectCrypto(blog, SIGNING_LABEL_COMMENT, signed, sigBytes);
|
||||
final BdfDictionary result =
|
||||
validator.validateMessage(message, group, m).getDictionary();
|
||||
|
||||
@@ -182,22 +191,33 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
||||
@Test
|
||||
public void testValidateProperWrappedPost()
|
||||
throws IOException, GeneralSecurityException {
|
||||
testValidateProperWrappedPost(blog, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateProperWrappedRssPost()
|
||||
throws IOException, GeneralSecurityException {
|
||||
testValidateProperWrappedPost(rssBlog, true);
|
||||
}
|
||||
|
||||
private void testValidateProperWrappedPost(final Blog b, boolean rssFeed)
|
||||
throws IOException, GeneralSecurityException {
|
||||
// group descriptor, timestamp, content, signature
|
||||
final byte[] sigBytes = TestUtils.getRandomBytes(42);
|
||||
BdfList m =
|
||||
BdfList.of(WRAPPED_POST.getInt(), descriptor,
|
||||
message.getTimestamp(), body, sigBytes);
|
||||
BdfList m = BdfList.of(WRAPPED_POST.getInt(), descriptor,
|
||||
message.getTimestamp(), body, sigBytes);
|
||||
|
||||
BdfList signed =
|
||||
BdfList.of(blog.getId(), message.getTimestamp(), body);
|
||||
expectCrypto(SIGNING_LABEL_POST, signed, sigBytes);
|
||||
BdfList signed = BdfList.of(b.getId(), message.getTimestamp(), body);
|
||||
expectCrypto(b, SIGNING_LABEL_POST, signed, sigBytes);
|
||||
|
||||
final BdfList originalList = BdfList.of(POST.getInt(), body, sigBytes);
|
||||
final byte[] originalBody = TestUtils.getRandomBytes(42);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(groupFactory).createGroup(clientId, descriptor);
|
||||
will(returnValue(blog.getGroup()));
|
||||
will(returnValue(b.getGroup()));
|
||||
oneOf(blogFactory).parseBlog(b.getGroup());
|
||||
will(returnValue(b));
|
||||
oneOf(clientHelper).toByteArray(originalList);
|
||||
will(returnValue(originalBody));
|
||||
oneOf(messageFactory)
|
||||
@@ -210,6 +230,7 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
||||
validator.validateMessage(message, group, m).getDictionary();
|
||||
|
||||
assertEquals(authorDict, result.getDictionary(KEY_AUTHOR));
|
||||
assertEquals(rssFeed, result.getBoolean(KEY_RSS_FEED));
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
|
||||
@@ -229,7 +250,7 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
||||
|
||||
BdfList signed = BdfList.of(blog.getId(), message.getTimestamp(),
|
||||
comment, originalId, oldId);
|
||||
expectCrypto(SIGNING_LABEL_COMMENT, signed, sigBytes);
|
||||
expectCrypto(blog, SIGNING_LABEL_COMMENT, signed, sigBytes);
|
||||
|
||||
final BdfList originalList = BdfList.of(COMMENT.getInt(), comment,
|
||||
originalId, oldId, sigBytes);
|
||||
@@ -257,11 +278,12 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
|
||||
private void expectCrypto(final String label, final BdfList signed,
|
||||
final byte[] sig) throws IOException, GeneralSecurityException {
|
||||
private void expectCrypto(final Blog b, final String label,
|
||||
final BdfList signed, final byte[] sig)
|
||||
throws IOException, GeneralSecurityException {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(blogFactory).parseBlog(group);
|
||||
will(returnValue(blog));
|
||||
will(returnValue(b));
|
||||
oneOf(clientHelper)
|
||||
.verifySignature(label, sig, author.getPublicKey(), signed);
|
||||
}});
|
||||
|
||||
@@ -4,6 +4,7 @@ import org.briarproject.bramble.api.client.ClientHelper;
|
||||
import org.briarproject.bramble.api.contact.ContactManager;
|
||||
import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||
import org.briarproject.bramble.api.event.EventBus;
|
||||
import org.briarproject.bramble.api.identity.AuthorFactory;
|
||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||
import org.briarproject.bramble.api.properties.TransportPropertyManager;
|
||||
@@ -136,4 +137,5 @@ public interface BriarIntegrationTestComponent {
|
||||
|
||||
TransportPropertyManager getTransportPropertyManager();
|
||||
|
||||
AuthorFactory getAuthorFactory();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user