Merge branch '700-update-blog-backend-to-match-current-usage' into 'master'

Update blog backend to match current usage

Closes #700

See merge request !371
This commit is contained in:
akwizgran
2016-11-01 10:56:02 +00:00
28 changed files with 154 additions and 386 deletions

View File

@@ -538,7 +538,7 @@ public class BlogManagerTest extends BriarIntegrationTest {
author0 = authorFactory author0 = authorFactory
.createLocalAuthor(AUTHOR1, publicKey0, privateKey0); .createLocalAuthor(AUTHOR1, publicKey0, privateKey0);
identityManager0.addLocalAuthor(author0); identityManager0.addLocalAuthor(author0);
blog0 = blogFactory.createPersonalBlog(author0); blog0 = blogFactory.createBlog(author0);
KeyPair keyPair1 = crypto.generateSignatureKeyPair(); KeyPair keyPair1 = crypto.generateSignatureKeyPair();
byte[] publicKey1 = keyPair1.getPublic().getEncoded(); byte[] publicKey1 = keyPair1.getPublic().getEncoded();
@@ -546,7 +546,7 @@ public class BlogManagerTest extends BriarIntegrationTest {
author1 = authorFactory author1 = authorFactory
.createLocalAuthor(AUTHOR2, publicKey1, privateKey1); .createLocalAuthor(AUTHOR2, publicKey1, privateKey1);
identityManager1.addLocalAuthor(author1); identityManager1.addLocalAuthor(author1);
blog1 = blogFactory.createPersonalBlog(author1); blog1 = blogFactory.createBlog(author1);
} }
private void addDefaultContacts() throws DbException { private void addDefaultContacts() throws DbException {

View File

@@ -72,12 +72,12 @@ public class BlogSharingIntegrationTest extends BriarIntegrationTest {
private BlogManager blogManager0, blogManager1; private BlogManager blogManager0, blogManager1;
private ContactManager contactManager0, contactManager1, contactManager2; private ContactManager contactManager0, contactManager1, contactManager2;
private Contact contact1, contact2, contact01, contact02; private Contact contact1, contact2, contact01, contact02;
private ContactId contactId1, contactId2, contactId01, contactId02; private ContactId contactId1, contactId01;
private IdentityManager identityManager0, identityManager1, private IdentityManager identityManager0, identityManager1,
identityManager2; identityManager2;
private LocalAuthor author0, author1, author2; private LocalAuthor author0, author1, author2;
private Blog blog0, blog1, blog2; private Blog blog0, blog1, blog2;
private SharerListener listener0, listener2; private SharerListener listener0;
private InviteeListener listener1; private InviteeListener listener1;
@Inject @Inject
@@ -670,7 +670,7 @@ public class BlogSharingIntegrationTest extends BriarIntegrationTest {
); );
contact1 = contactManager0.getContact(contactId1); contact1 = contactManager0.getContact(contactId1);
// sharer adds second contact // sharer adds second contact
contactId2 = contactManager0.addContact(author2, ContactId contactId2 = contactManager0.addContact(author2,
author0.getId(), master, clock.currentTimeMillis(), true, author0.getId(), master, clock.currentTimeMillis(), true,
true, true true, true
); );
@@ -681,7 +681,7 @@ public class BlogSharingIntegrationTest extends BriarIntegrationTest {
true, true true, true
); );
contact01 = contactManager1.getContact(contactId01); contact01 = contactManager1.getContact(contactId01);
contactId02 = contactManager2.addContact(author0, ContactId contactId02 = contactManager2.addContact(author0,
author2.getId(), master, clock.currentTimeMillis(), true, author2.getId(), master, clock.currentTimeMillis(), true,
true, true true, true
); );
@@ -699,7 +699,7 @@ public class BlogSharingIntegrationTest extends BriarIntegrationTest {
t0.getEventBus().addListener(listener0); t0.getEventBus().addListener(listener0);
listener1 = new InviteeListener(accept); listener1 = new InviteeListener(accept);
t1.getEventBus().addListener(listener1); t1.getEventBus().addListener(listener1);
listener2 = new SharerListener(); SharerListener listener2 = new SharerListener();
t2.getEventBus().addListener(listener2); t2.getEventBus().addListener(listener2);
} }

View File

@@ -41,7 +41,6 @@
<dimen name="message_bubble_timestamp_margin">7dp</dimen> <dimen name="message_bubble_timestamp_margin">7dp</dimen>
<dimen name="forum_nested_line_width">2dp</dimen> <dimen name="forum_nested_line_width">2dp</dimen>
<dimen name="forum_nested_indicator">24dp</dimen> <dimen name="forum_nested_indicator">24dp</dimen>
<dimen name="forum_avatar_size">20dp</dimen>
<dimen name="blogs_avatar_normal_size">30dp</dimen> <dimen name="blogs_avatar_normal_size">30dp</dimen>
<dimen name="blogs_avatar_icon_size">15dp</dimen> <dimen name="blogs_avatar_icon_size">15dp</dimen>

View File

@@ -240,25 +240,14 @@
<string name="nobody">Nobody</string> <string name="nobody">Nobody</string>
<!-- Blogs --> <!-- Blogs -->
<string name="blogs_my_blogs_create">Create Blog</string>
<string name="blogs_my_blogs_label">Add new Blog</string>
<string name="blogs_my_blogs_create_hint_title">Blog title (cannot be changed later)</string>
<string name="blogs_my_blogs_create_hint_desc">A short description of your new blog</string>
<string name="blogs_my_blogs_create_hint_desc_explanation">Potential readers may or may not subscribe to your blog based on the content of the description.</string>
<string name="blogs_my_blogs_created">Blog created</string>
<string name="blogs_blog_is_empty">This blog is empty</string>
<string name="blogs_other_blog_empty_state">This blog is currently empty.\n\nEither the author hasn\'t written anything yet, or the person who shared this blog with you needs to come online, so posts can be synchronized.</string> <string name="blogs_other_blog_empty_state">This blog is currently empty.\n\nEither the author hasn\'t written anything yet, or the person who shared this blog with you needs to come online, so posts can be synchronized.</string>
<string name="tag_new">NEW</string>
<string name="read_more">read more</string> <string name="read_more">read more</string>
<string name="blogs_write_blog_post">Write Blog Post</string> <string name="blogs_write_blog_post">Write Blog Post</string>
<string name="blogs_write_blog_post_title_hint">Add a title (optional)</string>
<string name="blogs_write_blog_post_body_hint">Type your blog post here</string> <string name="blogs_write_blog_post_body_hint">Type your blog post here</string>
<string name="blogs_publish_blog_post">Publish</string> <string name="blogs_publish_blog_post">Publish</string>
<string name="blogs_blog_post_created">Blog Post Created</string> <string name="blogs_blog_post_created">Blog Post Created</string>
<string name="blogs_blog_post_received">New Blog Post Received</string> <string name="blogs_blog_post_received">New Blog Post Received</string>
<string name="blogs_blog_post_scroll_to">Scroll To</string> <string name="blogs_blog_post_scroll_to">Scroll To</string>
<string name="blogs_blog_failed_to_load">Blog failed to load</string>
<string name="blogs_blog_post_failed_to_load">Blog post failed to load</string>
<string name="blogs_feed_empty_state">This is the global blog feed.\n\nIt looks like nobody blogged anything, yet.\n\nBe the first and tap the pen icon to write a new blog post.</string> <string name="blogs_feed_empty_state">This is the global blog feed.\n\nIt looks like nobody blogged anything, yet.\n\nBe the first and tap the pen icon to write a new blog post.</string>
<string name="blogs_personal_blog">%s\'s Personal Blog</string> <string name="blogs_personal_blog">%s\'s Personal Blog</string>
<string name="blogs_remove_blog">Remove Blog</string> <string name="blogs_remove_blog">Remove Blog</string>
@@ -268,9 +257,6 @@
<string name="blogs_reblog_comment_hint">Add an optional comment</string> <string name="blogs_reblog_comment_hint">Add an optional comment</string>
<string name="blogs_reblog_button">Reblog</string> <string name="blogs_reblog_button">Reblog</string>
<string name="blogs_blog_list">Blog List</string>
<string name="blogs_available_blogs">Available Blogs</string>
<!-- Blog Sharing --> <!-- Blog Sharing -->
<string name="blogs_sharing_share">Share Blog</string> <string name="blogs_sharing_share">Share Blog</string>
<string name="blogs_sharing_error">There was an error sharing this blog.</string> <string name="blogs_sharing_error">There was an error sharing this blog.</string>
@@ -353,12 +339,6 @@
<string name="link_warning_text">This can be used to identify you. Think about whether you trust the person that sent you this link and consider opening it with Orfox.</string> <string name="link_warning_text">This can be used to identify you. Think about whether you trust the person that sent you this link and consider opening it with Orfox.</string>
<string name="link_warning_open_link">Open Link</string> <string name="link_warning_open_link">Open Link</string>
<!-- Multiple Identities -->
<string name="anonymous">Anonymous</string>
<string name="new_identity_title">New Identity</string>
<string name="create_identity_button">Create Identity</string>
<string name="identity_created_toast">Identity created</string>
<!-- Crash Reporter --> <!-- Crash Reporter -->
<string name="crash_report_title">Briar Crash Report</string> <string name="crash_report_title">Briar Crash Report</string>
<string name="briar_crashed">Sorry, Briar has crashed.</string> <string name="briar_crashed">Sorry, Briar has crashed.</string>

View File

@@ -59,17 +59,6 @@
<item name="android:textColor">@android:color/primary_text_light</item> <item name="android:textColor">@android:color/primary_text_light</item>
</style> </style>
<style name="BriarTag">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginRight">@dimen/margin_medium</item>
<item name="android:paddingLeft">3dp</item>
<item name="android:paddingRight">3dp</item>
<item name="android:background">@color/briar_primary</item>
<item name="android:textSize">@dimen/text_size_tiny</item>
<item name="android:textColor">@color/briar_text_primary_inverse</item>
</style>
<style name="Divider"> <style name="Divider">
<item name="android:background">@color/divider</item> <item name="android:background">@color/divider</item>
</style> </style>

View File

@@ -2,7 +2,6 @@ package org.briarproject.android.blogs;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.widget.ProgressBar;
import org.briarproject.R; import org.briarproject.R;
import org.briarproject.android.ActivityComponent; import org.briarproject.android.ActivityComponent;
@@ -18,8 +17,6 @@ public class BlogActivity extends BriarActivity implements
static final int REQUEST_WRITE_POST = 1; static final int REQUEST_WRITE_POST = 1;
static final int REQUEST_SHARE = 2; static final int REQUEST_SHARE = 2;
static final String BLOG_NAME = "briar.BLOG_NAME";
static final String IS_NEW_BLOG = "briar.IS_NEW_BLOG";
@Inject @Inject
BlogController blogController; BlogController blogController;
@@ -35,17 +32,10 @@ public class BlogActivity extends BriarActivity implements
GroupId groupId = new GroupId(b); GroupId groupId = new GroupId(b);
blogController.setGroupId(groupId); blogController.setGroupId(groupId);
// Name of the blog
String blogName = i.getStringExtra(BLOG_NAME);
if (blogName != null) setTitle(blogName);
// Was this blog just created?
boolean isNew = i.getBooleanExtra(IS_NEW_BLOG, false);
setContentView(R.layout.activity_fragment_container); setContentView(R.layout.activity_fragment_container);
if (state == null) { if (state == null) {
BlogFragment f = BlogFragment.newInstance(groupId, blogName, isNew); BlogFragment f = BlogFragment.newInstance(groupId);
getSupportFragmentManager().beginTransaction() getSupportFragmentManager().beginTransaction()
.replace(R.id.fragmentContainer, f, f.getUniqueTag()) .replace(R.id.fragmentContainer, f, f.getUniqueTag())
.commit(); .commit();

View File

@@ -38,12 +38,9 @@ import javax.inject.Inject;
import static android.app.Activity.RESULT_OK; import static android.app.Activity.RESULT_OK;
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP; import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
import static android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP; import static android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP;
import static android.support.design.widget.Snackbar.LENGTH_LONG;
import static android.support.v4.app.ActivityOptionsCompat.makeCustomAnimation; import static android.support.v4.app.ActivityOptionsCompat.makeCustomAnimation;
import static android.widget.Toast.LENGTH_SHORT; import static android.widget.Toast.LENGTH_SHORT;
import static org.briarproject.android.BriarActivity.GROUP_ID; import static org.briarproject.android.BriarActivity.GROUP_ID;
import static org.briarproject.android.blogs.BlogActivity.BLOG_NAME;
import static org.briarproject.android.blogs.BlogActivity.IS_NEW_BLOG;
import static org.briarproject.android.blogs.BlogActivity.REQUEST_SHARE; import static org.briarproject.android.blogs.BlogActivity.REQUEST_SHARE;
import static org.briarproject.android.blogs.BlogActivity.REQUEST_WRITE_POST; import static org.briarproject.android.blogs.BlogActivity.REQUEST_WRITE_POST;
@@ -56,21 +53,17 @@ public class BlogFragment extends BaseFragment implements
BlogController blogController; BlogController blogController;
private GroupId groupId; private GroupId groupId;
private String blogName;
private BlogPostAdapter adapter; private BlogPostAdapter adapter;
private BriarRecyclerView list; private BriarRecyclerView list;
private MenuItem writeButton, deleteButton; private MenuItem writeButton, deleteButton;
private boolean isMyBlog = false, canDeleteBlog = false; private boolean isMyBlog = false, canDeleteBlog = false;
static BlogFragment newInstance(GroupId groupId, @Nullable String name, static BlogFragment newInstance(GroupId groupId) {
boolean isNew) {
BlogFragment f = new BlogFragment(); BlogFragment f = new BlogFragment();
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putByteArray(GROUP_ID, groupId.getBytes()); bundle.putByteArray(GROUP_ID, groupId.getBytes());
bundle.putString(BLOG_NAME, name);
bundle.putBoolean(IS_NEW_BLOG, isNew);
f.setArguments(bundle); f.setArguments(bundle);
return f; return f;
@@ -84,8 +77,6 @@ public class BlogFragment extends BaseFragment implements
byte[] b = args.getByteArray(GROUP_ID); byte[] b = args.getByteArray(GROUP_ID);
if (b == null) throw new IllegalStateException("No group ID in args"); if (b == null) throw new IllegalStateException("No group ID in args");
groupId = new GroupId(b); groupId = new GroupId(b);
blogName = args.getString(BLOG_NAME);
boolean isNew = args.getBoolean(IS_NEW_BLOG);
View v = inflater.inflate(R.layout.fragment_blog, container, false); View v = inflater.inflate(R.layout.fragment_blog, container, false);
@@ -97,16 +88,6 @@ public class BlogFragment extends BaseFragment implements
list.showProgressBar(); list.showProgressBar();
list.setEmptyText(getString(R.string.blogs_other_blog_empty_state)); list.setEmptyText(getString(R.string.blogs_other_blog_empty_state));
// show snackbar if this blog was just created
if (isNew) {
Snackbar s = Snackbar.make(list, R.string.blogs_my_blogs_created,
LENGTH_LONG);
s.getView().setBackgroundResource(R.color.briar_primary);
s.show();
// show only once
args.putBoolean(IS_NEW_BLOG, false);
}
return v; return v;
} }
@@ -152,7 +133,6 @@ public class BlogFragment extends BaseFragment implements
Intent i = new Intent(getActivity(), Intent i = new Intent(getActivity(),
WriteBlogPostActivity.class); WriteBlogPostActivity.class);
i.putExtra(GROUP_ID, groupId.getBytes()); i.putExtra(GROUP_ID, groupId.getBytes());
i.putExtra(BLOG_NAME, blogName);
startActivityForResult(i, REQUEST_WRITE_POST, startActivityForResult(i, REQUEST_WRITE_POST,
options.toBundle()); options.toBundle());
return true; return true;
@@ -266,10 +246,6 @@ public class BlogFragment extends BaseFragment implements
private void setToolbarTitle(Author a) { private void setToolbarTitle(Author a) {
String title = getString(R.string.blogs_personal_blog, a.getName()); String title = getString(R.string.blogs_personal_blog, a.getName());
getActivity().setTitle(title); getActivity().setTitle(title);
// safe title in intent, so it can be restored automatically
Intent intent = getActivity().getIntent();
intent.putExtra(BLOG_NAME, title);
} }
private void showWriteButton() { private void showWriteButton() {

View File

@@ -17,10 +17,6 @@ class BlogItem {
return blog; return blog;
} }
String getName() {
return blog.getName();
}
boolean isOurs() { boolean isOurs() {
return ours; return ours;
} }

View File

@@ -35,7 +35,6 @@ import static android.app.Activity.RESULT_OK;
import static android.support.design.widget.Snackbar.LENGTH_LONG; import static android.support.design.widget.Snackbar.LENGTH_LONG;
import static android.support.v4.app.ActivityOptionsCompat.makeCustomAnimation; import static android.support.v4.app.ActivityOptionsCompat.makeCustomAnimation;
import static org.briarproject.android.BriarActivity.GROUP_ID; import static org.briarproject.android.BriarActivity.GROUP_ID;
import static org.briarproject.android.blogs.BlogActivity.BLOG_NAME;
import static org.briarproject.android.blogs.BlogActivity.REQUEST_WRITE_POST; import static org.briarproject.android.blogs.BlogActivity.REQUEST_WRITE_POST;
public class FeedFragment extends BaseFragment implements public class FeedFragment extends BaseFragment implements
@@ -171,7 +170,6 @@ public class FeedFragment extends BaseFragment implements
Intent i1 = Intent i1 =
new Intent(getActivity(), WriteBlogPostActivity.class); new Intent(getActivity(), WriteBlogPostActivity.class);
i1.putExtra(GROUP_ID, personalBlog.getId().getBytes()); i1.putExtra(GROUP_ID, personalBlog.getId().getBytes());
i1.putExtra(BLOG_NAME, personalBlog.getName());
startActivityForResult(i1, REQUEST_WRITE_POST, startActivityForResult(i1, REQUEST_WRITE_POST,
options.toBundle()); options.toBundle());
return true; return true;

View File

@@ -5,7 +5,6 @@ import org.briarproject.api.identity.Author;
import org.briarproject.api.nullsafety.NotNullByDefault; import org.briarproject.api.nullsafety.NotNullByDefault;
import org.briarproject.api.sharing.Shareable; import org.briarproject.api.sharing.Shareable;
import org.briarproject.api.sync.Group; import org.briarproject.api.sync.Group;
import org.jetbrains.annotations.NotNull;
import javax.annotation.concurrent.Immutable; import javax.annotation.concurrent.Immutable;
@@ -13,21 +12,13 @@ import javax.annotation.concurrent.Immutable;
@NotNullByDefault @NotNullByDefault
public class Blog extends BaseGroup implements Shareable { public class Blog extends BaseGroup implements Shareable {
private final String description;
private final Author author; private final Author author;
public Blog(Group group, String name, String description, Author author) { public Blog(Group group, Author author) {
super(group, name); super(group);
this.description = description;
this.author = author; this.author = author;
} }
@NotNull
public String getDescription() {
return description;
}
@NotNull
public Author getAuthor() { public Author getAuthor() {
return author; return author;
} }
@@ -36,4 +27,13 @@ public class Blog extends BaseGroup implements Shareable {
public boolean equals(Object o) { public boolean equals(Object o) {
return o instanceof Blog && super.equals(o); return o instanceof Blog && super.equals(o);
} }
/**
* Returns the blog's author's name, not the name as shown in the UI.
*/
@Override
public String getName() {
return author.getName();
}
} }

View File

@@ -16,12 +16,7 @@ public interface BlogConstants {
/** The maximum length of a blog comment in bytes. */ /** The maximum length of a blog comment in bytes. */
int MAX_BLOG_COMMENT_LENGTH = MAX_BLOG_POST_BODY_LENGTH; int MAX_BLOG_COMMENT_LENGTH = MAX_BLOG_POST_BODY_LENGTH;
/** The internal name of personal blogs that are created automatically */
String PERSONAL_BLOG_NAME = "briar.PERSONAL_BLOG_NAME";
/* Blog Sharing Constants */ /* Blog Sharing Constants */
String BLOG_TITLE = "blogTitle";
String BLOG_DESC = "blogDescription";
String BLOG_AUTHOR_NAME = "blogAuthorName"; String BLOG_AUTHOR_NAME = "blogAuthorName";
String BLOG_PUBLIC_KEY = "blogPublicKey"; String BLOG_PUBLIC_KEY = "blogPublicKey";

View File

@@ -2,19 +2,17 @@ package org.briarproject.api.blogs;
import org.briarproject.api.FormatException; import org.briarproject.api.FormatException;
import org.briarproject.api.identity.Author; import org.briarproject.api.identity.Author;
import org.briarproject.api.nullsafety.NotNullByDefault;
import org.briarproject.api.sync.Group; import org.briarproject.api.sync.Group;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@NotNullByDefault
public interface BlogFactory { public interface BlogFactory {
/** Creates a blog with the given name, description and author. */
Blog createBlog(@NotNull String name, @NotNull String description,
@NotNull Author author);
/** Creates a personal blog for a given author. */ /** Creates a personal blog for a given author. */
Blog createPersonalBlog(@NotNull Author author); Blog createBlog(Author author);
/** Parses a blog with the given Group */
Blog parseBlog(@NotNull Group g) throws FormatException;
/** Parses a blog with the given Group and description */
Blog parseBlog(@NotNull Group g, @NotNull String description)
throws FormatException;
} }

View File

@@ -16,10 +16,6 @@ public interface BlogManager {
/** Returns the unique ID of the blog client. */ /** Returns the unique ID of the blog client. */
ClientId getClientId(); ClientId getClientId();
/** Creates a new Blog. */
Blog addBlog(LocalAuthor localAuthor, String name, String description)
throws DbException;
/** Returns true if a blog can be removed. */ /** Returns true if a blog can be removed. */
boolean canBeRemoved(GroupId g) throws DbException; boolean canBeRemoved(GroupId g) throws DbException;

View File

@@ -8,9 +8,7 @@ import org.briarproject.api.sharing.SharingMessage.Invitation;
import org.briarproject.api.sync.GroupId; import org.briarproject.api.sync.GroupId;
import static org.briarproject.api.blogs.BlogConstants.BLOG_AUTHOR_NAME; import static org.briarproject.api.blogs.BlogConstants.BLOG_AUTHOR_NAME;
import static org.briarproject.api.blogs.BlogConstants.BLOG_DESC;
import static org.briarproject.api.blogs.BlogConstants.BLOG_PUBLIC_KEY; import static org.briarproject.api.blogs.BlogConstants.BLOG_PUBLIC_KEY;
import static org.briarproject.api.blogs.BlogConstants.BLOG_TITLE;
import static org.briarproject.api.sharing.SharingConstants.INVITATION_MSG; import static org.briarproject.api.sharing.SharingConstants.INVITATION_MSG;
import static org.briarproject.api.sharing.SharingConstants.SESSION_ID; import static org.briarproject.api.sharing.SharingConstants.SESSION_ID;
import static org.briarproject.api.sharing.SharingConstants.TIME; import static org.briarproject.api.sharing.SharingConstants.TIME;
@@ -19,19 +17,14 @@ public interface BlogSharingMessage {
class BlogInvitation extends Invitation { class BlogInvitation extends Invitation {
private final String blogTitle;
private final String blogDesc;
private final String blogAuthorName; private final String blogAuthorName;
private final byte[] blogPublicKey; private final byte[] blogPublicKey;
public BlogInvitation(GroupId groupId, SessionId sessionId, public BlogInvitation(GroupId groupId, SessionId sessionId,
String blogTitle, String blogDesc, String blogAuthorName, String blogAuthorName, byte[] blogPublicKey, long time,
byte[] blogPublicKey, long time, String message) { String message) {
super(groupId, sessionId, time, message); super(groupId, sessionId, time, message);
this.blogTitle = blogTitle;
this.blogDesc = blogDesc;
this.blogAuthorName = blogAuthorName; this.blogAuthorName = blogAuthorName;
this.blogPublicKey = blogPublicKey; this.blogPublicKey = blogPublicKey;
} }
@@ -39,8 +32,6 @@ public interface BlogSharingMessage {
@Override @Override
public BdfList toBdfList() { public BdfList toBdfList() {
BdfList list = super.toBdfList(); BdfList list = super.toBdfList();
list.add(blogTitle);
list.add(blogDesc);
list.add(BdfList.of(blogAuthorName, blogPublicKey)); list.add(BdfList.of(blogAuthorName, blogPublicKey));
if (message != null) list.add(message); if (message != null) list.add(message);
return list; return list;
@@ -49,8 +40,6 @@ public interface BlogSharingMessage {
@Override @Override
public BdfDictionary toBdfDictionary() { public BdfDictionary toBdfDictionary() {
BdfDictionary d = toBdfDictionaryHelper(); BdfDictionary d = toBdfDictionaryHelper();
d.put(BLOG_TITLE, blogTitle);
d.put(BLOG_DESC, blogDesc);
d.put(BLOG_AUTHOR_NAME, blogAuthorName); d.put(BLOG_AUTHOR_NAME, blogAuthorName);
d.put(BLOG_PUBLIC_KEY, blogPublicKey); d.put(BLOG_PUBLIC_KEY, blogPublicKey);
if (message != null) d.put(INVITATION_MSG, message); if (message != null) d.put(INVITATION_MSG, message);
@@ -61,23 +50,13 @@ public interface BlogSharingMessage {
throws FormatException { throws FormatException {
SessionId sessionId = new SessionId(d.getRaw(SESSION_ID)); SessionId sessionId = new SessionId(d.getRaw(SESSION_ID));
String blogTitle = d.getString(BLOG_TITLE);
String blogDesc = d.getString(BLOG_DESC);
String blogAuthorName = d.getString(BLOG_AUTHOR_NAME); String blogAuthorName = d.getString(BLOG_AUTHOR_NAME);
byte[] blogPublicKey = d.getRaw(BLOG_PUBLIC_KEY); byte[] blogPublicKey = d.getRaw(BLOG_PUBLIC_KEY);
String message = d.getOptionalString(INVITATION_MSG); String message = d.getOptionalString(INVITATION_MSG);
long time = d.getLong(TIME); long time = d.getLong(TIME);
return new BlogInvitation(groupId, sessionId, blogTitle, return new BlogInvitation(groupId, sessionId, blogAuthorName,
blogDesc, blogAuthorName, blogPublicKey, time, message); blogPublicKey, time, message);
}
public String getBlogTitle() {
return blogTitle;
}
public String getBlogDesc() {
return blogDesc;
} }
public String getBlogAuthorName() { public String getBlogAuthorName() {

View File

@@ -3,7 +3,6 @@ package org.briarproject.api.clients;
import org.briarproject.api.nullsafety.NotNullByDefault; import org.briarproject.api.nullsafety.NotNullByDefault;
import org.briarproject.api.sync.Group; import org.briarproject.api.sync.Group;
import org.briarproject.api.sync.GroupId; import org.briarproject.api.sync.GroupId;
import org.jetbrains.annotations.NotNull;
import javax.annotation.concurrent.Immutable; import javax.annotation.concurrent.Immutable;
@@ -12,28 +11,19 @@ import javax.annotation.concurrent.Immutable;
public abstract class BaseGroup { public abstract class BaseGroup {
private final Group group; private final Group group;
private final String name;
public BaseGroup(Group group, String name) { public BaseGroup(Group group) {
this.group = group; this.group = group;
this.name = name;
} }
@NotNull
public GroupId getId() { public GroupId getId() {
return group.getId(); return group.getId();
} }
@NotNull
public Group getGroup() { public Group getGroup() {
return group; return group;
} }
@NotNull
public String getName() {
return name;
}
@Override @Override
public int hashCode() { public int hashCode() {
return group.hashCode(); return group.hashCode();

View File

@@ -10,13 +10,19 @@ import javax.annotation.concurrent.Immutable;
@NotNullByDefault @NotNullByDefault
public abstract class NamedGroup extends BaseGroup { public abstract class NamedGroup extends BaseGroup {
private final String name;
private final byte[] salt; private final byte[] salt;
public NamedGroup(@NotNull Group group, @NotNull String name, byte[] salt) { public NamedGroup(@NotNull Group group, @NotNull String name, byte[] salt) {
super(group, name); super(group);
this.name = name;
this.salt = salt; this.salt = salt;
} }
public String getName() {
return name;
}
public byte[] getSalt() { public byte[] getSalt() {
return salt; return salt;
} }

View File

@@ -3,17 +3,12 @@ package org.briarproject.api.event;
import org.briarproject.api.blogs.BlogInvitationResponse; import org.briarproject.api.blogs.BlogInvitationResponse;
import org.briarproject.api.contact.ContactId; import org.briarproject.api.contact.ContactId;
public class BlogInvitationResponseReceivedEvent extends InvitationResponseReceivedEvent { public class BlogInvitationResponseReceivedEvent
extends InvitationResponseReceivedEvent {
private final String blogTitle; public BlogInvitationResponseReceivedEvent(ContactId contactId,
BlogInvitationResponse response) {
public BlogInvitationResponseReceivedEvent(String blogTitle,
ContactId contactId, BlogInvitationResponse response) {
super(contactId, response); super(contactId, response);
this.blogTitle = blogTitle;
} }
public String getBlogTitle() {
return blogTitle;
}
} }

View File

@@ -7,14 +7,14 @@ import org.briarproject.api.clients.ClientHelper;
import org.briarproject.api.data.BdfList; import org.briarproject.api.data.BdfList;
import org.briarproject.api.identity.Author; import org.briarproject.api.identity.Author;
import org.briarproject.api.identity.AuthorFactory; import org.briarproject.api.identity.AuthorFactory;
import org.briarproject.api.nullsafety.NotNullByDefault;
import org.briarproject.api.sync.Group; import org.briarproject.api.sync.Group;
import org.briarproject.api.sync.GroupFactory; import org.briarproject.api.sync.GroupFactory;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import javax.inject.Inject; import javax.inject.Inject;
import static org.briarproject.api.blogs.BlogConstants.PERSONAL_BLOG_NAME; @NotNullByDefault
class BlogFactoryImpl implements BlogFactory { class BlogFactoryImpl implements BlogFactory {
private final GroupFactory groupFactory; private final GroupFactory groupFactory;
@@ -31,39 +31,29 @@ class BlogFactoryImpl implements BlogFactory {
} }
@Override @Override
public Blog createPersonalBlog(@NotNull Author a) { public Blog createBlog(Author a) {
return createBlog(PERSONAL_BLOG_NAME, "", a);
}
@Override
public Blog createBlog(@NotNull String name, @NotNull String description,
@NotNull Author author) {
try { try {
BdfList blog = BdfList.of( BdfList blog = BdfList.of(
name, a.getName(),
author.getName(), a.getPublicKey()
author.getPublicKey()
); );
byte[] descriptor = clientHelper.toByteArray(blog); byte[] descriptor = clientHelper.toByteArray(blog);
Group g = groupFactory Group g = groupFactory
.createGroup(BlogManagerImpl.CLIENT_ID, descriptor); .createGroup(BlogManagerImpl.CLIENT_ID, descriptor);
return new Blog(g, name, description, author); return new Blog(g, a);
} catch (FormatException e) { } catch (FormatException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
@Override @Override
public Blog parseBlog(@NotNull Group g, @NotNull String description) public Blog parseBlog(@NotNull Group g) throws FormatException {
throws FormatException {
byte[] descriptor = g.getDescriptor(); byte[] descriptor = g.getDescriptor();
// Blog Name, Author Name, Public Key // Author Name, Public Key
BdfList blog = clientHelper.toList(descriptor); BdfList blog = clientHelper.toList(descriptor);
String name = blog.getString(0);
Author a = Author a =
authorFactory.createAuthor(blog.getString(1), blog.getRaw(2)); authorFactory.createAuthor(blog.getString(0), blog.getRaw(1));
return new Blog(g, name, description, a); return new Blog(g, a);
} }
} }

View File

@@ -58,7 +58,6 @@ import static org.briarproject.api.blogs.BlogConstants.KEY_AUTHOR;
import static org.briarproject.api.blogs.BlogConstants.KEY_AUTHOR_ID; import static org.briarproject.api.blogs.BlogConstants.KEY_AUTHOR_ID;
import static org.briarproject.api.blogs.BlogConstants.KEY_AUTHOR_NAME; import static org.briarproject.api.blogs.BlogConstants.KEY_AUTHOR_NAME;
import static org.briarproject.api.blogs.BlogConstants.KEY_COMMENT; import static org.briarproject.api.blogs.BlogConstants.KEY_COMMENT;
import static org.briarproject.api.blogs.BlogConstants.KEY_DESCRIPTION;
import static org.briarproject.api.blogs.BlogConstants.KEY_ORIGINAL_MSG_ID; import static org.briarproject.api.blogs.BlogConstants.KEY_ORIGINAL_MSG_ID;
import static org.briarproject.api.blogs.BlogConstants.KEY_ORIGINAL_PARENT_MSG_ID; import static org.briarproject.api.blogs.BlogConstants.KEY_ORIGINAL_PARENT_MSG_ID;
import static org.briarproject.api.blogs.BlogConstants.KEY_PARENT_MSG_ID; import static org.briarproject.api.blogs.BlogConstants.KEY_PARENT_MSG_ID;
@@ -113,16 +112,14 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
@Override @Override
public void createLocalState(Transaction txn) throws DbException { public void createLocalState(Transaction txn) throws DbException {
// Ensure every identity does have its own personal blog // Ensure that the local identity has its own personal blog
// TODO this can probably be removed once #446 is resolved and all users migrated to a new version LocalAuthor la = identityManager.getLocalAuthor(txn);
for (LocalAuthor a : db.getLocalAuthors(txn)) { Blog b = blogFactory.createBlog(la);
Blog b = blogFactory.createPersonalBlog(a); Group g = b.getGroup();
Group g = b.getGroup(); if (!db.containsGroup(txn, g.getId())) {
if (!db.containsGroup(txn, g.getId())) { db.addGroup(txn, g);
db.addGroup(txn, g); for (ContactId c : db.getContacts(txn, la.getId())) {
for (ContactId c : db.getContacts(txn, a.getId())) { db.setVisibleToContact(txn, c, g.getId(), true);
db.setVisibleToContact(txn, c, g.getId(), true);
}
} }
} }
// Ensure that we have the personal blogs of all pre-existing contacts // Ensure that we have the personal blogs of all pre-existing contacts
@@ -132,7 +129,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
@Override @Override
public void addingContact(Transaction txn, Contact c) throws DbException { public void addingContact(Transaction txn, Contact c) throws DbException {
// get personal blog of the contact // get personal blog of the contact
Blog b = blogFactory.createPersonalBlog(c.getAuthor()); Blog b = blogFactory.createBlog(c.getAuthor());
Group g = b.getGroup(); Group g = b.getGroup();
if (!db.containsGroup(txn, g.getId())) { if (!db.containsGroup(txn, g.getId())) {
// add the personal blog of the contact // add the personal blog of the contact
@@ -141,7 +138,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
// share our personal blog with the new contact // share our personal blog with the new contact
LocalAuthor a = db.getLocalAuthor(txn, c.getLocalAuthorId()); LocalAuthor a = db.getLocalAuthor(txn, c.getLocalAuthorId());
Blog b2 = blogFactory.createPersonalBlog(a); Blog b2 = blogFactory.createBlog(a);
db.setVisibleToContact(txn, c.getId(), b2.getId(), true); db.setVisibleToContact(txn, c.getId(), b2.getId(), true);
} }
} }
@@ -149,7 +146,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
@Override @Override
public void removingContact(Transaction txn, Contact c) throws DbException { public void removingContact(Transaction txn, Contact c) throws DbException {
if (c != null) { if (c != null) {
Blog b = blogFactory.createPersonalBlog(c.getAuthor()); Blog b = blogFactory.createBlog(c.getAuthor());
db.removeGroup(txn, b.getGroup()); db.removeGroup(txn, b.getGroup());
} }
} }
@@ -160,7 +157,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
// add a personal blog for the new identity // add a personal blog for the new identity
LOG.info("New Personal Blog Added."); LOG.info("New Personal Blog Added.");
Blog b = blogFactory.createPersonalBlog(a); Blog b = blogFactory.createBlog(a);
db.addGroup(txn, b.getGroup()); db.addGroup(txn, b.getGroup());
} }
@@ -169,7 +166,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
throws DbException { throws DbException {
// remove the personal blog of that identity // remove the personal blog of that identity
Blog b = blogFactory.createPersonalBlog(a); Blog b = blogFactory.createBlog(a);
db.removeGroup(txn, b.getGroup()); db.removeGroup(txn, b.getGroup());
} }
@@ -219,29 +216,6 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
return false; return false;
} }
@Override
public Blog addBlog(LocalAuthor localAuthor, String name,
String description) throws DbException {
Blog b = blogFactory
.createBlog(name, description, localAuthor);
BdfDictionary metadata = BdfDictionary.of(
new BdfEntry(KEY_DESCRIPTION, b.getDescription())
);
Transaction txn = db.startTransaction(false);
try {
db.addGroup(txn, b.getGroup());
clientHelper.mergeGroupMetadata(txn, b.getId(), metadata);
txn.setComplete();
} catch (FormatException e) {
throw new DbException(e);
} finally {
db.endTransaction(txn);
}
return b;
}
@Override @Override
public boolean canBeRemoved(GroupId g) throws DbException { public boolean canBeRemoved(GroupId g) throws DbException {
Transaction txn = db.startTransaction(true); Transaction txn = db.startTransaction(true);
@@ -453,8 +427,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
public Blog getBlog(Transaction txn, GroupId g) throws DbException { public Blog getBlog(Transaction txn, GroupId g) throws DbException {
try { try {
Group group = db.getGroup(txn, g); Group group = db.getGroup(txn, g);
String description = getBlogDescription(txn, g); return blogFactory.parseBlog(group);
return blogFactory.parseBlog(group, description);
} catch (FormatException e) { } catch (FormatException e) {
throw new DbException(e); throw new DbException(e);
} }
@@ -476,7 +449,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
@Override @Override
public Blog getPersonalBlog(Author author) { public Blog getPersonalBlog(Author author) {
return blogFactory.createPersonalBlog(author); return blogFactory.createBlog(author);
} }
@Override @Override
@@ -488,8 +461,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
try { try {
groups = db.getGroups(txn, CLIENT_ID); groups = db.getGroups(txn, CLIENT_ID);
for (Group g : groups) { for (Group g : groups) {
String description = getBlogDescription(txn, g.getId()); blogs.add(blogFactory.parseBlog(g));
blogs.add(blogFactory.parseBlog(g, description));
} }
txn.setComplete(); txn.setComplete();
} finally { } finally {
@@ -613,12 +585,6 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
removeHooks.add(hook); removeHooks.add(hook);
} }
private String getBlogDescription(Transaction txn, GroupId g)
throws DbException, FormatException {
BdfDictionary d = clientHelper.getGroupMetadataAsDictionary(txn, g);
return d.getString(KEY_DESCRIPTION, "");
}
private BlogPostHeader getPostHeaderFromMetadata(Transaction txn, private BlogPostHeader getPostHeaderFromMetadata(Transaction txn,
GroupId groupId, MessageId id) throws DbException, FormatException { GroupId groupId, MessageId id) throws DbException, FormatException {
BdfDictionary meta = BdfDictionary meta =

View File

@@ -100,7 +100,7 @@ class BlogPostValidator extends BdfMessageValidator {
byte[] sig = body.getRaw(1); byte[] sig = body.getRaw(1);
checkLength(sig, 1, MAX_SIGNATURE_LENGTH); checkLength(sig, 1, MAX_SIGNATURE_LENGTH);
BdfList signed = BdfList.of(g.getId(), m.getTimestamp(), postBody); BdfList signed = BdfList.of(g.getId(), m.getTimestamp(), postBody);
Blog b = blogFactory.parseBlog(g, ""); // description doesn't matter Blog b = blogFactory.parseBlog(g);
Author a = b.getAuthor(); Author a = b.getAuthor();
try { try {
clientHelper.verifySignature(sig, a.getPublicKey(), signed); clientHelper.verifySignature(sig, a.getPublicKey(), signed);
@@ -145,7 +145,7 @@ class BlogPostValidator extends BdfMessageValidator {
BdfList signed = BdfList signed =
BdfList.of(g.getId(), m.getTimestamp(), comment, pOriginalId, BdfList.of(g.getId(), m.getTimestamp(), comment, pOriginalId,
currentId); currentId);
Blog b = blogFactory.parseBlog(g, ""); // description doesn't matter Blog b = blogFactory.parseBlog(g);
Author a = b.getAuthor(); Author a = b.getAuthor();
try { try {
clientHelper.verifySignature(sig, a.getPublicKey(), signed); clientHelper.verifySignature(sig, a.getPublicKey(), signed);

View File

@@ -3,53 +3,40 @@ package org.briarproject.sharing;
import org.briarproject.api.clients.SessionId; import org.briarproject.api.clients.SessionId;
import org.briarproject.api.contact.ContactId; import org.briarproject.api.contact.ContactId;
import org.briarproject.api.data.BdfDictionary; import org.briarproject.api.data.BdfDictionary;
import org.briarproject.api.nullsafety.NotNullByDefault;
import org.briarproject.api.sync.GroupId; import org.briarproject.api.sync.GroupId;
import org.briarproject.api.sync.MessageId; import org.briarproject.api.sync.MessageId;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.annotation.concurrent.NotThreadSafe;
import static org.briarproject.api.blogs.BlogConstants.BLOG_AUTHOR_NAME; import static org.briarproject.api.blogs.BlogConstants.BLOG_AUTHOR_NAME;
import static org.briarproject.api.blogs.BlogConstants.BLOG_DESC;
import static org.briarproject.api.blogs.BlogConstants.BLOG_PUBLIC_KEY; import static org.briarproject.api.blogs.BlogConstants.BLOG_PUBLIC_KEY;
import static org.briarproject.api.blogs.BlogConstants.BLOG_TITLE;
@NotThreadSafe
@NotNullByDefault
public class BlogInviteeSessionState extends InviteeSessionState { public class BlogInviteeSessionState extends InviteeSessionState {
private final String blogTitle;
private final String blogDesc;
private final String blogAuthorName; private final String blogAuthorName;
private final byte[] blogPublicKey; private final byte[] blogPublicKey;
public BlogInviteeSessionState(SessionId sessionId, MessageId storageId, public BlogInviteeSessionState(SessionId sessionId, MessageId storageId,
GroupId groupId, State state, ContactId contactId, GroupId blogId, GroupId groupId, State state, ContactId contactId, GroupId blogId,
String blogTitle, String blogDesc, String blogAuthorName, String blogAuthorName, byte[] blogPublicKey,
byte[] blogPublicKey, @NotNull MessageId invitationId) { @NotNull MessageId invitationId) {
super(sessionId, storageId, groupId, state, contactId, blogId, super(sessionId, storageId, groupId, state, contactId, blogId,
invitationId); invitationId);
this.blogTitle = blogTitle;
this.blogDesc = blogDesc;
this.blogAuthorName = blogAuthorName; this.blogAuthorName = blogAuthorName;
this.blogPublicKey = blogPublicKey; this.blogPublicKey = blogPublicKey;
} }
public BdfDictionary toBdfDictionary() { public BdfDictionary toBdfDictionary() {
BdfDictionary d = super.toBdfDictionary(); BdfDictionary d = super.toBdfDictionary();
d.put(BLOG_TITLE, getBlogTitle());
d.put(BLOG_DESC, getBlogDesc());
d.put(BLOG_AUTHOR_NAME, getBlogAuthorName()); d.put(BLOG_AUTHOR_NAME, getBlogAuthorName());
d.put(BLOG_PUBLIC_KEY, getBlogPublicKey()); d.put(BLOG_PUBLIC_KEY, getBlogPublicKey());
return d; return d;
} }
public String getBlogTitle() {
return blogTitle;
}
public String getBlogDesc() {
return blogDesc;
}
public String getBlogAuthorName() { public String getBlogAuthorName() {
return blogAuthorName; return blogAuthorName;
} }

View File

@@ -3,52 +3,41 @@ package org.briarproject.sharing;
import org.briarproject.api.clients.SessionId; import org.briarproject.api.clients.SessionId;
import org.briarproject.api.contact.ContactId; import org.briarproject.api.contact.ContactId;
import org.briarproject.api.data.BdfDictionary; import org.briarproject.api.data.BdfDictionary;
import org.briarproject.api.nullsafety.NotNullByDefault;
import org.briarproject.api.sync.GroupId; import org.briarproject.api.sync.GroupId;
import org.briarproject.api.sync.MessageId; import org.briarproject.api.sync.MessageId;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import static org.briarproject.api.blogs.BlogConstants.BLOG_AUTHOR_NAME; import javax.annotation.concurrent.NotThreadSafe;
import static org.briarproject.api.blogs.BlogConstants.BLOG_DESC;
import static org.briarproject.api.blogs.BlogConstants.BLOG_PUBLIC_KEY;
import static org.briarproject.api.blogs.BlogConstants.BLOG_TITLE;
import static org.briarproject.api.blogs.BlogConstants.BLOG_AUTHOR_NAME;
import static org.briarproject.api.blogs.BlogConstants.BLOG_PUBLIC_KEY;
@NotThreadSafe
@NotNullByDefault
public class BlogSharerSessionState extends SharerSessionState { public class BlogSharerSessionState extends SharerSessionState {
private final String blogTitle;
private final String blogDesc;
private final String blogAuthorName; private final String blogAuthorName;
private final byte[] blogPublicKey; private final byte[] blogPublicKey;
public BlogSharerSessionState(SessionId sessionId, MessageId storageId, public BlogSharerSessionState(SessionId sessionId, MessageId storageId,
GroupId groupId, State state, ContactId contactId, GroupId blogId, GroupId groupId, State state, ContactId contactId, GroupId blogId,
String blogTitle, String blogDesc, String blogAuthorName, String blogAuthorName,byte[] blogPublicKey,
byte[] blogPublicKey, @Nullable MessageId responseId) { @Nullable MessageId responseId) {
super(sessionId, storageId, groupId, state, contactId, blogId, super(sessionId, storageId, groupId, state, contactId, blogId,
responseId); responseId);
this.blogTitle = blogTitle;
this.blogDesc = blogDesc;
this.blogAuthorName = blogAuthorName; this.blogAuthorName = blogAuthorName;
this.blogPublicKey = blogPublicKey; this.blogPublicKey = blogPublicKey;
} }
public BdfDictionary toBdfDictionary() { public BdfDictionary toBdfDictionary() {
BdfDictionary d = super.toBdfDictionary(); BdfDictionary d = super.toBdfDictionary();
d.put(BLOG_TITLE, getBlogTitle());
d.put(BLOG_DESC, getBlogDesc());
d.put(BLOG_AUTHOR_NAME, getBlogAuthorName()); d.put(BLOG_AUTHOR_NAME, getBlogAuthorName());
d.put(BLOG_PUBLIC_KEY, getBlogPublicKey()); d.put(BLOG_PUBLIC_KEY, getBlogPublicKey());
return d; return d;
} }
public String getBlogTitle() {
return blogTitle;
}
public String getBlogDesc() {
return blogDesc;
}
public String getBlogAuthorName() { public String getBlogAuthorName() {
return blogAuthorName; return blogAuthorName;
} }

View File

@@ -40,9 +40,7 @@ import java.security.SecureRandom;
import javax.inject.Inject; import javax.inject.Inject;
import static org.briarproject.api.blogs.BlogConstants.BLOG_AUTHOR_NAME; import static org.briarproject.api.blogs.BlogConstants.BLOG_AUTHOR_NAME;
import static org.briarproject.api.blogs.BlogConstants.BLOG_DESC;
import static org.briarproject.api.blogs.BlogConstants.BLOG_PUBLIC_KEY; import static org.briarproject.api.blogs.BlogConstants.BLOG_PUBLIC_KEY;
import static org.briarproject.api.blogs.BlogConstants.BLOG_TITLE;
import static org.briarproject.api.sharing.SharingConstants.INVITATION_ID; import static org.briarproject.api.sharing.SharingConstants.INVITATION_ID;
import static org.briarproject.api.sharing.SharingConstants.RESPONSE_ID; import static org.briarproject.api.sharing.SharingConstants.RESPONSE_ID;
@@ -54,8 +52,7 @@ class BlogSharingManagerImpl extends
"bee438b5de0b3a685badc4e49d76e72d" "bee438b5de0b3a685badc4e49d76e72d"
+ "21e01c4b569a775112756bdae267a028")); + "21e01c4b569a775112756bdae267a028"));
@Inject private final IdentityManager identityManager;
IdentityManager identityManager;
private final BlogManager blogManager; private final BlogManager blogManager;
private final SFactory sFactory; private final SFactory sFactory;
@@ -70,12 +67,14 @@ class BlogSharingManagerImpl extends
BlogManager blogManager, ClientHelper clientHelper, Clock clock, BlogManager blogManager, ClientHelper clientHelper, Clock clock,
DatabaseComponent db, MessageQueueManager messageQueueManager, DatabaseComponent db, MessageQueueManager messageQueueManager,
MetadataEncoder metadataEncoder, MetadataParser metadataParser, MetadataEncoder metadataEncoder, MetadataParser metadataParser,
ContactGroupFactory contactGroupFactory, SecureRandom random) { ContactGroupFactory contactGroupFactory, SecureRandom random,
IdentityManager identityManager) {
super(db, messageQueueManager, clientHelper, metadataParser, super(db, messageQueueManager, clientHelper, metadataParser,
metadataEncoder, random, contactGroupFactory, clock); metadataEncoder, random, contactGroupFactory, clock);
this.blogManager = blogManager; this.blogManager = blogManager;
this.identityManager = identityManager;
sFactory = new SFactory(authorFactory, blogFactory, blogManager); sFactory = new SFactory(authorFactory, blogFactory, blogManager);
iFactory = new IFactory(); iFactory = new IFactory();
isFactory = new ISFactory(); isFactory = new ISFactory();
@@ -175,9 +174,12 @@ class BlogSharingManagerImpl extends
@Override @Override
public BdfList encode(Blog f) { public BdfList encode(Blog f) {
return BdfList.of(f.getName(), f.getDescription(), return BdfList.of(
BdfList.of(f.getAuthor().getName(), BdfList.of(
f.getAuthor().getPublicKey())); f.getAuthor().getName(),
f.getAuthor().getPublicKey()
)
);
} }
@Override @Override
@@ -189,19 +191,16 @@ class BlogSharingManagerImpl extends
@Override @Override
public Blog parse(BdfList shareable) throws FormatException { public Blog parse(BdfList shareable) throws FormatException {
Author author = authorFactory Author author = authorFactory
.createAuthor(shareable.getList(2).getString(0), .createAuthor(shareable.getList(0).getString(0),
shareable.getList(2).getRaw(1)); shareable.getList(0).getRaw(1));
return blogFactory return blogFactory.createBlog(author);
.createBlog(shareable.getString(0), shareable.getString(1),
author);
} }
@Override @Override
public Blog parse(BlogInvitation msg) { public Blog parse(BlogInvitation msg) {
Author author = authorFactory.createAuthor(msg.getBlogAuthorName(), Author author = authorFactory.createAuthor(msg.getBlogAuthorName(),
msg.getBlogPublicKey()); msg.getBlogPublicKey());
return blogFactory return blogFactory.createBlog(author);
.createBlog(msg.getBlogTitle(), msg.getBlogDesc(), author);
} }
@Override @Override
@@ -209,9 +208,7 @@ class BlogSharingManagerImpl extends
Author author = authorFactory Author author = authorFactory
.createAuthor(state.getBlogAuthorName(), .createAuthor(state.getBlogAuthorName(),
state.getBlogPublicKey()); state.getBlogPublicKey());
return blogFactory return blogFactory.createBlog(author);
.createBlog(state.getBlogTitle(), state.getBlogDesc(),
author);
} }
@Override @Override
@@ -219,9 +216,7 @@ class BlogSharingManagerImpl extends
Author author = authorFactory Author author = authorFactory
.createAuthor(state.getBlogAuthorName(), .createAuthor(state.getBlogAuthorName(),
state.getBlogPublicKey()); state.getBlogPublicKey());
return blogFactory return blogFactory.createBlog(author);
.createBlog(state.getBlogTitle(), state.getBlogDesc(),
author);
} }
} }
@@ -237,8 +232,7 @@ class BlogSharingManagerImpl extends
public BlogInvitation build(BlogSharerSessionState localState, public BlogInvitation build(BlogSharerSessionState localState,
long time) { long time) {
return new BlogInvitation(localState.getGroupId(), return new BlogInvitation(localState.getGroupId(),
localState.getSessionId(), localState.getBlogTitle(), localState.getSessionId(), localState.getBlogAuthorName(),
localState.getBlogDesc(), localState.getBlogAuthorName(),
localState.getBlogPublicKey(), time, localState.getBlogPublicKey(), time,
localState.getMessage()); localState.getMessage());
} }
@@ -251,14 +245,12 @@ class BlogSharingManagerImpl extends
MessageId storageId, GroupId groupId, MessageId storageId, GroupId groupId,
InviteeSessionState.State state, ContactId contactId, InviteeSessionState.State state, ContactId contactId,
GroupId blogId, BdfDictionary d) throws FormatException { GroupId blogId, BdfDictionary d) throws FormatException {
String blogTitle = d.getString(BLOG_TITLE);
String blogDesc = d.getString(BLOG_DESC);
String blogAuthorName = d.getString(BLOG_AUTHOR_NAME); String blogAuthorName = d.getString(BLOG_AUTHOR_NAME);
byte[] blogPublicKey = d.getRaw(BLOG_PUBLIC_KEY); byte[] blogPublicKey = d.getRaw(BLOG_PUBLIC_KEY);
MessageId invitationId = new MessageId(d.getRaw(INVITATION_ID)); MessageId invitationId = new MessageId(d.getRaw(INVITATION_ID));
return new BlogInviteeSessionState(sessionId, storageId, return new BlogInviteeSessionState(sessionId, storageId,
groupId, state, contactId, blogId, blogTitle, blogDesc, groupId, state, contactId, blogId, blogAuthorName,
blogAuthorName, blogPublicKey, invitationId); blogPublicKey, invitationId);
} }
@Override @Override
@@ -267,9 +259,9 @@ class BlogSharingManagerImpl extends
InviteeSessionState.State state, ContactId contactId, InviteeSessionState.State state, ContactId contactId,
Blog blog, MessageId invitationId) { Blog blog, MessageId invitationId) {
return new BlogInviteeSessionState(sessionId, storageId, return new BlogInviteeSessionState(sessionId, storageId,
groupId, state, contactId, blog.getId(), blog.getName(), groupId, state, contactId, blog.getId(),
blog.getDescription(), blog.getAuthor().getName(), blog.getAuthor().getName(), blog.getAuthor().getPublicKey(),
blog.getAuthor().getPublicKey(), invitationId); invitationId);
} }
} }
@@ -280,8 +272,6 @@ class BlogSharingManagerImpl extends
MessageId storageId, GroupId groupId, MessageId storageId, GroupId groupId,
SharerSessionState.State state, ContactId contactId, SharerSessionState.State state, ContactId contactId,
GroupId blogId, BdfDictionary d) throws FormatException { GroupId blogId, BdfDictionary d) throws FormatException {
String blogTitle = d.getString(BLOG_TITLE);
String blogDesc = d.getString(BLOG_DESC);
String blogAuthorName = d.getString(BLOG_AUTHOR_NAME); String blogAuthorName = d.getString(BLOG_AUTHOR_NAME);
byte[] blogPublicKey = d.getRaw(BLOG_PUBLIC_KEY); byte[] blogPublicKey = d.getRaw(BLOG_PUBLIC_KEY);
MessageId responseId = null; MessageId responseId = null;
@@ -289,8 +279,8 @@ class BlogSharingManagerImpl extends
if (responseIdBytes != null) if (responseIdBytes != null)
responseId = new MessageId(responseIdBytes); responseId = new MessageId(responseIdBytes);
return new BlogSharerSessionState(sessionId, storageId, return new BlogSharerSessionState(sessionId, storageId,
groupId, state, contactId, blogId, blogTitle, blogDesc, groupId, state, contactId, blogId, blogAuthorName,
blogAuthorName, blogPublicKey, responseId); blogPublicKey, responseId);
} }
@Override @Override
@@ -299,9 +289,9 @@ class BlogSharingManagerImpl extends
SharerSessionState.State state, ContactId contactId, SharerSessionState.State state, ContactId contactId,
Blog blog) { Blog blog) {
return new BlogSharerSessionState(sessionId, storageId, return new BlogSharerSessionState(sessionId, storageId,
groupId, state, contactId, blog.getId(), blog.getName(), groupId, state, contactId, blog.getId(),
blog.getDescription(), blog.getAuthor().getName(), blog.getAuthor().getName(), blog.getAuthor().getPublicKey(),
blog.getAuthor().getPublicKey(), null); null);
} }
} }
@@ -333,7 +323,6 @@ class BlogSharingManagerImpl extends
@Override @Override
public BlogInvitationResponseReceivedEvent build( public BlogInvitationResponseReceivedEvent build(
BlogSharerSessionState localState, boolean accept, long time) { BlogSharerSessionState localState, boolean accept, long time) {
String title = localState.getBlogTitle();
ContactId c = localState.getContactId(); ContactId c = localState.getContactId();
MessageId responseId = localState.getResponseId(); MessageId responseId = localState.getResponseId();
if (responseId == null) if (responseId == null)
@@ -343,7 +332,7 @@ class BlogSharingManagerImpl extends
localState.getSessionId(), localState.getGroupId(), localState.getSessionId(), localState.getGroupId(),
localState.getContactId(), accept, time, false, localState.getContactId(), accept, time, false,
false, false, false); false, false, false);
return new BlogInvitationResponseReceivedEvent(title, c, response); return new BlogInvitationResponseReceivedEvent(c, response);
} }
} }
} }

View File

@@ -15,11 +15,7 @@ import org.briarproject.clients.BdfMessageValidator;
import javax.inject.Inject; import javax.inject.Inject;
import static org.briarproject.api.blogs.BlogConstants.BLOG_AUTHOR_NAME; import static org.briarproject.api.blogs.BlogConstants.BLOG_AUTHOR_NAME;
import static org.briarproject.api.blogs.BlogConstants.BLOG_DESC;
import static org.briarproject.api.blogs.BlogConstants.BLOG_PUBLIC_KEY; import static org.briarproject.api.blogs.BlogConstants.BLOG_PUBLIC_KEY;
import static org.briarproject.api.blogs.BlogConstants.BLOG_TITLE;
import static org.briarproject.api.blogs.BlogConstants.MAX_BLOG_DESC_LENGTH;
import static org.briarproject.api.blogs.BlogConstants.MAX_BLOG_TITLE_LENGTH;
import static org.briarproject.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH; import static org.briarproject.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
import static org.briarproject.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH; import static org.briarproject.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
import static org.briarproject.api.sharing.SharingConstants.INVITATION_MSG; import static org.briarproject.api.sharing.SharingConstants.INVITATION_MSG;
@@ -52,30 +48,22 @@ class BlogSharingValidator extends BdfMessageValidator {
checkLength(id, SessionId.LENGTH); checkLength(id, SessionId.LENGTH);
if (type == SHARE_MSG_TYPE_INVITATION) { if (type == SHARE_MSG_TYPE_INVITATION) {
checkSize(body, 5, 6); checkSize(body, 3, 4);
String name = body.getString(2); BdfList author = body.getList(2);
checkLength(name, 1, MAX_BLOG_TITLE_LENGTH);
String desc = body.getString(3);
checkLength(desc, 0, MAX_BLOG_DESC_LENGTH);
BdfList author = body.getList(4);
checkSize(author, 2); checkSize(author, 2);
String authorName = author.getString(0); String authorName = author.getString(0);
checkLength(name, 1, MAX_AUTHOR_NAME_LENGTH); checkLength(authorName, 1, MAX_AUTHOR_NAME_LENGTH);
byte[] publicKey = author.getRaw(1); byte[] publicKey = author.getRaw(1);
checkLength(publicKey, 1, MAX_PUBLIC_KEY_LENGTH); checkLength(publicKey, 1, MAX_PUBLIC_KEY_LENGTH);
d.put(BLOG_TITLE, name);
d.put(BLOG_DESC, desc);
d.put(BLOG_AUTHOR_NAME, authorName); d.put(BLOG_AUTHOR_NAME, authorName);
d.put(BLOG_PUBLIC_KEY, publicKey); d.put(BLOG_PUBLIC_KEY, publicKey);
if (body.size() > 5) { if (body.size() > 3) {
String msg = body.getString(5); String msg = body.getString(3);
checkLength(msg, 0, MAX_INVITATION_MESSAGE_LENGTH); checkLength(msg, 0, MAX_INVITATION_MESSAGE_LENGTH);
d.put(INVITATION_MSG, msg); d.put(INVITATION_MSG, msg);
} }

View File

@@ -3,10 +3,13 @@ package org.briarproject.sharing;
import org.briarproject.api.clients.SessionId; import org.briarproject.api.clients.SessionId;
import org.briarproject.api.contact.ContactId; import org.briarproject.api.contact.ContactId;
import org.briarproject.api.data.BdfDictionary; import org.briarproject.api.data.BdfDictionary;
import org.briarproject.api.nullsafety.NotNullByDefault;
import org.briarproject.api.sync.GroupId; import org.briarproject.api.sync.GroupId;
import org.briarproject.api.sync.MessageId; import org.briarproject.api.sync.MessageId;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import javax.annotation.concurrent.NotThreadSafe;
import static org.briarproject.api.sharing.SharingConstants.INVITATION_ID; import static org.briarproject.api.sharing.SharingConstants.INVITATION_ID;
import static org.briarproject.api.sharing.SharingConstants.IS_SHARER; import static org.briarproject.api.sharing.SharingConstants.IS_SHARER;
import static org.briarproject.api.sharing.SharingConstants.SHARE_MSG_TYPE_ABORT; import static org.briarproject.api.sharing.SharingConstants.SHARE_MSG_TYPE_ABORT;
@@ -19,7 +22,8 @@ import static org.briarproject.sharing.InviteeSessionState.Action.LOCAL_LEAVE;
import static org.briarproject.sharing.InviteeSessionState.Action.REMOTE_INVITATION; import static org.briarproject.sharing.InviteeSessionState.Action.REMOTE_INVITATION;
import static org.briarproject.sharing.InviteeSessionState.Action.REMOTE_LEAVE; import static org.briarproject.sharing.InviteeSessionState.Action.REMOTE_LEAVE;
// This class is not thread-safe @NotThreadSafe
@NotNullByDefault
public abstract class InviteeSessionState extends SharingSessionState { public abstract class InviteeSessionState extends SharingSessionState {
private State state; private State state;

View File

@@ -3,10 +3,13 @@ package org.briarproject.sharing;
import org.briarproject.api.clients.SessionId; import org.briarproject.api.clients.SessionId;
import org.briarproject.api.contact.ContactId; import org.briarproject.api.contact.ContactId;
import org.briarproject.api.data.BdfDictionary; import org.briarproject.api.data.BdfDictionary;
import org.briarproject.api.nullsafety.NotNullByDefault;
import org.briarproject.api.sync.GroupId; import org.briarproject.api.sync.GroupId;
import org.briarproject.api.sync.MessageId; import org.briarproject.api.sync.MessageId;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import javax.annotation.concurrent.NotThreadSafe;
import static org.briarproject.api.sharing.SharingConstants.IS_SHARER; import static org.briarproject.api.sharing.SharingConstants.IS_SHARER;
import static org.briarproject.api.sharing.SharingConstants.RESPONSE_ID; import static org.briarproject.api.sharing.SharingConstants.RESPONSE_ID;
import static org.briarproject.api.sharing.SharingConstants.SHARE_MSG_TYPE_ABORT; import static org.briarproject.api.sharing.SharingConstants.SHARE_MSG_TYPE_ABORT;
@@ -20,7 +23,8 @@ import static org.briarproject.sharing.SharerSessionState.Action.REMOTE_ACCEPT;
import static org.briarproject.sharing.SharerSessionState.Action.REMOTE_DECLINE; import static org.briarproject.sharing.SharerSessionState.Action.REMOTE_DECLINE;
import static org.briarproject.sharing.SharerSessionState.Action.REMOTE_LEAVE; import static org.briarproject.sharing.SharerSessionState.Action.REMOTE_LEAVE;
// This class is not thread-safe @NotThreadSafe
@NotNullByDefault
public abstract class SharerSessionState extends SharingSessionState { public abstract class SharerSessionState extends SharingSessionState {
private State state; private State state;
@@ -58,6 +62,7 @@ public abstract class SharerSessionState extends SharingSessionState {
this.msg = msg; this.msg = msg;
} }
@Nullable
public String getMessage() { public String getMessage() {
return this.msg; return this.msg;
} }

View File

@@ -41,7 +41,6 @@ import static org.briarproject.TestUtils.getRandomId;
import static org.briarproject.api.blogs.BlogConstants.KEY_AUTHOR; import static org.briarproject.api.blogs.BlogConstants.KEY_AUTHOR;
import static org.briarproject.api.blogs.BlogConstants.KEY_AUTHOR_ID; import static org.briarproject.api.blogs.BlogConstants.KEY_AUTHOR_ID;
import static org.briarproject.api.blogs.BlogConstants.KEY_AUTHOR_NAME; import static org.briarproject.api.blogs.BlogConstants.KEY_AUTHOR_NAME;
import static org.briarproject.api.blogs.BlogConstants.KEY_DESCRIPTION;
import static org.briarproject.api.blogs.BlogConstants.KEY_PUBLIC_KEY; import static org.briarproject.api.blogs.BlogConstants.KEY_PUBLIC_KEY;
import static org.briarproject.api.blogs.BlogConstants.KEY_READ; import static org.briarproject.api.blogs.BlogConstants.KEY_READ;
import static org.briarproject.api.blogs.BlogConstants.KEY_TIMESTAMP; import static org.briarproject.api.blogs.BlogConstants.KEY_TIMESTAMP;
@@ -63,8 +62,6 @@ public class BlogManagerImplTest extends BriarTestCase {
private final IdentityManager identityManager = private final IdentityManager identityManager =
context.mock(IdentityManager.class); context.mock(IdentityManager.class);
private final ClientHelper clientHelper = context.mock(ClientHelper.class); private final ClientHelper clientHelper = context.mock(ClientHelper.class);
private final MetadataParser metadataParser =
context.mock(MetadataParser.class);
private final ContactManager contactManager = private final ContactManager contactManager =
context.mock(ContactManager.class); context.mock(ContactManager.class);
private final BlogFactory blogFactory = context.mock(BlogFactory.class); private final BlogFactory blogFactory = context.mock(BlogFactory.class);
@@ -78,11 +75,12 @@ public class BlogManagerImplTest extends BriarTestCase {
BlogPostFactory blogPostFactory; BlogPostFactory blogPostFactory;
public BlogManagerImplTest() { public BlogManagerImplTest() {
MetadataParser metadataParser = context.mock(MetadataParser.class);
blogManager = new BlogManagerImpl(db, identityManager, clientHelper, blogManager = new BlogManagerImpl(db, identityManager, clientHelper,
metadataParser, contactManager, blogFactory, blogPostFactory); metadataParser, contactManager, blogFactory, blogPostFactory);
blog1 = getBlog("Test Blog 1", "Test Description 1"); blog1 = createBlog();
blog2 = getBlog("Test Blog 2", "Test Description 2"); blog2 = createBlog();
messageId = new MessageId(getRandomId()); messageId = new MessageId(getRandomId());
message = new Message(messageId, blog1.getId(), 42, getRandomBytes(42)); message = new Message(messageId, blog1.getId(), 42, getRandomBytes(42));
} }
@@ -95,8 +93,7 @@ public class BlogManagerImplTest extends BriarTestCase {
@Test @Test
public void testCreateLocalState() throws DbException { public void testCreateLocalState() throws DbException {
final Transaction txn = new Transaction(null, false); final Transaction txn = new Transaction(null, false);
final Collection<LocalAuthor> localAuthors = final LocalAuthor localAuthor = (LocalAuthor) blog1.getAuthor();
Collections.singletonList((LocalAuthor) blog1.getAuthor());
final ContactId contactId = new ContactId(0); final ContactId contactId = new ContactId(0);
final Collection<ContactId> contactIds = final Collection<ContactId> contactIds =
@@ -107,9 +104,9 @@ public class BlogManagerImplTest extends BriarTestCase {
final Collection<Contact> contacts = Collections.singletonList(contact); final Collection<Contact> contacts = Collections.singletonList(contact);
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(db).getLocalAuthors(txn); oneOf(identityManager).getLocalAuthor(txn);
will(returnValue(localAuthors)); will(returnValue(localAuthor));
oneOf(blogFactory).createPersonalBlog(blog1.getAuthor()); oneOf(blogFactory).createBlog(blog1.getAuthor());
will(returnValue(blog1)); will(returnValue(blog1));
oneOf(db).containsGroup(txn, blog1.getId()); oneOf(db).containsGroup(txn, blog1.getId());
will(returnValue(false)); will(returnValue(false));
@@ -119,7 +116,7 @@ public class BlogManagerImplTest extends BriarTestCase {
oneOf(db).setVisibleToContact(txn, contactId, blog1.getId(), true); oneOf(db).setVisibleToContact(txn, contactId, blog1.getId(), true);
oneOf(db).getContacts(txn); oneOf(db).getContacts(txn);
will(returnValue(contacts)); will(returnValue(contacts));
oneOf(blogFactory).createPersonalBlog(blog2.getAuthor()); oneOf(blogFactory).createBlog(blog2.getAuthor());
will(returnValue(blog2)); will(returnValue(blog2));
oneOf(db).containsGroup(txn, blog2.getId()); oneOf(db).containsGroup(txn, blog2.getId());
will(returnValue(false)); will(returnValue(false));
@@ -127,7 +124,7 @@ public class BlogManagerImplTest extends BriarTestCase {
oneOf(db).setVisibleToContact(txn, contactId, blog2.getId(), true); oneOf(db).setVisibleToContact(txn, contactId, blog2.getId(), true);
oneOf(db).getLocalAuthor(txn, blog1.getAuthor().getId()); oneOf(db).getLocalAuthor(txn, blog1.getAuthor().getId());
will(returnValue(blog1.getAuthor())); will(returnValue(blog1.getAuthor()));
oneOf(blogFactory).createPersonalBlog(blog1.getAuthor()); oneOf(blogFactory).createBlog(blog1.getAuthor());
will(returnValue(blog1)); will(returnValue(blog1));
oneOf(db).setVisibleToContact(txn, contactId, blog1.getId(), true); oneOf(db).setVisibleToContact(txn, contactId, blog1.getId(), true);
}}); }});
@@ -145,7 +142,7 @@ public class BlogManagerImplTest extends BriarTestCase {
blog1.getAuthor().getId(), true, true); blog1.getAuthor().getId(), true, true);
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(blogFactory).createPersonalBlog(blog2.getAuthor()); oneOf(blogFactory).createBlog(blog2.getAuthor());
will(returnValue(blog2)); will(returnValue(blog2));
oneOf(db).removeGroup(txn, blog2.getGroup()); oneOf(db).removeGroup(txn, blog2.getGroup());
}}); }});
@@ -163,7 +160,7 @@ public class BlogManagerImplTest extends BriarTestCase {
a.getPublicKey(), 0); a.getPublicKey(), 0);
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(blogFactory).createPersonalBlog(localAuthor); oneOf(blogFactory).createBlog(localAuthor);
will(returnValue(blog1)); will(returnValue(blog1));
oneOf(db).addGroup(txn, blog1.getGroup()); oneOf(db).addGroup(txn, blog1.getGroup());
}}); }});
@@ -181,7 +178,7 @@ public class BlogManagerImplTest extends BriarTestCase {
a.getPublicKey(), 0); a.getPublicKey(), 0);
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(blogFactory).createPersonalBlog(localAuthor); oneOf(blogFactory).createBlog(localAuthor);
will(returnValue(blog1)); will(returnValue(blog1));
oneOf(db).removeGroup(txn, blog1.getGroup()); oneOf(db).removeGroup(txn, blog1.getGroup());
}}); }});
@@ -226,35 +223,6 @@ public class BlogManagerImplTest extends BriarTestCase {
assertEquals(blog1.getAuthor(), h.getAuthor()); assertEquals(blog1.getAuthor(), h.getAuthor());
} }
@Test
public void testAddBlog() throws DbException, FormatException {
final Transaction txn = new Transaction(null, false);
Author a = blog1.getAuthor();
final LocalAuthor localAuthor =
new LocalAuthor(a.getId(), a.getName(), a.getPublicKey(),
a.getPublicKey(), 0);
final BdfDictionary meta = BdfDictionary.of(
new BdfEntry(KEY_DESCRIPTION, blog1.getDescription())
);
context.checking(new Expectations() {{
oneOf(blogFactory)
.createBlog(blog1.getName(), blog1.getDescription(),
blog1.getAuthor());
will(returnValue(blog1));
oneOf(db).startTransaction(false);
will(returnValue(txn));
oneOf(db).addGroup(txn, blog1.getGroup());
oneOf(clientHelper).mergeGroupMetadata(txn, blog1.getId(), meta);
oneOf(db).endTransaction(txn);
}});
blogManager
.addBlog(localAuthor, blog1.getName(), blog1.getDescription());
context.assertIsSatisfied();
assertTrue(txn.isComplete());
}
@Test @Test
public void testRemoveBlog() throws Exception { public void testRemoveBlog() throws Exception {
final Transaction txn = new Transaction(null, false); final Transaction txn = new Transaction(null, false);
@@ -369,15 +337,12 @@ public class BlogManagerImplTest extends BriarTestCase {
will(returnValue(txn)); will(returnValue(txn));
oneOf(db).getGroup(txn, blog.getId()); oneOf(db).getGroup(txn, blog.getId());
will(returnValue(blog.getGroup())); will(returnValue(blog.getGroup()));
oneOf(clientHelper) oneOf(blogFactory).parseBlog(blog.getGroup());
.getGroupMetadataAsDictionary(txn, blog.getId());
will(returnValue(new BdfDictionary()));
oneOf(blogFactory).parseBlog(blog.getGroup(), "");
will(returnValue(blog)); will(returnValue(blog));
}}); }});
} }
private Blog getBlog(String name, String desc) { private Blog createBlog() {
final GroupId groupId = new GroupId(getRandomId()); final GroupId groupId = new GroupId(getRandomId());
final Group group = new Group(groupId, CLIENT_ID, getRandomBytes(42)); final Group group = new Group(groupId, CLIENT_ID, getRandomBytes(42));
final AuthorId authorId = new AuthorId(getRandomId()); final AuthorId authorId = new AuthorId(getRandomId());
@@ -387,7 +352,7 @@ public class BlogManagerImplTest extends BriarTestCase {
final LocalAuthor localAuthor = final LocalAuthor localAuthor =
new LocalAuthor(authorId, "Author", publicKey, privateKey, new LocalAuthor(authorId, "Author", publicKey, privateKey,
created); created);
return new Blog(group, name, desc, localAuthor); return new Blog(group, localAuthor);
} }
private BdfDictionary authorToBdfDictionary(Author a) { private BdfDictionary authorToBdfDictionary(Author a) {

View File

@@ -50,23 +50,19 @@ public class BlogPostValidatorTest extends BriarTestCase {
private final Mockery context = new Mockery(); private final Mockery context = new Mockery();
private final Blog blog; private final Blog blog;
private final Author author;
private final BdfDictionary authorDict; private final BdfDictionary authorDict;
private final ClientId clientId; private final ClientId clientId;
private final byte[] descriptor; private final byte[] descriptor;
private final Group group; private final Group group;
private final Message message; private final Message message;
private final BlogPostValidator validator; private final BlogPostValidator validator;
private final CryptoComponent cryptoComponent =
context.mock(CryptoComponent.class);
private final GroupFactory groupFactory = context.mock(GroupFactory.class); private final GroupFactory groupFactory = context.mock(GroupFactory.class);
private final MessageFactory messageFactory = private final MessageFactory messageFactory =
context.mock(MessageFactory.class); context.mock(MessageFactory.class);
private final BlogFactory blogFactory = context.mock(BlogFactory.class); private final BlogFactory blogFactory = context.mock(BlogFactory.class);
private final ClientHelper clientHelper = context.mock(ClientHelper.class); private final ClientHelper clientHelper = context.mock(ClientHelper.class);
private final Clock clock = new SystemClock(); private final Author author;
private final String body = TestUtils.getRandomString(42); private final String body = TestUtils.getRandomString(42);
private final String contentType = "text/plain";
public BlogPostValidatorTest() { public BlogPostValidatorTest() {
GroupId groupId = new GroupId(TestUtils.getRandomId()); GroupId groupId = new GroupId(TestUtils.getRandomId());
@@ -82,7 +78,7 @@ public class BlogPostValidatorTest extends BriarTestCase {
new BdfEntry(KEY_AUTHOR_NAME, author.getName()), new BdfEntry(KEY_AUTHOR_NAME, author.getName()),
new BdfEntry(KEY_PUBLIC_KEY, author.getPublicKey()) new BdfEntry(KEY_PUBLIC_KEY, author.getPublicKey())
); );
blog = new Blog(group, "Test Blog", "", author); blog = new Blog(group, author);
MessageId messageId = new MessageId(TestUtils.getRandomId()); MessageId messageId = new MessageId(TestUtils.getRandomId());
long timestamp = System.currentTimeMillis(); long timestamp = System.currentTimeMillis();
@@ -90,8 +86,10 @@ public class BlogPostValidatorTest extends BriarTestCase {
message = new Message(messageId, group.getId(), timestamp, raw); message = new Message(messageId, group.getId(), timestamp, raw);
MetadataEncoder metadataEncoder = context.mock(MetadataEncoder.class); MetadataEncoder metadataEncoder = context.mock(MetadataEncoder.class);
validator = new BlogPostValidator(groupFactory, messageFactory, Clock clock = new SystemClock();
blogFactory, clientHelper, metadataEncoder, clock); validator =
new BlogPostValidator(groupFactory, messageFactory, blogFactory,
clientHelper, metadataEncoder, clock);
context.assertIsSatisfied(); context.assertIsSatisfied();
} }
@@ -115,7 +113,7 @@ public class BlogPostValidatorTest extends BriarTestCase {
@Test(expected = FormatException.class) @Test(expected = FormatException.class)
public void testValidateBlogPostWithoutAttachments() public void testValidateBlogPostWithoutAttachments()
throws IOException, GeneralSecurityException { throws IOException, GeneralSecurityException {
BdfList content = BdfList.of(null, contentType, 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).getDictionary();
@@ -124,7 +122,7 @@ public class BlogPostValidatorTest extends BriarTestCase {
@Test(expected = FormatException.class) @Test(expected = FormatException.class)
public void testValidateBlogPostWithoutSignature() public void testValidateBlogPostWithoutSignature()
throws IOException, GeneralSecurityException { throws IOException, GeneralSecurityException {
BdfList content = BdfList.of(null, contentType, 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).getDictionary();
@@ -261,7 +259,7 @@ public class BlogPostValidatorTest extends BriarTestCase {
private void expectCrypto(final BdfList signed, final byte[] sig) private void expectCrypto(final BdfList signed, final byte[] sig)
throws IOException, GeneralSecurityException { throws IOException, GeneralSecurityException {
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(blogFactory).parseBlog(group, ""); oneOf(blogFactory).parseBlog(group);
will(returnValue(blog)); will(returnValue(blog));
oneOf(clientHelper) oneOf(clientHelper)
.verifySignature(sig, author.getPublicKey(), signed); .verifySignature(sig, author.getPublicKey(), signed);