Use "text" to refer to message text.

This commit is contained in:
akwizgran
2018-10-10 10:40:23 +01:00
parent a030f92275
commit 79d5612645
145 changed files with 750 additions and 764 deletions

View File

@@ -456,21 +456,22 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
}
@Override
public String getPostBody(MessageId m) throws DbException {
public String getPostText(MessageId m) throws DbException {
try {
return getPostBody(clientHelper.getMessageAsList(m));
return getPostText(clientHelper.getMessageAsList(m));
} catch (FormatException e) {
throw new DbException(e);
}
}
private String getPostBody(BdfList message) throws FormatException {
private String getPostText(BdfList message) throws FormatException {
MessageType type = MessageType.valueOf(message.getLong(0).intValue());
if (type == POST) {
// type, body, signature
// Type, text, signature
return message.getString(1);
} else if (type == WRAPPED_POST) {
// type, p_group descriptor, p_timestamp, p_content, p_signature
// Type, copied group descriptor, copied timestamp, copied text,
// copied signature
return message.getString(3);
} else {
throw new FormatException();

View File

@@ -20,8 +20,8 @@ import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
import javax.inject.Inject;
import static org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_COMMENT_LENGTH;
import static org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_POST_BODY_LENGTH;
import static org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_COMMENT_TEXT_LENGTH;
import static org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_POST_TEXT_LENGTH;
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.WRAPPED_COMMENT;
@@ -42,23 +42,23 @@ class BlogPostFactoryImpl implements BlogPostFactory {
@Override
public BlogPost createBlogPost(GroupId groupId, long timestamp,
@Nullable MessageId parent, LocalAuthor author, String body)
@Nullable MessageId parent, LocalAuthor author, String text)
throws FormatException, GeneralSecurityException {
// Validate the arguments
int bodyLength = StringUtils.toUtf8(body).length;
if (bodyLength > MAX_BLOG_POST_BODY_LENGTH)
int textLength = StringUtils.toUtf8(text).length;
if (textLength > MAX_BLOG_POST_TEXT_LENGTH)
throw new IllegalArgumentException();
// Serialise the data to be signed
BdfList signed = BdfList.of(groupId, timestamp, body);
BdfList signed = BdfList.of(groupId, timestamp, text);
// Generate the signature
byte[] sig = clientHelper
.sign(SIGNING_LABEL_POST, signed, author.getPrivateKey());
// Serialise the signed message
BdfList message = BdfList.of(POST.getInt(), body, sig);
BdfList message = BdfList.of(POST.getInt(), text, sig);
Message m = clientHelper.createMessage(groupId, timestamp, message);
return new BlogPost(m, parent, author);
}
@@ -72,7 +72,7 @@ class BlogPostFactoryImpl implements BlogPostFactory {
if (comment != null) {
int commentLength = StringUtils.toUtf8(comment).length;
if (commentLength == 0) throw new IllegalArgumentException();
if (commentLength > MAX_BLOG_COMMENT_LENGTH)
if (commentLength > MAX_BLOG_COMMENT_TEXT_LENGTH)
throw new IllegalArgumentException();
}
@@ -98,10 +98,10 @@ class BlogPostFactoryImpl implements BlogPostFactory {
throw new IllegalArgumentException("Needs to wrap a POST");
// Serialise the message
String content = body.getString(1);
String text = body.getString(1);
byte[] signature = body.getRaw(2);
BdfList message = BdfList.of(WRAPPED_POST.getInt(), descriptor,
timestamp, content, signature);
timestamp, text, signature);
return clientHelper
.createMessage(groupId, clock.currentTimeMillis(), message);
}
@@ -116,10 +116,10 @@ class BlogPostFactoryImpl implements BlogPostFactory {
// Serialise the message
byte[] descriptor = body.getRaw(1);
long timestamp = body.getLong(2);
String content = body.getString(3);
String text = body.getString(3);
byte[] signature = body.getRaw(4);
BdfList message = BdfList.of(WRAPPED_POST.getInt(), descriptor,
timestamp, content, signature);
timestamp, text, signature);
return clientHelper
.createMessage(groupId, clock.currentTimeMillis(), message);
}

View File

@@ -22,10 +22,10 @@ import org.briarproject.briar.api.blog.MessageType;
import java.security.GeneralSecurityException;
import java.util.Collection;
import java.util.Collections;
import javax.annotation.concurrent.Immutable;
import static java.util.Collections.singletonList;
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_SIGNATURE_LENGTH;
import static org.briarproject.bramble.util.ValidationUtils.checkLength;
import static org.briarproject.bramble.util.ValidationUtils.checkSize;
@@ -39,8 +39,8 @@ import static org.briarproject.briar.api.blog.BlogConstants.KEY_RSS_FEED;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_TIMESTAMP;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_TIME_RECEIVED;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_TYPE;
import static org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_COMMENT_LENGTH;
import static org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_POST_BODY_LENGTH;
import static org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_COMMENT_TEXT_LENGTH;
import static org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_POST_TEXT_LENGTH;
import static org.briarproject.briar.api.blog.BlogManager.CLIENT_ID;
import static org.briarproject.briar.api.blog.BlogManager.MAJOR_VERSION;
import static org.briarproject.briar.api.blog.BlogPostFactory.SIGNING_LABEL_COMMENT;
@@ -99,15 +99,15 @@ class BlogPostValidator extends BdfMessageValidator {
private BdfMessageContext validatePost(Message m, Group g, BdfList body)
throws InvalidMessageException, FormatException {
// Content, Signature
// Text, signature
checkSize(body, 2);
String postBody = body.getString(0);
checkLength(postBody, 0, MAX_BLOG_POST_BODY_LENGTH);
String text = body.getString(0);
checkLength(text, 0, MAX_BLOG_POST_TEXT_LENGTH);
// Verify Signature
// Verify signature
byte[] sig = body.getRaw(1);
checkLength(sig, 1, MAX_SIGNATURE_LENGTH);
BdfList signed = BdfList.of(g.getId(), m.getTimestamp(), postBody);
BdfList signed = BdfList.of(g.getId(), m.getTimestamp(), text);
Blog b = blogFactory.parseBlog(g);
Author a = b.getAuthor();
try {
@@ -128,23 +128,23 @@ class BlogPostValidator extends BdfMessageValidator {
private BdfMessageContext validateComment(Message m, Group g, BdfList body)
throws InvalidMessageException, FormatException {
// comment, parent_original_id, parent_id, signature
// Comment, parent original ID, parent ID, signature
checkSize(body, 4);
// Comment
String comment = body.getOptionalString(0);
checkLength(comment, 1, MAX_BLOG_COMMENT_LENGTH);
checkLength(comment, 1, MAX_BLOG_COMMENT_TEXT_LENGTH);
// parent_original_id
// The ID of a post or comment in this group or another group
// Parent original ID
// The ID of a post or comment in this blog or another blog
byte[] pOriginalIdBytes = body.getRaw(1);
checkLength(pOriginalIdBytes, MessageId.LENGTH);
MessageId pOriginalId = new MessageId(pOriginalIdBytes);
// parent_id
// The ID of a post, comment, wrapped post or wrapped comment in this
// group, which had the ID parent_original_id in the group
// where it was originally posted
// Parent ID
// The ID of the comment's parent, which is a post, comment, wrapped
// post or wrapped comment in this blog, which had the ID
// parentOriginalId in the blog where it was originally posted
byte[] currentIdBytes = body.getRaw(2);
checkLength(currentIdBytes, MessageId.LENGTH);
MessageId currentId = new MessageId(currentIdBytes);
@@ -170,35 +170,37 @@ class BlogPostValidator extends BdfMessageValidator {
meta.put(KEY_ORIGINAL_PARENT_MSG_ID, pOriginalId);
meta.put(KEY_PARENT_MSG_ID, currentId);
meta.put(KEY_AUTHOR, clientHelper.toList(a));
Collection<MessageId> dependencies = Collections.singleton(currentId);
Collection<MessageId> dependencies = singletonList(currentId);
return new BdfMessageContext(meta, dependencies);
}
private BdfMessageContext validateWrappedPost(BdfList body)
throws InvalidMessageException, FormatException {
// p_group descriptor, p_timestamp, p_content, p_signature
// Copied group descriptor, copied timestamp, copied text, copied
// signature
checkSize(body, 4);
// Group Descriptor
// Copied group descriptor of original post
byte[] descriptor = body.getRaw(0);
// Timestamp of Wrapped Post
// Copied timestamp of original post
long wTimestamp = body.getLong(1);
if (wTimestamp < 0) throw new FormatException();
// Content of Wrapped Post
String content = body.getString(2);
// Copied text of original post
String text = body.getString(2);
checkLength(text, 0, MAX_BLOG_POST_TEXT_LENGTH);
// Signature of Wrapped Post
// Copied signature of original post
byte[] signature = body.getRaw(3);
checkLength(signature, 1, MAX_SIGNATURE_LENGTH);
// Get and Validate the Wrapped Message
// Reconstruct and validate the original post
Group wGroup = groupFactory.createGroup(CLIENT_ID, MAJOR_VERSION,
descriptor);
Blog wBlog = blogFactory.parseBlog(wGroup);
BdfList wBodyList = BdfList.of(POST.getInt(), content, signature);
BdfList wBodyList = BdfList.of(POST.getInt(), text, signature);
byte[] wBody = clientHelper.toByteArray(wBodyList);
Message wMessage =
messageFactory.createMessage(wGroup.getId(), wTimestamp, wBody);
@@ -217,47 +219,46 @@ class BlogPostValidator extends BdfMessageValidator {
private BdfMessageContext validateWrappedComment(BdfList body)
throws InvalidMessageException, FormatException {
// c_group descriptor, c_timestamp, c_comment, c_parent_original_id,
// c_parent_id, c_signature, parent_id
// Copied group descriptor, copied timestamp, copied text, copied
// parent original ID, copied parent ID, copied signature, parent ID
checkSize(body, 7);
// Group Descriptor
// Copied group descriptor of original comment
byte[] descriptor = body.getRaw(0);
// Timestamp of Wrapped Comment
// Copied timestamp of original comment
long wTimestamp = body.getLong(1);
if (wTimestamp < 0) throw new FormatException();
// Body of Wrapped Comment
// Copied text of original comment
String comment = body.getOptionalString(2);
checkLength(comment, 1, MAX_BLOG_COMMENT_LENGTH);
checkLength(comment, 1, MAX_BLOG_COMMENT_TEXT_LENGTH);
// c_parent_original_id
// Taken from the original comment
// Copied parent original ID of original comment
byte[] pOriginalIdBytes = body.getRaw(3);
checkLength(pOriginalIdBytes, MessageId.LENGTH);
MessageId pOriginalId = new MessageId(pOriginalIdBytes);
// c_parent_id
// Taken from the original comment
// Copied parent ID of original comment
byte[] oldIdBytes = body.getRaw(4);
checkLength(oldIdBytes, MessageId.LENGTH);
MessageId oldId = new MessageId(oldIdBytes);
// c_signature
// Taken from the original comment
// Copied signature of original comment
byte[] signature = body.getRaw(5);
checkLength(signature, 1, MAX_SIGNATURE_LENGTH);
// parent_id
// The ID of a post, comment, wrapped post or wrapped comment in this
// group, which had the ID c_parent_original_id in the group
// where it was originally posted
// Parent ID
// The ID of this comment's parent, which is a post, comment, wrapped
// post or wrapped comment in this blog, which had the ID
// copiedParentOriginalId in the blog where the parent was originally
// posted, and the ID copiedParentId in the blog where this comment was
// originally posted
byte[] parentIdBytes = body.getRaw(6);
checkLength(parentIdBytes, MessageId.LENGTH);
MessageId parentId = new MessageId(parentIdBytes);
// Get and Validate the Wrapped Comment
// Reconstruct and validate the original comment
Group wGroup = groupFactory.createGroup(CLIENT_ID, MAJOR_VERSION,
descriptor);
BdfList wBodyList = BdfList.of(COMMENT.getInt(), comment, pOriginalId,
@@ -269,7 +270,7 @@ class BlogPostValidator extends BdfMessageValidator {
BdfMessageContext c = validateComment(wMessage, wGroup, wBodyList);
// Return the metadata and dependencies
Collection<MessageId> dependencies = Collections.singleton(parentId);
Collection<MessageId> dependencies = singletonList(parentId);
BdfDictionary meta = new BdfDictionary();
meta.put(KEY_ORIGINAL_MSG_ID, wMessage.getId());
meta.put(KEY_ORIGINAL_PARENT_MSG_ID, pOriginalId);

View File

@@ -64,7 +64,7 @@ import okhttp3.ResponseBody;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.logging.Level.WARNING;
import static org.briarproject.bramble.util.LogUtils.logException;
import static org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_POST_BODY_LENGTH;
import static org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_POST_TEXT_LENGTH;
import static org.briarproject.briar.api.feed.FeedConstants.FETCH_DELAY_INITIAL;
import static org.briarproject.briar.api.feed.FeedConstants.FETCH_INTERVAL;
import static org.briarproject.briar.api.feed.FeedConstants.FETCH_UNIT;
@@ -410,11 +410,10 @@ class FeedManagerImpl implements FeedManager, Client, EventListener,
return lastEntryTime;
}
private void postEntry(Transaction txn, Feed feed, SyndEntry entry)
throws DbException {
private void postEntry(Transaction txn, Feed feed, SyndEntry entry) {
LOG.info("Adding new entry...");
// build post body
// build post text
StringBuilder b = new StringBuilder();
if (!StringUtils.isNullOrEmpty(entry.getTitle())) {
@@ -454,12 +453,12 @@ class FeedManagerImpl implements FeedManager, Client, EventListener,
if (date == null) date = entry.getPublishedDate();
if (date == null) time = now;
else time = Math.max(0, Math.min(date.getTime(), now));
String body = getPostBody(b.toString());
String text = getPostText(b.toString());
try {
// create and store post
LocalAuthor localAuthor = feed.getLocalAuthor();
BlogPost post = blogPostFactory
.createBlogPost(groupId, time, null, localAuthor, body);
.createBlogPost(groupId, time, null, localAuthor, text);
blogManager.addLocalPost(txn, post);
} catch (DbException | GeneralSecurityException | FormatException e) {
logException(LOG, WARNING, e);
@@ -470,9 +469,9 @@ class FeedManagerImpl implements FeedManager, Client, EventListener,
}
}
private String getPostBody(String text) {
private String getPostText(String text) {
text = clean(text, ARTICLE);
return StringUtils.truncateUtf8(text, MAX_BLOG_POST_BODY_LENGTH);
return StringUtils.truncateUtf8(text, MAX_BLOG_POST_TEXT_LENGTH);
}
private Comparator<SyndEntry> getEntryComparator() {

View File

@@ -82,9 +82,9 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
messageTracker.trackIncomingMessage(txn, m);
ForumPostHeader header = getForumPostHeader(txn, m.getId(), meta);
String postBody = getPostBody(body);
String text = getPostText(body);
ForumPostReceivedEvent event =
new ForumPostReceivedEvent(m.getGroupId(), header, postBody);
new ForumPostReceivedEvent(m.getGroupId(), header, text);
txn.attach(event);
// share message
@@ -113,12 +113,12 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
}
@Override
public ForumPost createLocalPost(GroupId groupId, String body,
public ForumPost createLocalPost(GroupId groupId, String text,
long timestamp, @Nullable MessageId parentId, LocalAuthor author) {
ForumPost p;
try {
p = forumPostFactory.createPost(groupId, timestamp, parentId,
author, body);
author, text);
} catch (GeneralSecurityException | FormatException e) {
throw new AssertionError(e);
}
@@ -175,16 +175,16 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
}
@Override
public String getPostBody(MessageId m) throws DbException {
public String getPostText(MessageId m) throws DbException {
try {
return getPostBody(clientHelper.getMessageAsList(m));
return getPostText(clientHelper.getMessageAsList(m));
} catch (FormatException e) {
throw new DbException(e);
}
}
private String getPostBody(BdfList body) throws FormatException {
// Parent ID, author, forum post body, signature
private String getPostText(BdfList body) throws FormatException {
// Parent ID, author, text, signature
return body.getString(2);
}

View File

@@ -8,7 +8,6 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.sync.GroupId;
import org.briarproject.bramble.api.sync.Message;
import org.briarproject.bramble.api.sync.MessageId;
import org.briarproject.bramble.util.StringUtils;
import org.briarproject.briar.api.forum.ForumPost;
import org.briarproject.briar.api.forum.ForumPostFactory;
@@ -18,7 +17,8 @@ import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
import javax.inject.Inject;
import static org.briarproject.briar.api.forum.ForumConstants.MAX_FORUM_POST_BODY_LENGTH;
import static org.briarproject.bramble.util.StringUtils.utf8IsTooLong;
import static org.briarproject.briar.api.forum.ForumConstants.MAX_FORUM_POST_TEXT_LENGTH;
@Immutable
@NotNullByDefault
@@ -33,20 +33,20 @@ class ForumPostFactoryImpl implements ForumPostFactory {
@Override
public ForumPost createPost(GroupId groupId, long timestamp,
@Nullable MessageId parent, LocalAuthor author, String body)
@Nullable MessageId parent, LocalAuthor author, String text)
throws FormatException, GeneralSecurityException {
// Validate the arguments
if (StringUtils.utf8IsTooLong(body, MAX_FORUM_POST_BODY_LENGTH))
if (utf8IsTooLong(text, MAX_FORUM_POST_TEXT_LENGTH))
throw new IllegalArgumentException();
// Serialise the data to be signed
BdfList authorList = clientHelper.toList(author);
BdfList signed = BdfList.of(groupId, timestamp, parent, authorList,
body);
text);
// Sign the data
byte[] sig = clientHelper.sign(SIGNING_LABEL_POST, signed,
author.getPrivateKey());
// Serialise the signed message
BdfList message = BdfList.of(parent, authorList, body, sig);
BdfList message = BdfList.of(parent, authorList, text, sig);
Message m = clientHelper.createMessage(groupId, timestamp, message);
return new ForumPost(m, parent, author);
}

View File

@@ -18,10 +18,11 @@ import org.briarproject.bramble.api.system.Clock;
import java.security.GeneralSecurityException;
import java.util.Collection;
import java.util.Collections;
import javax.annotation.concurrent.Immutable;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_SIGNATURE_LENGTH;
import static org.briarproject.bramble.util.ValidationUtils.checkLength;
import static org.briarproject.bramble.util.ValidationUtils.checkSize;
@@ -29,7 +30,7 @@ import static org.briarproject.briar.api.forum.ForumConstants.KEY_AUTHOR;
import static org.briarproject.briar.api.forum.ForumConstants.KEY_PARENT;
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.MAX_FORUM_POST_BODY_LENGTH;
import static org.briarproject.briar.api.forum.ForumConstants.MAX_FORUM_POST_TEXT_LENGTH;
import static org.briarproject.briar.api.forum.ForumPostFactory.SIGNING_LABEL_POST;
@Immutable
@@ -44,7 +45,7 @@ class ForumPostValidator extends BdfMessageValidator {
@Override
protected BdfMessageContext validateMessage(Message m, Group g,
BdfList body) throws InvalidMessageException, FormatException {
// Parent ID, author, content type, forum post body, signature
// Parent ID, author, text, signature
checkSize(body, 4);
// Parent ID is optional
@@ -55,16 +56,17 @@ class ForumPostValidator extends BdfMessageValidator {
BdfList authorList = body.getList(1);
Author author = clientHelper.parseAndValidateAuthor(authorList);
// Forum post body
String content = body.getString(2);
checkLength(content, 0, MAX_FORUM_POST_BODY_LENGTH);
// Text
String text = body.getString(2);
checkLength(text, 0, MAX_FORUM_POST_TEXT_LENGTH);
// Signature
byte[] sig = body.getRaw(3);
checkLength(sig, 1, MAX_SIGNATURE_LENGTH);
// Verify the signature
BdfList signed = BdfList.of(g.getId(), m.getTimestamp(), parent,
authorList, content);
authorList, text);
try {
clientHelper.verifySignature(sig, SIGNING_LABEL_POST,
signed, author.getPublicKey());
@@ -74,11 +76,11 @@ class ForumPostValidator extends BdfMessageValidator {
// Return the metadata and dependencies
BdfDictionary meta = new BdfDictionary();
Collection<MessageId> dependencies = Collections.emptyList();
Collection<MessageId> dependencies = emptyList();
meta.put(KEY_TIMESTAMP, m.getTimestamp());
if (parent != null) {
meta.put(KEY_PARENT, parent);
dependencies = Collections.singletonList(new MessageId(parent));
dependencies = singletonList(new MessageId(parent));
}
meta.put(KEY_AUTHOR, authorList);
meta.put(KEY_READ, false);

View File

@@ -72,11 +72,11 @@ abstract class AbstractProtocolEngine<S extends Session>
}
Message sendRequestMessage(Transaction txn, PeerSession s,
long timestamp, Author author, @Nullable String message)
long timestamp, Author author, @Nullable String text)
throws DbException {
Message m = messageEncoder
.encodeRequestMessage(s.getContactGroupId(), timestamp,
s.getLastLocalMessageId(), author, message);
s.getLastLocalMessageId(), author, text);
sendMessage(txn, REQUEST, s.getSessionId(), m, true);
return m;
}

View File

@@ -85,8 +85,7 @@ class IntroduceeProtocolEngine
@Override
public IntroduceeSession onRequestAction(Transaction txn,
IntroduceeSession session, @Nullable String message,
long timestamp) {
IntroduceeSession session, @Nullable String text, long timestamp) {
throw new UnsupportedOperationException(); // Invalid in this role
}
@@ -256,7 +255,7 @@ class IntroduceeProtocolEngine
.contactExists(txn, m.getAuthor().getId(), localAuthor.getId());
IntroductionRequest request = new IntroductionRequest(m.getMessageId(),
m.getGroupId(), m.getTimestamp(), false, false, false, false,
s.getSessionId(), m.getAuthor(), m.getMessage(), false,
s.getSessionId(), m.getAuthor(), m.getText(), false,
contactExists);
IntroductionRequestReceivedEvent e =
new IntroductionRequestReceivedEvent(request, c.getId());

View File

@@ -58,11 +58,11 @@ class IntroducerProtocolEngine
@Override
public IntroducerSession onRequestAction(Transaction txn,
IntroducerSession s, @Nullable String message, long timestamp)
IntroducerSession s, @Nullable String text, long timestamp)
throws DbException {
switch (s.getState()) {
case START:
return onLocalRequest(txn, s, message, timestamp);
return onLocalRequest(txn, s, text, timestamp);
case AWAIT_RESPONSES:
case AWAIT_RESPONSE_A:
case AWAIT_RESPONSE_B:
@@ -222,7 +222,7 @@ class IntroducerProtocolEngine
}
private IntroducerSession onLocalRequest(Transaction txn,
IntroducerSession s, @Nullable String message, long timestamp)
IntroducerSession s, @Nullable String text, long timestamp)
throws DbException {
// Send REQUEST messages
long maxIntroduceeTimestamp =
@@ -230,11 +230,9 @@ class IntroducerProtocolEngine
getLocalTimestamp(s, s.getIntroduceeB()));
long localTimestamp = Math.max(timestamp, maxIntroduceeTimestamp);
Message sentA = sendRequestMessage(txn, s.getIntroduceeA(),
localTimestamp, s.getIntroduceeB().author, message
);
localTimestamp, s.getIntroduceeB().author, text);
Message sentB = sendRequestMessage(txn, s.getIntroduceeB(),
localTimestamp, s.getIntroduceeA().author, message
);
localTimestamp, s.getIntroduceeA().author, text);
// Track the messages
messageTracker.trackOutgoingMessage(txn, sentA);
messageTracker.trackOutgoingMessage(txn, sentB);

View File

@@ -316,7 +316,7 @@ class IntroductionManagerImpl extends ConversationClientImpl
}
@Override
public void makeIntroduction(Contact c1, Contact c2, @Nullable String msg,
public void makeIntroduction(Contact c1, Contact c2, @Nullable String text,
long timestamp) throws DbException {
Transaction txn = db.startTransaction(false);
try {
@@ -350,7 +350,7 @@ class IntroductionManagerImpl extends ConversationClientImpl
}
// Handle the request action
session = introducerEngine
.onRequestAction(txn, session, msg, timestamp);
.onRequestAction(txn, session, text, timestamp);
// Store the updated session
storeSession(txn, storageId, session);
db.commitTransaction(txn);
@@ -461,14 +461,14 @@ class IntroductionManagerImpl extends ConversationClientImpl
Message msg = clientHelper.getMessage(txn, m);
BdfList body = clientHelper.toList(msg);
RequestMessage rm = messageParser.parseRequestMessage(msg, body);
String message = rm.getMessage();
String text = rm.getText();
LocalAuthor localAuthor = identityManager.getLocalAuthor(txn);
boolean contactExists = contactManager
.contactExists(txn, rm.getAuthor().getId(),
localAuthor.getId());
return new IntroductionRequest(m, contactGroupId, meta.getTimestamp(),
meta.isLocal(), status.isSent(), status.isSeen(), meta.isRead(),
sessionId, author, message, !meta.isAvailableToAnswer(),
sessionId, author, text, !meta.isAvailableToAnswer(),
contactExists);
}

View File

@@ -24,7 +24,7 @@ import static org.briarproject.bramble.api.crypto.CryptoConstants.MAX_SIGNATURE_
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
import static org.briarproject.bramble.util.ValidationUtils.checkLength;
import static org.briarproject.bramble.util.ValidationUtils.checkSize;
import static org.briarproject.briar.api.introduction.IntroductionConstants.MAX_REQUEST_MESSAGE_LENGTH;
import static org.briarproject.briar.api.introduction.IntroductionConstants.MAX_INTRODUCTION_TEXT_LENGTH;
import static org.briarproject.briar.introduction.MessageType.ACCEPT;
import static org.briarproject.briar.introduction.MessageType.ACTIVATE;
import static org.briarproject.briar.introduction.MessageType.AUTH;
@@ -75,8 +75,8 @@ class IntroductionValidator extends BdfMessageValidator {
BdfList authorList = body.getList(2);
clientHelper.parseAndValidateAuthor(authorList);
String msg = body.getOptionalString(3);
checkLength(msg, 1, MAX_REQUEST_MESSAGE_LENGTH);
String text = body.getOptionalString(3);
checkLength(text, 1, MAX_INTRODUCTION_TEXT_LENGTH);
BdfDictionary meta =
messageEncoder.encodeRequestMetadata(m.getTimestamp());

View File

@@ -31,7 +31,7 @@ interface MessageEncoder {
Message encodeRequestMessage(GroupId contactGroupId, long timestamp,
@Nullable MessageId previousMessageId, Author author,
@Nullable String message);
@Nullable String text);
Message encodeAcceptMessage(GroupId contactGroupId, long timestamp,
@Nullable MessageId previousMessageId, SessionId sessionId,

View File

@@ -89,15 +89,15 @@ class MessageEncoderImpl implements MessageEncoder {
@Override
public Message encodeRequestMessage(GroupId contactGroupId, long timestamp,
@Nullable MessageId previousMessageId, Author author,
@Nullable String message) {
if (message != null && message.equals("")) {
@Nullable String text) {
if (text != null && text.isEmpty()) {
throw new IllegalArgumentException();
}
BdfList body = BdfList.of(
REQUEST.getValue(),
previousMessageId,
clientHelper.toList(author),
message
text
);
return createMessage(contactGroupId, timestamp, body);
}

View File

@@ -74,9 +74,9 @@ class MessageParserImpl implements MessageParser {
MessageId previousMessageId = (previousMsgBytes == null ? null :
new MessageId(previousMsgBytes));
Author author = clientHelper.parseAndValidateAuthor(body.getList(2));
String message = body.getOptionalString(3);
String text = body.getOptionalString(3);
return new RequestMessage(m.getId(), m.getGroupId(),
m.getTimestamp(), previousMessageId, author, message);
m.getTimestamp(), previousMessageId, author, text);
}
@Override

View File

@@ -10,7 +10,7 @@ import javax.annotation.Nullable;
@NotNullByDefault
interface ProtocolEngine<S extends Session> {
S onRequestAction(Transaction txn, S session, @Nullable String message,
S onRequestAction(Transaction txn, S session, @Nullable String text,
long timestamp) throws DbException;
S onAcceptAction(Transaction txn, S session, long timestamp)

View File

@@ -14,14 +14,14 @@ class RequestMessage extends AbstractIntroductionMessage {
private final Author author;
@Nullable
private final String message;
private final String text;
protected RequestMessage(MessageId messageId, GroupId groupId,
long timestamp, @Nullable MessageId previousMessageId,
Author author, @Nullable String message) {
RequestMessage(MessageId messageId, GroupId groupId, long timestamp,
@Nullable MessageId previousMessageId, Author author,
@Nullable String text) {
super(messageId, groupId, timestamp, previousMessageId);
this.author = author;
this.message = message;
this.text = text;
}
public Author getAuthor() {
@@ -29,8 +29,8 @@ class RequestMessage extends AbstractIntroductionMessage {
}
@Nullable
public String getMessage() {
return message;
public String getText() {
return text;
}
}

View File

@@ -209,9 +209,9 @@ class MessagingManagerImpl extends ConversationClientImpl
}
@Override
public String getMessageBody(MessageId m) throws DbException {
public String getMessageText(MessageId m) throws DbException {
try {
// 0: private message body
// 0: private message text
return clientHelper.getMessageAsList(m).getString(0);
} catch (FormatException e) {
throw new DbException(e);

View File

@@ -13,7 +13,7 @@ import javax.annotation.concurrent.Immutable;
import javax.inject.Inject;
import static org.briarproject.bramble.util.StringUtils.utf8IsTooLong;
import static org.briarproject.briar.api.messaging.MessagingConstants.MAX_PRIVATE_MESSAGE_BODY_LENGTH;
import static org.briarproject.briar.api.messaging.MessagingConstants.MAX_PRIVATE_MESSAGE_TEXT_LENGTH;
@Immutable
@NotNullByDefault
@@ -28,12 +28,12 @@ class PrivateMessageFactoryImpl implements PrivateMessageFactory {
@Override
public PrivateMessage createPrivateMessage(GroupId groupId, long timestamp,
String body) throws FormatException {
String text) throws FormatException {
// Validate the arguments
if (utf8IsTooLong(body, MAX_PRIVATE_MESSAGE_BODY_LENGTH))
if (utf8IsTooLong(text, MAX_PRIVATE_MESSAGE_TEXT_LENGTH))
throw new IllegalArgumentException();
// Serialise the message
BdfList message = BdfList.of(body);
BdfList message = BdfList.of(text);
Message m = clientHelper.createMessage(groupId, timestamp, message);
return new PrivateMessage(m);
}

View File

@@ -16,7 +16,7 @@ import javax.annotation.concurrent.Immutable;
import static org.briarproject.bramble.util.ValidationUtils.checkLength;
import static org.briarproject.bramble.util.ValidationUtils.checkSize;
import static org.briarproject.briar.api.messaging.MessagingConstants.MAX_PRIVATE_MESSAGE_BODY_LENGTH;
import static org.briarproject.briar.api.messaging.MessagingConstants.MAX_PRIVATE_MESSAGE_TEXT_LENGTH;
import static org.briarproject.briar.client.MessageTrackerConstants.MSG_KEY_READ;
@Immutable
@@ -31,11 +31,10 @@ class PrivateMessageValidator extends BdfMessageValidator {
@Override
protected BdfMessageContext validateMessage(Message m, Group g,
BdfList body) throws FormatException {
// private message body
// Private message text
checkSize(body, 1);
// Private message body
String privateMessageBody = body.getString(0);
checkLength(privateMessageBody, 0, MAX_PRIVATE_MESSAGE_BODY_LENGTH);
String text = body.getString(0);
checkLength(text, 0, MAX_PRIVATE_MESSAGE_TEXT_LENGTH);
// Return the metadata
BdfDictionary meta = new BdfDictionary();
meta.put("timestamp", m.getTimestamp());

View File

@@ -78,7 +78,7 @@ class GroupMessageFactoryImpl implements GroupMessageFactory {
@Override
public GroupMessage createGroupMessage(GroupId groupId, long timestamp,
@Nullable MessageId parentId, LocalAuthor member, String content,
@Nullable MessageId parentId, LocalAuthor member, String text,
MessageId previousMsgId) {
try {
// Generate the signature
@@ -89,7 +89,7 @@ class GroupMessageFactoryImpl implements GroupMessageFactory {
memberList,
parentId,
previousMsgId,
content
text
);
byte[] signature = clientHelper.sign(SIGNING_LABEL_POST, toSign,
member.getPrivateKey());
@@ -100,7 +100,7 @@ class GroupMessageFactoryImpl implements GroupMessageFactory {
memberList,
parentId,
previousMsgId,
content,
text,
signature
);
Message m = clientHelper.createMessage(groupId, timestamp, body);

View File

@@ -31,7 +31,7 @@ import static org.briarproject.briar.api.privategroup.GroupMessageFactory.SIGNIN
import static org.briarproject.briar.api.privategroup.GroupMessageFactory.SIGNING_LABEL_POST;
import static org.briarproject.briar.api.privategroup.MessageType.JOIN;
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_TEXT_LENGTH;
import static org.briarproject.briar.api.privategroup.invitation.GroupInvitationFactory.SIGNING_LABEL_INVITE;
import static org.briarproject.briar.privategroup.GroupConstants.KEY_INITIAL_JOIN_MSG;
import static org.briarproject.briar.privategroup.GroupConstants.KEY_MEMBER;
@@ -65,7 +65,7 @@ class GroupMessageValidator extends BdfMessageValidator {
// Message type (int)
int type = body.getLong(0).intValue();
// Member (list of int, string, raw)
// Member (author)
BdfList memberList = body.getList(1);
Author member = clientHelper.parseAndValidateAuthor(memberList);
@@ -144,14 +144,14 @@ class GroupMessageValidator extends BdfMessageValidator {
private BdfMessageContext validatePost(Message m, Group g, BdfList body,
Author member) throws FormatException {
// Message type, member, optional parent ID, previous message ID,
// content, signature
// text, signature
checkSize(body, 6);
byte[] parentId = body.getOptionalRaw(2);
checkLength(parentId, MessageId.LENGTH);
byte[] previousMessageId = body.getRaw(3);
checkLength(previousMessageId, MessageId.LENGTH);
String content = body.getString(4);
checkLength(content, 1, MAX_GROUP_POST_BODY_LENGTH);
String text = body.getString(4);
checkLength(text, 1, MAX_GROUP_POST_TEXT_LENGTH);
byte[] signature = body.getRaw(5);
checkLength(signature, 1, MAX_SIGNATURE_LENGTH);
@@ -163,7 +163,7 @@ class GroupMessageValidator extends BdfMessageValidator {
memberList,
parentId,
previousMessageId,
content
text
);
try {
clientHelper.verifySignature(signature, SIGNING_LABEL_POST,

View File

@@ -299,17 +299,17 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
}
@Override
public String getMessageBody(MessageId m) throws DbException {
public String getMessageText(MessageId m) throws DbException {
try {
return getMessageBody(clientHelper.getMessageAsList(m));
return getMessageText(clientHelper.getMessageAsList(m));
} catch (FormatException e) {
throw new DbException(e);
}
}
private String getMessageBody(BdfList body) throws FormatException {
private String getMessageText(BdfList body) throws FormatException {
// Message type (0), member (1), parent ID (2), previous message ID (3),
// content (4), signature (5)
// text (4), signature (5)
return body.getString(4);
}
@@ -570,8 +570,8 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
throws DbException, FormatException {
GroupMessageHeader header = getGroupMessageHeader(txn, m.getGroupId(),
m.getId(), meta, Collections.emptyMap());
String body = getMessageBody(clientHelper.toList(m));
txn.attach(new GroupMessageAddedEvent(m.getGroupId(), header, body,
String text = getMessageText(clientHelper.toList(m));
txn.attach(new GroupMessageAddedEvent(m.getGroupId(), header, text,
local));
}

View File

@@ -107,7 +107,7 @@ abstract class AbstractProtocolEngine<S extends Session>
}
Message sendInviteMessage(Transaction txn, S session,
@Nullable String message, long timestamp, byte[] signature)
@Nullable String text, long timestamp, byte[] signature)
throws DbException {
Group g = db.getGroup(txn, session.getPrivateGroupId());
PrivateGroup privateGroup;
@@ -119,7 +119,7 @@ abstract class AbstractProtocolEngine<S extends Session>
Message m = messageEncoder.encodeInviteMessage(
session.getContactGroupId(), privateGroup.getId(),
timestamp, privateGroup.getName(), privateGroup.getCreator(),
privateGroup.getSalt(), message, signature);
privateGroup.getSalt(), text, signature);
sendMessage(txn, m, INVITE, privateGroup.getId(), true);
return m;
}

View File

@@ -51,11 +51,11 @@ class CreatorProtocolEngine extends AbstractProtocolEngine<CreatorSession> {
@Override
public CreatorSession onInviteAction(Transaction txn, CreatorSession s,
@Nullable String message, long timestamp, byte[] signature)
@Nullable String text, long timestamp, byte[] signature)
throws DbException {
switch (s.getState()) {
case START:
return onLocalInvite(txn, s, message, timestamp, signature);
return onLocalInvite(txn, s, text, timestamp, signature);
case INVITED:
case JOINED:
case LEFT:
@@ -145,10 +145,10 @@ class CreatorProtocolEngine extends AbstractProtocolEngine<CreatorSession> {
}
private CreatorSession onLocalInvite(Transaction txn, CreatorSession s,
@Nullable String message, long timestamp, byte[] signature)
@Nullable String text, long timestamp, byte[] signature)
throws DbException {
// Send an INVITE message
Message sent = sendInviteMessage(txn, s, message, timestamp, signature);
Message sent = sendInviteMessage(txn, s, text, timestamp, signature);
// Track the message
messageTracker.trackOutgoingMessage(txn, sent);
// Move to the INVITED state

View File

@@ -260,7 +260,7 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
@Override
public void sendInvitation(GroupId privateGroupId, ContactId c,
@Nullable String message, long timestamp, byte[] signature)
@Nullable String text, long timestamp, byte[] signature)
throws DbException {
SessionId sessionId = getSessionId(privateGroupId);
Transaction txn = db.startTransaction(false);
@@ -283,7 +283,7 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
storageId = ss.storageId;
}
// Handle the invite action
session = creatorEngine.onInviteAction(txn, session, message,
session = creatorEngine.onInviteAction(txn, session, text,
timestamp, signature);
// Store the updated session
storeSession(txn, storageId, session);
@@ -416,7 +416,7 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
return new GroupInvitationRequest(m, contactGroupId,
meta.getTimestamp(), meta.isLocal(), status.isSent(),
status.isSeen(), meta.isRead(), sessionId, pg,
invite.getMessage(), meta.isAvailableToAnswer(), canBeOpened);
invite.getText(), meta.isAvailableToAnswer(), canBeOpened);
}
private GroupInvitationResponse parseInvitationResponse(

View File

@@ -27,7 +27,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.checkSize;
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.GROUP_SALT_LENGTH;
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_GROUP_INVITATION_MSG_LENGTH;
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_GROUP_INVITATION_TEXT_LENGTH;
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_GROUP_NAME_LENGTH;
import static org.briarproject.briar.api.privategroup.invitation.GroupInvitationFactory.SIGNING_LABEL_INVITE;
import static org.briarproject.briar.privategroup.invitation.MessageType.ABORT;
@@ -71,15 +71,15 @@ class GroupInvitationValidator extends BdfMessageValidator {
private BdfMessageContext validateInviteMessage(Message m, BdfList body)
throws FormatException {
// Message type, creator, group name, salt, optional message, signature
// Message type, creator, group name, salt, optional text, signature
checkSize(body, 6);
BdfList creatorList = body.getList(1);
String groupName = body.getString(2);
checkLength(groupName, 1, MAX_GROUP_NAME_LENGTH);
byte[] salt = body.getRaw(3);
checkLength(salt, GROUP_SALT_LENGTH);
String message = body.getOptionalString(4);
checkLength(message, 1, MAX_GROUP_INVITATION_MSG_LENGTH);
String text = body.getOptionalString(4);
checkLength(text, 1, MAX_GROUP_INVITATION_TEXT_LENGTH);
byte[] signature = body.getRaw(5);
checkLength(signature, 1, MAX_SIGNATURE_LENGTH);

View File

@@ -16,16 +16,16 @@ class InviteMessage extends GroupInvitationMessage {
private final Author creator;
private final byte[] salt, signature;
@Nullable
private final String message;
private final String text;
InviteMessage(MessageId id, GroupId contactGroupId, GroupId privateGroupId,
long timestamp, String groupName, Author creator, byte[] salt,
@Nullable String message, byte[] signature) {
@Nullable String text, byte[] signature) {
super(id, contactGroupId, privateGroupId, timestamp);
this.groupName = groupName;
this.creator = creator;
this.salt = salt;
this.message = message;
this.text = text;
this.signature = signature;
}
@@ -42,8 +42,8 @@ class InviteMessage extends GroupInvitationMessage {
}
@Nullable
String getMessage() {
return message;
String getText() {
return text;
}
byte[] getSignature() {

View File

@@ -56,7 +56,7 @@ class InviteeProtocolEngine extends AbstractProtocolEngine<InviteeSession> {
@Override
public InviteeSession onInviteAction(Transaction txn, InviteeSession s,
@Nullable String message, long timestamp, byte[] signature) {
@Nullable String text, long timestamp, byte[] signature) {
throw new UnsupportedOperationException(); // Invalid in this role
}
@@ -330,7 +330,7 @@ class InviteeProtocolEngine extends AbstractProtocolEngine<InviteeSession> {
SessionId sessionId = new SessionId(m.getPrivateGroupId().getBytes());
return new GroupInvitationRequest(m.getId(), m.getContactGroupId(),
m.getTimestamp(), false, false, true, false, sessionId, pg,
m.getMessage(), true, false);
m.getText(), true, false);
}
}

View File

@@ -24,7 +24,7 @@ interface MessageEncoder {
Message encodeInviteMessage(GroupId contactGroupId, GroupId privateGroupId,
long timestamp, String groupName, Author creator, byte[] salt,
@Nullable String message, byte[] signature);
@Nullable String text, byte[] signature);
Message encodeJoinMessage(GroupId contactGroupId, GroupId privateGroupId,
long timestamp, @Nullable MessageId previousMessageId);

View File

@@ -76,7 +76,7 @@ class MessageEncoderImpl implements MessageEncoder {
@Override
public Message encodeInviteMessage(GroupId contactGroupId,
GroupId privateGroupId, long timestamp, String groupName,
Author creator, byte[] salt, @Nullable String message,
Author creator, byte[] salt, @Nullable String text,
byte[] signature) {
BdfList creatorList = clientHelper.toList(creator);
BdfList body = BdfList.of(
@@ -84,7 +84,7 @@ class MessageEncoderImpl implements MessageEncoder {
creatorList,
groupName,
salt,
message,
text,
signature
);
try {

View File

@@ -98,11 +98,11 @@ class MessageParserImpl implements MessageParser {
@Override
public InviteMessage parseInviteMessage(Message m, BdfList body)
throws FormatException {
// Message type, creator, group name, salt, optional message, signature
// Message type, creator, group name, salt, optional text, signature
BdfList creatorList = body.getList(1);
String groupName = body.getString(2);
byte[] salt = body.getRaw(3);
String message = body.getOptionalString(4);
String text = body.getOptionalString(4);
byte[] signature = body.getRaw(5);
// Format version, name, public key
@@ -117,7 +117,7 @@ class MessageParserImpl implements MessageParser {
groupName, creator, salt);
return new InviteMessage(m.getId(), m.getGroupId(),
privateGroup.getId(), m.getTimestamp(), groupName, creator,
salt, message, signature);
salt, text, signature);
}
@Override

View File

@@ -51,8 +51,7 @@ class PeerProtocolEngine extends AbstractProtocolEngine<PeerSession> {
@Override
public PeerSession onInviteAction(Transaction txn, PeerSession s,
@Nullable String message, long timestamp, byte[] signature)
throws DbException {
@Nullable String text, long timestamp, byte[] signature) {
throw new UnsupportedOperationException(); // Invalid in this role
}

View File

@@ -10,7 +10,7 @@ import javax.annotation.Nullable;
@NotNullByDefault
interface ProtocolEngine<S extends Session> {
S onInviteAction(Transaction txn, S session, @Nullable String message,
S onInviteAction(Transaction txn, S session, @Nullable String text,
long timestamp, byte[] signature) throws DbException;
S onJoinAction(Transaction txn, S session) throws DbException;

View File

@@ -24,7 +24,7 @@ public class BlogInvitationFactoryImpl
SessionId sessionId = new SessionId(m.getShareableId().getBytes());
return new BlogInvitationRequest(m.getId(), m.getContactGroupId(),
m.getTimestamp(), local, sent, seen, read, sessionId,
m.getShareable(), m.getMessage(), available, canBeOpened);
m.getShareable(), m.getText(), available, canBeOpened);
}
@Override

View File

@@ -24,7 +24,7 @@ public class ForumInvitationFactoryImpl
SessionId sessionId = new SessionId(m.getShareableId().getBytes());
return new ForumInvitationRequest(m.getId(), m.getContactGroupId(),
m.getTimestamp(), local, sent, seen, read, sessionId,
m.getShareable(), m.getMessage(), available, canBeOpened);
m.getShareable(), m.getText(), available, canBeOpened);
}
@Override

View File

@@ -14,17 +14,17 @@ class InviteMessage<S extends Shareable> extends SharingMessage {
private final S shareable;
@Nullable
private final String message;
private final String text;
InviteMessage(MessageId id, @Nullable MessageId previousMessageId,
GroupId contactGroupId, S shareable, @Nullable String message,
GroupId contactGroupId, S shareable, @Nullable String text,
long timestamp) {
super(id, contactGroupId, shareable.getId(), timestamp,
previousMessageId);
if (message != null && message.equals(""))
if (text != null && text.isEmpty())
throw new IllegalArgumentException();
this.shareable = shareable;
this.message = message;
this.text = text;
}
public S getShareable() {
@@ -32,8 +32,8 @@ class InviteMessage<S extends Shareable> extends SharingMessage {
}
@Nullable
public String getMessage() {
return message;
public String getText() {
return text;
}
}

View File

@@ -24,7 +24,7 @@ interface MessageEncoder {
Message encodeInviteMessage(GroupId contactGroupId, long timestamp,
@Nullable MessageId previousMessageId, BdfList descriptor,
@Nullable String message);
@Nullable String text);
Message encodeAcceptMessage(GroupId contactGroupId, GroupId shareableId,
long timestamp, @Nullable MessageId previousMessageId);

View File

@@ -76,14 +76,14 @@ class MessageEncoderImpl implements MessageEncoder {
@Override
public Message encodeInviteMessage(GroupId contactGroupId, long timestamp,
@Nullable MessageId previousMessageId, BdfList descriptor,
@Nullable String message) {
if (message != null && message.equals(""))
@Nullable String text) {
if (text != null && text.isEmpty())
throw new IllegalArgumentException();
BdfList body = BdfList.of(
INVITE.getValue(),
previousMessageId,
descriptor,
message
text
);
try {
return messageFactory.createMessage(contactGroupId, timestamp,

View File

@@ -89,9 +89,9 @@ abstract class MessageParserImpl<S extends Shareable>
MessageId previousMessageId = (b == null ? null : new MessageId(b));
BdfList descriptor = body.getList(2);
S shareable = createShareable(descriptor);
String message = body.getOptionalString(3);
String text = body.getOptionalString(3);
return new InviteMessage<>(m.getId(), previousMessageId,
m.getGroupId(), shareable, message, m.getTimestamp());
m.getGroupId(), shareable, text, m.getTimestamp());
}
@Override

View File

@@ -12,7 +12,7 @@ import javax.annotation.Nullable;
interface ProtocolEngine<S extends Shareable> {
Session onInviteAction(Transaction txn, Session session,
@Nullable String message, long timestamp) throws DbException;
@Nullable String text, long timestamp) throws DbException;
Session onAcceptAction(Transaction txn, Session session) throws DbException;

View File

@@ -78,10 +78,10 @@ abstract class ProtocolEngineImpl<S extends Shareable>
@Override
public Session onInviteAction(Transaction txn, Session s,
@Nullable String message, long timestamp) throws DbException {
@Nullable String text, long timestamp) throws DbException {
switch (s.getState()) {
case START:
return onLocalInvite(txn, s, message, timestamp);
return onLocalInvite(txn, s, text, timestamp);
case LOCAL_INVITED:
case REMOTE_INVITED:
case SHARING:
@@ -94,9 +94,9 @@ abstract class ProtocolEngineImpl<S extends Shareable>
}
private Session onLocalInvite(Transaction txn, Session s,
@Nullable String message, long timestamp) throws DbException {
@Nullable String text, long timestamp) throws DbException {
// Send an INVITE message
Message sent = sendInviteMessage(txn, s, message, timestamp);
Message sent = sendInviteMessage(txn, s, text, timestamp);
// Track the message
messageTracker.trackOutgoingMessage(txn, sent);
// Make the shareable visible to the contact
@@ -112,7 +112,7 @@ abstract class ProtocolEngineImpl<S extends Shareable>
}
private Message sendInviteMessage(Transaction txn, Session s,
@Nullable String message, long timestamp) throws DbException {
@Nullable String text, long timestamp) throws DbException {
Group g = db.getGroup(txn, s.getShareableId());
BdfList descriptor;
try {
@@ -122,7 +122,7 @@ abstract class ProtocolEngineImpl<S extends Shareable>
}
long localTimestamp = Math.max(timestamp, getLocalTimestamp(s));
Message m = messageEncoder.encodeInviteMessage(s.getContactGroupId(),
localTimestamp, s.getLastLocalMessageId(), descriptor, message);
localTimestamp, s.getLastLocalMessageId(), descriptor, text);
sendMessage(txn, m, INVITE, s.getShareableId(), true);
return m;
}

View File

@@ -252,7 +252,7 @@ abstract class SharingManagerImpl<S extends Shareable>
@Override
public void sendInvitation(GroupId shareableId, ContactId contactId,
@Nullable String message, long timestamp) throws DbException {
@Nullable String text, long timestamp) throws DbException {
SessionId sessionId = getSessionId(shareableId);
Transaction txn = db.startTransaction(false);
try {
@@ -277,7 +277,7 @@ abstract class SharingManagerImpl<S extends Shareable>
storageId = ss.storageId;
}
// Handle the invite action
session = engine.onInviteAction(txn, session, message, timestamp);
session = engine.onInviteAction(txn, session, text, timestamp);
// Store the updated session
storeSession(txn, storageId, session);
db.commitTransaction(txn);

View File

@@ -21,7 +21,7 @@ import javax.annotation.concurrent.Immutable;
import static org.briarproject.bramble.util.ValidationUtils.checkLength;
import static org.briarproject.bramble.util.ValidationUtils.checkSize;
import static org.briarproject.briar.api.sharing.SharingConstants.MAX_INVITATION_MESSAGE_LENGTH;
import static org.briarproject.briar.api.sharing.SharingConstants.MAX_INVITATION_TEXT_LENGTH;
import static org.briarproject.briar.sharing.MessageType.INVITE;
@Immutable
@@ -60,8 +60,8 @@ abstract class SharingValidator extends BdfMessageValidator {
checkLength(previousMessageId, UniqueId.LENGTH);
BdfList descriptor = body.getList(2);
GroupId shareableId = validateDescriptor(descriptor);
String msg = body.getOptionalString(3);
checkLength(msg, 1, MAX_INVITATION_MESSAGE_LENGTH);
String text = body.getOptionalString(3);
checkLength(text, 1, MAX_INVITATION_TEXT_LENGTH);
BdfDictionary meta = messageEncoder
.encodeMetadata(INVITE, shareableId, m.getTimestamp(), false,

View File

@@ -312,15 +312,15 @@ public class TestDataCreatorImpl implements TestDataCreator {
private void createRandomPrivateMessage(GroupId groupId, int num)
throws DbException, FormatException {
long timestamp = clock.currentTimeMillis() - num * 60 * 1000;
String body = getRandomText();
String text = getRandomText();
boolean local = random.nextBoolean();
createPrivateMessage(groupId, body, timestamp, local);
createPrivateMessage(groupId, text, timestamp, local);
}
private void createPrivateMessage(GroupId groupId, String body,
private void createPrivateMessage(GroupId groupId, String text,
long timestamp, boolean local) throws DbException, FormatException {
PrivateMessage m = privateMessageFactory
.createPrivateMessage(groupId, timestamp, body);
.createPrivateMessage(groupId, timestamp, text);
BdfDictionary meta = new BdfDictionary();
meta.put("timestamp", timestamp);
meta.put("local", local);
@@ -338,10 +338,10 @@ public class TestDataCreatorImpl implements TestDataCreator {
}
@Override
public void addPrivateMessage(Contact contact, String body, long time,
public void addPrivateMessage(Contact contact, String text, long time,
boolean local) throws DbException, FormatException {
Group group = messagingManager.getContactGroup(contact);
createPrivateMessage(group.getId(), body, time, local);
createPrivateMessage(group.getId(), text, time, local);
}
private void createBlogPosts(List<Contact> contacts, int numBlogPosts)
@@ -359,10 +359,10 @@ public class TestDataCreatorImpl implements TestDataCreator {
private void addBlogPost(LocalAuthor author, int num) throws DbException {
Blog blog = blogManager.getPersonalBlog(author);
long timestamp = clock.currentTimeMillis() - num * 60 * 1000;
String body = getRandomText();
String text = getRandomText();
try {
BlogPost blogPost = blogPostFactory.createBlogPost(blog.getId(),
timestamp, null, author, body);
timestamp, null, author, text);
blogManager.addLocalPost(blogPost);
} catch (FormatException | GeneralSecurityException e) {
throw new RuntimeException(e);
@@ -404,14 +404,14 @@ public class TestDataCreatorImpl implements TestDataCreator {
Contact contact = contacts.get(random.nextInt(contacts.size()));
LocalAuthor author = localAuthors.get(contact);
long timestamp = clock.currentTimeMillis() - i * 60 * 1000;
String body = getRandomText();
String text = getRandomText();
MessageId parent = null;
if (random.nextBoolean() && posts.size() > 0) {
ForumPost parentPost =
posts.get(random.nextInt(posts.size()));
parent = parentPost.getMessage().getId();
}
ForumPost post = forumManager.createLocalPost(forum.getId(), body,
ForumPost post = forumManager.createLocalPost(forum.getId(), text,
timestamp, parent, author);
posts.add(post);
forumManager.addLocalPost(post);

View File

@@ -47,7 +47,7 @@ import static org.briarproject.briar.api.blog.BlogConstants.KEY_RSS_FEED;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_TIMESTAMP;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_TIME_RECEIVED;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_TYPE;
import static org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_COMMENT_LENGTH;
import static org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_COMMENT_TEXT_LENGTH;
import static org.briarproject.briar.api.blog.BlogManager.CLIENT_ID;
import static org.briarproject.briar.api.blog.BlogManager.MAJOR_VERSION;
import static org.briarproject.briar.api.blog.MessageType.COMMENT;
@@ -99,7 +99,7 @@ public class BlogManagerImplTest extends BriarTestCase {
rssMessageId = rssMessage.getId();
timestamp = message.getTimestamp();
timeReceived = timestamp + 1;
comment = getRandomString(MAX_BLOG_COMMENT_LENGTH);
comment = getRandomString(MAX_BLOG_COMMENT_TEXT_LENGTH);
}
@Test
@@ -694,7 +694,7 @@ public class BlogManagerImplTest extends BriarTestCase {
new BdfEntry(KEY_TIMESTAMP, timestamp),
new BdfEntry(KEY_TIME_RECEIVED, timeReceived)
);
String localComment = getRandomString(MAX_BLOG_COMMENT_LENGTH);
String localComment = getRandomString(MAX_BLOG_COMMENT_TEXT_LENGTH);
Message localCommentMsg = getMessage(blog2.getId());
MessageId localCommentId = localCommentMsg.getId();
BdfDictionary localCommentMeta = BdfDictionary.of(

View File

@@ -122,15 +122,14 @@ public class BlogManagerIntegrationTest
@Test
public void testBlogPost() throws Exception {
// check that blog0 has no posts
String body = getRandomString(42);
String text = getRandomString(42);
Collection<BlogPostHeader> headers0 =
blogManager0.getPostHeaders(blog0.getId());
assertEquals(0, headers0.size());
// add a post to blog0
BlogPost p = blogPostFactory
.createBlogPost(blog0.getId(), clock.currentTimeMillis(), null,
author0, body);
BlogPost p = blogPostFactory.createBlogPost(blog0.getId(),
clock.currentTimeMillis(), null, author0, text);
blogManager0.addLocalPost(p);
// check that post is now in blog0
@@ -138,7 +137,7 @@ public class BlogManagerIntegrationTest
assertEquals(1, headers0.size());
// check that body is there
assertEquals(body, blogManager0.getPostBody(p.getMessage().getId()));
assertEquals(text, blogManager0.getPostText(p.getMessage().getId()));
// make sure that blog0 at author1 doesn't have the post yet
Collection<BlogPostHeader> headers1 =
@@ -154,16 +153,16 @@ public class BlogManagerIntegrationTest
assertEquals(POST, headers1.iterator().next().getType());
// check that body is there
assertEquals(body, blogManager1.getPostBody(p.getMessage().getId()));
assertEquals(text, blogManager1.getPostText(p.getMessage().getId()));
}
@Test
public void testBlogPostInWrongBlog() throws Exception {
// add a post to blog1
String body = getRandomString(42);
String text = getRandomString(42);
BlogPost p = blogPostFactory
.createBlogPost(blog1.getId(), clock.currentTimeMillis(), null,
author0, body);
author0, text);
blogManager0.addLocalPost(p);
// check that post is now in blog1
@@ -199,10 +198,10 @@ public class BlogManagerIntegrationTest
@Test
public void testBlogComment() throws Exception {
// add a post to blog0
String body = getRandomString(42);
String text = getRandomString(42);
BlogPost p = blogPostFactory
.createBlogPost(blog0.getId(), clock.currentTimeMillis(), null,
author0, body);
author0, text);
blogManager0.addLocalPost(p);
// sync the post over
@@ -234,7 +233,7 @@ public class BlogManagerIntegrationTest
// ensure that body can be retrieved from wrapped post
MessageId parentId = h.getParentId();
assertNotNull(parentId);
assertEquals(body, blogManager0.getPostBody(parentId));
assertEquals(text, blogManager0.getPostText(parentId));
// 1 has only their own comment in their blog
headers1 = blogManager1.getPostHeaders(blog1.getId());
@@ -244,10 +243,10 @@ public class BlogManagerIntegrationTest
@Test
public void testBlogCommentOnOwnPost() throws Exception {
// add a post to blog0
String body = getRandomString(42);
String text = getRandomString(42);
BlogPost p = blogPostFactory
.createBlogPost(blog0.getId(), clock.currentTimeMillis(), null,
author0, body);
author0, text);
blogManager0.addLocalPost(p);
// get header of own post
@@ -270,7 +269,7 @@ public class BlogManagerIntegrationTest
assertEquals(2, headers1.size());
for (BlogPostHeader h : headers1) {
if (h.getType() == POST) {
assertEquals(body, blogManager1.getPostBody(h.getId()));
assertEquals(text, blogManager1.getPostText(h.getId()));
} else {
assertEquals(comment, ((BlogCommentHeader) h).getComment());
}
@@ -280,10 +279,10 @@ public class BlogManagerIntegrationTest
@Test
public void testCommentOnComment() throws Exception {
// add a post to blog0
String body = getRandomString(42);
String text = getRandomString(42);
BlogPost p = blogPostFactory
.createBlogPost(blog0.getId(), clock.currentTimeMillis(), null,
author0, body);
author0, text);
blogManager0.addLocalPost(p);
// sync the post over
@@ -368,10 +367,10 @@ public class BlogManagerIntegrationTest
@Test
public void testCommentOnOwnComment() throws Exception {
// add a post to blog0
String body = getRandomString(42);
String text = getRandomString(42);
BlogPost p = blogPostFactory
.createBlogPost(blog0.getId(), clock.currentTimeMillis(), null,
author0, body);
author0, text);
blogManager0.addLocalPost(p);
// sync the post over
@@ -413,10 +412,10 @@ public class BlogManagerIntegrationTest
assertTrue(rssBlog.isRssFeed());
// add a feed post to rssBlog
String body = getRandomString(42);
String text = getRandomString(42);
BlogPost p = blogPostFactory
.createBlogPost(rssBlog.getId(), clock.currentTimeMillis(),
null, author0, body);
null, author0, text);
blogManager0.addLocalPost(p);
// make sure it got saved as an RSS feed post
@@ -432,10 +431,10 @@ public class BlogManagerIntegrationTest
@Test
public void testFeedReblog() throws Exception {
// add a feed post to rssBlog
String body = getRandomString(42);
String text = getRandomString(42);
BlogPost p = blogPostFactory
.createBlogPost(rssBlog.getId(), clock.currentTimeMillis(),
null, author0, body);
null, author0, text);
blogManager0.addLocalPost(p);
// reblog feed post to own blog

View File

@@ -62,7 +62,7 @@ public class BlogPostValidatorTest extends BriarTestCase {
private final BlogFactory blogFactory = context.mock(BlogFactory.class);
private final ClientHelper clientHelper = context.mock(ClientHelper.class);
private final Author author;
private final String body = getRandomString(42);
private final String text = getRandomString(42);
public BlogPostValidatorTest() {
group = getGroup(CLIENT_ID, MAJOR_VERSION);
@@ -99,9 +99,9 @@ public class BlogPostValidatorTest extends BriarTestCase {
private void testValidateProperBlogPost(Blog b, boolean rssFeed)
throws IOException, GeneralSecurityException {
byte[] sigBytes = getRandomBytes(42);
BdfList m = BdfList.of(POST.getInt(), body, sigBytes);
BdfList m = BdfList.of(POST.getInt(), text, sigBytes);
BdfList signed = BdfList.of(b.getId(), message.getTimestamp(), body);
BdfList signed = BdfList.of(b.getId(), message.getTimestamp(), text);
expectCrypto(b, SIGNING_LABEL_POST, signed, sigBytes);
BdfDictionary result =
validator.validateMessage(message, group, m).getDictionary();
@@ -114,7 +114,7 @@ public class BlogPostValidatorTest extends BriarTestCase {
@Test(expected = FormatException.class)
public void testValidateBlogPostWithoutAttachments() throws IOException {
BdfList content = BdfList.of(null, null, body);
BdfList content = BdfList.of(null, null, text);
BdfList m = BdfList.of(POST.getInt(), content, null);
validator.validateMessage(message, group, m);
@@ -122,7 +122,7 @@ public class BlogPostValidatorTest extends BriarTestCase {
@Test(expected = FormatException.class)
public void testValidateBlogPostWithoutSignature() throws IOException {
BdfList content = BdfList.of(null, null, body, null);
BdfList content = BdfList.of(null, null, text, null);
BdfList m = BdfList.of(POST.getInt(), content, null);
validator.validateMessage(message, group, m);
@@ -191,12 +191,12 @@ public class BlogPostValidatorTest extends BriarTestCase {
// group descriptor, timestamp, content, signature
byte[] sigBytes = getRandomBytes(42);
BdfList m = BdfList.of(WRAPPED_POST.getInt(), descriptor,
message.getTimestamp(), body, sigBytes);
message.getTimestamp(), text, sigBytes);
BdfList signed = BdfList.of(b.getId(), message.getTimestamp(), body);
BdfList signed = BdfList.of(b.getId(), message.getTimestamp(), text);
expectCrypto(b, SIGNING_LABEL_POST, signed, sigBytes);
BdfList originalList = BdfList.of(POST.getInt(), body, sigBytes);
BdfList originalList = BdfList.of(POST.getInt(), text, sigBytes);
byte[] originalBody = getRandomBytes(42);
context.checking(new Expectations() {{

View File

@@ -106,7 +106,7 @@ public class FeedManagerImplTest extends BrambleMockTestCase {
SyndEntry entry = new SyndEntryImpl();
entry.setUpdatedDate(new Date());
entries.add(entry);
String body = "<p> (" + entry.getUpdatedDate().toString() + ")</p>";
String text = "<p> (" + entry.getUpdatedDate().toString() + ")</p>";
Message msg = getMessage(blogGroupId);
BlogPost post = new BlogPost(msg, null, localAuthor);
@@ -116,7 +116,7 @@ public class FeedManagerImplTest extends BrambleMockTestCase {
oneOf(clock).currentTimeMillis();
will(returnValue(42L));
oneOf(blogPostFactory).createBlogPost(feed.getBlogId(), 42L, null,
localAuthor, body);
localAuthor, text);
will(returnValue(post));
oneOf(blogManager).addLocalPost(txn, post);
oneOf(db).commitTransaction(txn);

View File

@@ -72,24 +72,24 @@ public class ForumManagerTest
}
private ForumPost createForumPost(GroupId groupId,
@Nullable ForumPost parent, String body, long ms) throws Exception {
@Nullable ForumPost parent, String text, long ms) throws Exception {
return forumPostFactory.createPost(groupId, ms,
parent == null ? null : parent.getMessage().getId(),
author0, body);
author0, text);
}
@Test
public void testForumPost() throws Exception {
assertEquals(1, forumManager0.getForums().size());
long ms1 = clock.currentTimeMillis() - 1000L;
String body1 = "some forum text";
String text1 = "some forum text";
long ms2 = clock.currentTimeMillis();
String body2 = "some other forum text";
String text2 = "some other forum text";
ForumPost post1 =
createForumPost(forum0.getGroup().getId(), null, body1, ms1);
createForumPost(forum0.getGroup().getId(), null, text1, ms1);
assertEquals(ms1, post1.getMessage().getTimestamp());
ForumPost post2 =
createForumPost(forum0.getGroup().getId(), post1, body2, ms2);
createForumPost(forum0.getGroup().getId(), post1, text2, ms2);
assertEquals(ms2, post2.getMessage().getTimestamp());
forumManager0.addLocalPost(post1);
forumManager0.setReadFlag(forum0.getGroup().getId(),
@@ -109,19 +109,19 @@ public class ForumManagerTest
forumManager0.getPostHeaders(forum0.getGroup().getId());
assertEquals(2, headers.size());
for (ForumPostHeader h : headers) {
String hBody = forumManager0.getPostBody(h.getId());
String hText = forumManager0.getPostText(h.getId());
boolean isPost1 = h.getId().equals(post1.getMessage().getId());
boolean isPost2 = h.getId().equals(post2.getMessage().getId());
assertTrue(isPost1 || isPost2);
if (isPost1) {
assertEquals(h.getTimestamp(), ms1);
assertEquals(body1, hBody);
assertEquals(text1, hText);
assertNull(h.getParentId());
assertTrue(h.isRead());
} else {
assertEquals(h.getTimestamp(), ms2);
assertEquals(body2, hBody);
assertEquals(text2, hText);
assertEquals(h.getParentId(), post2.getParent());
assertFalse(h.isRead());
}

View File

@@ -24,7 +24,7 @@ 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_PARENT;
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_TEXT_LENGTH;
import static org.briarproject.briar.api.forum.ForumPostFactory.SIGNING_LABEL_POST;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
@@ -33,7 +33,7 @@ import static org.junit.Assert.assertFalse;
public class ForumPostValidatorTest extends ValidatorTestCase {
private final MessageId parentId = new MessageId(getRandomId());
private final String content = getRandomString(MAX_FORUM_POST_BODY_LENGTH);
private final String text = getRandomString(MAX_FORUM_POST_TEXT_LENGTH);
private final byte[] signature = getRandomBytes(MAX_SIGNATURE_LENGTH);
private final Author author = getAuthor();
private final String authorName = author.getName();
@@ -41,9 +41,9 @@ public class ForumPostValidatorTest extends ValidatorTestCase {
private final BdfList authorList = BdfList.of(author.getFormatVersion(),
authorName, authorPublicKey);
private final BdfList signedWithParent = BdfList.of(groupId, timestamp,
parentId.getBytes(), authorList, content);
parentId.getBytes(), authorList, text);
private final BdfList signedWithoutParent = BdfList.of(groupId, timestamp,
null, authorList, content);
null, authorList, text);
private final ForumPostValidator v = new ForumPostValidator(clientHelper,
metadataEncoder, clock);
@@ -51,13 +51,13 @@ public class ForumPostValidatorTest extends ValidatorTestCase {
@Test(expected = FormatException.class)
public void testRejectsTooShortBody() throws Exception {
v.validateMessage(message, group,
BdfList.of(parentId, authorList, content));
BdfList.of(parentId, authorList, text));
}
@Test(expected = FormatException.class)
public void testRejectsTooLongBody() throws Exception {
v.validateMessage(message, group,
BdfList.of(parentId, authorList, content, signature, 123));
BdfList.of(parentId, authorList, text, signature, 123));
}
@Test
@@ -69,40 +69,40 @@ public class ForumPostValidatorTest extends ValidatorTestCase {
}});
BdfMessageContext messageContext = v.validateMessage(message, group,
BdfList.of(null, authorList, content, signature));
BdfList.of(null, authorList, text, signature));
assertExpectedContext(messageContext, false);
}
@Test(expected = FormatException.class)
public void testRejectsNonRawParentId() throws Exception {
v.validateMessage(message, group,
BdfList.of(123, authorList, content, signature));
BdfList.of(123, authorList, text, signature));
}
@Test(expected = FormatException.class)
public void testRejectsTooShortParentId() throws Exception {
byte[] invalidParentId = getRandomBytes(UniqueId.LENGTH - 1);
v.validateMessage(message, group,
BdfList.of(invalidParentId, authorList, content, signature));
BdfList.of(invalidParentId, authorList, text, signature));
}
@Test(expected = FormatException.class)
public void testRejectsTooLongParentId() throws Exception {
byte[] invalidParentId = getRandomBytes(UniqueId.LENGTH + 1);
v.validateMessage(message, group,
BdfList.of(invalidParentId, authorList, content, signature));
BdfList.of(invalidParentId, authorList, text, signature));
}
@Test(expected = FormatException.class)
public void testRejectsNullAuthorList() throws Exception {
v.validateMessage(message, group,
BdfList.of(parentId, null, content, signature));
BdfList.of(parentId, null, text, signature));
}
@Test(expected = FormatException.class)
public void testRejectsNonListAuthorList() throws Exception {
v.validateMessage(message, group,
BdfList.of(parentId, 123, content, signature));
BdfList.of(parentId, 123, text, signature));
}
@Test(expected = FormatException.class)
@@ -112,11 +112,11 @@ public class ForumPostValidatorTest extends ValidatorTestCase {
will(throwException(new FormatException()));
}});
v.validateMessage(message, group,
BdfList.of(parentId, authorList, content, signature));
BdfList.of(parentId, authorList, text, signature));
}
@Test(expected = FormatException.class)
public void testRejectsNullContent() throws Exception {
public void testRejectsNullText() throws Exception {
expectCreateAuthor();
v.validateMessage(message, group,
@@ -124,7 +124,7 @@ public class ForumPostValidatorTest extends ValidatorTestCase {
}
@Test(expected = FormatException.class)
public void testRejectsNonStringContent() throws Exception {
public void testRejectsNonStringText() throws Exception {
expectCreateAuthor();
v.validateMessage(message, group,
@@ -132,30 +132,30 @@ public class ForumPostValidatorTest extends ValidatorTestCase {
}
@Test
public void testAcceptsMinLengthContent() throws Exception {
String shortContent = "";
BdfList signedWithShortContent = BdfList.of(groupId, timestamp,
parentId.getBytes(), authorList, shortContent);
public void testAcceptsMinLengthText() throws Exception {
String shortText = "";
BdfList signedWithShortText = BdfList.of(groupId, timestamp,
parentId.getBytes(), authorList, shortText);
expectCreateAuthor();
context.checking(new Expectations() {{
oneOf(clientHelper).verifySignature(signature, SIGNING_LABEL_POST,
signedWithShortContent, authorPublicKey);
signedWithShortText, authorPublicKey);
}});
BdfMessageContext messageContext = v.validateMessage(message, group,
BdfList.of(parentId, authorList, shortContent, signature));
BdfList.of(parentId, authorList, shortText, signature));
assertExpectedContext(messageContext, true);
}
@Test(expected = FormatException.class)
public void testRejectsTooLongContent() throws Exception {
String invalidContent = getRandomString(MAX_FORUM_POST_BODY_LENGTH + 1);
public void testRejectsTooLongText() throws Exception {
String invalidText = getRandomString(MAX_FORUM_POST_TEXT_LENGTH + 1);
expectCreateAuthor();
v.validateMessage(message, group,
BdfList.of(parentId, authorList, invalidContent, signature));
BdfList.of(parentId, authorList, invalidText, signature));
}
@Test(expected = FormatException.class)
@@ -163,7 +163,7 @@ public class ForumPostValidatorTest extends ValidatorTestCase {
expectCreateAuthor();
v.validateMessage(message, group,
BdfList.of(parentId, authorList, content, null));
BdfList.of(parentId, authorList, text, null));
}
@Test(expected = FormatException.class)
@@ -171,7 +171,7 @@ public class ForumPostValidatorTest extends ValidatorTestCase {
expectCreateAuthor();
v.validateMessage(message, group,
BdfList.of(parentId, authorList, content, 123));
BdfList.of(parentId, authorList, text, 123));
}
@Test(expected = FormatException.class)
@@ -181,7 +181,7 @@ public class ForumPostValidatorTest extends ValidatorTestCase {
expectCreateAuthor();
v.validateMessage(message, group,
BdfList.of(parentId, authorList, content, invalidSignature));
BdfList.of(parentId, authorList, text, invalidSignature));
}
@Test(expected = FormatException.class)
@@ -195,7 +195,7 @@ public class ForumPostValidatorTest extends ValidatorTestCase {
}});
v.validateMessage(message, group,
BdfList.of(parentId, authorList, content, signature));
BdfList.of(parentId, authorList, text, signature));
}
@Test(expected = InvalidMessageException.class)
@@ -209,7 +209,7 @@ public class ForumPostValidatorTest extends ValidatorTestCase {
}});
v.validateMessage(message, group,
BdfList.of(parentId, authorList, content, signature));
BdfList.of(parentId, authorList, text, signature));
}
private void expectCreateAuthor() throws Exception {

View File

@@ -19,7 +19,7 @@ import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_K
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
import static org.briarproject.bramble.test.TestUtils.getRandomId;
import static org.briarproject.bramble.util.StringUtils.getRandomString;
import static org.briarproject.briar.api.introduction.IntroductionConstants.MAX_REQUEST_MESSAGE_LENGTH;
import static org.briarproject.briar.api.introduction.IntroductionConstants.MAX_INTRODUCTION_TEXT_LENGTH;
import static org.briarproject.briar.introduction.MessageType.ABORT;
import static org.briarproject.briar.introduction.MessageType.ACCEPT;
import static org.briarproject.briar.introduction.MessageType.ACTIVATE;
@@ -38,7 +38,7 @@ public class IntroductionValidatorTest extends ValidatorTestCase {
private final SessionId sessionId = new SessionId(getRandomId());
private final MessageId previousMsgId = new MessageId(getRandomId());
private final String text = getRandomString(MAX_REQUEST_MESSAGE_LENGTH);
private final String text = getRandomString(MAX_INTRODUCTION_TEXT_LENGTH);
private final BdfDictionary meta = new BdfDictionary();
private final long acceptTimestamp = 42;
private final BdfDictionary transportProperties = BdfDictionary.of(

View File

@@ -30,7 +30,7 @@ import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
import static org.briarproject.bramble.test.TestUtils.getRandomId;
import static org.briarproject.bramble.test.TestUtils.getTransportPropertiesMap;
import static org.briarproject.bramble.util.StringUtils.getRandomString;
import static org.briarproject.briar.api.introduction.IntroductionConstants.MAX_REQUEST_MESSAGE_LENGTH;
import static org.briarproject.briar.api.introduction.IntroductionConstants.MAX_INTRODUCTION_TEXT_LENGTH;
import static org.briarproject.briar.api.introduction.IntroductionManager.CLIENT_ID;
import static org.briarproject.briar.api.introduction.IntroductionManager.MAJOR_VERSION;
import static org.briarproject.briar.introduction.MessageType.ABORT;
@@ -65,7 +65,7 @@ public class MessageEncoderParserIntegrationTest extends BrambleTestCase {
private final SessionId sessionId = new SessionId(getRandomId());
private final MessageId previousMsgId = new MessageId(getRandomId());
private final Author author;
private final String text = getRandomString(MAX_REQUEST_MESSAGE_LENGTH);
private final String text = getRandomString(MAX_INTRODUCTION_TEXT_LENGTH);
private final byte[] ephemeralPublicKey =
getRandomBytes(MAX_PUBLIC_KEY_LENGTH);
private final byte[] mac = getRandomBytes(MAC_BYTES);
@@ -128,7 +128,7 @@ public class MessageEncoderParserIntegrationTest extends BrambleTestCase {
assertEquals(m.getTimestamp(), rm.getTimestamp());
assertEquals(previousMsgId, rm.getPreviousMessageId());
assertEquals(author, rm.getAuthor());
assertEquals(text, rm.getMessage());
assertEquals(text, rm.getText());
}
@Test
@@ -151,7 +151,7 @@ public class MessageEncoderParserIntegrationTest extends BrambleTestCase {
RequestMessage rm =
messageParser.parseRequestMessage(m, clientHelper.toList(m));
assertNull(rm.getMessage());
assertNull(rm.getText());
}
@Test

View File

@@ -16,7 +16,7 @@ import static org.briarproject.bramble.test.TestUtils.getAuthor;
import static org.briarproject.bramble.test.TestUtils.getMessage;
import static org.briarproject.bramble.test.TestUtils.getRandomId;
import static org.briarproject.bramble.util.StringUtils.getRandomString;
import static org.briarproject.briar.api.introduction.IntroductionConstants.MAX_REQUEST_MESSAGE_LENGTH;
import static org.briarproject.briar.api.introduction.IntroductionConstants.MAX_INTRODUCTION_TEXT_LENGTH;
import static org.briarproject.briar.introduction.MessageType.REQUEST;
public class MessageEncoderTest extends BrambleMockTestCase {
@@ -34,7 +34,7 @@ public class MessageEncoderTest extends BrambleMockTestCase {
private final byte[] body = message.getBody();
private final Author author = getAuthor();
private final BdfList authorList = new BdfList();
private final String text = getRandomString(MAX_REQUEST_MESSAGE_LENGTH);
private final String text = getRandomString(MAX_INTRODUCTION_TEXT_LENGTH);
@Test
public void testEncodeRequestMessage() throws FormatException {

View File

@@ -29,8 +29,8 @@ import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_K
import static org.briarproject.bramble.api.record.Record.MAX_RECORD_PAYLOAD_BYTES;
import static org.briarproject.bramble.test.TestUtils.getRandomId;
import static org.briarproject.bramble.util.StringUtils.getRandomString;
import static org.briarproject.briar.api.forum.ForumConstants.MAX_FORUM_POST_BODY_LENGTH;
import static org.briarproject.briar.api.messaging.MessagingConstants.MAX_PRIVATE_MESSAGE_BODY_LENGTH;
import static org.briarproject.briar.api.forum.ForumConstants.MAX_FORUM_POST_TEXT_LENGTH;
import static org.briarproject.briar.api.messaging.MessagingConstants.MAX_PRIVATE_MESSAGE_TEXT_LENGTH;
import static org.junit.Assert.assertTrue;
public class MessageSizeIntegrationTest extends BriarTestCase {
@@ -56,13 +56,13 @@ public class MessageSizeIntegrationTest extends BriarTestCase {
// Create a maximum-length private message
GroupId groupId = new GroupId(getRandomId());
long timestamp = Long.MAX_VALUE;
String body = getRandomString(MAX_PRIVATE_MESSAGE_BODY_LENGTH);
String text = getRandomString(MAX_PRIVATE_MESSAGE_TEXT_LENGTH);
PrivateMessage message = privateMessageFactory.createPrivateMessage(
groupId, timestamp, body);
groupId, timestamp, text);
// Check the size of the serialised message
int length = message.getMessage().getRawLength();
assertTrue(length > UniqueId.LENGTH + 8
+ MAX_PRIVATE_MESSAGE_BODY_LENGTH);
+ MAX_PRIVATE_MESSAGE_TEXT_LENGTH);
assertTrue(length <= MAX_RECORD_PAYLOAD_BYTES);
}
@@ -79,14 +79,14 @@ public class MessageSizeIntegrationTest extends BriarTestCase {
GroupId groupId = new GroupId(getRandomId());
long timestamp = Long.MAX_VALUE;
MessageId parent = new MessageId(getRandomId());
String body = getRandomString(MAX_FORUM_POST_BODY_LENGTH);
String text = getRandomString(MAX_FORUM_POST_TEXT_LENGTH);
ForumPost post = forumPostFactory.createPost(groupId,
timestamp, parent, author, body);
timestamp, parent, author, text);
// Check the size of the serialised message
int length = post.getMessage().getRawLength();
assertTrue(length > UniqueId.LENGTH + 8 + UniqueId.LENGTH + 4
+ MAX_AUTHOR_NAME_LENGTH + MAX_PUBLIC_KEY_LENGTH
+ MAX_FORUM_POST_BODY_LENGTH);
+ MAX_FORUM_POST_TEXT_LENGTH);
assertTrue(length <= MAX_RECORD_PAYLOAD_BYTES);
}

View File

@@ -5,10 +5,10 @@ import org.briarproject.bramble.api.client.BdfMessageContext;
import org.briarproject.bramble.api.data.BdfDictionary;
import org.briarproject.bramble.api.data.BdfList;
import org.briarproject.bramble.test.ValidatorTestCase;
import org.briarproject.bramble.util.StringUtils;
import org.junit.Test;
import static org.briarproject.briar.api.messaging.MessagingConstants.MAX_PRIVATE_MESSAGE_BODY_LENGTH;
import static org.briarproject.bramble.util.StringUtils.getRandomString;
import static org.briarproject.briar.api.messaging.MessagingConstants.MAX_PRIVATE_MESSAGE_TEXT_LENGTH;
import static org.briarproject.briar.client.MessageTrackerConstants.MSG_KEY_READ;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -30,41 +30,40 @@ public class PrivateMessageValidatorTest extends ValidatorTestCase {
}
@Test(expected = FormatException.class)
public void testRejectsNullContent() throws Exception {
public void testRejectsNullText() throws Exception {
PrivateMessageValidator v = new PrivateMessageValidator(clientHelper,
metadataEncoder, clock);
v.validateMessage(message, group, BdfList.of((String) null));
}
@Test(expected = FormatException.class)
public void testRejectsNonStringContent() throws Exception {
public void testRejectsNonStringText() throws Exception {
PrivateMessageValidator v = new PrivateMessageValidator(clientHelper,
metadataEncoder, clock);
v.validateMessage(message, group, BdfList.of(123));
}
@Test(expected = FormatException.class)
public void testRejectsTooLongContent() throws Exception {
public void testRejectsTooLongText() throws Exception {
PrivateMessageValidator v = new PrivateMessageValidator(clientHelper,
metadataEncoder, clock);
String invalidContent =
StringUtils.getRandomString(MAX_PRIVATE_MESSAGE_BODY_LENGTH + 1);
v.validateMessage(message, group, BdfList.of(invalidContent));
String invalidText =
getRandomString(MAX_PRIVATE_MESSAGE_TEXT_LENGTH + 1);
v.validateMessage(message, group, BdfList.of(invalidText));
}
@Test
public void testAcceptsMaxLengthContent() throws Exception {
public void testAcceptsMaxLengthText() throws Exception {
PrivateMessageValidator v = new PrivateMessageValidator(clientHelper,
metadataEncoder, clock);
String content =
StringUtils.getRandomString(MAX_PRIVATE_MESSAGE_BODY_LENGTH);
String text = getRandomString(MAX_PRIVATE_MESSAGE_TEXT_LENGTH);
BdfMessageContext messageContext =
v.validateMessage(message, group, BdfList.of(content));
v.validateMessage(message, group, BdfList.of(text));
assertExpectedContext(messageContext);
}
@Test
public void testAcceptsMinLengthContent() throws Exception {
public void testAcceptsMinLengthText() throws Exception {
PrivateMessageValidator v = new PrivateMessageValidator(clientHelper,
metadataEncoder, clock);
BdfMessageContext messageContext =

View File

@@ -31,7 +31,7 @@ import static org.briarproject.briar.api.privategroup.MessageType.JOIN;
import static org.briarproject.briar.api.privategroup.MessageType.POST;
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.GROUP_SALT_LENGTH;
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_GROUP_NAME_LENGTH;
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_GROUP_POST_BODY_LENGTH;
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_GROUP_POST_TEXT_LENGTH;
import static org.briarproject.briar.api.privategroup.invitation.GroupInvitationFactory.SIGNING_LABEL_INVITE;
import static org.briarproject.briar.privategroup.GroupConstants.KEY_INITIAL_JOIN_MSG;
import static org.briarproject.briar.privategroup.GroupConstants.KEY_MEMBER;
@@ -76,7 +76,7 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
private final BdfList token = new BdfList();
private final MessageId parentId = new MessageId(getRandomId());
private final MessageId previousMsgId = new MessageId(getRandomId());
private final String content = getRandomString(MAX_GROUP_POST_BODY_LENGTH);
private final String text = getRandomString(MAX_GROUP_POST_TEXT_LENGTH);
private final GroupMessageValidator validator =
new GroupMessageValidator(privateGroupFactory, clientHelper,
@@ -432,7 +432,7 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
@Test(expected = FormatException.class)
public void testRejectsTooShortPost() throws Exception {
BdfList body = BdfList.of(POST.getInt(), memberList, parentId,
previousMsgId, content);
previousMsgId, text);
expectParseAuthor(memberList, member);
validator.validateMessage(message, group, body);
}
@@ -440,21 +440,21 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
@Test(expected = FormatException.class)
public void testRejectsTooLongPost() throws Exception {
BdfList body = BdfList.of(POST.getInt(), memberList, parentId,
previousMsgId, content, memberSignature, "");
previousMsgId, text, memberSignature, "");
validator.validateMessage(message, group, body);
}
@Test(expected = FormatException.class)
public void testRejectsPostWithNullAuthor() throws Exception {
BdfList body = BdfList.of(POST.getInt(), null, parentId, previousMsgId,
content, memberSignature);
text, memberSignature);
validator.validateMessage(message, group, body);
}
@Test(expected = FormatException.class)
public void testRejectsPostWithNonListAuthor() throws Exception {
BdfList body = BdfList.of(POST.getInt(), 123, parentId, previousMsgId,
content, memberSignature);
text, memberSignature);
validator.validateMessage(message, group, body);
}
@@ -462,14 +462,14 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
public void testRejectsPostWithInvalidAuthor() throws Exception {
expectRejectAuthor(memberList);
BdfList body = BdfList.of(POST.getInt(), memberList, parentId,
previousMsgId, content, memberSignature);
previousMsgId, text, memberSignature);
validator.validateMessage(message, group, body);
}
@Test(expected = FormatException.class)
public void testRejectsPostWithTooShortParentId() throws Exception {
BdfList body = BdfList.of(POST.getInt(), memberList,
getRandomBytes(MessageId.LENGTH - 1), previousMsgId, content,
getRandomBytes(MessageId.LENGTH - 1), previousMsgId, text,
memberSignature);
expectParseAuthor(memberList, member);
validator.validateMessage(message, group, body);
@@ -478,7 +478,7 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
@Test(expected = FormatException.class)
public void testRejectsPostWithTooLongParentId() throws Exception {
BdfList body = BdfList.of(POST.getInt(), memberList,
getRandomBytes(MessageId.LENGTH + 1), previousMsgId, content,
getRandomBytes(MessageId.LENGTH + 1), previousMsgId, text,
memberSignature);
expectParseAuthor(memberList, member);
validator.validateMessage(message, group, body);
@@ -487,7 +487,7 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
@Test(expected = FormatException.class)
public void testRejectsPostWithNonRawParentId() throws Exception {
BdfList body = BdfList.of(POST.getInt(), memberList, "not raw",
previousMsgId, content, memberSignature);
previousMsgId, text, memberSignature);
expectParseAuthor(memberList, member);
validator.validateMessage(message, group, body);
}
@@ -495,7 +495,7 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
@Test(expected = FormatException.class)
public void testRejectsPostWithTooShortPreviousMsgId() throws Exception {
BdfList body = BdfList.of(POST.getInt(), memberList, parentId,
getRandomBytes(MessageId.LENGTH - 1), content, memberSignature);
getRandomBytes(MessageId.LENGTH - 1), text, memberSignature);
expectParseAuthor(memberList, member);
validator.validateMessage(message, group, body);
}
@@ -503,7 +503,7 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
@Test(expected = FormatException.class)
public void testRejectsPostWithTooLongPreviousMsgId() throws Exception {
BdfList body = BdfList.of(POST.getInt(), memberList, parentId,
getRandomBytes(MessageId.LENGTH + 1), content, memberSignature);
getRandomBytes(MessageId.LENGTH + 1), text, memberSignature);
expectParseAuthor(memberList, member);
validator.validateMessage(message, group, body);
}
@@ -511,7 +511,7 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
@Test(expected = FormatException.class)
public void testRejectsPostWithNullPreviousMsgId() throws Exception {
BdfList body = BdfList.of(POST.getInt(), memberList, parentId, null,
content, memberSignature);
text, memberSignature);
expectParseAuthor(memberList, member);
validator.validateMessage(message, group, body);
}
@@ -519,13 +519,13 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
@Test(expected = FormatException.class)
public void testRejectsPostWithNonRawPreviousMsgId() throws Exception {
BdfList body = BdfList.of(POST.getInt(), memberList, parentId,
"not raw", content, memberSignature);
"not raw", text, memberSignature);
expectParseAuthor(memberList, member);
validator.validateMessage(message, group, body);
}
@Test(expected = FormatException.class)
public void testRejectsPostWithTooShortContent() throws Exception {
public void testRejectsPostWithTooShortText() throws Exception {
BdfList body = BdfList.of(POST.getInt(), memberList, parentId,
previousMsgId, "", memberSignature);
expectParseAuthor(memberList, member);
@@ -533,16 +533,16 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
}
@Test(expected = FormatException.class)
public void testRejectsPostWithTooLongContent() throws Exception {
public void testRejectsPostWithTooLongText() throws Exception {
BdfList body = BdfList.of(POST.getInt(), memberList, parentId,
previousMsgId, getRandomString(MAX_GROUP_POST_BODY_LENGTH + 1),
previousMsgId, getRandomString(MAX_GROUP_POST_TEXT_LENGTH + 1),
memberSignature);
expectParseAuthor(memberList, member);
validator.validateMessage(message, group, body);
}
@Test(expected = FormatException.class)
public void testRejectsPostWithNullContent() throws Exception {
public void testRejectsPostWithNullText() throws Exception {
BdfList body = BdfList.of(POST.getInt(), memberList, parentId,
previousMsgId, null, memberSignature);
expectParseAuthor(memberList, member);
@@ -550,7 +550,7 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
}
@Test(expected = FormatException.class)
public void testRejectsPostWithNonStringContent() throws Exception {
public void testRejectsPostWithNonStringText() throws Exception {
BdfList body = BdfList.of(POST.getInt(), memberList, parentId,
previousMsgId, getRandomBytes(5), memberSignature);
expectParseAuthor(memberList, member);
@@ -560,7 +560,7 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
@Test(expected = FormatException.class)
public void testRejectsPostWithTooShortSignature() throws Exception {
BdfList body = BdfList.of(POST.getInt(), memberList, parentId,
previousMsgId, content, new byte[0]);
previousMsgId, text, new byte[0]);
expectParseAuthor(memberList, member);
validator.validateMessage(message, group, body);
}
@@ -568,7 +568,7 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
@Test(expected = FormatException.class)
public void testRejectsPostWithTooLongSignature() throws Exception {
BdfList body = BdfList.of(POST.getInt(), memberList, parentId,
previousMsgId, content,
previousMsgId, text,
getRandomBytes(MAX_SIGNATURE_LENGTH + 1));
expectParseAuthor(memberList, member);
validator.validateMessage(message, group, body);
@@ -577,7 +577,7 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
@Test(expected = FormatException.class)
public void testRejectsPostWithNullSignature() throws Exception {
BdfList body = BdfList.of(POST.getInt(), memberList, parentId,
previousMsgId, content, null);
previousMsgId, text, null);
expectParseAuthor(memberList, member);
validator.validateMessage(message, group, body);
}
@@ -585,7 +585,7 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
@Test(expected = FormatException.class)
public void testRejectsPostWithNonRawSignature() throws Exception {
BdfList body = BdfList.of(POST.getInt(), memberList, parentId,
previousMsgId, content, "not raw");
previousMsgId, text, "not raw");
expectParseAuthor(memberList, member);
validator.validateMessage(message, group, body);
}
@@ -593,7 +593,7 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
@Test(expected = FormatException.class)
public void testRejectsPostWithInvalidSignature() throws Exception {
BdfList body = BdfList.of(POST.getInt(), memberList, parentId,
previousMsgId, content, memberSignature);
previousMsgId, text, memberSignature);
expectPostMessage(parentId, false);
validator.validateMessage(message, group, body);
}
@@ -601,7 +601,7 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
@Test
public void testAcceptsPost() throws Exception {
BdfList body = BdfList.of(POST.getInt(), memberList, parentId,
previousMsgId, content, memberSignature);
previousMsgId, text, memberSignature);
expectPostMessage(parentId, true);
BdfMessageContext messageContext =
validator.validateMessage(message, group, body);
@@ -616,7 +616,7 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
@Test
public void testAcceptsTopLevelPost() throws Exception {
BdfList body = BdfList.of(POST.getInt(), memberList, null,
previousMsgId, content, memberSignature);
previousMsgId, text, memberSignature);
expectPostMessage(null, true);
BdfMessageContext messageContext =
validator.validateMessage(message, group, body);
@@ -636,7 +636,7 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
memberList,
parentId == null ? null : parentId.getBytes(),
previousMsgId.getBytes(),
content
text
);
expectParseAuthor(memberList, member);
context.checking(new Expectations() {{
@@ -662,7 +662,7 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
@Test(expected = InvalidMessageException.class)
public void testRejectsMessageWithUnknownType() throws Exception {
BdfList body = BdfList.of(POST.getInt() + 1, memberList,
parentId, previousMsgId, content, memberSignature);
parentId, previousMsgId, text, memberSignature);
expectParseAuthor(memberList, member);
validator.validateMessage(message, group, body);
}

View File

@@ -176,10 +176,10 @@ public class PrivateGroupIntegrationTest
// 2 sends a message to the group
long time = clock.currentTimeMillis();
String body = "This is a test message!";
String text = "This is a test message!";
MessageId previousMsgId = groupManager2.getPreviousMsgId(groupId0);
GroupMessage msg = groupMessageFactory
.createGroupMessage(groupId0, time, null, author2, body,
.createGroupMessage(groupId0, time, null, author2, text,
previousMsgId);
groupManager2.addLocalMessage(msg);
@@ -209,13 +209,13 @@ public class PrivateGroupIntegrationTest
}
private void sendInvitation(ContactId c, long timestamp,
@Nullable String msg) throws DbException {
@Nullable String text) throws DbException {
Contact contact = contactManager0.getContact(c);
byte[] signature = groupInvitationFactory
.signInvitation(contact, groupId0, timestamp,
author0.getPrivateKey());
groupInvitationManager0
.sendInvitation(groupId0, c, msg, timestamp, signature);
.sendInvitation(groupId0, c, text, timestamp, signature);
}
private GroupMember getGroupMember(PrivateGroupManager groupManager,

View File

@@ -80,11 +80,11 @@ public class PrivateGroupManagerIntegrationTest
// create and add test message
long time = clock.currentTimeMillis();
String body = "This is a test message!";
String text = "This is a test message!";
MessageId previousMsgId =
groupManager0.getPreviousMsgId(groupId0);
GroupMessage msg = groupMessageFactory
.createGroupMessage(groupId0, time, null, author0, body,
.createGroupMessage(groupId0, time, null, author0, text,
previousMsgId);
groupManager0.addLocalMessage(msg);
assertEquals(msg.getMessage().getId(),
@@ -108,7 +108,7 @@ public class PrivateGroupManagerIntegrationTest
assertEquals(author0, header.getAuthor());
assertEquals(time, header.getTimestamp());
assertEquals(VERIFIED, header.getAuthorStatus());
assertEquals(body, groupManager1.getMessageBody(header.getId()));
assertEquals(text, groupManager1.getMessageText(header.getId()));
GroupCount count = groupManager1.getGroupCount(groupId0);
assertEquals(2, count.getUnreadCount());
assertEquals(time, count.getLatestMsgTime());

View File

@@ -34,7 +34,7 @@ import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
import static org.briarproject.bramble.test.TestUtils.getRandomId;
import static org.briarproject.bramble.util.StringUtils.getRandomString;
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.GROUP_SALT_LENGTH;
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_GROUP_INVITATION_MSG_LENGTH;
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_GROUP_INVITATION_TEXT_LENGTH;
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_GROUP_NAME_LENGTH;
import static org.briarproject.briar.api.privategroup.PrivateGroupManager.CLIENT_ID;
import static org.briarproject.briar.api.privategroup.PrivateGroupManager.MAJOR_VERSION;
@@ -89,7 +89,7 @@ abstract class AbstractProtocolEngineTest extends BrambleMockTestCase {
new InviteMessage(new MessageId(getRandomId()), contactGroupId,
privateGroupId, 0L, privateGroup.getName(),
privateGroup.getCreator(), privateGroup.getSalt(),
getRandomString(MAX_GROUP_INVITATION_MSG_LENGTH),
getRandomString(MAX_GROUP_INVITATION_TEXT_LENGTH),
signature);
final JoinMessage joinMessage =
new JoinMessage(new MessageId(getRandomId()), contactGroupId,
@@ -121,12 +121,12 @@ abstract class AbstractProtocolEngineTest extends BrambleMockTestCase {
}});
}
void expectSendInviteMessage(String msg) throws Exception {
void expectSendInviteMessage(String text) throws Exception {
context.checking(new Expectations() {{
oneOf(messageEncoder)
.encodeInviteMessage(contactGroupId, privateGroupId,
inviteTimestamp, privateGroup.getName(), author,
privateGroup.getSalt(), msg, signature);
privateGroup.getSalt(), text, signature);
will(returnValue(message));
}});
expectSendMessage(INVITE, true);

View File

@@ -15,6 +15,7 @@ import static org.briarproject.briar.privategroup.invitation.CreatorState.JOINED
import static org.briarproject.briar.privategroup.invitation.CreatorState.LEFT;
import static org.briarproject.briar.privategroup.invitation.CreatorState.START;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
public class CreatorProtocolEngineTest extends AbstractProtocolEngineTest {
@@ -36,15 +37,15 @@ public class CreatorProtocolEngineTest extends AbstractProtocolEngineTest {
public void testOnInviteActionFromStart() throws Exception {
CreatorSession session =
new CreatorSession(contactGroupId, privateGroupId);
String message = "Invitation Message";
String text = "Invitation text";
expectOnLocalInvite(message);
expectOnLocalInvite(text);
CreatorSession newSession =
engine.onInviteAction(txn, session, message, inviteTimestamp,
engine.onInviteAction(txn, session, text, inviteTimestamp,
signature);
assertEquals(INVITED, newSession.getState());
assertEquals(messageId, newSession.getLastLocalMessageId());
assertEquals(null, newSession.getLastRemoteMessageId());
assertNull(newSession.getLastRemoteMessageId());
assertEquals(messageTimestamp, newSession.getLocalTimestamp());
assertEquals(inviteTimestamp, newSession.getInviteTimestamp());
assertSessionConstantsUnchanged(session, newSession);
@@ -61,13 +62,13 @@ public class CreatorProtocolEngineTest extends AbstractProtocolEngineTest {
signature);
assertEquals(INVITED, newSession.getState());
assertEquals(messageId, newSession.getLastLocalMessageId());
assertEquals(null, newSession.getLastRemoteMessageId());
assertNull(newSession.getLastRemoteMessageId());
assertEquals(messageTimestamp, newSession.getLocalTimestamp());
assertEquals(inviteTimestamp, newSession.getInviteTimestamp());
assertSessionConstantsUnchanged(session, newSession);
}
private void expectOnLocalInvite(String msg) throws Exception {
private void expectOnLocalInvite(String text) throws Exception {
context.checking(new Expectations() {{
oneOf(db).getGroup(txn, privateGroupId);
will(returnValue(privateGroupGroup));
@@ -75,7 +76,7 @@ public class CreatorProtocolEngineTest extends AbstractProtocolEngineTest {
will(returnValue(privateGroup));
oneOf(messageTracker).trackOutgoingMessage(txn, message);
}});
expectSendInviteMessage(msg);
expectSendInviteMessage(text);
expectGetLocalTimestamp(messageTimestamp);
}
@@ -112,7 +113,7 @@ public class CreatorProtocolEngineTest extends AbstractProtocolEngineTest {
// onJoinAction
@Test(expected = UnsupportedOperationException.class)
public void testOnJoinActionFails() throws Exception {
public void testOnJoinActionFails() {
engine.onJoinAction(txn, getDefaultSession(START));
}
@@ -186,7 +187,7 @@ public class CreatorProtocolEngineTest extends AbstractProtocolEngineTest {
// onMemberAddedAction
@Test
public void testOnMemberAddedAction() throws Exception {
public void testOnMemberAddedAction() {
CreatorSession session = getDefaultSession(START);
assertEquals(session, engine.onMemberAddedAction(txn, session));

View File

@@ -76,8 +76,8 @@ public class GroupInvitationIntegrationTest
@Test
public void testSendInvitation() throws Exception {
long timestamp = clock.currentTimeMillis();
String msg = "Hi!";
sendInvitation(timestamp, msg);
String text = "Hi!";
sendInvitation(timestamp, text);
sync0To1(1, true);
@@ -97,7 +97,7 @@ public class GroupInvitationIntegrationTest
assertEquals(1, messages.size());
GroupInvitationRequest request =
(GroupInvitationRequest) messages.iterator().next();
assertEquals(msg, request.getMessage());
assertEquals(text, request.getText());
assertEquals(author0, request.getNameable().getCreator());
assertEquals(timestamp, request.getTimestamp());
assertEquals(privateGroup0.getName(), request.getNameable().getName());
@@ -442,12 +442,12 @@ public class GroupInvitationIntegrationTest
sync1To0(1, true);
}
private void sendInvitation(long timestamp, @Nullable String msg) throws
private void sendInvitation(long timestamp, @Nullable String text) throws
DbException {
byte[] signature = groupInvitationFactory.signInvitation(contact1From0,
privateGroup0.getId(), timestamp, author0.getPrivateKey());
groupInvitationManager0
.sendInvitation(privateGroup0.getId(), contactId1From0, msg,
.sendInvitation(privateGroup0.getId(), contactId1From0, text,
timestamp, signature);
}

View File

@@ -464,7 +464,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
@Test
public void testSendFirstInvitation() throws Exception {
String msg = "Invitation text for first invitation";
String text = "Invitation text for first invitation";
long time = 42L;
byte[] signature = getRandomBytes(42);
@@ -481,7 +481,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
expectCreateStorageId();
context.checking(new Expectations() {{
oneOf(creatorEngine).onInviteAction(with(txn),
with(any(CreatorSession.class)), with(msg), with(time),
with(any(CreatorSession.class)), with(text), with(time),
with(signature));
will(returnValue(creatorSession));
}});
@@ -491,12 +491,12 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
oneOf(db).endTransaction(txn);
}});
groupInvitationManager.sendInvitation(privateGroup.getId(), contactId,
msg, time, signature);
text, time, signature);
}
@Test
public void testSendSubsequentInvitation() throws Exception {
String msg = "Invitation text for subsequent invitation";
String text = "Invitation text for subsequent invitation";
long time = 43L;
byte[] signature = getRandomBytes(43);
@@ -513,7 +513,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
.parseCreatorSession(contactGroup.getId(), bdfSession);
will(returnValue(creatorSession));
oneOf(creatorEngine).onInviteAction(with(txn),
with(any(CreatorSession.class)), with(msg), with(time),
with(any(CreatorSession.class)), with(text), with(time),
with(signature));
will(returnValue(creatorSession));
}});
@@ -523,7 +523,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
oneOf(db).endTransaction(txn);
}});
groupInvitationManager.sendInvitation(privateGroup.getId(), contactId,
msg, time, signature);
text, time, signature);
}
@Test(expected = IllegalArgumentException.class)

View File

@@ -22,7 +22,7 @@ import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
import static org.briarproject.bramble.test.TestUtils.getRandomId;
import static org.briarproject.bramble.util.StringUtils.getRandomString;
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.GROUP_SALT_LENGTH;
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_GROUP_INVITATION_MSG_LENGTH;
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_GROUP_INVITATION_TEXT_LENGTH;
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_GROUP_NAME_LENGTH;
import static org.briarproject.briar.api.privategroup.invitation.GroupInvitationFactory.SIGNING_LABEL_INVITE;
import static org.briarproject.briar.privategroup.invitation.MessageType.ABORT;
@@ -47,8 +47,8 @@ public class GroupInvitationValidatorTest extends ValidatorTestCase {
);
private final String groupName = getRandomString(MAX_GROUP_NAME_LENGTH);
private final byte[] salt = getRandomBytes(GROUP_SALT_LENGTH);
private final String content =
getRandomString(MAX_GROUP_INVITATION_MSG_LENGTH);
private final String text =
getRandomString(MAX_GROUP_INVITATION_TEXT_LENGTH);
private final byte[] signature = getRandomBytes(MAX_SIGNATURE_LENGTH);
private final PrivateGroup privateGroup =
new PrivateGroup(group, groupName, creator, salt);
@@ -64,14 +64,14 @@ public class GroupInvitationValidatorTest extends ValidatorTestCase {
@Test(expected = FormatException.class)
public void testRejectsTooShortInviteMessage() throws Exception {
BdfList body = BdfList.of(INVITE.getValue(), creatorList, groupName,
salt, content);
salt, text);
validator.validateMessage(message, group, body);
}
@Test(expected = FormatException.class)
public void testRejectsTooLongInviteMessage() throws Exception {
BdfList body = BdfList.of(INVITE.getValue(), creatorList, groupName,
salt, content, signature, "");
salt, text, signature, "");
validator.validateMessage(message, group, body);
}
@@ -79,7 +79,7 @@ public class GroupInvitationValidatorTest extends ValidatorTestCase {
public void testRejectsInviteMessageWithTooShortGroupName()
throws Exception {
BdfList body = BdfList.of(INVITE.getValue(), creatorList, "", salt,
content, signature);
text, signature);
validator.validateMessage(message, group, body);
}
@@ -88,14 +88,14 @@ public class GroupInvitationValidatorTest extends ValidatorTestCase {
throws Exception {
String tooLongName = getRandomString(MAX_GROUP_NAME_LENGTH + 1);
BdfList body = BdfList.of(INVITE.getValue(), creatorList, tooLongName,
salt, content, signature);
salt, text, signature);
validator.validateMessage(message, group, body);
}
@Test(expected = FormatException.class)
public void testRejectsInviteMessageWithNullGroupName() throws Exception {
BdfList body = BdfList.of(INVITE.getValue(), creatorList, null, salt,
content, signature);
text, signature);
validator.validateMessage(message, group, body);
}
@@ -103,21 +103,21 @@ public class GroupInvitationValidatorTest extends ValidatorTestCase {
public void testRejectsInviteMessageWithNonStringGroupName()
throws Exception {
BdfList body = BdfList.of(INVITE.getValue(), creatorList,
getRandomBytes(5), salt, content, signature);
getRandomBytes(5), salt, text, signature);
validator.validateMessage(message, group, body);
}
@Test(expected = FormatException.class)
public void testRejectsInviteMessageWithNullCreator() throws Exception {
BdfList body = BdfList.of(INVITE.getValue(), null, groupName, salt,
content, signature);
text, signature);
validator.validateMessage(message, group, body);
}
@Test(expected = FormatException.class)
public void testRejectsInviteMessageWithNonListCreator() throws Exception {
BdfList body = BdfList.of(INVITE.getValue(), 123, groupName, salt,
content, signature);
text, signature);
validator.validateMessage(message, group, body);
}
@@ -129,7 +129,7 @@ public class GroupInvitationValidatorTest extends ValidatorTestCase {
}});
BdfList body = BdfList.of(INVITE.getValue(), creatorList, groupName,
salt, content, signature);
salt, text, signature);
validator.validateMessage(message, group, body);
}
@@ -137,7 +137,7 @@ public class GroupInvitationValidatorTest extends ValidatorTestCase {
public void testRejectsInviteMessageWithTooShortGroupSalt()
throws Exception {
BdfList body = BdfList.of(INVITE.getValue(), creatorList, groupName,
getRandomBytes(GROUP_SALT_LENGTH - 1), content, signature);
getRandomBytes(GROUP_SALT_LENGTH - 1), text, signature);
validator.validateMessage(message, group, body);
}
@@ -145,41 +145,41 @@ public class GroupInvitationValidatorTest extends ValidatorTestCase {
public void testRejectsInviteMessageWithTooLongGroupSalt()
throws Exception {
BdfList body = BdfList.of(INVITE.getValue(), creatorList, groupName,
getRandomBytes(GROUP_SALT_LENGTH + 1), content, signature);
getRandomBytes(GROUP_SALT_LENGTH + 1), text, signature);
validator.validateMessage(message, group, body);
}
@Test(expected = FormatException.class)
public void testRejectsInviteMessageWithNullGroupSalt() throws Exception {
BdfList body = BdfList.of(INVITE.getValue(), creatorList, groupName,
null, content, signature);
null, text, signature);
validator.validateMessage(message, group, body);
}
@Test(expected = FormatException.class)
public void testRejectsInviteMessageWithNonRawGroupSalt() throws Exception {
BdfList body = BdfList.of(INVITE.getValue(), creatorList, groupName,
"not raw", content, signature);
"not raw", text, signature);
validator.validateMessage(message, group, body);
}
@Test(expected = FormatException.class)
public void testRejectsInviteMessageWithTooShortContent() throws Exception {
public void testRejectsInviteMessageWithTooShortText() throws Exception {
BdfList body = BdfList.of(INVITE.getValue(), creatorList, groupName,
salt, "", signature);
validator.validateMessage(message, group, body);
}
@Test(expected = FormatException.class)
public void testRejectsInviteMessageWithTooLongContent() throws Exception {
public void testRejectsInviteMessageWithTooLongText() throws Exception {
BdfList body = BdfList.of(INVITE.getValue(), creatorList, groupName,
salt, getRandomString(MAX_GROUP_INVITATION_MSG_LENGTH + 1),
salt, getRandomString(MAX_GROUP_INVITATION_TEXT_LENGTH + 1),
signature);
validator.validateMessage(message, group, body);
}
@Test
public void testAcceptsInviteMessageWithNullContent() throws Exception {
public void testAcceptsInviteMessageWithNullText() throws Exception {
BdfList body = BdfList.of(INVITE.getValue(), creatorList, groupName,
salt, null, signature);
expectInviteMessage(false);
@@ -187,7 +187,7 @@ public class GroupInvitationValidatorTest extends ValidatorTestCase {
}
@Test(expected = FormatException.class)
public void testRejectsInviteMessageWithNonStringContent()
public void testRejectsInviteMessageWithNonStringText()
throws Exception {
BdfList body = BdfList.of(INVITE.getValue(), creatorList, groupName,
salt, getRandomBytes(5), signature);
@@ -198,7 +198,7 @@ public class GroupInvitationValidatorTest extends ValidatorTestCase {
public void testRejectsInviteMessageWithTooShortSignature()
throws Exception {
BdfList body = BdfList.of(INVITE.getValue(), creatorList, groupName,
salt, content, new byte[0]);
salt, text, new byte[0]);
validator.validateMessage(message, group, body);
}
@@ -206,21 +206,21 @@ public class GroupInvitationValidatorTest extends ValidatorTestCase {
public void testRejectsInviteMessageWithTooLongSignature()
throws Exception {
BdfList body = BdfList.of(INVITE.getValue(), creatorList, groupName,
salt, content, getRandomBytes(MAX_SIGNATURE_LENGTH + 1));
salt, text, getRandomBytes(MAX_SIGNATURE_LENGTH + 1));
validator.validateMessage(message, group, body);
}
@Test(expected = FormatException.class)
public void testRejectsInviteMessageWithNullSignature() throws Exception {
BdfList body = BdfList.of(INVITE.getValue(), creatorList, groupName,
salt, content, null);
salt, text, null);
validator.validateMessage(message, group, body);
}
@Test(expected = FormatException.class)
public void testRejectsInviteMessageWithNonRawSignature() throws Exception {
BdfList body = BdfList.of(INVITE.getValue(), creatorList, groupName,
salt, content, "not raw");
salt, text, "not raw");
validator.validateMessage(message, group, body);
}
@@ -228,7 +228,7 @@ public class GroupInvitationValidatorTest extends ValidatorTestCase {
public void testRejectsInviteMessageWithInvalidSignature()
throws Exception {
BdfList body = BdfList.of(INVITE.getValue(), creatorList, groupName,
salt, content, signature);
salt, text, signature);
expectInviteMessage(true);
validator.validateMessage(message, group, body);
}
@@ -236,7 +236,7 @@ public class GroupInvitationValidatorTest extends ValidatorTestCase {
@Test
public void testAcceptsValidInviteMessage() throws Exception {
BdfList body = BdfList.of(INVITE.getValue(), creatorList, groupName,
salt, content, signature);
salt, text, signature);
expectInviteMessage(false);
BdfMessageContext messageContext =
validator.validateMessage(message, group, body);

View File

@@ -21,7 +21,7 @@ import static org.briarproject.bramble.test.TestUtils.getAuthor;
import static org.briarproject.bramble.test.TestUtils.getLocalAuthor;
import static org.briarproject.bramble.test.TestUtils.getRandomId;
import static org.briarproject.bramble.util.StringUtils.getRandomString;
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_GROUP_INVITATION_MSG_LENGTH;
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_GROUP_INVITATION_TEXT_LENGTH;
import static org.briarproject.briar.privategroup.invitation.InviteeState.ACCEPTED;
import static org.briarproject.briar.privategroup.invitation.InviteeState.DISSOLVED;
import static org.briarproject.briar.privategroup.invitation.InviteeState.ERROR;
@@ -327,7 +327,7 @@ public class InviteeProtocolEngineTest extends AbstractProtocolEngineTest {
privateGroupId, session.getInviteTimestamp() + 1,
privateGroup.getName(), privateGroup.getCreator(),
privateGroup.getSalt(),
getRandomString(MAX_GROUP_INVITATION_MSG_LENGTH),
getRandomString(MAX_GROUP_INVITATION_TEXT_LENGTH),
signature);
Author notCreator = getAuthor();
Contact notCreatorContact = new Contact(contactId, notCreator,

View File

@@ -159,7 +159,7 @@ public class BlogSharingIntegrationTest
assertEquals(blog2.getAuthor().getName(),
invitation.getName());
assertFalse(invitation.getNameable().isRssFeed());
assertEquals("Hi!", invitation.getMessage());
assertEquals("Hi!", invitation.getText());
} else {
BlogInvitationResponse response = (BlogInvitationResponse) m;
assertEquals(blog2.getId(), response.getShareableId());
@@ -232,7 +232,7 @@ public class BlogSharingIntegrationTest
assertEquals(rssBlog.getAuthor().getName(),
invitation.getName());
assertTrue(invitation.getNameable().isRssFeed());
assertEquals("Hi!", invitation.getMessage());
assertEquals("Hi!", invitation.getText());
} else {
BlogInvitationResponse response = (BlogInvitationResponse) m;
assertEquals(rssBlog.getId(), response.getShareableId());
@@ -293,7 +293,7 @@ public class BlogSharingIntegrationTest
assertTrue(invitation.wasAnswered());
assertEquals(blog2.getAuthor().getName(),
invitation.getName());
assertNull(invitation.getMessage());
assertNull(invitation.getText());
} else {
BlogInvitationResponse response = (BlogInvitationResponse) m;
assertEquals(blog2.getId(), response.getShareableId());

View File

@@ -10,7 +10,7 @@ import org.junit.Test;
import static org.briarproject.bramble.test.TestUtils.getAuthor;
import static org.briarproject.bramble.util.StringUtils.getRandomString;
import static org.briarproject.briar.api.sharing.SharingConstants.MAX_INVITATION_MESSAGE_LENGTH;
import static org.briarproject.briar.api.sharing.SharingConstants.MAX_INVITATION_TEXT_LENGTH;
import static org.briarproject.briar.sharing.MessageType.INVITE;
public class BlogSharingValidatorTest extends SharingValidatorTest {
@@ -20,8 +20,7 @@ public class BlogSharingValidatorTest extends SharingValidatorTest {
private final BdfList authorList = BdfList.of(author.getFormatVersion(),
author.getName(), author.getPublicKey());
private final BdfList descriptor = BdfList.of(authorList, false);
private final String content =
getRandomString(MAX_INVITATION_MESSAGE_LENGTH);
private final String text = getRandomString(MAX_INVITATION_TEXT_LENGTH);
@Override
SharingValidator getValidator() {
@@ -30,17 +29,16 @@ public class BlogSharingValidatorTest extends SharingValidatorTest {
}
@Test
public void testAcceptsInvitationWithContent() throws Exception {
public void testAcceptsInvitationWithText() throws Exception {
expectCreateBlog();
expectEncodeMetadata(INVITE);
BdfMessageContext context = validator.validateMessage(message, group,
BdfList.of(INVITE.getValue(), previousMsgId, descriptor,
content));
BdfList.of(INVITE.getValue(), previousMsgId, descriptor, text));
assertExpectedContext(context, previousMsgId);
}
@Test
public void testAcceptsInvitationWithNullContent() throws Exception {
public void testAcceptsInvitationWithNullText() throws Exception {
expectCreateBlog();
expectEncodeMetadata(INVITE);
BdfMessageContext context = validator.validateMessage(message, group,
@@ -53,7 +51,7 @@ public class BlogSharingValidatorTest extends SharingValidatorTest {
expectCreateBlog();
expectEncodeMetadata(INVITE);
BdfMessageContext context = validator.validateMessage(message, group,
BdfList.of(INVITE.getValue(), null, descriptor, content));
BdfList.of(INVITE.getValue(), null, descriptor, text));
assertExpectedContext(context, null);
}
@@ -64,7 +62,7 @@ public class BlogSharingValidatorTest extends SharingValidatorTest {
BdfList rssDescriptor = BdfList.of(authorList, true);
BdfMessageContext context = validator.validateMessage(message, group,
BdfList.of(INVITE.getValue(), previousMsgId, rssDescriptor,
content));
text));
assertExpectedContext(context, previousMsgId);
}
@@ -85,32 +83,30 @@ public class BlogSharingValidatorTest extends SharingValidatorTest {
}
@Test(expected = FormatException.class)
public void testRejectsNonStringContent() throws Exception {
public void testRejectsNonStringText() throws Exception {
expectCreateBlog();
validator.validateMessage(message, group,
BdfList.of(INVITE.getValue(), previousMsgId, descriptor,
123));
BdfList.of(INVITE.getValue(), previousMsgId, descriptor, 123));
}
@Test
public void testAcceptsMinLengthContent() throws Exception {
String shortContent = getRandomString(1);
public void testAcceptsMinLengthText() throws Exception {
String shortText = getRandomString(1);
expectCreateBlog();
expectEncodeMetadata(INVITE);
BdfMessageContext context = validator.validateMessage(message, group,
BdfList.of(INVITE.getValue(), previousMsgId, descriptor,
shortContent));
shortText));
assertExpectedContext(context, previousMsgId);
}
@Test(expected = FormatException.class)
public void testRejectsTooLongContent() throws Exception {
String invalidContent =
getRandomString(MAX_INVITATION_MESSAGE_LENGTH + 1);
public void testRejectsTooLongText() throws Exception {
String invalidText = getRandomString(MAX_INVITATION_TEXT_LENGTH + 1);
expectCreateBlog();
validator.validateMessage(message, group,
BdfList.of(INVITE.getValue(), previousMsgId, descriptor,
invalidContent));
invalidText));
}
private void expectCreateBlog() throws Exception {

View File

@@ -139,7 +139,7 @@ public class ForumSharingIntegrationTest
assertTrue(invitation.wasAnswered());
assertEquals(forum0.getName(), invitation.getName());
assertEquals(forum0, invitation.getNameable());
assertEquals("Hi!", invitation.getMessage());
assertEquals("Hi!", invitation.getText());
assertTrue(invitation.canBeOpened());
} else {
ForumInvitationResponse response = (ForumInvitationResponse) m;
@@ -195,7 +195,7 @@ public class ForumSharingIntegrationTest
assertEquals(forum0, invitation.getNameable());
assertTrue(invitation.wasAnswered());
assertEquals(forum0.getName(), invitation.getName());
assertNull(invitation.getMessage());
assertNull(invitation.getText());
assertFalse(invitation.canBeOpened());
} else {
ForumInvitationResponse response = (ForumInvitationResponse) m;
@@ -635,10 +635,9 @@ public class ForumSharingIntegrationTest
// sharer posts into the forum
long time = clock.currentTimeMillis();
String body = getRandomString(42);
String text = getRandomString(42);
ForumPost p = forumPostFactory
.createPost(forum0.getId(), time, null, author0,
body);
.createPost(forum0.getId(), time, null, author0, text);
forumManager0.addLocalPost(p);
// sync forum post
@@ -654,10 +653,9 @@ public class ForumSharingIntegrationTest
// now invitee creates a post
time = clock.currentTimeMillis();
body = getRandomString(42);
text = getRandomString(42);
p = forumPostFactory
.createPost(forum0.getId(), time, null, author1,
body);
.createPost(forum0.getId(), time, null, author1, text);
forumManager1.addLocalPost(p);
// sync forum post
@@ -697,10 +695,9 @@ public class ForumSharingIntegrationTest
// now invitee creates a post
time = clock.currentTimeMillis();
body = getRandomString(42);
text = getRandomString(42);
p = forumPostFactory
.createPost(forum0.getId(), time, null, author1,
body);
.createPost(forum0.getId(), time, null, author1, text);
forumManager1.addLocalPost(p);
// sync forum post

View File

@@ -11,7 +11,7 @@ import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
import static org.briarproject.bramble.util.StringUtils.getRandomString;
import static org.briarproject.briar.api.forum.ForumConstants.FORUM_SALT_LENGTH;
import static org.briarproject.briar.api.forum.ForumConstants.MAX_FORUM_NAME_LENGTH;
import static org.briarproject.briar.api.sharing.SharingConstants.MAX_INVITATION_MESSAGE_LENGTH;
import static org.briarproject.briar.api.sharing.SharingConstants.MAX_INVITATION_TEXT_LENGTH;
import static org.briarproject.briar.sharing.MessageType.INVITE;
public class ForumSharingValidatorTest extends SharingValidatorTest {
@@ -20,8 +20,7 @@ public class ForumSharingValidatorTest extends SharingValidatorTest {
private final byte[] salt = getRandomBytes(FORUM_SALT_LENGTH);
private final Forum forum = new Forum(group, forumName, salt);
private final BdfList descriptor = BdfList.of(forumName, salt);
private final String content =
getRandomString(MAX_INVITATION_MESSAGE_LENGTH);
private final String text = getRandomString(MAX_INVITATION_TEXT_LENGTH);
@Override
SharingValidator getValidator() {
@@ -30,17 +29,16 @@ public class ForumSharingValidatorTest extends SharingValidatorTest {
}
@Test
public void testAcceptsInvitationWithContent() throws Exception {
public void testAcceptsInvitationWithText() throws Exception {
expectCreateForum(forumName);
expectEncodeMetadata(INVITE);
BdfMessageContext context = validator.validateMessage(message, group,
BdfList.of(INVITE.getValue(), previousMsgId, descriptor,
content));
BdfList.of(INVITE.getValue(), previousMsgId, descriptor, text));
assertExpectedContext(context, previousMsgId);
}
@Test
public void testAcceptsInvitationWithNullContent() throws Exception {
public void testAcceptsInvitationWithNullText() throws Exception {
expectCreateForum(forumName);
expectEncodeMetadata(INVITE);
BdfMessageContext context = validator.validateMessage(message, group,
@@ -137,14 +135,14 @@ public class ForumSharingValidatorTest extends SharingValidatorTest {
}
@Test(expected = FormatException.class)
public void testRejectsNonStringContent() throws Exception {
public void testRejectsNonStringText() throws Exception {
expectCreateForum(forumName);
validator.validateMessage(message, group,
BdfList.of(INVITE.getValue(), previousMsgId, descriptor, 123));
}
@Test
public void testAcceptsMinLengthContent() throws Exception {
public void testAcceptsMinLengthText() throws Exception {
expectCreateForum(forumName);
expectEncodeMetadata(INVITE);
BdfMessageContext context = validator.validateMessage(message, group,
@@ -153,13 +151,12 @@ public class ForumSharingValidatorTest extends SharingValidatorTest {
}
@Test(expected = FormatException.class)
public void testRejectsTooLongContent() throws Exception {
String invalidContent =
getRandomString(MAX_INVITATION_MESSAGE_LENGTH + 1);
public void testRejectsTooLongText() throws Exception {
String invalidText = getRandomString(MAX_INVITATION_TEXT_LENGTH + 1);
expectCreateForum(forumName);
validator.validateMessage(message, group,
BdfList.of(INVITE.getValue(), previousMsgId, descriptor,
invalidContent));
invalidText));
}
private void expectCreateForum(String name) {