mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-19 14:19:53 +01:00
Use author encoding and parsing helpers everywhere.
This commit is contained in:
@@ -44,8 +44,8 @@ class RssFeedAdapter extends BriarAdapter<Feed, RssFeedAdapter.FeedViewHolder> {
|
|||||||
ui.delete.setOnClickListener(v -> listener.onDeleteClick(item));
|
ui.delete.setOnClickListener(v -> listener.onDeleteClick(item));
|
||||||
|
|
||||||
// Author
|
// Author
|
||||||
if (item.getAuthor() != null) {
|
if (item.getRssAuthor() != null) {
|
||||||
ui.author.setText(item.getAuthor());
|
ui.author.setText(item.getRssAuthor());
|
||||||
ui.author.setVisibility(VISIBLE);
|
ui.author.setVisibility(VISIBLE);
|
||||||
ui.authorLabel.setVisibility(VISIBLE);
|
ui.authorLabel.setVisibility(VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -24,10 +24,6 @@ public interface BlogConstants {
|
|||||||
String KEY_TYPE = "type";
|
String KEY_TYPE = "type";
|
||||||
String KEY_TIMESTAMP = "timestamp";
|
String KEY_TIMESTAMP = "timestamp";
|
||||||
String KEY_TIME_RECEIVED = "timeReceived";
|
String KEY_TIME_RECEIVED = "timeReceived";
|
||||||
String KEY_AUTHOR_ID = "id";
|
|
||||||
String KEY_FORMAT_VERSION = "formatVersion";
|
|
||||||
String KEY_AUTHOR_NAME = "name";
|
|
||||||
String KEY_PUBLIC_KEY = "publicKey";
|
|
||||||
String KEY_AUTHOR = "author";
|
String KEY_AUTHOR = "author";
|
||||||
String KEY_RSS_FEED = "rssFeed";
|
String KEY_RSS_FEED = "rssFeed";
|
||||||
String KEY_READ = "read";
|
String KEY_READ = "read";
|
||||||
|
|||||||
@@ -16,26 +16,26 @@ public class Feed {
|
|||||||
private final Blog blog;
|
private final Blog blog;
|
||||||
private final LocalAuthor localAuthor;
|
private final LocalAuthor localAuthor;
|
||||||
@Nullable
|
@Nullable
|
||||||
private final String description, author;
|
private final String description, rssAuthor;
|
||||||
private final long added, updated, lastEntryTime;
|
private final long added, updated, lastEntryTime;
|
||||||
|
|
||||||
public Feed(String url, Blog blog, LocalAuthor localAuthor,
|
public Feed(String url, Blog blog, LocalAuthor localAuthor,
|
||||||
@Nullable String description, @Nullable String author, long added,
|
@Nullable String description, @Nullable String rssAuthor,
|
||||||
long updated, long lastEntryTime) {
|
long added, long updated, long lastEntryTime) {
|
||||||
|
|
||||||
this.url = url;
|
this.url = url;
|
||||||
this.blog = blog;
|
this.blog = blog;
|
||||||
this.localAuthor = localAuthor;
|
this.localAuthor = localAuthor;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.author = author;
|
this.rssAuthor = rssAuthor;
|
||||||
this.added = added;
|
this.added = added;
|
||||||
this.updated = updated;
|
this.updated = updated;
|
||||||
this.lastEntryTime = lastEntryTime;
|
this.lastEntryTime = lastEntryTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Feed(String url, Blog blog, LocalAuthor localAuthor,
|
public Feed(String url, Blog blog, LocalAuthor localAuthor,
|
||||||
@Nullable String description, @Nullable String author, long added) {
|
@Nullable String description, @Nullable String rssAuthor,
|
||||||
this(url, blog, localAuthor, description, author, added, 0L, 0L);
|
long added) {
|
||||||
|
this(url, blog, localAuthor, description, rssAuthor, added, 0L, 0L);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Feed(String url, Blog blog, LocalAuthor localAuthor, long added) {
|
public Feed(String url, Blog blog, LocalAuthor localAuthor, long added) {
|
||||||
@@ -68,8 +68,8 @@ public class Feed {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public String getAuthor() {
|
public String getRssAuthor() {
|
||||||
return author;
|
return rssAuthor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getAdded() {
|
public long getAdded() {
|
||||||
|
|||||||
@@ -18,12 +18,10 @@ public interface FeedConstants {
|
|||||||
// group metadata keys
|
// group metadata keys
|
||||||
String KEY_FEEDS = "feeds";
|
String KEY_FEEDS = "feeds";
|
||||||
String KEY_FEED_URL = "feedURL";
|
String KEY_FEED_URL = "feedURL";
|
||||||
String KEY_FORMAT_VERSION = "formatVersion";
|
|
||||||
String KEY_BLOG_TITLE = "blogTitle";
|
|
||||||
String KEY_PUBLIC_KEY = "publicKey";
|
|
||||||
String KEY_PRIVATE_KEY = "privateKey";
|
|
||||||
String KEY_FEED_DESC = "feedDesc";
|
|
||||||
String KEY_FEED_AUTHOR = "feedAuthor";
|
String KEY_FEED_AUTHOR = "feedAuthor";
|
||||||
|
String KEY_FEED_PRIVATE_KEY = "feedPrivateKey";
|
||||||
|
String KEY_FEED_DESC = "feedDesc";
|
||||||
|
String KEY_FEED_RSS_AUTHOR = "feedRssAuthor";
|
||||||
String KEY_FEED_ADDED = "feedAdded";
|
String KEY_FEED_ADDED = "feedAdded";
|
||||||
String KEY_FEED_UPDATED = "feedUpdated";
|
String KEY_FEED_UPDATED = "feedUpdated";
|
||||||
String KEY_FEED_LAST_ENTRY = "feedLastEntryTime";
|
String KEY_FEED_LAST_ENTRY = "feedLastEntryTime";
|
||||||
|
|||||||
@@ -23,10 +23,6 @@ public interface ForumConstants {
|
|||||||
String KEY_TIMESTAMP = "timestamp";
|
String KEY_TIMESTAMP = "timestamp";
|
||||||
String KEY_PARENT = "parent";
|
String KEY_PARENT = "parent";
|
||||||
String KEY_AUTHOR = "author";
|
String KEY_AUTHOR = "author";
|
||||||
String KEY_ID = "id";
|
|
||||||
String KEY_FORMAT_VERSION = "formatVersion";
|
|
||||||
String KEY_NAME = "name";
|
|
||||||
String KEY_PUBLIC_KEY = "publicKey";
|
|
||||||
String KEY_LOCAL = "local";
|
String KEY_LOCAL = "local";
|
||||||
String KEY_READ = "read";
|
String KEY_READ = "read";
|
||||||
|
|
||||||
|
|||||||
@@ -11,12 +11,12 @@ public interface PrivateGroupFactory {
|
|||||||
/**
|
/**
|
||||||
* Creates a private group with the given name and author.
|
* Creates a private group with the given name and author.
|
||||||
*/
|
*/
|
||||||
PrivateGroup createPrivateGroup(String name, Author author);
|
PrivateGroup createPrivateGroup(String name, Author creator);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a private group with the given name, author and salt.
|
* Creates a private group with the given name, author and salt.
|
||||||
*/
|
*/
|
||||||
PrivateGroup createPrivateGroup(String name, Author author, byte[] salt);
|
PrivateGroup createPrivateGroup(String name, Author creator, byte[] salt);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses a group and returns the corresponding PrivateGroup.
|
* Parses a group and returns the corresponding PrivateGroup.
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import org.briarproject.bramble.api.FormatException;
|
|||||||
import org.briarproject.bramble.api.client.ClientHelper;
|
import org.briarproject.bramble.api.client.ClientHelper;
|
||||||
import org.briarproject.bramble.api.data.BdfList;
|
import org.briarproject.bramble.api.data.BdfList;
|
||||||
import org.briarproject.bramble.api.identity.Author;
|
import org.briarproject.bramble.api.identity.Author;
|
||||||
import org.briarproject.bramble.api.identity.AuthorFactory;
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.sync.Group;
|
import org.briarproject.bramble.api.sync.Group;
|
||||||
import org.briarproject.bramble.api.sync.GroupFactory;
|
import org.briarproject.bramble.api.sync.GroupFactory;
|
||||||
@@ -23,15 +22,12 @@ import static org.briarproject.briar.api.blog.BlogManager.CLIENT_VERSION;
|
|||||||
class BlogFactoryImpl implements BlogFactory {
|
class BlogFactoryImpl implements BlogFactory {
|
||||||
|
|
||||||
private final GroupFactory groupFactory;
|
private final GroupFactory groupFactory;
|
||||||
private final AuthorFactory authorFactory;
|
|
||||||
private final ClientHelper clientHelper;
|
private final ClientHelper clientHelper;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
BlogFactoryImpl(GroupFactory groupFactory, AuthorFactory authorFactory,
|
BlogFactoryImpl(GroupFactory groupFactory, ClientHelper clientHelper) {
|
||||||
ClientHelper clientHelper) {
|
|
||||||
|
|
||||||
this.groupFactory = groupFactory;
|
this.groupFactory = groupFactory;
|
||||||
this.authorFactory = authorFactory;
|
|
||||||
this.clientHelper = clientHelper;
|
this.clientHelper = clientHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,12 +43,7 @@ class BlogFactoryImpl implements BlogFactory {
|
|||||||
|
|
||||||
private Blog createBlog(Author a, boolean rssFeed) {
|
private Blog createBlog(Author a, boolean rssFeed) {
|
||||||
try {
|
try {
|
||||||
BdfList authorList = BdfList.of(
|
BdfList blog = BdfList.of(clientHelper.toList(a), rssFeed);
|
||||||
a.getFormatVersion(),
|
|
||||||
a.getName(),
|
|
||||||
a.getPublicKey()
|
|
||||||
);
|
|
||||||
BdfList blog = BdfList.of(authorList, rssFeed);
|
|
||||||
byte[] descriptor = clientHelper.toByteArray(blog);
|
byte[] descriptor = clientHelper.toByteArray(blog);
|
||||||
Group g = groupFactory.createGroup(CLIENT_ID, CLIENT_VERSION,
|
Group g = groupFactory.createGroup(CLIENT_ID, CLIENT_VERSION,
|
||||||
descriptor);
|
descriptor);
|
||||||
|
|||||||
@@ -49,16 +49,11 @@ import javax.annotation.Nullable;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import static org.briarproject.bramble.api.contact.ContactManager.RemoveContactHook;
|
import static org.briarproject.bramble.api.contact.ContactManager.RemoveContactHook;
|
||||||
import static org.briarproject.bramble.api.identity.Author.FORMAT_VERSION;
|
|
||||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_AUTHOR;
|
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_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_MSG_ID;
|
||||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_ORIGINAL_PARENT_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_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_READ;
|
||||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_RSS_FEED;
|
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_TIMESTAMP;
|
||||||
@@ -68,7 +63,6 @@ import static org.briarproject.briar.api.blog.MessageType.COMMENT;
|
|||||||
import static org.briarproject.briar.api.blog.MessageType.POST;
|
import static org.briarproject.briar.api.blog.MessageType.POST;
|
||||||
import static org.briarproject.briar.api.blog.MessageType.WRAPPED_COMMENT;
|
import static org.briarproject.briar.api.blog.MessageType.WRAPPED_COMMENT;
|
||||||
import static org.briarproject.briar.api.blog.MessageType.WRAPPED_POST;
|
import static org.briarproject.briar.api.blog.MessageType.WRAPPED_POST;
|
||||||
import static org.briarproject.briar.blog.BlogPostValidator.authorToBdfDictionary;
|
|
||||||
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
||||||
@@ -229,7 +223,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
|||||||
BdfDictionary meta = new BdfDictionary();
|
BdfDictionary meta = new BdfDictionary();
|
||||||
meta.put(KEY_TYPE, POST.getInt());
|
meta.put(KEY_TYPE, POST.getInt());
|
||||||
meta.put(KEY_TIMESTAMP, p.getMessage().getTimestamp());
|
meta.put(KEY_TIMESTAMP, p.getMessage().getTimestamp());
|
||||||
meta.put(KEY_AUTHOR, authorToBdfDictionary(p.getAuthor()));
|
meta.put(KEY_AUTHOR, clientHelper.toList(p.getAuthor()));
|
||||||
meta.put(KEY_READ, true);
|
meta.put(KEY_READ, true);
|
||||||
meta.put(KEY_RSS_FEED, b.isRssFeed());
|
meta.put(KEY_RSS_FEED, b.isRssFeed());
|
||||||
clientHelper.addLocalMessage(txn, p.getMessage(), meta, true);
|
clientHelper.addLocalMessage(txn, p.getMessage(), meta, true);
|
||||||
@@ -272,7 +266,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
|||||||
meta.put(KEY_ORIGINAL_MSG_ID, message.getId());
|
meta.put(KEY_ORIGINAL_MSG_ID, message.getId());
|
||||||
meta.put(KEY_ORIGINAL_PARENT_MSG_ID, parentOriginalId);
|
meta.put(KEY_ORIGINAL_PARENT_MSG_ID, parentOriginalId);
|
||||||
meta.put(KEY_PARENT_MSG_ID, parentCurrentId);
|
meta.put(KEY_PARENT_MSG_ID, parentCurrentId);
|
||||||
meta.put(KEY_AUTHOR, authorToBdfDictionary(author));
|
meta.put(KEY_AUTHOR, clientHelper.toList(author));
|
||||||
|
|
||||||
// Send comment
|
// Send comment
|
||||||
clientHelper.addLocalMessage(txn, message, meta, true);
|
clientHelper.addLocalMessage(txn, message, meta, true);
|
||||||
@@ -369,7 +363,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
|||||||
"Unknown Message Type: " + type);
|
"Unknown Message Type: " + type);
|
||||||
}
|
}
|
||||||
meta.put(KEY_ORIGINAL_MSG_ID, originalId);
|
meta.put(KEY_ORIGINAL_MSG_ID, originalId);
|
||||||
meta.put(KEY_AUTHOR, authorToBdfDictionary(header.getAuthor()));
|
meta.put(KEY_AUTHOR, clientHelper.toList(header.getAuthor()));
|
||||||
meta.put(KEY_TIMESTAMP, header.getTimestamp());
|
meta.put(KEY_TIMESTAMP, header.getTimestamp());
|
||||||
meta.put(KEY_TIME_RECEIVED, header.getTimeReceived());
|
meta.put(KEY_TIME_RECEIVED, header.getTimeReceived());
|
||||||
|
|
||||||
@@ -508,9 +502,9 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
|||||||
// get all authors we need to get the status for
|
// get all authors we need to get the status for
|
||||||
Set<AuthorId> authors = new HashSet<>();
|
Set<AuthorId> authors = new HashSet<>();
|
||||||
for (Entry<MessageId, BdfDictionary> entry : metadata.entrySet()) {
|
for (Entry<MessageId, BdfDictionary> entry : metadata.entrySet()) {
|
||||||
authors.add(new AuthorId(
|
BdfList authorList = entry.getValue().getList(KEY_AUTHOR);
|
||||||
entry.getValue().getDictionary(KEY_AUTHOR)
|
Author a = clientHelper.parseAndValidateAuthor(authorList);
|
||||||
.getRaw(KEY_AUTHOR_ID)));
|
authors.add(a.getId());
|
||||||
}
|
}
|
||||||
// get statuses for all authors
|
// get statuses for all authors
|
||||||
Map<AuthorId, Status> authorStatuses = new HashMap<>();
|
Map<AuthorId, Status> authorStatuses = new HashMap<>();
|
||||||
@@ -575,21 +569,16 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
|||||||
long timestamp = meta.getLong(KEY_TIMESTAMP);
|
long timestamp = meta.getLong(KEY_TIMESTAMP);
|
||||||
long timeReceived = meta.getLong(KEY_TIME_RECEIVED, timestamp);
|
long timeReceived = meta.getLong(KEY_TIME_RECEIVED, timestamp);
|
||||||
|
|
||||||
BdfDictionary authorDict = meta.getDictionary(KEY_AUTHOR);
|
BdfList authorList = meta.getList(KEY_AUTHOR);
|
||||||
AuthorId authorId = new AuthorId(authorDict.getRaw(KEY_AUTHOR_ID));
|
Author author = clientHelper.parseAndValidateAuthor(authorList);
|
||||||
int formatVersion = authorDict.getLong(KEY_FORMAT_VERSION).intValue();
|
|
||||||
if (formatVersion != FORMAT_VERSION) throw new FormatException();
|
|
||||||
String name = authorDict.getString(KEY_AUTHOR_NAME);
|
|
||||||
byte[] publicKey = authorDict.getRaw(KEY_PUBLIC_KEY);
|
|
||||||
Author author = new Author(authorId, formatVersion, name, publicKey);
|
|
||||||
boolean isFeedPost = meta.getBoolean(KEY_RSS_FEED, false);
|
boolean isFeedPost = meta.getBoolean(KEY_RSS_FEED, false);
|
||||||
Status authorStatus;
|
Status authorStatus;
|
||||||
if (isFeedPost) {
|
if (isFeedPost) {
|
||||||
authorStatus = Status.NONE;
|
authorStatus = Status.NONE;
|
||||||
} else if (authorStatuses.containsKey(authorId)) {
|
} else if (authorStatuses.containsKey(author.getId())) {
|
||||||
authorStatus = authorStatuses.get(authorId);
|
authorStatus = authorStatuses.get(author.getId());
|
||||||
} else {
|
} else {
|
||||||
authorStatus = identityManager.getAuthorStatus(txn, authorId);
|
authorStatus = identityManager.getAuthorStatus(txn, author.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean read = meta.getBoolean(KEY_READ, false);
|
boolean read = meta.getBoolean(KEY_READ, false);
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package org.briarproject.briar.blog;
|
|||||||
import org.briarproject.bramble.api.client.ClientHelper;
|
import org.briarproject.bramble.api.client.ClientHelper;
|
||||||
import org.briarproject.bramble.api.contact.ContactManager;
|
import org.briarproject.bramble.api.contact.ContactManager;
|
||||||
import org.briarproject.bramble.api.data.MetadataEncoder;
|
import org.briarproject.bramble.api.data.MetadataEncoder;
|
||||||
import org.briarproject.bramble.api.identity.AuthorFactory;
|
|
||||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||||
import org.briarproject.bramble.api.sync.GroupFactory;
|
import org.briarproject.bramble.api.sync.GroupFactory;
|
||||||
import org.briarproject.bramble.api.sync.MessageFactory;
|
import org.briarproject.bramble.api.sync.MessageFactory;
|
||||||
@@ -44,15 +43,14 @@ public class BlogModule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
BlogPostFactory provideBlogPostFactory(ClientHelper clientHelper,
|
BlogPostFactory provideBlogPostFactory(
|
||||||
Clock clock) {
|
BlogPostFactoryImpl blogPostFactory) {
|
||||||
return new BlogPostFactoryImpl(clientHelper, clock);
|
return blogPostFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
BlogFactory provideBlogFactory(GroupFactory groupFactory,
|
BlogFactory provideBlogFactory(BlogFactoryImpl blogFactory) {
|
||||||
AuthorFactory authorFactory, ClientHelper clientHelper) {
|
return blogFactory;
|
||||||
return new BlogFactoryImpl(groupFactory, authorFactory, clientHelper);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import org.briarproject.bramble.api.client.BdfMessageContext;
|
|||||||
import org.briarproject.bramble.api.client.BdfMessageValidator;
|
import org.briarproject.bramble.api.client.BdfMessageValidator;
|
||||||
import org.briarproject.bramble.api.client.ClientHelper;
|
import org.briarproject.bramble.api.client.ClientHelper;
|
||||||
import org.briarproject.bramble.api.data.BdfDictionary;
|
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.BdfList;
|
||||||
import org.briarproject.bramble.api.data.MetadataEncoder;
|
import org.briarproject.bramble.api.data.MetadataEncoder;
|
||||||
import org.briarproject.bramble.api.identity.Author;
|
import org.briarproject.bramble.api.identity.Author;
|
||||||
@@ -31,14 +30,10 @@ import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_SIGNATUR
|
|||||||
import static org.briarproject.bramble.util.ValidationUtils.checkLength;
|
import static org.briarproject.bramble.util.ValidationUtils.checkLength;
|
||||||
import static org.briarproject.bramble.util.ValidationUtils.checkSize;
|
import static org.briarproject.bramble.util.ValidationUtils.checkSize;
|
||||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_AUTHOR;
|
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_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_MSG_ID;
|
||||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_ORIGINAL_PARENT_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_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_READ;
|
||||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_RSS_FEED;
|
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_TIMESTAMP;
|
||||||
@@ -125,7 +120,7 @@ class BlogPostValidator extends BdfMessageValidator {
|
|||||||
// Return the metadata and dependencies
|
// Return the metadata and dependencies
|
||||||
BdfDictionary meta = new BdfDictionary();
|
BdfDictionary meta = new BdfDictionary();
|
||||||
meta.put(KEY_ORIGINAL_MSG_ID, m.getId());
|
meta.put(KEY_ORIGINAL_MSG_ID, m.getId());
|
||||||
meta.put(KEY_AUTHOR, authorToBdfDictionary(a));
|
meta.put(KEY_AUTHOR, clientHelper.toList(a));
|
||||||
meta.put(KEY_RSS_FEED, b.isRssFeed());
|
meta.put(KEY_RSS_FEED, b.isRssFeed());
|
||||||
return new BdfMessageContext(meta);
|
return new BdfMessageContext(meta);
|
||||||
}
|
}
|
||||||
@@ -174,7 +169,7 @@ class BlogPostValidator extends BdfMessageValidator {
|
|||||||
meta.put(KEY_ORIGINAL_MSG_ID, m.getId());
|
meta.put(KEY_ORIGINAL_MSG_ID, m.getId());
|
||||||
meta.put(KEY_ORIGINAL_PARENT_MSG_ID, pOriginalId);
|
meta.put(KEY_ORIGINAL_PARENT_MSG_ID, pOriginalId);
|
||||||
meta.put(KEY_PARENT_MSG_ID, currentId);
|
meta.put(KEY_PARENT_MSG_ID, currentId);
|
||||||
meta.put(KEY_AUTHOR, authorToBdfDictionary(a));
|
meta.put(KEY_AUTHOR, clientHelper.toList(a));
|
||||||
Collection<MessageId> dependencies = Collections.singleton(currentId);
|
Collection<MessageId> dependencies = Collections.singleton(currentId);
|
||||||
return new BdfMessageContext(meta, dependencies);
|
return new BdfMessageContext(meta, dependencies);
|
||||||
}
|
}
|
||||||
@@ -214,7 +209,7 @@ class BlogPostValidator extends BdfMessageValidator {
|
|||||||
BdfDictionary meta = new BdfDictionary();
|
BdfDictionary meta = new BdfDictionary();
|
||||||
meta.put(KEY_ORIGINAL_MSG_ID, wMessage.getId());
|
meta.put(KEY_ORIGINAL_MSG_ID, wMessage.getId());
|
||||||
meta.put(KEY_TIMESTAMP, wTimestamp);
|
meta.put(KEY_TIMESTAMP, wTimestamp);
|
||||||
meta.put(KEY_AUTHOR, c.getDictionary().getDictionary(KEY_AUTHOR));
|
meta.put(KEY_AUTHOR, c.getDictionary().getList(KEY_AUTHOR));
|
||||||
meta.put(KEY_RSS_FEED, wBlog.isRssFeed());
|
meta.put(KEY_RSS_FEED, wBlog.isRssFeed());
|
||||||
return new BdfMessageContext(meta);
|
return new BdfMessageContext(meta);
|
||||||
}
|
}
|
||||||
@@ -281,19 +276,10 @@ class BlogPostValidator extends BdfMessageValidator {
|
|||||||
meta.put(KEY_PARENT_MSG_ID, parentId);
|
meta.put(KEY_PARENT_MSG_ID, parentId);
|
||||||
meta.put(KEY_TIMESTAMP, wTimestamp);
|
meta.put(KEY_TIMESTAMP, wTimestamp);
|
||||||
if (comment != null) meta.put(KEY_COMMENT, comment);
|
if (comment != null) meta.put(KEY_COMMENT, comment);
|
||||||
meta.put(KEY_AUTHOR, c.getDictionary().getDictionary(KEY_AUTHOR));
|
meta.put(KEY_AUTHOR, c.getDictionary().getList(KEY_AUTHOR));
|
||||||
return new BdfMessageContext(meta, dependencies);
|
return new BdfMessageContext(meta, dependencies);
|
||||||
}
|
}
|
||||||
|
|
||||||
static 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 void addMessageMetadata(BdfMessageContext c, long time) {
|
private void addMessageMetadata(BdfMessageContext c, long time) {
|
||||||
c.getDictionary().put(KEY_TIMESTAMP, time);
|
c.getDictionary().put(KEY_TIMESTAMP, time);
|
||||||
c.getDictionary().put(KEY_TIME_RECEIVED, clock.currentTimeMillis());
|
c.getDictionary().put(KEY_TIME_RECEIVED, clock.currentTimeMillis());
|
||||||
|
|||||||
@@ -3,10 +3,13 @@ package org.briarproject.briar.feed;
|
|||||||
import com.rometools.rome.feed.synd.SyndFeed;
|
import com.rometools.rome.feed.synd.SyndFeed;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.FormatException;
|
import org.briarproject.bramble.api.FormatException;
|
||||||
|
import org.briarproject.bramble.api.client.ClientHelper;
|
||||||
import org.briarproject.bramble.api.crypto.CryptoComponent;
|
import org.briarproject.bramble.api.crypto.CryptoComponent;
|
||||||
import org.briarproject.bramble.api.crypto.KeyPair;
|
import org.briarproject.bramble.api.crypto.KeyPair;
|
||||||
import org.briarproject.bramble.api.data.BdfDictionary;
|
import org.briarproject.bramble.api.data.BdfDictionary;
|
||||||
import org.briarproject.bramble.api.data.BdfEntry;
|
import org.briarproject.bramble.api.data.BdfEntry;
|
||||||
|
import org.briarproject.bramble.api.data.BdfList;
|
||||||
|
import org.briarproject.bramble.api.identity.Author;
|
||||||
import org.briarproject.bramble.api.identity.AuthorFactory;
|
import org.briarproject.bramble.api.identity.AuthorFactory;
|
||||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
@@ -18,30 +21,31 @@ import org.briarproject.briar.api.feed.Feed;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import static org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_NAME_LENGTH;
|
import static org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_NAME_LENGTH;
|
||||||
import static org.briarproject.briar.api.feed.FeedConstants.KEY_BLOG_TITLE;
|
|
||||||
import static org.briarproject.briar.api.feed.FeedConstants.KEY_FEED_ADDED;
|
import static org.briarproject.briar.api.feed.FeedConstants.KEY_FEED_ADDED;
|
||||||
import static org.briarproject.briar.api.feed.FeedConstants.KEY_FEED_AUTHOR;
|
import static org.briarproject.briar.api.feed.FeedConstants.KEY_FEED_AUTHOR;
|
||||||
import static org.briarproject.briar.api.feed.FeedConstants.KEY_FEED_DESC;
|
import static org.briarproject.briar.api.feed.FeedConstants.KEY_FEED_DESC;
|
||||||
import static org.briarproject.briar.api.feed.FeedConstants.KEY_FEED_LAST_ENTRY;
|
import static org.briarproject.briar.api.feed.FeedConstants.KEY_FEED_LAST_ENTRY;
|
||||||
|
import static org.briarproject.briar.api.feed.FeedConstants.KEY_FEED_PRIVATE_KEY;
|
||||||
|
import static org.briarproject.briar.api.feed.FeedConstants.KEY_FEED_RSS_AUTHOR;
|
||||||
import static org.briarproject.briar.api.feed.FeedConstants.KEY_FEED_UPDATED;
|
import static org.briarproject.briar.api.feed.FeedConstants.KEY_FEED_UPDATED;
|
||||||
import static org.briarproject.briar.api.feed.FeedConstants.KEY_FEED_URL;
|
import static org.briarproject.briar.api.feed.FeedConstants.KEY_FEED_URL;
|
||||||
import static org.briarproject.briar.api.feed.FeedConstants.KEY_FORMAT_VERSION;
|
|
||||||
import static org.briarproject.briar.api.feed.FeedConstants.KEY_PRIVATE_KEY;
|
|
||||||
import static org.briarproject.briar.api.feed.FeedConstants.KEY_PUBLIC_KEY;
|
|
||||||
|
|
||||||
class FeedFactoryImpl implements FeedFactory {
|
class FeedFactoryImpl implements FeedFactory {
|
||||||
|
|
||||||
private final CryptoComponent cryptoComponent;
|
private final CryptoComponent cryptoComponent;
|
||||||
private final AuthorFactory authorFactory;
|
private final AuthorFactory authorFactory;
|
||||||
private final BlogFactory blogFactory;
|
private final BlogFactory blogFactory;
|
||||||
|
private final ClientHelper clientHelper;
|
||||||
private final Clock clock;
|
private final Clock clock;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
FeedFactoryImpl(CryptoComponent cryptoComponent,
|
FeedFactoryImpl(CryptoComponent cryptoComponent,
|
||||||
AuthorFactory authorFactory, BlogFactory blogFactory, Clock clock) {
|
AuthorFactory authorFactory, BlogFactory blogFactory,
|
||||||
|
ClientHelper clientHelper, Clock clock) {
|
||||||
this.cryptoComponent = cryptoComponent;
|
this.cryptoComponent = cryptoComponent;
|
||||||
this.authorFactory = authorFactory;
|
this.authorFactory = authorFactory;
|
||||||
this.blogFactory = blogFactory;
|
this.blogFactory = blogFactory;
|
||||||
|
this.clientHelper = clientHelper;
|
||||||
this.clock = clock;
|
this.clock = clock;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,41 +77,40 @@ class FeedFactoryImpl implements FeedFactory {
|
|||||||
public Feed createFeed(BdfDictionary d) throws FormatException {
|
public Feed createFeed(BdfDictionary d) throws FormatException {
|
||||||
String url = d.getString(KEY_FEED_URL);
|
String url = d.getString(KEY_FEED_URL);
|
||||||
|
|
||||||
int formatVersion = d.getLong(KEY_FORMAT_VERSION).intValue();
|
BdfList authorList = d.getList(KEY_FEED_AUTHOR);
|
||||||
String blogTitle = d.getString(KEY_BLOG_TITLE);
|
byte[] privateKey = d.getRaw(KEY_FEED_PRIVATE_KEY);
|
||||||
byte[] publicKey = d.getRaw(KEY_PUBLIC_KEY);
|
Author author = clientHelper.parseAndValidateAuthor(authorList);
|
||||||
byte[] privateKey = d.getRaw(KEY_PRIVATE_KEY);
|
|
||||||
LocalAuthor localAuthor = authorFactory.createLocalAuthor(
|
LocalAuthor localAuthor = authorFactory.createLocalAuthor(
|
||||||
formatVersion, blogTitle, publicKey, privateKey);
|
author.getFormatVersion(), author.getName(),
|
||||||
|
author.getPublicKey(), privateKey);
|
||||||
Blog blog = blogFactory.createFeedBlog(localAuthor);
|
Blog blog = blogFactory.createFeedBlog(localAuthor);
|
||||||
|
|
||||||
String desc = d.getOptionalString(KEY_FEED_DESC);
|
String desc = d.getOptionalString(KEY_FEED_DESC);
|
||||||
String author = d.getOptionalString(KEY_FEED_AUTHOR);
|
String rssAuthor = d.getOptionalString(KEY_FEED_RSS_AUTHOR);
|
||||||
long added = d.getLong(KEY_FEED_ADDED, 0L);
|
long added = d.getLong(KEY_FEED_ADDED, 0L);
|
||||||
long updated = d.getLong(KEY_FEED_UPDATED, 0L);
|
long updated = d.getLong(KEY_FEED_UPDATED, 0L);
|
||||||
long lastEntryTime = d.getLong(KEY_FEED_LAST_ENTRY, 0L);
|
long lastEntryTime = d.getLong(KEY_FEED_LAST_ENTRY, 0L);
|
||||||
|
|
||||||
return new Feed(url, blog, localAuthor, desc, author, added,
|
return new Feed(url, blog, localAuthor, desc, rssAuthor, added,
|
||||||
updated, lastEntryTime);
|
updated, lastEntryTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BdfDictionary feedToBdfDictionary(Feed feed) {
|
public BdfDictionary feedToBdfDictionary(Feed feed) {
|
||||||
LocalAuthor localAuthor = feed.getLocalAuthor();
|
LocalAuthor localAuthor = feed.getLocalAuthor();
|
||||||
|
BdfList authorList = clientHelper.toList(localAuthor);
|
||||||
BdfDictionary d = BdfDictionary.of(
|
BdfDictionary d = BdfDictionary.of(
|
||||||
new BdfEntry(KEY_FEED_URL, feed.getUrl()),
|
new BdfEntry(KEY_FEED_URL, feed.getUrl()),
|
||||||
new BdfEntry(KEY_FORMAT_VERSION,
|
new BdfEntry(KEY_FEED_AUTHOR, authorList),
|
||||||
localAuthor.getFormatVersion()),
|
new BdfEntry(KEY_FEED_PRIVATE_KEY, localAuthor.getPrivateKey()),
|
||||||
new BdfEntry(KEY_BLOG_TITLE, localAuthor.getName()),
|
|
||||||
new BdfEntry(KEY_PUBLIC_KEY, localAuthor.getPublicKey()),
|
|
||||||
new BdfEntry(KEY_PRIVATE_KEY, localAuthor.getPrivateKey()),
|
|
||||||
new BdfEntry(KEY_FEED_ADDED, feed.getAdded()),
|
new BdfEntry(KEY_FEED_ADDED, feed.getAdded()),
|
||||||
new BdfEntry(KEY_FEED_UPDATED, feed.getUpdated()),
|
new BdfEntry(KEY_FEED_UPDATED, feed.getUpdated()),
|
||||||
new BdfEntry(KEY_FEED_LAST_ENTRY, feed.getLastEntryTime())
|
new BdfEntry(KEY_FEED_LAST_ENTRY, feed.getLastEntryTime())
|
||||||
);
|
);
|
||||||
if (feed.getDescription() != null)
|
if (feed.getDescription() != null)
|
||||||
d.put(KEY_FEED_DESC, feed.getDescription());
|
d.put(KEY_FEED_DESC, feed.getDescription());
|
||||||
if (feed.getAuthor() != null) d.put(KEY_FEED_AUTHOR, feed.getAuthor());
|
if (feed.getRssAuthor() != null)
|
||||||
|
d.put(KEY_FEED_RSS_AUTHOR, feed.getRssAuthor());
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,15 +45,10 @@ import javax.annotation.Nullable;
|
|||||||
import javax.annotation.concurrent.ThreadSafe;
|
import javax.annotation.concurrent.ThreadSafe;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import static org.briarproject.bramble.api.identity.Author.FORMAT_VERSION;
|
|
||||||
import static org.briarproject.bramble.api.identity.Author.Status.OURSELVES;
|
import static org.briarproject.bramble.api.identity.Author.Status.OURSELVES;
|
||||||
import static org.briarproject.briar.api.forum.ForumConstants.KEY_AUTHOR;
|
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_LOCAL;
|
import static org.briarproject.briar.api.forum.ForumConstants.KEY_LOCAL;
|
||||||
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_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.KEY_TIMESTAMP;
|
||||||
import static org.briarproject.briar.client.MessageTrackerConstants.MSG_KEY_READ;
|
import static org.briarproject.briar.client.MessageTrackerConstants.MSG_KEY_READ;
|
||||||
|
|
||||||
@@ -149,12 +144,7 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
|
|||||||
meta.put(KEY_TIMESTAMP, p.getMessage().getTimestamp());
|
meta.put(KEY_TIMESTAMP, p.getMessage().getTimestamp());
|
||||||
if (p.getParent() != null) meta.put(KEY_PARENT, p.getParent());
|
if (p.getParent() != null) meta.put(KEY_PARENT, p.getParent());
|
||||||
Author a = p.getAuthor();
|
Author a = p.getAuthor();
|
||||||
BdfDictionary authorMeta = new BdfDictionary();
|
meta.put(KEY_AUTHOR, clientHelper.toList(a));
|
||||||
authorMeta.put(KEY_ID, a.getId());
|
|
||||||
authorMeta.put(KEY_FORMAT_VERSION, a.getFormatVersion());
|
|
||||||
authorMeta.put(KEY_NAME, a.getName());
|
|
||||||
authorMeta.put(KEY_PUBLIC_KEY, a.getPublicKey());
|
|
||||||
meta.put(KEY_AUTHOR, authorMeta);
|
|
||||||
meta.put(KEY_LOCAL, true);
|
meta.put(KEY_LOCAL, true);
|
||||||
meta.put(MSG_KEY_READ, true);
|
meta.put(MSG_KEY_READ, true);
|
||||||
clientHelper.addLocalMessage(txn, p.getMessage(), meta, true);
|
clientHelper.addLocalMessage(txn, p.getMessage(), meta, true);
|
||||||
@@ -240,10 +230,9 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
|
|||||||
// get all authors we need to get the status for
|
// get all authors we need to get the status for
|
||||||
Set<AuthorId> authors = new HashSet<>();
|
Set<AuthorId> authors = new HashSet<>();
|
||||||
for (Entry<MessageId, BdfDictionary> entry : metadata.entrySet()) {
|
for (Entry<MessageId, BdfDictionary> entry : metadata.entrySet()) {
|
||||||
BdfDictionary d =
|
BdfList authorList = entry.getValue().getList(KEY_AUTHOR);
|
||||||
entry.getValue().getDictionary(KEY_AUTHOR, null);
|
Author a = clientHelper.parseAndValidateAuthor(authorList);
|
||||||
if (d != null)
|
authors.add(a.getId());
|
||||||
authors.add(new AuthorId(d.getRaw(KEY_ID)));
|
|
||||||
}
|
}
|
||||||
// get statuses for all authors
|
// get statuses for all authors
|
||||||
Map<AuthorId, Status> statuses = new HashMap<>();
|
Map<AuthorId, Status> statuses = new HashMap<>();
|
||||||
@@ -301,14 +290,9 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
|
|||||||
MessageId parentId = null;
|
MessageId parentId = null;
|
||||||
if (meta.containsKey(KEY_PARENT))
|
if (meta.containsKey(KEY_PARENT))
|
||||||
parentId = new MessageId(meta.getRaw(KEY_PARENT));
|
parentId = new MessageId(meta.getRaw(KEY_PARENT));
|
||||||
BdfDictionary authorDict = meta.getDictionary(KEY_AUTHOR);
|
BdfList authorList = meta.getList(KEY_AUTHOR);
|
||||||
AuthorId authorId = new AuthorId(authorDict.getRaw(KEY_ID));
|
Author author = clientHelper.parseAndValidateAuthor(authorList);
|
||||||
int formatVersion = authorDict.getLong(KEY_FORMAT_VERSION).intValue();
|
Status status = statuses.get(author.getId());
|
||||||
if (formatVersion != FORMAT_VERSION) throw new FormatException();
|
|
||||||
String name = authorDict.getString(KEY_NAME);
|
|
||||||
byte[] publicKey = authorDict.getRaw(KEY_PUBLIC_KEY);
|
|
||||||
Author author = new Author(authorId, formatVersion, name, publicKey);
|
|
||||||
Status status = statuses.get(authorId);
|
|
||||||
if (status == null)
|
if (status == null)
|
||||||
status = identityManager.getAuthorStatus(txn, author.getId());
|
status = identityManager.getAuthorStatus(txn, author.getId());
|
||||||
boolean read = meta.getBoolean(MSG_KEY_READ);
|
boolean read = meta.getBoolean(MSG_KEY_READ);
|
||||||
|
|||||||
@@ -39,11 +39,7 @@ class ForumPostFactoryImpl implements ForumPostFactory {
|
|||||||
if (StringUtils.utf8IsTooLong(body, MAX_FORUM_POST_BODY_LENGTH))
|
if (StringUtils.utf8IsTooLong(body, MAX_FORUM_POST_BODY_LENGTH))
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
// Serialise the data to be signed
|
// Serialise the data to be signed
|
||||||
BdfList authorList = BdfList.of(
|
BdfList authorList = clientHelper.toList(author);
|
||||||
author.getFormatVersion(),
|
|
||||||
author.getName(),
|
|
||||||
author.getPublicKey()
|
|
||||||
);
|
|
||||||
BdfList signed = BdfList.of(groupId, timestamp, parent, authorList,
|
BdfList signed = BdfList.of(groupId, timestamp, parent, authorList,
|
||||||
body);
|
body);
|
||||||
// Sign the data
|
// Sign the data
|
||||||
|
|||||||
@@ -26,11 +26,7 @@ import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_SIGNATUR
|
|||||||
import static org.briarproject.bramble.util.ValidationUtils.checkLength;
|
import static org.briarproject.bramble.util.ValidationUtils.checkLength;
|
||||||
import static org.briarproject.bramble.util.ValidationUtils.checkSize;
|
import static org.briarproject.bramble.util.ValidationUtils.checkSize;
|
||||||
import static org.briarproject.briar.api.forum.ForumConstants.KEY_AUTHOR;
|
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_PARENT;
|
||||||
import static org.briarproject.briar.api.forum.ForumConstants.KEY_PUBLIC_KEY;
|
|
||||||
import static org.briarproject.briar.api.forum.ForumConstants.KEY_READ;
|
import static org.briarproject.briar.api.forum.ForumConstants.KEY_READ;
|
||||||
import static org.briarproject.briar.api.forum.ForumConstants.KEY_TIMESTAMP;
|
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.ForumConstants.MAX_FORUM_POST_BODY_LENGTH;
|
||||||
@@ -84,12 +80,7 @@ class ForumPostValidator extends BdfMessageValidator {
|
|||||||
meta.put(KEY_PARENT, parent);
|
meta.put(KEY_PARENT, parent);
|
||||||
dependencies = Collections.singletonList(new MessageId(parent));
|
dependencies = Collections.singletonList(new MessageId(parent));
|
||||||
}
|
}
|
||||||
BdfDictionary authorMeta = new BdfDictionary();
|
meta.put(KEY_AUTHOR, authorList);
|
||||||
authorMeta.put(KEY_ID, author.getId());
|
|
||||||
authorMeta.put(KEY_FORMAT_VERSION, author.getFormatVersion());
|
|
||||||
authorMeta.put(KEY_NAME, author.getName());
|
|
||||||
authorMeta.put(KEY_PUBLIC_KEY, author.getPublicKey());
|
|
||||||
meta.put(KEY_AUTHOR, authorMeta);
|
|
||||||
meta.put(KEY_READ, false);
|
meta.put(KEY_READ, false);
|
||||||
return new BdfMessageContext(meta, dependencies);
|
return new BdfMessageContext(meta, dependencies);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,10 +10,7 @@ interface GroupConstants {
|
|||||||
String KEY_READ = MSG_KEY_READ;
|
String KEY_READ = MSG_KEY_READ;
|
||||||
String KEY_PARENT_MSG_ID = "parentMsgId";
|
String KEY_PARENT_MSG_ID = "parentMsgId";
|
||||||
String KEY_PREVIOUS_MSG_ID = "previousMsgId";
|
String KEY_PREVIOUS_MSG_ID = "previousMsgId";
|
||||||
String KEY_MEMBER_ID = "memberId";
|
String KEY_MEMBER = "member";
|
||||||
String KEY_MEMBER_FORMAT_VERSION = "formatVersion";
|
|
||||||
String KEY_MEMBER_NAME = "memberName";
|
|
||||||
String KEY_MEMBER_PUBLIC_KEY = "memberPublicKey";
|
|
||||||
String KEY_INITIAL_JOIN_MSG = "initialJoinMsg";
|
String KEY_INITIAL_JOIN_MSG = "initialJoinMsg";
|
||||||
|
|
||||||
String GROUP_KEY_MEMBERS = "members";
|
String GROUP_KEY_MEMBERS = "members";
|
||||||
|
|||||||
@@ -50,11 +50,7 @@ class GroupMessageFactoryImpl implements GroupMessageFactory {
|
|||||||
LocalAuthor member, @Nullable BdfList invite) {
|
LocalAuthor member, @Nullable BdfList invite) {
|
||||||
try {
|
try {
|
||||||
// Generate the signature
|
// Generate the signature
|
||||||
BdfList memberList = BdfList.of(
|
BdfList memberList = clientHelper.toList(member);
|
||||||
member.getFormatVersion(),
|
|
||||||
member.getName(),
|
|
||||||
member.getPublicKey()
|
|
||||||
);
|
|
||||||
BdfList toSign = BdfList.of(
|
BdfList toSign = BdfList.of(
|
||||||
groupId,
|
groupId,
|
||||||
timestamp,
|
timestamp,
|
||||||
@@ -86,11 +82,7 @@ class GroupMessageFactoryImpl implements GroupMessageFactory {
|
|||||||
MessageId previousMsgId) {
|
MessageId previousMsgId) {
|
||||||
try {
|
try {
|
||||||
// Generate the signature
|
// Generate the signature
|
||||||
BdfList memberList = BdfList.of(
|
BdfList memberList = clientHelper.toList(member);
|
||||||
member.getFormatVersion(),
|
|
||||||
member.getName(),
|
|
||||||
member.getPublicKey()
|
|
||||||
);
|
|
||||||
BdfList toSign = BdfList.of(
|
BdfList toSign = BdfList.of(
|
||||||
groupId,
|
groupId,
|
||||||
timestamp,
|
timestamp,
|
||||||
|
|||||||
@@ -34,10 +34,7 @@ import static org.briarproject.briar.api.privategroup.MessageType.POST;
|
|||||||
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_GROUP_POST_BODY_LENGTH;
|
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.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_INITIAL_JOIN_MSG;
|
||||||
import static org.briarproject.briar.privategroup.GroupConstants.KEY_MEMBER_FORMAT_VERSION;
|
import static org.briarproject.briar.privategroup.GroupConstants.KEY_MEMBER;
|
||||||
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_PARENT_MSG_ID;
|
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_PREVIOUS_MSG_ID;
|
||||||
import static org.briarproject.briar.privategroup.GroupConstants.KEY_READ;
|
import static org.briarproject.briar.privategroup.GroupConstants.KEY_READ;
|
||||||
@@ -75,10 +72,10 @@ class GroupMessageValidator extends BdfMessageValidator {
|
|||||||
BdfMessageContext c;
|
BdfMessageContext c;
|
||||||
if (type == JOIN.getInt()) {
|
if (type == JOIN.getInt()) {
|
||||||
c = validateJoin(m, g, body, member);
|
c = validateJoin(m, g, body, member);
|
||||||
addMessageMetadata(c, member, m.getTimestamp());
|
addMessageMetadata(c, memberList, m.getTimestamp());
|
||||||
} else if (type == POST.getInt()) {
|
} else if (type == POST.getInt()) {
|
||||||
c = validatePost(m, g, body, member);
|
c = validatePost(m, g, body, member);
|
||||||
addMessageMetadata(c, member, m.getTimestamp());
|
addMessageMetadata(c, memberList, m.getTimestamp());
|
||||||
} else {
|
} else {
|
||||||
throw new InvalidMessageException("Unknown Message Type");
|
throw new InvalidMessageException("Unknown Message Type");
|
||||||
}
|
}
|
||||||
@@ -187,15 +184,11 @@ class GroupMessageValidator extends BdfMessageValidator {
|
|||||||
return new BdfMessageContext(meta, dependencies);
|
return new BdfMessageContext(meta, dependencies);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addMessageMetadata(BdfMessageContext c, Author member,
|
private void addMessageMetadata(BdfMessageContext c, BdfList member,
|
||||||
long timestamp) {
|
long timestamp) {
|
||||||
|
c.getDictionary().put(KEY_MEMBER, member);
|
||||||
c.getDictionary().put(KEY_TIMESTAMP, timestamp);
|
c.getDictionary().put(KEY_TIMESTAMP, timestamp);
|
||||||
c.getDictionary().put(KEY_READ, false);
|
c.getDictionary().put(KEY_READ, false);
|
||||||
c.getDictionary().put(KEY_MEMBER_ID, member.getId());
|
|
||||||
c.getDictionary().put(KEY_MEMBER_FORMAT_VERSION,
|
|
||||||
member.getFormatVersion());
|
|
||||||
c.getDictionary().put(KEY_MEMBER_NAME, member.getName());
|
|
||||||
c.getDictionary().put(KEY_MEMBER_PUBLIC_KEY, member.getPublicKey());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,29 +41,25 @@ class PrivateGroupFactoryImpl implements PrivateGroupFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PrivateGroup createPrivateGroup(String name, Author author) {
|
public PrivateGroup createPrivateGroup(String name, Author creator) {
|
||||||
int length = StringUtils.toUtf8(name).length;
|
int length = StringUtils.toUtf8(name).length;
|
||||||
if (length == 0 || length > MAX_GROUP_NAME_LENGTH)
|
if (length == 0 || length > MAX_GROUP_NAME_LENGTH)
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
byte[] salt = new byte[GROUP_SALT_LENGTH];
|
byte[] salt = new byte[GROUP_SALT_LENGTH];
|
||||||
random.nextBytes(salt);
|
random.nextBytes(salt);
|
||||||
return createPrivateGroup(name, author, salt);
|
return createPrivateGroup(name, creator, salt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PrivateGroup createPrivateGroup(String name, Author author,
|
public PrivateGroup createPrivateGroup(String name, Author creator,
|
||||||
byte[] salt) {
|
byte[] salt) {
|
||||||
try {
|
try {
|
||||||
BdfList creatorList = BdfList.of(
|
BdfList creatorList = clientHelper.toList(creator);
|
||||||
author.getFormatVersion(),
|
|
||||||
author.getName(),
|
|
||||||
author.getPublicKey()
|
|
||||||
);
|
|
||||||
BdfList group = BdfList.of(creatorList, name, salt);
|
BdfList group = BdfList.of(creatorList, name, salt);
|
||||||
byte[] descriptor = clientHelper.toByteArray(group);
|
byte[] descriptor = clientHelper.toByteArray(group);
|
||||||
Group g = groupFactory.createGroup(CLIENT_ID, CLIENT_VERSION,
|
Group g = groupFactory.createGroup(CLIENT_ID, CLIENT_VERSION,
|
||||||
descriptor);
|
descriptor);
|
||||||
return new PrivateGroup(g, name, author, salt);
|
return new PrivateGroup(g, name, creator, salt);
|
||||||
} catch (FormatException e) {
|
} catch (FormatException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ import org.briarproject.briar.api.privategroup.event.GroupMessageAddedEvent;
|
|||||||
import org.briarproject.briar.client.BdfIncomingMessageHook;
|
import org.briarproject.briar.client.BdfIncomingMessageHook;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -54,7 +53,6 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
|||||||
import javax.annotation.concurrent.ThreadSafe;
|
import javax.annotation.concurrent.ThreadSafe;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import static org.briarproject.bramble.api.identity.Author.FORMAT_VERSION;
|
|
||||||
import static org.briarproject.bramble.api.identity.Author.Status.OURSELVES;
|
import static org.briarproject.bramble.api.identity.Author.Status.OURSELVES;
|
||||||
import static org.briarproject.bramble.api.identity.Author.Status.UNVERIFIED;
|
import static org.briarproject.bramble.api.identity.Author.Status.UNVERIFIED;
|
||||||
import static org.briarproject.bramble.api.identity.Author.Status.VERIFIED;
|
import static org.briarproject.bramble.api.identity.Author.Status.VERIFIED;
|
||||||
@@ -70,10 +68,7 @@ import static org.briarproject.briar.privategroup.GroupConstants.GROUP_KEY_MEMBE
|
|||||||
import static org.briarproject.briar.privategroup.GroupConstants.GROUP_KEY_OUR_GROUP;
|
import static org.briarproject.briar.privategroup.GroupConstants.GROUP_KEY_OUR_GROUP;
|
||||||
import static org.briarproject.briar.privategroup.GroupConstants.GROUP_KEY_VISIBILITY;
|
import static org.briarproject.briar.privategroup.GroupConstants.GROUP_KEY_VISIBILITY;
|
||||||
import static org.briarproject.briar.privategroup.GroupConstants.KEY_INITIAL_JOIN_MSG;
|
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;
|
||||||
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_PARENT_MSG_ID;
|
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_PREVIOUS_MSG_ID;
|
||||||
import static org.briarproject.briar.privategroup.GroupConstants.KEY_READ;
|
import static org.briarproject.briar.privategroup.GroupConstants.KEY_READ;
|
||||||
@@ -242,12 +237,9 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void addMessageMetadata(BdfDictionary meta, GroupMessage m) {
|
private void addMessageMetadata(BdfDictionary meta, GroupMessage m) {
|
||||||
|
meta.put(KEY_MEMBER, clientHelper.toList(m.getMember()));
|
||||||
meta.put(KEY_TIMESTAMP, m.getMessage().getTimestamp());
|
meta.put(KEY_TIMESTAMP, m.getMessage().getTimestamp());
|
||||||
meta.put(KEY_READ, true);
|
meta.put(KEY_READ, true);
|
||||||
meta.put(KEY_MEMBER_ID, m.getMember().getId());
|
|
||||||
meta.put(KEY_MEMBER_FORMAT_VERSION, m.getMember().getFormatVersion());
|
|
||||||
meta.put(KEY_MEMBER_NAME, m.getMember().getName());
|
|
||||||
meta.put(KEY_MEMBER_PUBLIC_KEY, m.getMember().getPublicKey());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -334,8 +326,7 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
|
|||||||
// get all authors we need to get the status for
|
// get all authors we need to get the status for
|
||||||
Set<AuthorId> authors = new HashSet<>();
|
Set<AuthorId> authors = new HashSet<>();
|
||||||
for (BdfDictionary meta : metadata.values()) {
|
for (BdfDictionary meta : metadata.values()) {
|
||||||
byte[] idBytes = meta.getRaw(KEY_MEMBER_ID);
|
authors.add(getAuthor(meta).getId());
|
||||||
authors.add(new AuthorId(idBytes));
|
|
||||||
}
|
}
|
||||||
// get statuses for all authors
|
// get statuses for all authors
|
||||||
Map<AuthorId, Status> statuses = new HashMap<>();
|
Map<AuthorId, Status> statuses = new HashMap<>();
|
||||||
@@ -350,13 +341,11 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
|
|||||||
if (meta.getLong(KEY_TYPE) == JOIN.getInt()) {
|
if (meta.getLong(KEY_TYPE) == JOIN.getInt()) {
|
||||||
Author member = getAuthor(meta);
|
Author member = getAuthor(meta);
|
||||||
Visibility v = visibilities.get(member);
|
Visibility v = visibilities.get(member);
|
||||||
headers.add(
|
headers.add(getJoinMessageHeader(txn, g, entry.getKey(),
|
||||||
getJoinMessageHeader(txn, g, entry.getKey(), meta,
|
meta, statuses, v));
|
||||||
statuses, v));
|
|
||||||
} else {
|
} else {
|
||||||
headers.add(
|
headers.add(getGroupMessageHeader(txn, g, entry.getKey(),
|
||||||
getGroupMessageHeader(txn, g, entry.getKey(), meta,
|
meta, statuses));
|
||||||
statuses));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
db.commitTransaction(txn);
|
db.commitTransaction(txn);
|
||||||
@@ -378,16 +367,16 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
|
|||||||
}
|
}
|
||||||
long timestamp = meta.getLong(KEY_TIMESTAMP);
|
long timestamp = meta.getLong(KEY_TIMESTAMP);
|
||||||
|
|
||||||
Author author = getAuthor(meta);
|
Author member = getAuthor(meta);
|
||||||
Status status;
|
Status status;
|
||||||
if (statuses.containsKey(author.getId())) {
|
if (statuses.containsKey(member.getId())) {
|
||||||
status = statuses.get(author.getId());
|
status = statuses.get(member.getId());
|
||||||
} else {
|
} else {
|
||||||
status = identityManager.getAuthorStatus(txn, author.getId());
|
status = identityManager.getAuthorStatus(txn, member.getId());
|
||||||
}
|
}
|
||||||
boolean read = meta.getBoolean(KEY_READ);
|
boolean read = meta.getBoolean(KEY_READ);
|
||||||
|
|
||||||
return new GroupMessageHeader(g, id, parentId, timestamp, author,
|
return new GroupMessageHeader(g, id, parentId, timestamp, member,
|
||||||
status, read);
|
status, read);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -477,8 +466,7 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
|
|||||||
boolean foundMember = false, changed = false;
|
boolean foundMember = false, changed = false;
|
||||||
for (int i = 0; i < members.size(); i++) {
|
for (int i = 0; i < members.size(); i++) {
|
||||||
BdfDictionary d = members.getDictionary(i);
|
BdfDictionary d = members.getDictionary(i);
|
||||||
AuthorId memberId = new AuthorId(d.getRaw(KEY_MEMBER_ID));
|
if (a.equals(getAuthor(d).getId())) {
|
||||||
if (a.equals(memberId)) {
|
|
||||||
foundMember = true;
|
foundMember = true;
|
||||||
// Don't update the visibility if the contact is already visible
|
// Don't update the visibility if the contact is already visible
|
||||||
if (getVisibility(d) == INVISIBLE) {
|
if (getVisibility(d) == INVISIBLE) {
|
||||||
@@ -567,8 +555,7 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
|
|||||||
if (timestamp <= previousMeta.getLong(KEY_TIMESTAMP))
|
if (timestamp <= previousMeta.getLong(KEY_TIMESTAMP))
|
||||||
throw new FormatException();
|
throw new FormatException();
|
||||||
// previous message must be from same member
|
// previous message must be from same member
|
||||||
if (!Arrays.equals(meta.getRaw(KEY_MEMBER_ID),
|
if (!getAuthor(meta).equals(getAuthor(previousMeta)))
|
||||||
previousMeta.getRaw(KEY_MEMBER_ID)))
|
|
||||||
throw new FormatException();
|
throw new FormatException();
|
||||||
// previous message must be a POST or JOIN
|
// previous message must be a POST or JOIN
|
||||||
MessageType previousType = MessageType
|
MessageType previousType = MessageType
|
||||||
@@ -605,10 +592,7 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
|
|||||||
BdfDictionary meta = clientHelper.getGroupMetadataAsDictionary(txn, g);
|
BdfDictionary meta = clientHelper.getGroupMetadataAsDictionary(txn, g);
|
||||||
BdfList members = meta.getList(GROUP_KEY_MEMBERS);
|
BdfList members = meta.getList(GROUP_KEY_MEMBERS);
|
||||||
members.add(BdfDictionary.of(
|
members.add(BdfDictionary.of(
|
||||||
new BdfEntry(KEY_MEMBER_ID, a.getId()),
|
new BdfEntry(KEY_MEMBER, clientHelper.toList(a)),
|
||||||
new BdfEntry(KEY_MEMBER_FORMAT_VERSION, a.getFormatVersion()),
|
|
||||||
new BdfEntry(KEY_MEMBER_NAME, a.getName()),
|
|
||||||
new BdfEntry(KEY_MEMBER_PUBLIC_KEY, a.getPublicKey()),
|
|
||||||
new BdfEntry(GROUP_KEY_VISIBILITY, v.getInt())
|
new BdfEntry(GROUP_KEY_VISIBILITY, v.getInt())
|
||||||
));
|
));
|
||||||
clientHelper.mergeGroupMetadata(txn, g, meta);
|
clientHelper.mergeGroupMetadata(txn, g, meta);
|
||||||
@@ -618,12 +602,7 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Author getAuthor(BdfDictionary meta) throws FormatException {
|
private Author getAuthor(BdfDictionary meta) throws FormatException {
|
||||||
AuthorId authorId = new AuthorId(meta.getRaw(KEY_MEMBER_ID));
|
return clientHelper.parseAndValidateAuthor(meta.getList(KEY_MEMBER));
|
||||||
int formatVersion = meta.getLong(KEY_MEMBER_FORMAT_VERSION).intValue();
|
|
||||||
if (formatVersion != FORMAT_VERSION) throw new FormatException();
|
|
||||||
String name = meta.getString(KEY_MEMBER_NAME);
|
|
||||||
byte[] publicKey = meta.getRaw(KEY_MEMBER_PUBLIC_KEY);
|
|
||||||
return new Author(authorId, formatVersion, name, publicKey);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Visibility getVisibility(BdfDictionary meta)
|
private Visibility getVisibility(BdfDictionary meta)
|
||||||
|
|||||||
@@ -78,11 +78,7 @@ class MessageEncoderImpl implements MessageEncoder {
|
|||||||
GroupId privateGroupId, long timestamp, String groupName,
|
GroupId privateGroupId, long timestamp, String groupName,
|
||||||
Author creator, byte[] salt, @Nullable String message,
|
Author creator, byte[] salt, @Nullable String message,
|
||||||
byte[] signature) {
|
byte[] signature) {
|
||||||
BdfList creatorList = BdfList.of(
|
BdfList creatorList = clientHelper.toList(creator);
|
||||||
creator.getFormatVersion(),
|
|
||||||
creator.getName(),
|
|
||||||
creator.getPublicKey()
|
|
||||||
);
|
|
||||||
BdfList body = BdfList.of(
|
BdfList body = BdfList.of(
|
||||||
INVITE.getValue(),
|
INVITE.getValue(),
|
||||||
creatorList,
|
creatorList,
|
||||||
|
|||||||
@@ -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.test.TestUtils.getRandomId;
|
||||||
import static org.briarproject.bramble.util.StringUtils.getRandomString;
|
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;
|
||||||
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_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_MSG_ID;
|
||||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_ORIGINAL_PARENT_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_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_READ;
|
||||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_RSS_FEED;
|
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_TIMESTAMP;
|
||||||
@@ -76,7 +72,7 @@ public class BlogManagerImplTest extends BriarTestCase {
|
|||||||
context.mock(BlogPostFactory.class);
|
context.mock(BlogPostFactory.class);
|
||||||
|
|
||||||
private final LocalAuthor localAuthor1, localAuthor2, rssLocalAuthor;
|
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 Blog blog1, blog2, rssBlog;
|
||||||
private final long timestamp, timeReceived;
|
private final long timestamp, timeReceived;
|
||||||
private final MessageId messageId, rssMessageId;
|
private final MessageId messageId, rssMessageId;
|
||||||
@@ -91,9 +87,9 @@ public class BlogManagerImplTest extends BriarTestCase {
|
|||||||
localAuthor1 = getLocalAuthor();
|
localAuthor1 = getLocalAuthor();
|
||||||
localAuthor2 = getLocalAuthor();
|
localAuthor2 = getLocalAuthor();
|
||||||
rssLocalAuthor = getLocalAuthor();
|
rssLocalAuthor = getLocalAuthor();
|
||||||
authorDict1 = authorToBdfDictionary(localAuthor1);
|
authorList1 = authorToBdfList(localAuthor1);
|
||||||
authorDict2 = authorToBdfDictionary(localAuthor2);
|
authorList2 = authorToBdfList(localAuthor2);
|
||||||
rssAuthorDict = authorToBdfDictionary(rssLocalAuthor);
|
rssAuthorList = authorToBdfList(rssLocalAuthor);
|
||||||
blog1 = createBlog(localAuthor1, false);
|
blog1 = createBlog(localAuthor1, false);
|
||||||
blog2 = createBlog(localAuthor2, false);
|
blog2 = createBlog(localAuthor2, false);
|
||||||
rssBlog = createBlog(rssLocalAuthor, true);
|
rssBlog = createBlog(rssLocalAuthor, true);
|
||||||
@@ -173,12 +169,14 @@ public class BlogManagerImplTest extends BriarTestCase {
|
|||||||
new BdfEntry(KEY_TYPE, POST.getInt()),
|
new BdfEntry(KEY_TYPE, POST.getInt()),
|
||||||
new BdfEntry(KEY_TIMESTAMP, timestamp),
|
new BdfEntry(KEY_TIMESTAMP, timestamp),
|
||||||
new BdfEntry(KEY_TIME_RECEIVED, timeReceived),
|
new BdfEntry(KEY_TIME_RECEIVED, timeReceived),
|
||||||
new BdfEntry(KEY_AUTHOR, authorDict1),
|
new BdfEntry(KEY_AUTHOR, authorList1),
|
||||||
new BdfEntry(KEY_READ, false),
|
new BdfEntry(KEY_READ, false),
|
||||||
new BdfEntry(KEY_RSS_FEED, false)
|
new BdfEntry(KEY_RSS_FEED, false)
|
||||||
);
|
);
|
||||||
|
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
|
oneOf(clientHelper).parseAndValidateAuthor(authorList1);
|
||||||
|
will(returnValue(localAuthor1));
|
||||||
oneOf(identityManager).getAuthorStatus(txn, localAuthor1.getId());
|
oneOf(identityManager).getAuthorStatus(txn, localAuthor1.getId());
|
||||||
will(returnValue(VERIFIED));
|
will(returnValue(VERIFIED));
|
||||||
}});
|
}});
|
||||||
@@ -212,11 +210,16 @@ public class BlogManagerImplTest extends BriarTestCase {
|
|||||||
new BdfEntry(KEY_TYPE, POST.getInt()),
|
new BdfEntry(KEY_TYPE, POST.getInt()),
|
||||||
new BdfEntry(KEY_TIMESTAMP, timestamp),
|
new BdfEntry(KEY_TIMESTAMP, timestamp),
|
||||||
new BdfEntry(KEY_TIME_RECEIVED, timeReceived),
|
new BdfEntry(KEY_TIME_RECEIVED, timeReceived),
|
||||||
new BdfEntry(KEY_AUTHOR, rssAuthorDict),
|
new BdfEntry(KEY_AUTHOR, rssAuthorList),
|
||||||
new BdfEntry(KEY_READ, false),
|
new BdfEntry(KEY_READ, false),
|
||||||
new BdfEntry(KEY_RSS_FEED, true)
|
new BdfEntry(KEY_RSS_FEED, true)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
context.checking(new Expectations() {{
|
||||||
|
oneOf(clientHelper).parseAndValidateAuthor(rssAuthorList);
|
||||||
|
will(returnValue(rssLocalAuthor));
|
||||||
|
}});
|
||||||
|
|
||||||
blogManager.incomingMessage(txn, rssMessage, body, meta);
|
blogManager.incomingMessage(txn, rssMessage, body, meta);
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
|
|
||||||
@@ -263,7 +266,7 @@ public class BlogManagerImplTest extends BriarTestCase {
|
|||||||
BdfDictionary meta = BdfDictionary.of(
|
BdfDictionary meta = BdfDictionary.of(
|
||||||
new BdfEntry(KEY_TYPE, POST.getInt()),
|
new BdfEntry(KEY_TYPE, POST.getInt()),
|
||||||
new BdfEntry(KEY_TIMESTAMP, timestamp),
|
new BdfEntry(KEY_TIMESTAMP, timestamp),
|
||||||
new BdfEntry(KEY_AUTHOR, authorDict1),
|
new BdfEntry(KEY_AUTHOR, authorList1),
|
||||||
new BdfEntry(KEY_READ, true),
|
new BdfEntry(KEY_READ, true),
|
||||||
new BdfEntry(KEY_RSS_FEED, false)
|
new BdfEntry(KEY_RSS_FEED, false)
|
||||||
);
|
);
|
||||||
@@ -275,7 +278,11 @@ public class BlogManagerImplTest extends BriarTestCase {
|
|||||||
will(returnValue(blog1.getGroup()));
|
will(returnValue(blog1.getGroup()));
|
||||||
oneOf(blogFactory).parseBlog(blog1.getGroup());
|
oneOf(blogFactory).parseBlog(blog1.getGroup());
|
||||||
will(returnValue(blog1));
|
will(returnValue(blog1));
|
||||||
|
oneOf(clientHelper).toList(localAuthor1);
|
||||||
|
will(returnValue(authorList1));
|
||||||
oneOf(clientHelper).addLocalMessage(txn, message, meta, true);
|
oneOf(clientHelper).addLocalMessage(txn, message, meta, true);
|
||||||
|
oneOf(clientHelper).parseAndValidateAuthor(authorList1);
|
||||||
|
will(returnValue(localAuthor1));
|
||||||
oneOf(identityManager).getAuthorStatus(txn, localAuthor1.getId());
|
oneOf(identityManager).getAuthorStatus(txn, localAuthor1.getId());
|
||||||
will(returnValue(OURSELVES));
|
will(returnValue(OURSELVES));
|
||||||
oneOf(db).commitTransaction(txn);
|
oneOf(db).commitTransaction(txn);
|
||||||
@@ -309,7 +316,7 @@ public class BlogManagerImplTest extends BriarTestCase {
|
|||||||
BdfDictionary meta = BdfDictionary.of(
|
BdfDictionary meta = BdfDictionary.of(
|
||||||
new BdfEntry(KEY_TYPE, POST.getInt()),
|
new BdfEntry(KEY_TYPE, POST.getInt()),
|
||||||
new BdfEntry(KEY_TIMESTAMP, timestamp),
|
new BdfEntry(KEY_TIMESTAMP, timestamp),
|
||||||
new BdfEntry(KEY_AUTHOR, rssAuthorDict),
|
new BdfEntry(KEY_AUTHOR, rssAuthorList),
|
||||||
new BdfEntry(KEY_READ, true),
|
new BdfEntry(KEY_READ, true),
|
||||||
new BdfEntry(KEY_RSS_FEED, true)
|
new BdfEntry(KEY_RSS_FEED, true)
|
||||||
);
|
);
|
||||||
@@ -321,7 +328,11 @@ public class BlogManagerImplTest extends BriarTestCase {
|
|||||||
will(returnValue(rssBlog.getGroup()));
|
will(returnValue(rssBlog.getGroup()));
|
||||||
oneOf(blogFactory).parseBlog(rssBlog.getGroup());
|
oneOf(blogFactory).parseBlog(rssBlog.getGroup());
|
||||||
will(returnValue(rssBlog));
|
will(returnValue(rssBlog));
|
||||||
|
oneOf(clientHelper).toList(rssLocalAuthor);
|
||||||
|
will(returnValue(rssAuthorList));
|
||||||
oneOf(clientHelper).addLocalMessage(txn, rssMessage, meta, true);
|
oneOf(clientHelper).addLocalMessage(txn, rssMessage, meta, true);
|
||||||
|
oneOf(clientHelper).parseAndValidateAuthor(rssAuthorList);
|
||||||
|
will(returnValue(rssLocalAuthor));
|
||||||
oneOf(db).commitTransaction(txn);
|
oneOf(db).commitTransaction(txn);
|
||||||
oneOf(db).endTransaction(txn);
|
oneOf(db).endTransaction(txn);
|
||||||
}});
|
}});
|
||||||
@@ -356,7 +367,7 @@ public class BlogManagerImplTest extends BriarTestCase {
|
|||||||
new BdfEntry(KEY_TYPE, POST.getInt()),
|
new BdfEntry(KEY_TYPE, POST.getInt()),
|
||||||
new BdfEntry(KEY_RSS_FEED, false),
|
new BdfEntry(KEY_RSS_FEED, false),
|
||||||
new BdfEntry(KEY_ORIGINAL_MSG_ID, messageId),
|
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_TIMESTAMP, timestamp),
|
||||||
new BdfEntry(KEY_TIME_RECEIVED, timeReceived)
|
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_MSG_ID, commentId),
|
||||||
new BdfEntry(KEY_ORIGINAL_PARENT_MSG_ID, messageId),
|
new BdfEntry(KEY_ORIGINAL_PARENT_MSG_ID, messageId),
|
||||||
new BdfEntry(KEY_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() {{
|
context.checking(new Expectations() {{
|
||||||
@@ -380,14 +391,20 @@ public class BlogManagerImplTest extends BriarTestCase {
|
|||||||
oneOf(blogPostFactory).createBlogComment(blog1.getId(),
|
oneOf(blogPostFactory).createBlogComment(blog1.getId(),
|
||||||
localAuthor1, comment, messageId, messageId);
|
localAuthor1, comment, messageId, messageId);
|
||||||
will(returnValue(commentMsg));
|
will(returnValue(commentMsg));
|
||||||
|
oneOf(clientHelper).toList(localAuthor1);
|
||||||
|
will(returnValue(authorList1));
|
||||||
// Store the comment
|
// Store the comment
|
||||||
oneOf(clientHelper).addLocalMessage(txn, commentMsg, commentMeta,
|
oneOf(clientHelper).addLocalMessage(txn, commentMsg, commentMeta,
|
||||||
true);
|
true);
|
||||||
// Create the headers for the comment and its parent
|
// Create the headers for the comment and its parent
|
||||||
|
oneOf(clientHelper).parseAndValidateAuthor(authorList1);
|
||||||
|
will(returnValue(localAuthor1));
|
||||||
oneOf(identityManager).getAuthorStatus(txn, localAuthor1.getId());
|
oneOf(identityManager).getAuthorStatus(txn, localAuthor1.getId());
|
||||||
will(returnValue(OURSELVES));
|
will(returnValue(OURSELVES));
|
||||||
oneOf(clientHelper).getMessageMetadataAsDictionary(txn, messageId);
|
oneOf(clientHelper).getMessageMetadataAsDictionary(txn, messageId);
|
||||||
will(returnValue(postMeta));
|
will(returnValue(postMeta));
|
||||||
|
oneOf(clientHelper).parseAndValidateAuthor(authorList1);
|
||||||
|
will(returnValue(localAuthor1));
|
||||||
oneOf(identityManager).getAuthorStatus(txn, localAuthor1.getId());
|
oneOf(identityManager).getAuthorStatus(txn, localAuthor1.getId());
|
||||||
will(returnValue(OURSELVES));
|
will(returnValue(OURSELVES));
|
||||||
oneOf(db).commitTransaction(txn);
|
oneOf(db).commitTransaction(txn);
|
||||||
@@ -446,7 +463,7 @@ public class BlogManagerImplTest extends BriarTestCase {
|
|||||||
new BdfEntry(KEY_TYPE, WRAPPED_POST.getInt()),
|
new BdfEntry(KEY_TYPE, WRAPPED_POST.getInt()),
|
||||||
new BdfEntry(KEY_RSS_FEED, false),
|
new BdfEntry(KEY_RSS_FEED, false),
|
||||||
new BdfEntry(KEY_ORIGINAL_MSG_ID, messageId),
|
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_TIMESTAMP, timestamp),
|
||||||
new BdfEntry(KEY_TIME_RECEIVED, timeReceived)
|
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_MSG_ID, commentId),
|
||||||
new BdfEntry(KEY_ORIGINAL_PARENT_MSG_ID, messageId),
|
new BdfEntry(KEY_ORIGINAL_PARENT_MSG_ID, messageId),
|
||||||
new BdfEntry(KEY_PARENT_MSG_ID, wrappedPostId),
|
new BdfEntry(KEY_PARENT_MSG_ID, wrappedPostId),
|
||||||
new BdfEntry(KEY_AUTHOR, authorDict2)
|
new BdfEntry(KEY_AUTHOR, authorList2)
|
||||||
);
|
);
|
||||||
|
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
@@ -475,6 +492,8 @@ public class BlogManagerImplTest extends BriarTestCase {
|
|||||||
blog1.getGroup().getDescriptor(), timestamp,
|
blog1.getGroup().getDescriptor(), timestamp,
|
||||||
originalPostBody);
|
originalPostBody);
|
||||||
will(returnValue(wrappedPostMsg));
|
will(returnValue(wrappedPostMsg));
|
||||||
|
oneOf(clientHelper).toList(localAuthor1);
|
||||||
|
will(returnValue(authorList1));
|
||||||
// Store the wrapped post
|
// Store the wrapped post
|
||||||
oneOf(clientHelper).addLocalMessage(txn, wrappedPostMsg,
|
oneOf(clientHelper).addLocalMessage(txn, wrappedPostMsg,
|
||||||
wrappedPostMeta, true);
|
wrappedPostMeta, true);
|
||||||
@@ -482,15 +501,21 @@ public class BlogManagerImplTest extends BriarTestCase {
|
|||||||
oneOf(blogPostFactory).createBlogComment(blog2.getId(),
|
oneOf(blogPostFactory).createBlogComment(blog2.getId(),
|
||||||
localAuthor2, comment, messageId, wrappedPostId);
|
localAuthor2, comment, messageId, wrappedPostId);
|
||||||
will(returnValue(commentMsg));
|
will(returnValue(commentMsg));
|
||||||
|
oneOf(clientHelper).toList(localAuthor2);
|
||||||
|
will(returnValue(authorList2));
|
||||||
// Store the comment
|
// Store the comment
|
||||||
oneOf(clientHelper).addLocalMessage(txn, commentMsg, commentMeta,
|
oneOf(clientHelper).addLocalMessage(txn, commentMsg, commentMeta,
|
||||||
true);
|
true);
|
||||||
// Create the headers for the comment and the wrapped post
|
// Create the headers for the comment and the wrapped post
|
||||||
|
oneOf(clientHelper).parseAndValidateAuthor(authorList2);
|
||||||
|
will(returnValue(localAuthor2));
|
||||||
oneOf(identityManager).getAuthorStatus(txn, localAuthor2.getId());
|
oneOf(identityManager).getAuthorStatus(txn, localAuthor2.getId());
|
||||||
will(returnValue(OURSELVES));
|
will(returnValue(OURSELVES));
|
||||||
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
||||||
wrappedPostId);
|
wrappedPostId);
|
||||||
will(returnValue(wrappedPostMeta));
|
will(returnValue(wrappedPostMeta));
|
||||||
|
oneOf(clientHelper).parseAndValidateAuthor(authorList1);
|
||||||
|
will(returnValue(localAuthor1));
|
||||||
oneOf(identityManager).getAuthorStatus(txn, localAuthor1.getId());
|
oneOf(identityManager).getAuthorStatus(txn, localAuthor1.getId());
|
||||||
will(returnValue(VERIFIED));
|
will(returnValue(VERIFIED));
|
||||||
oneOf(db).commitTransaction(txn);
|
oneOf(db).commitTransaction(txn);
|
||||||
@@ -549,7 +574,7 @@ public class BlogManagerImplTest extends BriarTestCase {
|
|||||||
new BdfEntry(KEY_TYPE, WRAPPED_POST.getInt()),
|
new BdfEntry(KEY_TYPE, WRAPPED_POST.getInt()),
|
||||||
new BdfEntry(KEY_RSS_FEED, true),
|
new BdfEntry(KEY_RSS_FEED, true),
|
||||||
new BdfEntry(KEY_ORIGINAL_MSG_ID, rssMessageId),
|
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_TIMESTAMP, timestamp),
|
||||||
new BdfEntry(KEY_TIME_RECEIVED, timeReceived)
|
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_MSG_ID, commentId),
|
||||||
new BdfEntry(KEY_ORIGINAL_PARENT_MSG_ID, rssMessageId),
|
new BdfEntry(KEY_ORIGINAL_PARENT_MSG_ID, rssMessageId),
|
||||||
new BdfEntry(KEY_PARENT_MSG_ID, wrappedPostId),
|
new BdfEntry(KEY_PARENT_MSG_ID, wrappedPostId),
|
||||||
new BdfEntry(KEY_AUTHOR, authorDict1)
|
new BdfEntry(KEY_AUTHOR, authorList1)
|
||||||
);
|
);
|
||||||
|
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
@@ -578,6 +603,8 @@ public class BlogManagerImplTest extends BriarTestCase {
|
|||||||
rssBlog.getGroup().getDescriptor(), timestamp,
|
rssBlog.getGroup().getDescriptor(), timestamp,
|
||||||
originalPostBody);
|
originalPostBody);
|
||||||
will(returnValue(wrappedPostMsg));
|
will(returnValue(wrappedPostMsg));
|
||||||
|
oneOf(clientHelper).toList(rssLocalAuthor);
|
||||||
|
will(returnValue(rssAuthorList));
|
||||||
// Store the wrapped post
|
// Store the wrapped post
|
||||||
oneOf(clientHelper).addLocalMessage(txn, wrappedPostMsg,
|
oneOf(clientHelper).addLocalMessage(txn, wrappedPostMsg,
|
||||||
wrappedPostMeta, true);
|
wrappedPostMeta, true);
|
||||||
@@ -585,15 +612,21 @@ public class BlogManagerImplTest extends BriarTestCase {
|
|||||||
oneOf(blogPostFactory).createBlogComment(blog1.getId(),
|
oneOf(blogPostFactory).createBlogComment(blog1.getId(),
|
||||||
localAuthor1, comment, rssMessageId, wrappedPostId);
|
localAuthor1, comment, rssMessageId, wrappedPostId);
|
||||||
will(returnValue(commentMsg));
|
will(returnValue(commentMsg));
|
||||||
|
oneOf(clientHelper).toList(localAuthor1);
|
||||||
|
will(returnValue(authorList1));
|
||||||
// Store the comment
|
// Store the comment
|
||||||
oneOf(clientHelper).addLocalMessage(txn, commentMsg, commentMeta,
|
oneOf(clientHelper).addLocalMessage(txn, commentMsg, commentMeta,
|
||||||
true);
|
true);
|
||||||
// Create the headers for the comment and the wrapped post
|
// Create the headers for the comment and the wrapped post
|
||||||
|
oneOf(clientHelper).parseAndValidateAuthor(authorList1);
|
||||||
|
will(returnValue(localAuthor1));
|
||||||
oneOf(identityManager).getAuthorStatus(txn, localAuthor1.getId());
|
oneOf(identityManager).getAuthorStatus(txn, localAuthor1.getId());
|
||||||
will(returnValue(OURSELVES));
|
will(returnValue(OURSELVES));
|
||||||
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
||||||
wrappedPostId);
|
wrappedPostId);
|
||||||
will(returnValue(wrappedPostMeta));
|
will(returnValue(wrappedPostMeta));
|
||||||
|
oneOf(clientHelper).parseAndValidateAuthor(rssAuthorList);
|
||||||
|
will(returnValue(rssLocalAuthor));
|
||||||
oneOf(db).commitTransaction(txn);
|
oneOf(db).commitTransaction(txn);
|
||||||
oneOf(db).endTransaction(txn);
|
oneOf(db).endTransaction(txn);
|
||||||
}});
|
}});
|
||||||
@@ -654,7 +687,7 @@ public class BlogManagerImplTest extends BriarTestCase {
|
|||||||
new BdfEntry(KEY_TYPE, WRAPPED_POST.getInt()),
|
new BdfEntry(KEY_TYPE, WRAPPED_POST.getInt()),
|
||||||
new BdfEntry(KEY_RSS_FEED, true),
|
new BdfEntry(KEY_RSS_FEED, true),
|
||||||
new BdfEntry(KEY_ORIGINAL_MSG_ID, messageId),
|
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_TIMESTAMP, timestamp),
|
||||||
new BdfEntry(KEY_TIME_RECEIVED, timeReceived)
|
new BdfEntry(KEY_TIME_RECEIVED, timeReceived)
|
||||||
);
|
);
|
||||||
@@ -666,7 +699,7 @@ public class BlogManagerImplTest extends BriarTestCase {
|
|||||||
new BdfEntry(KEY_COMMENT, comment),
|
new BdfEntry(KEY_COMMENT, comment),
|
||||||
new BdfEntry(KEY_PARENT_MSG_ID, rewrappedPostId),
|
new BdfEntry(KEY_PARENT_MSG_ID, rewrappedPostId),
|
||||||
new BdfEntry(KEY_ORIGINAL_MSG_ID, originalCommentId),
|
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_TIMESTAMP, timestamp),
|
||||||
new BdfEntry(KEY_TIME_RECEIVED, timeReceived)
|
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_MSG_ID, localCommentId),
|
||||||
new BdfEntry(KEY_ORIGINAL_PARENT_MSG_ID, originalCommentId),
|
new BdfEntry(KEY_ORIGINAL_PARENT_MSG_ID, originalCommentId),
|
||||||
new BdfEntry(KEY_PARENT_MSG_ID, wrappedCommentId),
|
new BdfEntry(KEY_PARENT_MSG_ID, wrappedCommentId),
|
||||||
new BdfEntry(KEY_AUTHOR, authorDict2)
|
new BdfEntry(KEY_AUTHOR, authorList2)
|
||||||
);
|
);
|
||||||
|
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
@@ -693,6 +726,8 @@ public class BlogManagerImplTest extends BriarTestCase {
|
|||||||
oneOf(blogPostFactory).rewrapWrappedPost(blog2.getId(),
|
oneOf(blogPostFactory).rewrapWrappedPost(blog2.getId(),
|
||||||
wrappedPostBody);
|
wrappedPostBody);
|
||||||
will(returnValue(rewrappedPostMsg));
|
will(returnValue(rewrappedPostMsg));
|
||||||
|
oneOf(clientHelper).toList(rssLocalAuthor);
|
||||||
|
will(returnValue(rssAuthorList));
|
||||||
// Store the rewrapped post
|
// Store the rewrapped post
|
||||||
oneOf(clientHelper).addLocalMessage(txn, rewrappedPostMsg,
|
oneOf(clientHelper).addLocalMessage(txn, rewrappedPostMsg,
|
||||||
rewrappedPostMeta, true);
|
rewrappedPostMeta, true);
|
||||||
@@ -708,6 +743,8 @@ public class BlogManagerImplTest extends BriarTestCase {
|
|||||||
blog1.getGroup().getDescriptor(), timestamp,
|
blog1.getGroup().getDescriptor(), timestamp,
|
||||||
originalCommentBody, rewrappedPostId);
|
originalCommentBody, rewrappedPostId);
|
||||||
will(returnValue(wrappedCommentMsg));
|
will(returnValue(wrappedCommentMsg));
|
||||||
|
oneOf(clientHelper).toList(localAuthor1);
|
||||||
|
will(returnValue(authorList1));
|
||||||
// Store the wrapped comment
|
// Store the wrapped comment
|
||||||
oneOf(clientHelper).addLocalMessage(txn, wrappedCommentMsg,
|
oneOf(clientHelper).addLocalMessage(txn, wrappedCommentMsg,
|
||||||
wrappedCommentMeta, true);
|
wrappedCommentMeta, true);
|
||||||
@@ -716,21 +753,29 @@ public class BlogManagerImplTest extends BriarTestCase {
|
|||||||
localAuthor2, localComment, originalCommentId,
|
localAuthor2, localComment, originalCommentId,
|
||||||
wrappedCommentId);
|
wrappedCommentId);
|
||||||
will(returnValue(localCommentMsg));
|
will(returnValue(localCommentMsg));
|
||||||
|
oneOf(clientHelper).toList(localAuthor2);
|
||||||
|
will(returnValue(authorList2));
|
||||||
// Store the new comment
|
// Store the new comment
|
||||||
oneOf(clientHelper).addLocalMessage(txn, localCommentMsg,
|
oneOf(clientHelper).addLocalMessage(txn, localCommentMsg,
|
||||||
localCommentMeta, true);
|
localCommentMeta, true);
|
||||||
// Create the headers for the new comment, the wrapped comment and
|
// Create the headers for the new comment, the wrapped comment and
|
||||||
// the rewrapped post
|
// the rewrapped post
|
||||||
|
oneOf(clientHelper).parseAndValidateAuthor(authorList2);
|
||||||
|
will(returnValue(localAuthor2));
|
||||||
oneOf(identityManager).getAuthorStatus(txn, localAuthor2.getId());
|
oneOf(identityManager).getAuthorStatus(txn, localAuthor2.getId());
|
||||||
will(returnValue(OURSELVES));
|
will(returnValue(OURSELVES));
|
||||||
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
||||||
wrappedCommentId);
|
wrappedCommentId);
|
||||||
will(returnValue(wrappedCommentMeta));
|
will(returnValue(wrappedCommentMeta));
|
||||||
|
oneOf(clientHelper).parseAndValidateAuthor(authorList1);
|
||||||
|
will(returnValue(localAuthor1));
|
||||||
oneOf(identityManager).getAuthorStatus(txn, localAuthor1.getId());
|
oneOf(identityManager).getAuthorStatus(txn, localAuthor1.getId());
|
||||||
will(returnValue(VERIFIED));
|
will(returnValue(VERIFIED));
|
||||||
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
||||||
rewrappedPostId);
|
rewrappedPostId);
|
||||||
will(returnValue(rewrappedPostMeta));
|
will(returnValue(rewrappedPostMeta));
|
||||||
|
oneOf(clientHelper).parseAndValidateAuthor(rssAuthorList);
|
||||||
|
will(returnValue(rssLocalAuthor));
|
||||||
oneOf(db).commitTransaction(txn);
|
oneOf(db).commitTransaction(txn);
|
||||||
oneOf(db).endTransaction(txn);
|
oneOf(db).endTransaction(txn);
|
||||||
}});
|
}});
|
||||||
@@ -827,13 +872,8 @@ public class BlogManagerImplTest extends BriarTestCase {
|
|||||||
return new Blog(group, localAuthor, rssFeed);
|
return new Blog(group, localAuthor, rssFeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
private BdfDictionary authorToBdfDictionary(Author a) {
|
private BdfList authorToBdfList(Author a) {
|
||||||
return BdfDictionary.of(
|
return BdfList.of(a.getFormatVersion(), a.getName(), a.getPublicKey());
|
||||||
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())
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,6 @@ package org.briarproject.briar.blog;
|
|||||||
import org.briarproject.bramble.api.FormatException;
|
import org.briarproject.bramble.api.FormatException;
|
||||||
import org.briarproject.bramble.api.client.ClientHelper;
|
import org.briarproject.bramble.api.client.ClientHelper;
|
||||||
import org.briarproject.bramble.api.data.BdfDictionary;
|
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.BdfList;
|
||||||
import org.briarproject.bramble.api.data.MetadataEncoder;
|
import org.briarproject.bramble.api.data.MetadataEncoder;
|
||||||
import org.briarproject.bramble.api.identity.Author;
|
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.test.TestUtils.getRandomId;
|
||||||
import static org.briarproject.bramble.util.StringUtils.getRandomString;
|
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;
|
||||||
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_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_MSG_ID;
|
||||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_ORIGINAL_PARENT_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_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_READ;
|
||||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_RSS_FEED;
|
import static org.briarproject.briar.api.blog.BlogConstants.KEY_RSS_FEED;
|
||||||
import static org.briarproject.briar.api.blog.BlogManager.CLIENT_ID;
|
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 Mockery context = new Mockery();
|
||||||
private final Blog blog, rssBlog;
|
private final Blog blog, rssBlog;
|
||||||
private final BdfDictionary authorDict;
|
private final BdfList authorList;
|
||||||
private final byte[] descriptor;
|
private final byte[] descriptor;
|
||||||
private final Group group;
|
private final Group group;
|
||||||
private final Message message;
|
private final Message message;
|
||||||
@@ -73,11 +68,10 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
|||||||
descriptor = getRandomBytes(42);
|
descriptor = getRandomBytes(42);
|
||||||
group = new Group(groupId, CLIENT_ID, descriptor);
|
group = new Group(groupId, CLIENT_ID, descriptor);
|
||||||
author = getAuthor();
|
author = getAuthor();
|
||||||
authorDict = BdfDictionary.of(
|
authorList = BdfList.of(
|
||||||
new BdfEntry(KEY_AUTHOR_ID, author.getId()),
|
author.getFormatVersion(),
|
||||||
new BdfEntry(KEY_FORMAT_VERSION, author.getFormatVersion()),
|
author.getName(),
|
||||||
new BdfEntry(KEY_AUTHOR_NAME, author.getName()),
|
author.getPublicKey()
|
||||||
new BdfEntry(KEY_PUBLIC_KEY, author.getPublicKey())
|
|
||||||
);
|
);
|
||||||
blog = new Blog(group, author, false);
|
blog = new Blog(group, author, false);
|
||||||
rssBlog = new Blog(group, author, true);
|
rssBlog = new Blog(group, author, true);
|
||||||
@@ -117,7 +111,7 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
|||||||
BdfDictionary result =
|
BdfDictionary result =
|
||||||
validator.validateMessage(message, group, m).getDictionary();
|
validator.validateMessage(message, group, m).getDictionary();
|
||||||
|
|
||||||
assertEquals(authorDict, result.getDictionary(KEY_AUTHOR));
|
assertEquals(authorList, result.getList(KEY_AUTHOR));
|
||||||
assertFalse(result.getBoolean(KEY_READ));
|
assertFalse(result.getBoolean(KEY_READ));
|
||||||
assertEquals(rssFeed, result.getBoolean(KEY_RSS_FEED));
|
assertEquals(rssFeed, result.getBoolean(KEY_RSS_FEED));
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
@@ -129,7 +123,7 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
|||||||
BdfList content = BdfList.of(null, null, body);
|
BdfList content = BdfList.of(null, null, body);
|
||||||
BdfList m = BdfList.of(POST.getInt(), content, null);
|
BdfList m = BdfList.of(POST.getInt(), content, null);
|
||||||
|
|
||||||
validator.validateMessage(message, group, m).getDictionary();
|
validator.validateMessage(message, group, m);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = FormatException.class)
|
@Test(expected = FormatException.class)
|
||||||
@@ -138,7 +132,7 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
|||||||
BdfList content = BdfList.of(null, null, body, null);
|
BdfList content = BdfList.of(null, null, body, null);
|
||||||
BdfList m = BdfList.of(POST.getInt(), content, null);
|
BdfList m = BdfList.of(POST.getInt(), content, null);
|
||||||
|
|
||||||
validator.validateMessage(message, group, m).getDictionary();
|
validator.validateMessage(message, group, m);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -159,7 +153,7 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
|||||||
validator.validateMessage(message, group, m).getDictionary();
|
validator.validateMessage(message, group, m).getDictionary();
|
||||||
|
|
||||||
assertEquals(comment, result.getString(KEY_COMMENT));
|
assertEquals(comment, result.getString(KEY_COMMENT));
|
||||||
assertEquals(authorDict, result.getDictionary(KEY_AUTHOR));
|
assertEquals(authorList, result.getList(KEY_AUTHOR));
|
||||||
assertEquals(pOriginalId.getBytes(),
|
assertEquals(pOriginalId.getBytes(),
|
||||||
result.getRaw(KEY_ORIGINAL_PARENT_MSG_ID));
|
result.getRaw(KEY_ORIGINAL_PARENT_MSG_ID));
|
||||||
assertEquals(currentId.getBytes(), result.getRaw(KEY_PARENT_MSG_ID));
|
assertEquals(currentId.getBytes(), result.getRaw(KEY_PARENT_MSG_ID));
|
||||||
@@ -229,7 +223,7 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
|||||||
BdfDictionary result =
|
BdfDictionary result =
|
||||||
validator.validateMessage(message, group, m).getDictionary();
|
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));
|
assertEquals(rssFeed, result.getBoolean(KEY_RSS_FEED));
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
}
|
}
|
||||||
@@ -272,7 +266,7 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
|||||||
validator.validateMessage(message, group, m).getDictionary();
|
validator.validateMessage(message, group, m).getDictionary();
|
||||||
|
|
||||||
assertEquals(comment, result.getString(KEY_COMMENT));
|
assertEquals(comment, result.getString(KEY_COMMENT));
|
||||||
assertEquals(authorDict, result.getDictionary(KEY_AUTHOR));
|
assertEquals(authorList, result.getList(KEY_AUTHOR));
|
||||||
assertEquals(
|
assertEquals(
|
||||||
message.getId().getBytes(), result.getRaw(KEY_ORIGINAL_MSG_ID));
|
message.getId().getBytes(), result.getRaw(KEY_ORIGINAL_MSG_ID));
|
||||||
assertEquals(currentId.getBytes(), result.getRaw(KEY_PARENT_MSG_ID));
|
assertEquals(currentId.getBytes(), result.getRaw(KEY_PARENT_MSG_ID));
|
||||||
@@ -284,6 +278,8 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
|||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(blogFactory).parseBlog(group);
|
oneOf(blogFactory).parseBlog(group);
|
||||||
will(returnValue(b));
|
will(returnValue(b));
|
||||||
|
oneOf(clientHelper).toList(b.getAuthor());
|
||||||
|
will(returnValue(authorList));
|
||||||
oneOf(clientHelper)
|
oneOf(clientHelper)
|
||||||
.verifySignature(label, sig, author.getPublicKey(), signed);
|
.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.bramble.util.StringUtils.getRandomString;
|
||||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_READ;
|
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_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_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.KEY_TIMESTAMP;
|
||||||
import static org.briarproject.briar.api.forum.ForumConstants.MAX_FORUM_POST_BODY_LENGTH;
|
import static org.briarproject.briar.api.forum.ForumConstants.MAX_FORUM_POST_BODY_LENGTH;
|
||||||
import static org.briarproject.briar.api.forum.ForumPostFactory.SIGNING_LABEL_POST;
|
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,
|
BdfMessageContext messageContext = v.validateMessage(message, group,
|
||||||
BdfList.of(null, authorList, content, signature));
|
BdfList.of(null, authorList, content, signature));
|
||||||
assertExpectedContext(messageContext, false, authorName);
|
assertExpectedContext(messageContext, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = FormatException.class)
|
@Test(expected = FormatException.class)
|
||||||
@@ -149,7 +145,7 @@ public class ForumPostValidatorTest extends ValidatorTestCase {
|
|||||||
|
|
||||||
BdfMessageContext messageContext = v.validateMessage(message, group,
|
BdfMessageContext messageContext = v.validateMessage(message, group,
|
||||||
BdfList.of(parentId, authorList, shortContent, signature));
|
BdfList.of(parentId, authorList, shortContent, signature));
|
||||||
assertExpectedContext(messageContext, true, authorName);
|
assertExpectedContext(messageContext, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = FormatException.class)
|
@Test(expected = FormatException.class)
|
||||||
@@ -224,7 +220,7 @@ public class ForumPostValidatorTest extends ValidatorTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void assertExpectedContext(BdfMessageContext messageContext,
|
private void assertExpectedContext(BdfMessageContext messageContext,
|
||||||
boolean hasParent, String authorName) throws FormatException {
|
boolean hasParent) throws FormatException {
|
||||||
BdfDictionary meta = messageContext.getDictionary();
|
BdfDictionary meta = messageContext.getDictionary();
|
||||||
Collection<MessageId> dependencies = messageContext.getDependencies();
|
Collection<MessageId> dependencies = messageContext.getDependencies();
|
||||||
if (hasParent) {
|
if (hasParent) {
|
||||||
@@ -238,12 +234,6 @@ public class ForumPostValidatorTest extends ValidatorTestCase {
|
|||||||
}
|
}
|
||||||
assertEquals(timestamp, meta.getLong(KEY_TIMESTAMP).longValue());
|
assertEquals(timestamp, meta.getLong(KEY_TIMESTAMP).longValue());
|
||||||
assertFalse(meta.getBoolean(KEY_READ));
|
assertFalse(meta.getBoolean(KEY_READ));
|
||||||
BdfDictionary authorMeta = meta.getDictionary(KEY_AUTHOR);
|
assertEquals(authorList, meta.getList(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));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.PrivateGroupConstants.MAX_GROUP_POST_BODY_LENGTH;
|
||||||
import static org.briarproject.briar.api.privategroup.invitation.GroupInvitationFactory.SIGNING_LABEL_INVITE;
|
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_INITIAL_JOIN_MSG;
|
||||||
import static org.briarproject.briar.privategroup.GroupConstants.KEY_MEMBER_FORMAT_VERSION;
|
import static org.briarproject.briar.privategroup.GroupConstants.KEY_MEMBER;
|
||||||
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_PARENT_MSG_ID;
|
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_PREVIOUS_MSG_ID;
|
||||||
import static org.briarproject.briar.privategroup.GroupConstants.KEY_READ;
|
import static org.briarproject.briar.privategroup.GroupConstants.KEY_READ;
|
||||||
@@ -180,7 +177,7 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
|
|||||||
memberSignature);
|
memberSignature);
|
||||||
BdfMessageContext messageContext =
|
BdfMessageContext messageContext =
|
||||||
validator.validateMessage(message, group, body);
|
validator.validateMessage(message, group, body);
|
||||||
assertExpectedMessageContext(messageContext, JOIN, creator,
|
assertExpectedMessageContext(messageContext, JOIN, creatorList,
|
||||||
Collections.emptyList());
|
Collections.emptyList());
|
||||||
assertTrue(messageContext.getDictionary()
|
assertTrue(messageContext.getDictionary()
|
||||||
.getBoolean(KEY_INITIAL_JOIN_MSG));
|
.getBoolean(KEY_INITIAL_JOIN_MSG));
|
||||||
@@ -365,7 +362,7 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
|
|||||||
memberSignature);
|
memberSignature);
|
||||||
BdfMessageContext messageContext =
|
BdfMessageContext messageContext =
|
||||||
validator.validateMessage(message, group, body);
|
validator.validateMessage(message, group, body);
|
||||||
assertExpectedMessageContext(messageContext, JOIN, member,
|
assertExpectedMessageContext(messageContext, JOIN, memberList,
|
||||||
Collections.emptyList());
|
Collections.emptyList());
|
||||||
assertFalse(messageContext.getDictionary()
|
assertFalse(messageContext.getDictionary()
|
||||||
.getBoolean(KEY_INITIAL_JOIN_MSG));
|
.getBoolean(KEY_INITIAL_JOIN_MSG));
|
||||||
@@ -616,7 +613,7 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
|
|||||||
expectPostMessage(parentId, true);
|
expectPostMessage(parentId, true);
|
||||||
BdfMessageContext messageContext =
|
BdfMessageContext messageContext =
|
||||||
validator.validateMessage(message, group, body);
|
validator.validateMessage(message, group, body);
|
||||||
assertExpectedMessageContext(messageContext, POST, member,
|
assertExpectedMessageContext(messageContext, POST, memberList,
|
||||||
Arrays.asList(parentId, previousMsgId));
|
Arrays.asList(parentId, previousMsgId));
|
||||||
assertArrayEquals(previousMsgId.getBytes(),
|
assertArrayEquals(previousMsgId.getBytes(),
|
||||||
messageContext.getDictionary().getRaw(KEY_PREVIOUS_MSG_ID));
|
messageContext.getDictionary().getRaw(KEY_PREVIOUS_MSG_ID));
|
||||||
@@ -631,7 +628,7 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
|
|||||||
expectPostMessage(null, true);
|
expectPostMessage(null, true);
|
||||||
BdfMessageContext messageContext =
|
BdfMessageContext messageContext =
|
||||||
validator.validateMessage(message, group, body);
|
validator.validateMessage(message, group, body);
|
||||||
assertExpectedMessageContext(messageContext, POST, member,
|
assertExpectedMessageContext(messageContext, POST, memberList,
|
||||||
Collections.singletonList(previousMsgId));
|
Collections.singletonList(previousMsgId));
|
||||||
assertArrayEquals(previousMsgId.getBytes(),
|
assertArrayEquals(previousMsgId.getBytes(),
|
||||||
messageContext.getDictionary().getRaw(KEY_PREVIOUS_MSG_ID));
|
messageContext.getDictionary().getRaw(KEY_PREVIOUS_MSG_ID));
|
||||||
@@ -659,18 +656,14 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void assertExpectedMessageContext(BdfMessageContext c,
|
private void assertExpectedMessageContext(BdfMessageContext c,
|
||||||
MessageType type, Author member,
|
MessageType type, BdfList member,
|
||||||
Collection<MessageId> dependencies) throws FormatException {
|
Collection<MessageId> dependencies) throws FormatException {
|
||||||
BdfDictionary d = c.getDictionary();
|
BdfDictionary d = c.getDictionary();
|
||||||
assertEquals(type.getInt(), d.getLong(KEY_TYPE).intValue());
|
assertEquals(type.getInt(), d.getLong(KEY_TYPE).intValue());
|
||||||
assertEquals(message.getTimestamp(),
|
assertEquals(message.getTimestamp(),
|
||||||
d.getLong(KEY_TIMESTAMP).longValue());
|
d.getLong(KEY_TIMESTAMP).longValue());
|
||||||
assertFalse(d.getBoolean(KEY_READ));
|
assertFalse(d.getBoolean(KEY_READ));
|
||||||
assertEquals(member.getId().getBytes(), d.getRaw(KEY_MEMBER_ID));
|
assertEquals(member, d.getList(KEY_MEMBER));
|
||||||
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(dependencies, c.getDependencies());
|
assertEquals(dependencies, c.getDependencies());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user