mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 19:59:05 +01:00
Add an option to debug builds to create fake test data
This commit is contained in:
@@ -39,7 +39,7 @@ import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_K
|
||||
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_LENGTH;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomString;
|
||||
import static org.briarproject.bramble.util.StringUtils.getRandomString;
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_AUTHOR;
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_AUTHOR_ID;
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_AUTHOR_NAME;
|
||||
|
||||
@@ -25,7 +25,7 @@ import static junit.framework.Assert.assertNotNull;
|
||||
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
|
||||
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomString;
|
||||
import static org.briarproject.bramble.util.StringUtils.getRandomString;
|
||||
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;
|
||||
|
||||
@@ -18,6 +18,7 @@ import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.bramble.api.system.Clock;
|
||||
import org.briarproject.bramble.system.SystemClock;
|
||||
import org.briarproject.bramble.test.TestUtils;
|
||||
import org.briarproject.bramble.util.StringUtils;
|
||||
import org.briarproject.briar.api.blog.Blog;
|
||||
import org.briarproject.briar.api.blog.BlogFactory;
|
||||
import org.briarproject.briar.test.BriarTestCase;
|
||||
@@ -64,7 +65,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 = TestUtils.getRandomString(42);
|
||||
private final String body = StringUtils.getRandomString(42);
|
||||
|
||||
public BlogPostValidatorTest() {
|
||||
GroupId groupId = new GroupId(TestUtils.getRandomId());
|
||||
|
||||
@@ -19,6 +19,7 @@ import org.briarproject.bramble.api.sync.ValidationManager.MessageValidator;
|
||||
import org.briarproject.bramble.test.CaptureArgumentAction;
|
||||
import org.briarproject.bramble.test.TestUtils;
|
||||
import org.briarproject.bramble.util.ByteUtils;
|
||||
import org.briarproject.bramble.util.StringUtils;
|
||||
import org.briarproject.briar.api.client.MessageQueueManager.IncomingQueueMessageHook;
|
||||
import org.briarproject.briar.api.client.MessageQueueManager.QueueMessageValidator;
|
||||
import org.briarproject.briar.api.client.QueueMessage;
|
||||
@@ -45,7 +46,7 @@ public class MessageQueueManagerImplTest extends BriarTestCase {
|
||||
|
||||
private final GroupId groupId = new GroupId(TestUtils.getRandomId());
|
||||
private final ClientId clientId =
|
||||
new ClientId(TestUtils.getRandomString(5));
|
||||
new ClientId(StringUtils.getRandomString(5));
|
||||
private final byte[] descriptor = new byte[0];
|
||||
private final Group group = new Group(groupId, clientId, descriptor);
|
||||
private final long timestamp = System.currentTimeMillis();
|
||||
|
||||
@@ -11,6 +11,7 @@ import org.briarproject.bramble.api.sync.InvalidMessageException;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.bramble.test.TestUtils;
|
||||
import org.briarproject.bramble.test.ValidatorTestCase;
|
||||
import org.briarproject.bramble.util.StringUtils;
|
||||
import org.jmock.Expectations;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -30,12 +31,12 @@ public class ForumPostValidatorTest extends ValidatorTestCase {
|
||||
|
||||
private final MessageId parentId = new MessageId(TestUtils.getRandomId());
|
||||
private final String authorName =
|
||||
TestUtils.getRandomString(MAX_AUTHOR_NAME_LENGTH);
|
||||
StringUtils.getRandomString(MAX_AUTHOR_NAME_LENGTH);
|
||||
private final byte[] authorPublicKey =
|
||||
TestUtils.getRandomBytes(MAX_PUBLIC_KEY_LENGTH);
|
||||
private final BdfList authorList = BdfList.of(authorName, authorPublicKey);
|
||||
private final String content =
|
||||
TestUtils.getRandomString(MAX_FORUM_POST_BODY_LENGTH);
|
||||
StringUtils.getRandomString(MAX_FORUM_POST_BODY_LENGTH);
|
||||
private final byte[] signature =
|
||||
TestUtils.getRandomBytes(MAX_SIGNATURE_LENGTH);
|
||||
private final AuthorId authorId = new AuthorId(TestUtils.getRandomId());
|
||||
@@ -165,7 +166,7 @@ public class ForumPostValidatorTest extends ValidatorTestCase {
|
||||
|
||||
@Test
|
||||
public void testAcceptsMinLengthAuthorName() throws Exception {
|
||||
final String shortAuthorName = TestUtils.getRandomString(1);
|
||||
final String shortAuthorName = StringUtils.getRandomString(1);
|
||||
BdfList shortNameAuthorList =
|
||||
BdfList.of(shortAuthorName, authorPublicKey);
|
||||
final Author shortNameAuthor =
|
||||
@@ -190,7 +191,7 @@ public class ForumPostValidatorTest extends ValidatorTestCase {
|
||||
@Test(expected = FormatException.class)
|
||||
public void testRejectsTooLongAuthorName() throws Exception {
|
||||
String invalidAuthorName =
|
||||
TestUtils.getRandomString(MAX_AUTHOR_NAME_LENGTH + 1);
|
||||
StringUtils.getRandomString(MAX_AUTHOR_NAME_LENGTH + 1);
|
||||
BdfList invalidAuthorList =
|
||||
BdfList.of(invalidAuthorName, authorPublicKey);
|
||||
ForumPostValidator v = new ForumPostValidator(authorFactory,
|
||||
@@ -278,7 +279,7 @@ public class ForumPostValidatorTest extends ValidatorTestCase {
|
||||
@Test(expected = FormatException.class)
|
||||
public void testRejectsTooLongContent() throws Exception {
|
||||
String invalidContent =
|
||||
TestUtils.getRandomString(MAX_FORUM_POST_BODY_LENGTH + 1);
|
||||
StringUtils.getRandomString(MAX_FORUM_POST_BODY_LENGTH + 1);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(authorFactory).createAuthor(authorName, authorPublicKey);
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.bramble.test.TestDatabaseModule;
|
||||
import org.briarproject.bramble.test.TestUtils;
|
||||
import org.briarproject.bramble.util.StringUtils;
|
||||
import org.briarproject.briar.api.client.SessionId;
|
||||
import org.briarproject.briar.api.introduction.IntroductionManager;
|
||||
import org.briarproject.briar.api.introduction.IntroductionMessage;
|
||||
@@ -479,7 +480,7 @@ public class IntroductionIntegrationTest
|
||||
new BdfEntry(TYPE, TYPE_REQUEST),
|
||||
new BdfEntry(SESSION_ID, sessionId),
|
||||
new BdfEntry(GROUP_ID, group.getId()),
|
||||
new BdfEntry(NAME, TestUtils.getRandomString(42)),
|
||||
new BdfEntry(NAME, StringUtils.getRandomString(42)),
|
||||
new BdfEntry(PUBLIC_KEY,
|
||||
TestUtils.getRandomBytes(MAX_PUBLIC_KEY_LENGTH))
|
||||
);
|
||||
|
||||
@@ -20,6 +20,7 @@ import org.briarproject.bramble.api.sync.Message;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.bramble.api.sync.MessageStatus;
|
||||
import org.briarproject.bramble.test.TestUtils;
|
||||
import org.briarproject.bramble.util.StringUtils;
|
||||
import org.briarproject.briar.api.client.MessageTracker;
|
||||
import org.briarproject.briar.api.client.SessionId;
|
||||
import org.briarproject.briar.test.BriarTestCase;
|
||||
@@ -81,7 +82,7 @@ public class IntroductionManagerImplTest extends BriarTestCase {
|
||||
introducee2 =
|
||||
new Contact(contactId2, author2, localAuthorId2, true, true);
|
||||
|
||||
ClientId clientId = new ClientId(TestUtils.getRandomString(5));
|
||||
ClientId clientId = new ClientId(StringUtils.getRandomString(5));
|
||||
introductionGroup1 = new Group(new GroupId(TestUtils.getRandomId()),
|
||||
clientId, new byte[0]);
|
||||
introductionGroup2 = new Group(new GroupId(TestUtils.getRandomId()),
|
||||
|
||||
@@ -15,6 +15,7 @@ import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.bramble.api.system.Clock;
|
||||
import org.briarproject.bramble.system.SystemClock;
|
||||
import org.briarproject.bramble.test.TestUtils;
|
||||
import org.briarproject.bramble.util.StringUtils;
|
||||
import org.briarproject.briar.api.client.SessionId;
|
||||
import org.briarproject.briar.test.BriarTestCase;
|
||||
import org.jmock.Mockery;
|
||||
@@ -59,7 +60,7 @@ public class IntroductionValidatorTest extends BriarTestCase {
|
||||
|
||||
public IntroductionValidatorTest() {
|
||||
GroupId groupId = new GroupId(TestUtils.getRandomId());
|
||||
ClientId clientId = new ClientId(TestUtils.getRandomString(5));
|
||||
ClientId clientId = new ClientId(StringUtils.getRandomString(5));
|
||||
byte[] descriptor = TestUtils.getRandomBytes(12);
|
||||
group = new Group(groupId, clientId, descriptor);
|
||||
|
||||
@@ -83,11 +84,11 @@ public class IntroductionValidatorTest extends BriarTestCase {
|
||||
@Test
|
||||
public void testValidateProperIntroductionRequest() throws IOException {
|
||||
final byte[] sessionId = TestUtils.getRandomId();
|
||||
final String name = TestUtils.getRandomString(MAX_AUTHOR_NAME_LENGTH);
|
||||
final String name = StringUtils.getRandomString(MAX_AUTHOR_NAME_LENGTH);
|
||||
final byte[] publicKey =
|
||||
TestUtils.getRandomBytes(MAX_PUBLIC_KEY_LENGTH);
|
||||
final String text =
|
||||
TestUtils.getRandomString(MAX_INTRODUCTION_MESSAGE_LENGTH);
|
||||
StringUtils.getRandomString(MAX_INTRODUCTION_MESSAGE_LENGTH);
|
||||
|
||||
BdfList body = BdfList.of(TYPE_REQUEST, sessionId,
|
||||
name, publicKey, text);
|
||||
@@ -144,9 +145,9 @@ public class IntroductionValidatorTest extends BriarTestCase {
|
||||
|
||||
private BdfDictionary getValidIntroductionRequest() throws FormatException {
|
||||
byte[] sessionId = TestUtils.getRandomId();
|
||||
String name = TestUtils.getRandomString(MAX_AUTHOR_NAME_LENGTH);
|
||||
String name = StringUtils.getRandomString(MAX_AUTHOR_NAME_LENGTH);
|
||||
byte[] publicKey = TestUtils.getRandomBytes(MAX_PUBLIC_KEY_LENGTH);
|
||||
String text = TestUtils.getRandomString(MAX_MESSAGE_BODY_LENGTH);
|
||||
String text = StringUtils.getRandomString(MAX_MESSAGE_BODY_LENGTH);
|
||||
|
||||
BdfDictionary msg = new BdfDictionary();
|
||||
msg.put(TYPE, TYPE_REQUEST);
|
||||
@@ -168,11 +169,11 @@ public class IntroductionValidatorTest extends BriarTestCase {
|
||||
byte[] sessionId = TestUtils.getRandomId();
|
||||
long time = clock.currentTimeMillis();
|
||||
byte[] publicKey = TestUtils.getRandomBytes(MAX_PUBLIC_KEY_LENGTH);
|
||||
String transportId = TestUtils
|
||||
String transportId = StringUtils
|
||||
.getRandomString(TransportId.MAX_TRANSPORT_ID_LENGTH);
|
||||
BdfDictionary tProps = BdfDictionary.of(
|
||||
new BdfEntry(TestUtils.getRandomString(MAX_PROPERTY_LENGTH),
|
||||
TestUtils.getRandomString(MAX_PROPERTY_LENGTH))
|
||||
new BdfEntry(StringUtils.getRandomString(MAX_PROPERTY_LENGTH),
|
||||
StringUtils.getRandomString(MAX_PROPERTY_LENGTH))
|
||||
);
|
||||
BdfDictionary tp = BdfDictionary.of(
|
||||
new BdfEntry(transportId, tProps)
|
||||
@@ -230,7 +231,7 @@ public class IntroductionValidatorTest extends BriarTestCase {
|
||||
throws IOException {
|
||||
BdfDictionary msg = getValidIntroductionResponse(true);
|
||||
BdfDictionary tp = msg.getDictionary(TRANSPORT);
|
||||
tp.put(TestUtils
|
||||
tp.put(StringUtils
|
||||
.getRandomString(TransportId.MAX_TRANSPORT_ID_LENGTH), "X");
|
||||
msg.put(TRANSPORT, tp);
|
||||
|
||||
@@ -260,11 +261,11 @@ public class IntroductionValidatorTest extends BriarTestCase {
|
||||
byte[] sessionId = TestUtils.getRandomId();
|
||||
long time = clock.currentTimeMillis();
|
||||
byte[] publicKey = TestUtils.getRandomBytes(MAX_PUBLIC_KEY_LENGTH);
|
||||
String transportId = TestUtils
|
||||
String transportId = StringUtils
|
||||
.getRandomString(TransportId.MAX_TRANSPORT_ID_LENGTH);
|
||||
BdfDictionary tProps = BdfDictionary.of(
|
||||
new BdfEntry(TestUtils.getRandomString(MAX_PROPERTY_LENGTH),
|
||||
TestUtils.getRandomString(MAX_PROPERTY_LENGTH))
|
||||
new BdfEntry(StringUtils.getRandomString(MAX_PROPERTY_LENGTH),
|
||||
StringUtils.getRandomString(MAX_PROPERTY_LENGTH))
|
||||
);
|
||||
BdfDictionary tp = BdfDictionary.of(
|
||||
new BdfEntry(transportId, tProps)
|
||||
@@ -310,7 +311,7 @@ public class IntroductionValidatorTest extends BriarTestCase {
|
||||
BdfDictionary msg = BdfDictionary.of(
|
||||
new BdfEntry(TYPE, TYPE_ACK),
|
||||
new BdfEntry(SESSION_ID, TestUtils.getRandomId()),
|
||||
new BdfEntry("garbage", TestUtils.getRandomString(255))
|
||||
new BdfEntry("garbage", StringUtils.getRandomString(255))
|
||||
);
|
||||
BdfList body = BdfList.of(msg.getLong(TYPE), msg.getRaw(SESSION_ID),
|
||||
msg.getString("garbage"));
|
||||
@@ -357,7 +358,7 @@ public class IntroductionValidatorTest extends BriarTestCase {
|
||||
BdfDictionary msg = BdfDictionary.of(
|
||||
new BdfEntry(TYPE, TYPE_ABORT),
|
||||
new BdfEntry(SESSION_ID, TestUtils.getRandomId()),
|
||||
new BdfEntry("garbage", TestUtils.getRandomString(255))
|
||||
new BdfEntry("garbage", StringUtils.getRandomString(255))
|
||||
);
|
||||
BdfList body = BdfList.of(msg.getLong(TYPE), msg.getRaw(SESSION_ID),
|
||||
msg.getString("garbage"));
|
||||
|
||||
@@ -15,6 +15,7 @@ import org.briarproject.bramble.api.sync.Group;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.system.Clock;
|
||||
import org.briarproject.bramble.test.TestUtils;
|
||||
import org.briarproject.bramble.util.StringUtils;
|
||||
import org.briarproject.briar.api.client.MessageQueueManager;
|
||||
import org.briarproject.briar.api.client.SessionId;
|
||||
import org.briarproject.briar.test.BriarTestCase;
|
||||
@@ -60,7 +61,7 @@ public class MessageSenderTest extends BriarTestCase {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
final Group privateGroup =
|
||||
new Group(new GroupId(TestUtils.getRandomId()),
|
||||
new ClientId(TestUtils.getRandomString(5)),
|
||||
new ClientId(StringUtils.getRandomString(5)),
|
||||
new byte[0]);
|
||||
final SessionId sessionId = new SessionId(TestUtils.getRandomId());
|
||||
byte[] mac = TestUtils.getRandomBytes(42);
|
||||
|
||||
@@ -65,7 +65,7 @@ public class MessageSizeIntegrationTest extends BriarTestCase {
|
||||
@Test
|
||||
public void testForumPostFitsIntoPacket() throws Exception {
|
||||
// Create a maximum-length author
|
||||
String authorName = TestUtils.getRandomString(
|
||||
String authorName = StringUtils.getRandomString(
|
||||
MAX_AUTHOR_NAME_LENGTH);
|
||||
byte[] authorPublic = new byte[MAX_PUBLIC_KEY_LENGTH];
|
||||
PrivateKey privateKey = crypto.generateSignatureKeyPair().getPrivate();
|
||||
@@ -76,7 +76,7 @@ public class MessageSizeIntegrationTest extends BriarTestCase {
|
||||
GroupId groupId = new GroupId(getRandomId());
|
||||
long timestamp = Long.MAX_VALUE;
|
||||
MessageId parent = new MessageId(getRandomId());
|
||||
String body = TestUtils.getRandomString(MAX_FORUM_POST_BODY_LENGTH);
|
||||
String body = StringUtils.getRandomString(MAX_FORUM_POST_BODY_LENGTH);
|
||||
ForumPost post = forumPostFactory.createPost(groupId,
|
||||
timestamp, parent, author, body);
|
||||
// Check the size of the serialised message
|
||||
|
||||
@@ -4,8 +4,8 @@ import org.briarproject.bramble.api.FormatException;
|
||||
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.TestUtils;
|
||||
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;
|
||||
@@ -48,7 +48,7 @@ public class PrivateMessageValidatorTest extends ValidatorTestCase {
|
||||
PrivateMessageValidator v = new PrivateMessageValidator(clientHelper,
|
||||
metadataEncoder, clock);
|
||||
String invalidContent =
|
||||
TestUtils.getRandomString(MAX_PRIVATE_MESSAGE_BODY_LENGTH + 1);
|
||||
StringUtils.getRandomString(MAX_PRIVATE_MESSAGE_BODY_LENGTH + 1);
|
||||
v.validateMessage(message, group, BdfList.of(invalidContent));
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public class PrivateMessageValidatorTest extends ValidatorTestCase {
|
||||
PrivateMessageValidator v = new PrivateMessageValidator(clientHelper,
|
||||
metadataEncoder, clock);
|
||||
String content =
|
||||
TestUtils.getRandomString(MAX_PRIVATE_MESSAGE_BODY_LENGTH);
|
||||
StringUtils.getRandomString(MAX_PRIVATE_MESSAGE_BODY_LENGTH);
|
||||
BdfMessageContext messageContext =
|
||||
v.validateMessage(message, group, BdfList.of(content));
|
||||
assertExpectedContext(messageContext);
|
||||
|
||||
@@ -26,7 +26,7 @@ import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_K
|
||||
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_SIGNATURE_LENGTH;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomString;
|
||||
import static org.briarproject.bramble.util.StringUtils.getRandomString;
|
||||
import static org.briarproject.briar.api.privategroup.GroupMessageFactory.SIGNING_LABEL_JOIN;
|
||||
import static org.briarproject.briar.api.privategroup.GroupMessageFactory.SIGNING_LABEL_POST;
|
||||
import static org.briarproject.briar.api.privategroup.MessageType.JOIN;
|
||||
|
||||
@@ -48,7 +48,7 @@ import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
|
||||
import static org.briarproject.bramble.api.sync.SyncConstants.MESSAGE_HEADER_LENGTH;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomString;
|
||||
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_NAME_LENGTH;
|
||||
import static org.briarproject.briar.api.privategroup.invitation.GroupInvitationManager.CLIENT_ID;
|
||||
|
||||
@@ -23,7 +23,7 @@ import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_K
|
||||
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_SIGNATURE_LENGTH;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomString;
|
||||
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_NAME_LENGTH;
|
||||
|
||||
@@ -6,6 +6,7 @@ import org.briarproject.bramble.api.data.BdfList;
|
||||
import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.identity.AuthorId;
|
||||
import org.briarproject.bramble.test.TestUtils;
|
||||
import org.briarproject.bramble.util.StringUtils;
|
||||
import org.briarproject.briar.api.blog.Blog;
|
||||
import org.jmock.Expectations;
|
||||
import org.junit.Test;
|
||||
@@ -19,14 +20,14 @@ import static org.briarproject.briar.sharing.MessageType.INVITE;
|
||||
public class BlogSharingValidatorTest extends SharingValidatorTest {
|
||||
|
||||
private final AuthorId authorId = new AuthorId(getRandomId());
|
||||
private final String authorName = TestUtils.getRandomString(42);
|
||||
private final String authorName = StringUtils.getRandomString(42);
|
||||
private final byte[] publicKey =
|
||||
TestUtils.getRandomBytes(MAX_PUBLIC_KEY_LENGTH);
|
||||
private final Author author = new Author(authorId, authorName, publicKey);
|
||||
private final Blog blog = new Blog(group, author, false);
|
||||
private final BdfList descriptor = BdfList.of(authorName, publicKey, false);
|
||||
private final String content =
|
||||
TestUtils.getRandomString(MAX_INVITATION_MESSAGE_LENGTH);
|
||||
StringUtils.getRandomString(MAX_INVITATION_MESSAGE_LENGTH);
|
||||
|
||||
@Override
|
||||
SharingValidator getValidator() {
|
||||
@@ -88,7 +89,7 @@ public class BlogSharingValidatorTest extends SharingValidatorTest {
|
||||
|
||||
@Test
|
||||
public void testAcceptsMinLengthBlogName() throws Exception {
|
||||
String shortBlogName = TestUtils.getRandomString(1);
|
||||
String shortBlogName = StringUtils.getRandomString(1);
|
||||
BdfList validDescriptor = BdfList.of(shortBlogName, publicKey, false);
|
||||
expectCreateBlog(shortBlogName, publicKey);
|
||||
expectEncodeMetadata(INVITE);
|
||||
@@ -101,7 +102,7 @@ public class BlogSharingValidatorTest extends SharingValidatorTest {
|
||||
@Test(expected = FormatException.class)
|
||||
public void testRejectsTooLongBlogName() throws Exception {
|
||||
String invalidBlogName =
|
||||
TestUtils.getRandomString(MAX_BLOG_NAME_LENGTH + 1);
|
||||
StringUtils.getRandomString(MAX_BLOG_NAME_LENGTH + 1);
|
||||
BdfList invalidDescriptor =
|
||||
BdfList.of(invalidBlogName, publicKey, false);
|
||||
v.validateMessage(message, group,
|
||||
@@ -167,7 +168,7 @@ public class BlogSharingValidatorTest extends SharingValidatorTest {
|
||||
@Test(expected = FormatException.class)
|
||||
public void testRejectsTooLongContent() throws Exception {
|
||||
String invalidContent =
|
||||
TestUtils.getRandomString(MAX_INVITATION_MESSAGE_LENGTH + 1);
|
||||
StringUtils.getRandomString(MAX_INVITATION_MESSAGE_LENGTH + 1);
|
||||
expectCreateBlog(authorName, publicKey);
|
||||
v.validateMessage(message, group,
|
||||
BdfList.of(INVITE.getValue(), previousMsgId, descriptor,
|
||||
|
||||
@@ -37,7 +37,7 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomString;
|
||||
import static org.briarproject.bramble.util.StringUtils.getRandomString;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@@ -4,6 +4,7 @@ import org.briarproject.bramble.api.FormatException;
|
||||
import org.briarproject.bramble.api.client.BdfMessageContext;
|
||||
import org.briarproject.bramble.api.data.BdfList;
|
||||
import org.briarproject.bramble.test.TestUtils;
|
||||
import org.briarproject.bramble.util.StringUtils;
|
||||
import org.briarproject.briar.api.forum.Forum;
|
||||
import org.jmock.Expectations;
|
||||
import org.junit.Test;
|
||||
@@ -16,12 +17,12 @@ import static org.briarproject.briar.sharing.MessageType.INVITE;
|
||||
public class ForumSharingValidatorTest extends SharingValidatorTest {
|
||||
|
||||
private final String forumName =
|
||||
TestUtils.getRandomString(MAX_FORUM_NAME_LENGTH);
|
||||
StringUtils.getRandomString(MAX_FORUM_NAME_LENGTH);
|
||||
private final byte[] salt = TestUtils.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 =
|
||||
TestUtils.getRandomString(MAX_INVITATION_MESSAGE_LENGTH);
|
||||
StringUtils.getRandomString(MAX_INVITATION_MESSAGE_LENGTH);
|
||||
|
||||
@Override
|
||||
SharingValidator getValidator() {
|
||||
@@ -83,7 +84,7 @@ public class ForumSharingValidatorTest extends SharingValidatorTest {
|
||||
|
||||
@Test
|
||||
public void testAcceptsMinLengthForumName() throws Exception {
|
||||
String shortForumName = TestUtils.getRandomString(1);
|
||||
String shortForumName = StringUtils.getRandomString(1);
|
||||
BdfList validDescriptor = BdfList.of(shortForumName, salt);
|
||||
expectCreateForum(shortForumName);
|
||||
expectEncodeMetadata(INVITE);
|
||||
@@ -96,7 +97,7 @@ public class ForumSharingValidatorTest extends SharingValidatorTest {
|
||||
@Test(expected = FormatException.class)
|
||||
public void testRejectsTooLongForumName() throws Exception {
|
||||
String invalidForumName =
|
||||
TestUtils.getRandomString(MAX_FORUM_NAME_LENGTH + 1);
|
||||
StringUtils.getRandomString(MAX_FORUM_NAME_LENGTH + 1);
|
||||
BdfList invalidDescriptor = BdfList.of(invalidForumName, salt);
|
||||
v.validateMessage(message, group,
|
||||
BdfList.of(INVITE.getValue(), previousMsgId, invalidDescriptor,
|
||||
@@ -157,7 +158,7 @@ public class ForumSharingValidatorTest extends SharingValidatorTest {
|
||||
@Test(expected = FormatException.class)
|
||||
public void testRejectsTooLongContent() throws Exception {
|
||||
String invalidContent =
|
||||
TestUtils.getRandomString(MAX_INVITATION_MESSAGE_LENGTH + 1);
|
||||
StringUtils.getRandomString(MAX_INVITATION_MESSAGE_LENGTH + 1);
|
||||
expectCreateForum(forumName);
|
||||
v.validateMessage(message, group,
|
||||
BdfList.of(INVITE.getValue(), previousMsgId, descriptor,
|
||||
|
||||
Reference in New Issue
Block a user