mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 11:49:04 +01:00
Merge branch '224-unique-author-id' into 'master'
Allow different identities to have the same contact. #224 Previous fix was incomplete, the DB still had a unique constraint on the author ID column of the contacts table. See merge request !91
This commit is contained in:
@@ -100,7 +100,6 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
+ " localAuthorId HASH NOT NULL,"
|
+ " localAuthorId HASH NOT NULL,"
|
||||||
+ " status INT NOT NULL,"
|
+ " status INT NOT NULL,"
|
||||||
+ " PRIMARY KEY (contactId),"
|
+ " PRIMARY KEY (contactId),"
|
||||||
+ " UNIQUE (authorId),"
|
|
||||||
+ " FOREIGN KEY (localAuthorId)"
|
+ " FOREIGN KEY (localAuthorId)"
|
||||||
+ " REFERENCES localAuthors (authorId)"
|
+ " REFERENCES localAuthors (authorId)"
|
||||||
+ " ON DELETE CASCADE)";
|
+ " ON DELETE CASCADE)";
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ import static org.briarproject.api.sync.ValidationManager.Validity.VALID;
|
|||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
@@ -1157,6 +1158,35 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
db.close();
|
db.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDifferentLocalPseudonymsCanHaveTheSameContact()
|
||||||
|
throws Exception {
|
||||||
|
AuthorId localAuthorId1 = new AuthorId(TestUtils.getRandomId());
|
||||||
|
LocalAuthor localAuthor1 = new LocalAuthor(localAuthorId1, "Carol",
|
||||||
|
new byte[MAX_PUBLIC_KEY_LENGTH], new byte[123], timestamp,
|
||||||
|
StorageStatus.ACTIVE);
|
||||||
|
|
||||||
|
Database<Connection> db = open(false);
|
||||||
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
|
// Add two local pseudonyms
|
||||||
|
db.addLocalAuthor(txn, localAuthor);
|
||||||
|
db.addLocalAuthor(txn, localAuthor1);
|
||||||
|
|
||||||
|
// Add the same contact for each local pseudonym
|
||||||
|
ContactId contactId = db.addContact(txn, author, localAuthorId);
|
||||||
|
ContactId contactId1 = db.addContact(txn, author, localAuthorId1);
|
||||||
|
|
||||||
|
// The contacts should be distinct
|
||||||
|
assertNotEquals(contactId, contactId1);
|
||||||
|
assertEquals(2, db.getContacts(txn).size());
|
||||||
|
assertEquals(1, db.getContacts(txn, localAuthorId).size());
|
||||||
|
assertEquals(1, db.getContacts(txn, localAuthorId1).size());
|
||||||
|
|
||||||
|
db.commitTransaction(txn);
|
||||||
|
db.close();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExceptionHandling() throws Exception {
|
public void testExceptionHandling() throws Exception {
|
||||||
Database<Connection> db = open(false);
|
Database<Connection> db = open(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user