Search in sources :

Example 16 with ChatMessage

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

the class ChatMessageValidatorTestCase method testAsciiValidMessageOneKey.

/**
 * Tests that a valid ASCII-based message is correctly found as valid when
 * there is only one public key associated to the validator.
 */
@Test
public void testAsciiValidMessageOneKey() {
    validator = new ChatMessageValidator(buildPubkeyList(0, 1));
    ChatMessage message = messageFixtures.get(0);
    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 17 with ChatMessage

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

the class ChatMessageValidatorTestCase method testInvalidBase64Signature.

/**
 * Tests that when the signature is not a valid base64 string, the validator
 * simply says the message is not valid.
 */
@Test
public void testInvalidBase64Signature() {
    validator = new ChatMessageValidator(buildPubkeyList(0, 1));
    ChatMessage message = buildChatMessage("This is a message!", "This is not valid base64...");
    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 18 with ChatMessage

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

the class RSASignerTestCase method testPrivateKeyNull.

/**
 * Tests that when the private key associated with
 * the signer is null, the signer returns null.
 */
@Test
public void testPrivateKeyNull() {
    signer = new RSASigner(null);
    ChatMessage message = messageFixtures.get(0);
    assertThat(signer.sign(message.getText())).isNull();
}
Also used : ChatMessage(de.tum.in.tumcampusapp.component.ui.chat.model.ChatMessage) RSASigner(de.tum.in.tumcampusapp.utils.RSASigner) Test(org.junit.Test)

Example 19 with ChatMessage

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

the class RSASignerTestCase method testUnicodeKoreanMessageSigning.

/**
 * Tests that a unicode (korean) message is correctly signed.
 */
@Test
public void testUnicodeKoreanMessageSigning() {
    signer = new RSASigner(privateKeyFixture);
    ChatMessage message = messageFixtures.get(2);
    assertThat(signer.sign(message.getText())).isEqualTo(message.getSignature());
}
Also used : ChatMessage(de.tum.in.tumcampusapp.component.ui.chat.model.ChatMessage) RSASigner(de.tum.in.tumcampusapp.utils.RSASigner) 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