That fuck shit the fascists are using
at master 204 lines 7.6 kB view raw
1package org.tm.archive.database 2 3import androidx.test.ext.junit.runners.AndroidJUnit4 4import org.junit.Assert.assertEquals 5import org.junit.Assert.assertFalse 6import org.junit.Assert.assertNotEquals 7import org.junit.Rule 8import org.junit.Test 9import org.junit.runner.RunWith 10import org.signal.core.util.CursorUtil 11import org.tm.archive.profiles.ProfileName 12import org.tm.archive.recipients.RecipientId 13import org.tm.archive.testing.SignalActivityRule 14import org.whispersystems.signalservice.api.push.ServiceId.ACI 15import org.whispersystems.signalservice.api.push.ServiceId.PNI 16import java.util.UUID 17 18@RunWith(AndroidJUnit4::class) 19class RecipientTableTest { 20 21 @get:Rule 22 val harness = SignalActivityRule() 23 24 @Test 25 fun givenAHiddenRecipient_whenIQueryAllContacts_thenIExpectHiddenToBeReturned() { 26 val hiddenRecipient = harness.others[0] 27 SignalDatabase.recipients.setProfileName(hiddenRecipient, ProfileName.fromParts("Hidden", "Person")) 28 SignalDatabase.recipients.markHidden(hiddenRecipient) 29 30 val results = SignalDatabase.recipients.queryAllContacts("Hidden")!! 31 32 assertEquals(1, results.count) 33 } 34 35 @Test 36 fun givenAHiddenRecipient_whenIGetSignalContacts_thenIDoNotExpectHiddenToBeReturned() { 37 val hiddenRecipient = harness.others[0] 38 SignalDatabase.recipients.setProfileName(hiddenRecipient, ProfileName.fromParts("Hidden", "Person")) 39 SignalDatabase.recipients.markHidden(hiddenRecipient) 40 41 val results: MutableList<RecipientId> = SignalDatabase.recipients.getSignalContacts(false)?.use { 42 val ids = mutableListOf<RecipientId>() 43 while (it.moveToNext()) { 44 ids.add(RecipientId.from(CursorUtil.requireLong(it, RecipientTable.ID))) 45 } 46 47 ids 48 }!! 49 50 assertNotEquals(0, results.size) 51 assertFalse(hiddenRecipient in results) 52 } 53 54 @Test 55 fun givenAHiddenRecipient_whenIQuerySignalContacts_thenIDoNotExpectHiddenToBeReturned() { 56 val hiddenRecipient = harness.others[0] 57 SignalDatabase.recipients.setProfileName(hiddenRecipient, ProfileName.fromParts("Hidden", "Person")) 58 SignalDatabase.recipients.markHidden(hiddenRecipient) 59 60 val results = SignalDatabase.recipients.querySignalContacts(RecipientTable.ContactSearchQuery("Hidden", false))!! 61 62 assertEquals(0, results.count) 63 } 64 65 @Test 66 fun givenAHiddenRecipient_whenIQueryNonGroupContacts_thenIDoNotExpectHiddenToBeReturned() { 67 val hiddenRecipient = harness.others[0] 68 SignalDatabase.recipients.setProfileName(hiddenRecipient, ProfileName.fromParts("Hidden", "Person")) 69 SignalDatabase.recipients.markHidden(hiddenRecipient) 70 71 val results = SignalDatabase.recipients.queryNonGroupContacts("Hidden", false)!! 72 73 assertEquals(0, results.count) 74 } 75 76 @Test 77 fun givenAHiddenRecipient_whenIGetNonGroupContacts_thenIDoNotExpectHiddenToBeReturned() { 78 val hiddenRecipient = harness.others[0] 79 SignalDatabase.recipients.setProfileName(hiddenRecipient, ProfileName.fromParts("Hidden", "Person")) 80 SignalDatabase.recipients.markHidden(hiddenRecipient) 81 82 val results: MutableList<RecipientId> = SignalDatabase.recipients.getNonGroupContacts(false)?.use { 83 val ids = mutableListOf<RecipientId>() 84 while (it.moveToNext()) { 85 ids.add(RecipientId.from(CursorUtil.requireLong(it, RecipientTable.ID))) 86 } 87 88 ids 89 }!! 90 91 assertNotEquals(0, results.size) 92 assertFalse(hiddenRecipient in results) 93 } 94 95 @Test 96 fun givenABlockedRecipient_whenIQueryAllContacts_thenIDoNotExpectBlockedToBeReturned() { 97 val blockedRecipient = harness.others[0] 98 SignalDatabase.recipients.setProfileName(blockedRecipient, ProfileName.fromParts("Blocked", "Person")) 99 SignalDatabase.recipients.setBlocked(blockedRecipient, true) 100 101 val results = SignalDatabase.recipients.queryAllContacts("Blocked")!! 102 103 assertEquals(0, results.count) 104 } 105 106 @Test 107 fun givenABlockedRecipient_whenIGetSignalContacts_thenIDoNotExpectBlockedToBeReturned() { 108 val blockedRecipient = harness.others[0] 109 SignalDatabase.recipients.setProfileName(blockedRecipient, ProfileName.fromParts("Blocked", "Person")) 110 SignalDatabase.recipients.setBlocked(blockedRecipient, true) 111 112 val results: MutableList<RecipientId> = SignalDatabase.recipients.getSignalContacts(false)?.use { 113 val ids = mutableListOf<RecipientId>() 114 while (it.moveToNext()) { 115 ids.add(RecipientId.from(CursorUtil.requireLong(it, RecipientTable.ID))) 116 } 117 118 ids 119 }!! 120 121 assertNotEquals(0, results.size) 122 assertFalse(blockedRecipient in results) 123 } 124 125 @Test 126 fun givenABlockedRecipient_whenIQuerySignalContacts_thenIDoNotExpectBlockedToBeReturned() { 127 val blockedRecipient = harness.others[0] 128 SignalDatabase.recipients.setProfileName(blockedRecipient, ProfileName.fromParts("Blocked", "Person")) 129 SignalDatabase.recipients.setBlocked(blockedRecipient, true) 130 131 val results = SignalDatabase.recipients.querySignalContacts(RecipientTable.ContactSearchQuery("Blocked", false))!! 132 133 assertEquals(0, results.count) 134 } 135 136 @Test 137 fun givenABlockedRecipient_whenIQueryNonGroupContacts_thenIDoNotExpectBlockedToBeReturned() { 138 val blockedRecipient = harness.others[0] 139 SignalDatabase.recipients.setProfileName(blockedRecipient, ProfileName.fromParts("Blocked", "Person")) 140 SignalDatabase.recipients.setBlocked(blockedRecipient, true) 141 142 val results = SignalDatabase.recipients.queryNonGroupContacts("Blocked", false)!! 143 144 assertEquals(0, results.count) 145 } 146 147 @Test 148 fun givenABlockedRecipient_whenIGetNonGroupContacts_thenIDoNotExpectBlockedToBeReturned() { 149 val blockedRecipient = harness.others[0] 150 SignalDatabase.recipients.setProfileName(blockedRecipient, ProfileName.fromParts("Blocked", "Person")) 151 SignalDatabase.recipients.setBlocked(blockedRecipient, true) 152 153 val results: MutableList<RecipientId> = SignalDatabase.recipients.getNonGroupContacts(false)?.use { 154 val ids = mutableListOf<RecipientId>() 155 while (it.moveToNext()) { 156 ids.add(RecipientId.from(CursorUtil.requireLong(it, RecipientTable.ID))) 157 } 158 159 ids 160 }!! 161 162 assertNotEquals(0, results.size) 163 assertFalse(blockedRecipient in results) 164 } 165 166 @Test 167 fun givenARecipientWithPniAndAci_whenIMarkItUnregistered_thenIExpectItToBeSplit() { 168 val mainId = SignalDatabase.recipients.getAndPossiblyMerge(ACI_A, PNI_A, E164_A) 169 170 SignalDatabase.recipients.markUnregistered(mainId) 171 172 val byAci: RecipientId = SignalDatabase.recipients.getByAci(ACI_A).get() 173 174 val byE164: RecipientId = SignalDatabase.recipients.getByE164(E164_A).get() 175 val byPni: RecipientId = SignalDatabase.recipients.getByPni(PNI_A).get() 176 177 assertEquals(mainId, byAci) 178 assertEquals(byE164, byPni) 179 assertNotEquals(byAci, byE164) 180 } 181 182 @Test 183 fun givenARecipientWithPniAndAci_whenISplitItForStorageSync_thenIExpectItToBeSplit() { 184 val mainId = SignalDatabase.recipients.getAndPossiblyMerge(ACI_A, PNI_A, E164_A) 185 val mainRecord = SignalDatabase.recipients.getRecord(mainId) 186 187 SignalDatabase.recipients.splitForStorageSyncIfNecessary(mainRecord.aci!!) 188 189 val byAci: RecipientId = SignalDatabase.recipients.getByAci(ACI_A).get() 190 191 val byE164: RecipientId = SignalDatabase.recipients.getByE164(E164_A).get() 192 val byPni: RecipientId = SignalDatabase.recipients.getByPni(PNI_A).get() 193 194 assertEquals(mainId, byAci) 195 assertEquals(byE164, byPni) 196 assertNotEquals(byAci, byE164) 197 } 198 199 companion object { 200 val ACI_A = ACI.from(UUID.fromString("aaaa0000-5a76-47fa-a98a-7e72c948a82e")) 201 val PNI_A = PNI.from(UUID.fromString("aaaa1111-c960-4f6c-8385-671ad2ffb999")) 202 const val E164_A = "+12222222222" 203 } 204}