Search in sources :

Example 1 with ChatMessage

use of de.tum.in.tumcampusapp.component.ui.chat.model.ChatMessage in project TumCampusApp by TCA-Team.

the class ChatMessageValidatorTestCase method testOneInvalidKey.

/**
 * Tests that a message is found valid regardless of the fact that there is one invalid
 * key in the list of public keys.
 */
@Test
public void testOneInvalidKey() {
    List<ChatPublicKey> list = new ArrayList<>();
    list.add(new ChatPublicKey("This is not a valid key"));
    list.add(publicKeyFixtures.get(0));
    validator = new ChatMessageValidator(list);
    ChatMessage message = messageFixtures.get(0);
    assertTrue(validator.validate(message));
}
Also used : ChatMessage(de.tum.in.tumcampusapp.component.ui.chat.model.ChatMessage) ArrayList(java.util.ArrayList) ChatPublicKey(de.tum.in.tumcampusapp.component.ui.chat.model.ChatPublicKey) ChatMessageValidator(de.tum.in.tumcampusapp.component.ui.chat.ChatMessageValidator) Test(org.junit.Test)

Example 2 with ChatMessage

use of de.tum.in.tumcampusapp.component.ui.chat.model.ChatMessage in project TumCampusApp by TCA-Team.

the class ChatMessageValidatorTestCase method testUnicodeKoreanValidMessageOneKey.

/**
 * Tests that a unicode (korean) message is correctly validated.
 */
@Test
public void testUnicodeKoreanValidMessageOneKey() {
    validator = new ChatMessageValidator(buildPubkeyList(0, 1));
    ChatMessage message = messageFixtures.get(2);
    assertTrue(validator.validate(message));
}
Also used : ChatMessage(de.tum.in.tumcampusapp.component.ui.chat.model.ChatMessage) ChatMessageValidator(de.tum.in.tumcampusapp.component.ui.chat.ChatMessageValidator) Test(org.junit.Test)

Example 3 with ChatMessage

use of de.tum.in.tumcampusapp.component.ui.chat.model.ChatMessage in project TumCampusApp by TCA-Team.

the class ChatMessageValidatorTestCase method testAsciiInvalidMessageOneKey.

/**
 * Tests that the validator finds an invalid signature attached to a message.
 * The signature is still a valid base64 string.
 */
@Test
public void testAsciiInvalidMessageOneKey() {
    validator = new ChatMessageValidator(buildPubkeyList(0, 1));
    ChatMessage message = messageFixtures.get(0);
    // Take a signature of a different message
    message.setSignature(messageFixtures.get(1).getSignature());
    assertFalse(validator.validate(message));
}
Also used : ChatMessage(de.tum.in.tumcampusapp.component.ui.chat.model.ChatMessage) ChatMessageValidator(de.tum.in.tumcampusapp.component.ui.chat.ChatMessageValidator) Test(org.junit.Test)

Example 4 with ChatMessage

use of de.tum.in.tumcampusapp.component.ui.chat.model.ChatMessage in project TumCampusApp by TCA-Team.

the class ChatMessageValidatorTestCase method buildChatMessage.

private ChatMessage buildChatMessage(String text, String signature) {
    ChatMessage message = new ChatMessage(text);
    message.setSignature(signature);
    return message;
}
Also used : ChatMessage(de.tum.in.tumcampusapp.component.ui.chat.model.ChatMessage)

Example 5 with ChatMessage

use of de.tum.in.tumcampusapp.component.ui.chat.model.ChatMessage in project TumCampusApp by TCA-Team.

the class ChatMessageValidatorTestCase method testInvalidBase64PublicKey.

/**
 * Tests that when the public key associated with the validator is not a valid
 * base64 string, the validator simply says the message is not valid.
 */
@Test
public void testInvalidBase64PublicKey() {
    List<ChatPublicKey> list = buildPubkeyList(0, 1);
    list.get(0).setKey("This is not valid base 64");
    validator = new ChatMessageValidator(list);
    ChatMessage message = messageFixtures.get(0);
    assertFalse(validator.validate(message));
}
Also used : ChatMessage(de.tum.in.tumcampusapp.component.ui.chat.model.ChatMessage) ChatPublicKey(de.tum.in.tumcampusapp.component.ui.chat.model.ChatPublicKey) ChatMessageValidator(de.tum.in.tumcampusapp.component.ui.chat.ChatMessageValidator) Test(org.junit.Test)

Aggregations

ChatMessage (de.tum.in.tumcampusapp.component.ui.chat.model.ChatMessage)19 Test (org.junit.Test)11 ChatMessageValidator (de.tum.in.tumcampusapp.component.ui.chat.ChatMessageValidator)7 RSASigner (de.tum.in.tumcampusapp.utils.RSASigner)4 Intent (android.content.Intent)2 ChatPublicKey (de.tum.in.tumcampusapp.component.ui.chat.model.ChatPublicKey)2 PendingIntent (android.app.PendingIntent)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 Gson (com.google.gson.Gson)1 AuthenticationManager (de.tum.in.tumcampusapp.api.app.AuthenticationManager)1 NoPrivateKey (de.tum.in.tumcampusapp.api.app.exception.NoPrivateKey)1 ChatMessageViewModel (de.tum.in.tumcampusapp.component.ui.chat.ChatMessageViewModel)1 ChatRoomsActivity (de.tum.in.tumcampusapp.component.ui.chat.activity.ChatRoomsActivity)1 ChatHistoryAdapter (de.tum.in.tumcampusapp.component.ui.chat.adapter.ChatHistoryAdapter)1 ChatMessageLocalRepository (de.tum.in.tumcampusapp.component.ui.chat.repository.ChatMessageLocalRepository)1 ChatMessageRemoteRepository (de.tum.in.tumcampusapp.component.ui.chat.repository.ChatMessageRemoteRepository)1 MainActivity (de.tum.in.tumcampusapp.component.ui.overview.MainActivity)1 TcaDb (de.tum.in.tumcampusapp.database.TcaDb)1