Manage identities on Android, pick one per bookmark, and give identities their own nicknames
Settings -> Identities lists them and creates, imports (an identity file or a TeamSpeak 3 settings.db), exports, renames and removes them, picks the default and improves an identity's security level; the search runs on until reached or stopped, whichever page is on screen. The Connect screen and each bookmark choose the identity to connect with. An identity keeps a nickname and phonetic nickname, in TeamSpeak's own INI keys, on both clients. A connect goes by the bookmark's nickname, else the identity's, else the global one; the phonetic one is sent in clientinit. Imported bookmarks no longer copy their identity's nickname. IdentityStore is now safe to share with the thread a connect resolves its identity on, and imports and exports through streams for Android's document picker. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
package com.ts3client.config;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
|
||||
class IdentityStoreTest {
|
||||
|
||||
@TempDir
|
||||
Path dir;
|
||||
|
||||
@BeforeEach
|
||||
void freshProfile() {
|
||||
AppDirs.init(dir.toFile(), dir.resolve("chats"));
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void defaultProfile() {
|
||||
AppDirs.init(null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
void exportedIdentityImportsWithItsName() throws Exception {
|
||||
IdentityStore store = IdentityStore.load(new Settings());
|
||||
IdentityEntry original = store.generate("Žofia's key", 0);
|
||||
|
||||
ByteArrayOutputStream exported = new ByteArrayOutputStream();
|
||||
store.exportTo(original, exported);
|
||||
IdentityEntry imported = store.importStream(new ByteArrayInputStream(exported.toByteArray()), null);
|
||||
|
||||
assertEquals("Žofia's key", imported.getName());
|
||||
assertEquals(original.getUniqueId(), imported.getUniqueId());
|
||||
assertNotEquals(original.getId(), imported.getId());
|
||||
assertEquals(2, IdentityStore.load(new Settings()).all().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void nicknamesTravelWithTheIdentity() throws Exception {
|
||||
IdentityStore store = IdentityStore.load(new Settings());
|
||||
IdentityEntry original = store.generate("Work", 0);
|
||||
store.setNicknames(original, " Žofia ", "Zofia");
|
||||
|
||||
IdentityEntry reloaded = IdentityStore.load(new Settings()).byId(original.getId());
|
||||
assertEquals("Žofia", reloaded.getNickname());
|
||||
assertEquals("Zofia", reloaded.getPhoneticNickname());
|
||||
|
||||
ByteArrayOutputStream exported = new ByteArrayOutputStream();
|
||||
store.exportTo(original, exported);
|
||||
IdentityEntry imported = store.importStream(new ByteArrayInputStream(exported.toByteArray()), null);
|
||||
assertEquals("Žofia", imported.getNickname());
|
||||
assertEquals("Zofia", imported.getPhoneticNickname());
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenNameWinsOverTheFilesOwn() throws Exception {
|
||||
IdentityStore store = IdentityStore.load(new Settings());
|
||||
ByteArrayOutputStream exported = new ByteArrayOutputStream();
|
||||
store.exportTo(store.generate("First", 0), exported);
|
||||
|
||||
IdentityEntry imported = store.importStream(new ByteArrayInputStream(exported.toByteArray()), "Second");
|
||||
|
||||
assertEquals("Second", imported.getName());
|
||||
}
|
||||
}
|
||||
@@ -64,7 +64,8 @@ class TeamSpeakImporterTest {
|
||||
|
||||
Bookmark byId = all.get(2);
|
||||
assertEquals("/42", byId.channel);
|
||||
assertEquals("SyncTester", byId.nickname, "the default identity's nickname");
|
||||
assertEquals("", byId.nickname, "takes the identity's nickname as it connects");
|
||||
assertEquals("SyncTester", imported.getNickname());
|
||||
assertEquals("", byId.identityId, "connects with whatever the default identity is");
|
||||
assertEquals("SyncTester", settings.nickname);
|
||||
|
||||
@@ -88,7 +89,9 @@ class TeamSpeakImporterTest {
|
||||
|
||||
new TeamSpeakImporter(identities, bookmarks, settings).importAll(List.of(bookmark, identity));
|
||||
assertEquals(identities.all().get(0).getId(), bookmarks.all().get(0).identityId);
|
||||
assertEquals(identity.nickname(), bookmarks.all().get(0).nickname);
|
||||
assertEquals("", bookmarks.all().get(0).nickname);
|
||||
assertEquals(identity.nickname(), identities.all().get(0).getNickname());
|
||||
assertEquals(identity.phoneticNickname(), identities.all().get(0).getPhoneticNickname());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user