2015-11-18 18:09:39 -08:00
|
|
|
package org.thoughtcrime.securesms.service;
|
|
|
|
|
|
|
|
import org.junit.Before;
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.thoughtcrime.securesms.BaseUnitTest;
|
2018-12-12 13:12:44 -08:00
|
|
|
import org.whispersystems.libsignal.util.guava.Optional;
|
2015-11-18 18:09:39 -08:00
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map.Entry;
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertEquals;
|
2018-12-12 13:12:44 -08:00
|
|
|
import static org.junit.Assert.assertTrue;
|
2015-11-18 18:09:39 -08:00
|
|
|
import static org.mockito.Matchers.anyBoolean;
|
|
|
|
import static org.mockito.Matchers.contains;
|
|
|
|
import static org.mockito.Mockito.when;
|
|
|
|
|
2018-12-12 13:12:44 -08:00
|
|
|
public class VerificationCodeParserTest extends BaseUnitTest {
|
2015-11-18 18:09:39 -08:00
|
|
|
private static Map<String, String> CHALLENGES = new HashMap<String,String>() {{
|
|
|
|
put("Your TextSecure verification code: 337-337", "337337");
|
|
|
|
put("XXX\nYour TextSecure verification code: 1337-1337", "13371337");
|
|
|
|
put("Your TextSecure verification code: 337-1337", "3371337");
|
|
|
|
put("Your TextSecure verification code: 1337-337", "1337337");
|
|
|
|
put("Your TextSecure verification code: 1337-1337", "13371337");
|
|
|
|
put("XXXYour TextSecure verification code: 1337-1337", "13371337");
|
|
|
|
put("Your TextSecure verification code: 1337-1337XXX", "13371337");
|
2016-03-23 23:47:13 +01:00
|
|
|
put("Your TextSecure verification code 1337-1337", "13371337");
|
2016-03-17 19:58:35 +01:00
|
|
|
|
|
|
|
put("Your Signal verification code: 337-337", "337337");
|
|
|
|
put("XXX\nYour Signal verification code: 1337-1337", "13371337");
|
|
|
|
put("Your Signal verification code: 337-1337", "3371337");
|
|
|
|
put("Your Signal verification code: 1337-337", "1337337");
|
|
|
|
put("Your Signal verification code: 1337-1337", "13371337");
|
|
|
|
put("XXXYour Signal verification code: 1337-1337", "13371337");
|
|
|
|
put("Your Signal verification code: 1337-1337XXX", "13371337");
|
2016-03-23 23:47:13 +01:00
|
|
|
put("Your Signal verification code 1337-1337", "13371337");
|
2015-11-18 18:09:39 -08:00
|
|
|
|
2018-12-12 13:12:44 -08:00
|
|
|
put("<#>Your Signal verification code: 1337-1337 aAbBcCdDeEf", "13371337");
|
|
|
|
put("<#> Your Signal verification code: 1337-1337 aAbBcCdDeEf", "13371337");
|
|
|
|
put("<#>Your Signal verification code: 1337-1337\naAbBcCdDeEf", "13371337");
|
|
|
|
put("<#> Your Signal verification code: 1337-1337\naAbBcCdDeEf", "13371337");
|
|
|
|
put("<#> Your Signal verification code: 1337-1337\n\naAbBcCdDeEf", "13371337");
|
|
|
|
}};
|
2015-11-18 18:09:39 -08:00
|
|
|
|
|
|
|
@Before
|
|
|
|
@Override
|
|
|
|
public void setUp() throws Exception {
|
|
|
|
super.setUp();
|
|
|
|
when(sharedPreferences.getBoolean(contains("pref_verifying"), anyBoolean())).thenReturn(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2018-12-12 13:12:44 -08:00
|
|
|
public void testChallenges() {
|
2015-11-18 18:09:39 -08:00
|
|
|
for (Entry<String,String> challenge : CHALLENGES.entrySet()) {
|
2018-12-12 13:12:44 -08:00
|
|
|
Optional<String> result = VerificationCodeParser.parse(context, challenge.getKey());
|
|
|
|
|
|
|
|
assertTrue(result.isPresent());
|
|
|
|
assertEquals(result.get(), challenge.getValue());
|
2015-11-18 18:09:39 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|