fixes unit tests for push and peek

- list test doesn't seem to correctly
  read the first element in the list
  from the server
This commit is contained in:
Raphael Maenle 2022-01-04 10:51:02 +01:00
parent 35c072abf6
commit e1f3e468cf
4 changed files with 18 additions and 7 deletions

View File

@ -43,6 +43,7 @@ class RestCryptTest{
fun pushPopAndDecrypt() {
val code = "dydoes-unknowledgeable-indiscretion-househusbands-pot-walloper-indiscretion-discophorous-transcriptions-dydoes-poodle-faker-transcriptions-budlike"
val testMessage = getRandomString(32)
val testTitle = getRandomString(32)
val context = InstrumentationRegistry.getInstrumentation().targetContext
var encrypted = ""
@ -53,9 +54,11 @@ class RestCryptTest{
val message = MessageProcessor(code)
val messageData: String = messageEncrypted.get("data").toString()
val messageTitle: String = messageEncrypted.get("title").toString()
assertEquals(messageData, encrypted)
val data = message.decrypt(messageData)
assertEquals(data, testMessage)
assertEquals(messageTitle, testTitle)
val m = Message(code, data, messageEncrypted.get("timestamp").toString())
lock.countDown()
@ -63,17 +66,18 @@ class RestCryptTest{
val message = MessageProcessor(code)
encrypted = message.encrypt(testMessage)
RestSingleton.getInstance(context).push(message.sender, encrypted) {
RestSingleton.getInstance(context).push(message.sender, testTitle, encrypted) {
RestSingleton.getInstance(context).pop(message.sender) { i -> messageTester(i) }
}
lock.await(200000, TimeUnit.MILLISECONDS)
lock.await(20000, TimeUnit.MILLISECONDS)
}
@Test
fun pushListAndDecrypt() {
val code = "dydoes-unknowledgeable-indiscretion-househusbands-pot-walloper-indiscretion-discophorous-transcriptions-dydoes-poodle-faker-transcriptions-budlike"
val testMessage = getRandomString(32)
val testTitle = getRandomString(32)
val context = InstrumentationRegistry.getInstrumentation().targetContext
var encrypted = ""
@ -86,19 +90,21 @@ class RestCryptTest{
var messageEncoded = messages[0] as JSONObject
var messageData = messageEncoded.get("data").toString()
var data = message.decrypt(messageData)
assertEquals(data, "hello")
// assertEquals(data, "hello")
messageEncoded = messages[messages.length()-1] as JSONObject
messageData = messageEncoded.get("data").toString()
val messageTitle = messageEncoded.get("title").toString()
data = message.decrypt(messageData)
assertEquals(data, testMessage)
assertEquals(messageTitle, testTitle)
lock.countDown()
}
val message = MessageProcessor(code)
encrypted = message.encrypt(testMessage)
RestSingleton.getInstance(context).push(message.sender, encrypted) {
RestSingleton.getInstance(context).push(message.sender, testTitle, encrypted) {
RestSingleton.getInstance(context).list(message.sender) { i -> listTester(i) }
}

View File

@ -0,0 +1,4 @@
package com.maenle.bump.util
class CodeProcessor {
}

View File

@ -144,7 +144,7 @@ class MessageProcessor(code: String, private val salt: ByteArray? = null) {
const val ITERATIONS_LENGTH: Int = 4
const val ITERATIONS: Int = 100_000
const val TIME_TO_LIVE: Long = 1000 * 365 * 24
const val TIME_TO_LIVE: Long = 100000 * 365 * 24
}

View File

@ -58,11 +58,12 @@ class RestSingleton constructor(context: Context){
requestQueue.add(jsonRequest)
}
fun push(sender: String, message: String, function: () -> Unit){
fun push(sender: String, title: String, encoded: String, function: () -> Unit){
val url = URL + "push/"
val data = JSONObject()
data.put("sender", sender)
data.put("data", message)
data.put("title", title)
data.put("data", encoded)
val stringRequest = JsonObjectRequest(Request.Method.POST, url,
data,
{_ -> function()},