Skip to content

Commit

Permalink
fix(message): added tst and created_at to lwt message
Browse files Browse the repository at this point in the history
Fixes #1766
  • Loading branch information
growse committed Jul 26, 2024
1 parent ca151d2 commit 67a5306
Show file tree
Hide file tree
Showing 25 changed files with 68 additions and 42 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Version 2.5.1

### Bug fixes

- Re-added `tst` from Lwt MQTT message type that was accidentally dropped in 2.5.0 (#1766)

## Version 2.5.0

### Breaking changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
import org.owntracks.android.R
import org.owntracks.android.model.Parser
import org.owntracks.android.model.messages.MessageLocation
import org.owntracks.android.services.BackgroundService
import org.owntracks.android.support.Parser
import org.owntracks.android.testutils.GPSMockDeviceLocation
import org.owntracks.android.testutils.MockDeviceLocation
import org.owntracks.android.testutils.TestWithAnActivity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ import org.junit.Test
import org.junit.runner.RunWith
import org.owntracks.android.R
import org.owntracks.android.model.BatteryStatus
import org.owntracks.android.model.Parser
import org.owntracks.android.model.messages.MessageCard
import org.owntracks.android.model.messages.MessageLocation
import org.owntracks.android.model.messages.MessageWaypoints
import org.owntracks.android.preferences.Preferences
import org.owntracks.android.preferences.types.MonitoringMode
import org.owntracks.android.support.Parser
import org.owntracks.android.testutils.GPSMockDeviceLocation
import org.owntracks.android.testutils.MockDeviceLocation
import org.owntracks.android.testutils.OWNTRACKS_ICON_BASE64
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import org.junit.Test
import org.junit.runner.RunWith
import org.owntracks.android.R
import org.owntracks.android.model.CommandAction
import org.owntracks.android.model.Parser
import org.owntracks.android.model.messages.MessageCmd
import org.owntracks.android.model.messages.MessageConfiguration
import org.owntracks.android.model.messages.MessageLocation
Expand All @@ -28,7 +29,6 @@ import org.owntracks.android.model.messages.MessageWaypoint
import org.owntracks.android.model.messages.MessageWaypoints
import org.owntracks.android.preferences.Preferences
import org.owntracks.android.support.MessageWaypointCollection
import org.owntracks.android.support.Parser
import org.owntracks.android.testutils.GPSMockDeviceLocation
import org.owntracks.android.testutils.MockDeviceLocation
import org.owntracks.android.testutils.TestWithAnActivity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.owntracks.android.R
import org.owntracks.android.model.Parser
import org.owntracks.android.model.messages.MessageCard
import org.owntracks.android.model.messages.MessageLocation
import org.owntracks.android.model.messages.MessageTransition
import org.owntracks.android.support.Parser
import org.owntracks.android.testutils.GPSMockDeviceLocation
import org.owntracks.android.testutils.MockDeviceLocation
import org.owntracks.android.testutils.TestWithAnActivity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import mqtt.packets.mqtt.MQTTPublish
import mqtt.packets.mqttv5.MQTT5Properties
import org.eclipse.paho.client.mqttv3.internal.websocket.Base64
import org.owntracks.android.R
import org.owntracks.android.model.Parser
import org.owntracks.android.model.messages.MessageBase
import org.owntracks.android.support.Parser
import org.owntracks.android.ui.clickOnAndWait
import org.owntracks.android.ui.preferences.load.LoadActivity
import timber.log.Timber
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import mqtt.packets.mqttv5.MQTT5Properties
import org.junit.Test
import org.junit.runner.RunWith
import org.owntracks.android.R
import org.owntracks.android.model.Parser
import org.owntracks.android.model.messages.MessageCard
import org.owntracks.android.model.messages.MessageClear
import org.owntracks.android.model.messages.MessageLocation
import org.owntracks.android.preferences.Preferences
import org.owntracks.android.preferences.types.MonitoringMode
import org.owntracks.android.support.Parser
import org.owntracks.android.testutils.OWNTRACKS_ICON_BASE64
import org.owntracks.android.testutils.TestWithAnActivity
import org.owntracks.android.testutils.TestWithAnMQTTBroker
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
package org.owntracks.android.support;
package org.owntracks.android.model;

import static org.libsodium.jni.SodiumConstants.XSALSA20_POLY1305_SECRETBOX_KEYBYTES;
import static org.libsodium.jni.SodiumConstants.XSALSA20_POLY1305_SECRETBOX_NONCEBYTES;

import android.util.Base64;

import androidx.annotation.NonNull;

import org.libsodium.jni.crypto.Random;
import org.libsodium.jni.crypto.SecretBox;
import org.owntracks.android.R;
import org.owntracks.android.preferences.Preferences;

import javax.inject.Singleton;
import java.util.Set;

import javax.inject.Inject;
import javax.inject.Singleton;

import timber.log.Timber;

import static org.libsodium.jni.SodiumConstants.XSALSA20_POLY1305_SECRETBOX_KEYBYTES;
import static org.libsodium.jni.SodiumConstants.XSALSA20_POLY1305_SECRETBOX_NONCEBYTES;

import java.util.List;
import java.util.Set;

@Singleton
public class EncryptionProvider {
private static final int crypto_secretbox_NONCEBYTES = XSALSA20_POLY1305_SECRETBOX_NONCEBYTES;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.owntracks.android.model

import java.time.Instant
import org.owntracks.android.model.messages.Clock

class FakeFixedClock(fakeTime: Instant = Instant.ofEpochMilli(25123)) : Clock {
override val time: Instant = fakeTime
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.owntracks.android.support
package org.owntracks.android.model

import com.fasterxml.jackson.core.JsonGenerator
import com.fasterxml.jackson.core.JsonParseException
Expand All @@ -12,7 +12,6 @@ import com.fasterxml.jackson.databind.SerializerProvider
import com.fasterxml.jackson.databind.deser.std.StdDeserializer
import com.fasterxml.jackson.databind.module.SimpleModule
import com.fasterxml.jackson.databind.ser.std.StdSerializer
import com.fasterxml.jackson.datatype.jsr310.ser.InstantSerializer
import java.io.IOException
import java.io.InputStream
import java.time.Instant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import com.fasterxml.jackson.annotation.JsonPropertyOrder
import com.fasterxml.jackson.annotation.JsonSubTypes
import com.fasterxml.jackson.annotation.JsonTypeInfo
import java.io.IOException
import org.owntracks.android.model.Parser
import org.owntracks.android.preferences.Preferences
import org.owntracks.android.preferences.types.ConnectionMode
import org.owntracks.android.support.Parser

@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.owntracks.android.model.messages

import org.owntracks.android.model.Parser
import org.owntracks.android.preferences.Preferences
import org.owntracks.android.support.Parser

class MessageClear : MessageBase(), MessageWithId {
override var messageId: MessageId = ZeroMessageId
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
package org.owntracks.android.model.messages

object MessageLwt : MessageBase(), MessageWithId {
const val TYPE = "lwt"
import com.fasterxml.jackson.annotation.JsonProperty

class MessageLwt(
private val messageWithCreatedAtImpl: MessageWithCreatedAt = MessageCreatedAtNow(RealClock())
) : MessageBase(), MessageWithId, MessageWithCreatedAt by messageWithCreatedAtImpl {
override var messageId: MessageId = ZeroMessageId

@JsonProperty("tst") var timestamp: Long = messageWithCreatedAtImpl.createdAt.epochSecond

override fun toString(): String = "[MessageLwt]"

companion object {
const val TYPE = "lwt"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import org.owntracks.android.data.EndpointState
import org.owntracks.android.data.repos.EndpointStateRepo
import org.owntracks.android.di.ApplicationScope
import org.owntracks.android.di.CoroutineScopes
import org.owntracks.android.model.Parser
import org.owntracks.android.model.messages.MessageBase
import org.owntracks.android.model.messages.MessageCard
import org.owntracks.android.model.messages.MessageLocation
Expand All @@ -33,7 +34,6 @@ import org.owntracks.android.net.OutgoingMessageSendingException
import org.owntracks.android.preferences.Preferences
import org.owntracks.android.preferences.types.ConnectionMode
import org.owntracks.android.services.MessageProcessor
import org.owntracks.android.support.Parser
import org.owntracks.android.support.SocketFactory
import org.owntracks.android.support.interfaces.ConfigurationIncompleteException
import timber.log.Timber
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import org.owntracks.android.data.EndpointState
import org.owntracks.android.data.repos.EndpointStateRepo
import org.owntracks.android.di.ApplicationScope
import org.owntracks.android.di.CoroutineScopes
import org.owntracks.android.model.Parser
import org.owntracks.android.model.messages.MessageBase
import org.owntracks.android.model.messages.MessageCard
import org.owntracks.android.model.messages.MessageClear
Expand All @@ -59,7 +60,6 @@ import org.owntracks.android.preferences.Preferences
import org.owntracks.android.preferences.types.ConnectionMode
import org.owntracks.android.services.MessageProcessor
import org.owntracks.android.services.worker.Scheduler
import org.owntracks.android.support.Parser
import org.owntracks.android.support.interfaces.ConfigurationIncompleteException
import org.owntracks.android.support.interfaces.StatefulServiceMessageProcessor
import org.owntracks.android.test.SimpleIdlingResource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import java.io.File
import java.io.IOException
import java.io.OutputStream
import java.util.concurrent.LinkedBlockingDeque
import org.owntracks.android.model.Parser
import org.owntracks.android.model.messages.MessageBase
import org.owntracks.android.model.messages.MessageEncrypted
import org.owntracks.android.model.messages.MessageUnknown
import org.owntracks.android.support.Parser
import timber.log.Timber

class BlockingDequeThatAlsoSometimesPersistsThingsToDiskMaybe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import org.owntracks.android.data.waypoints.WaypointsRepo
import org.owntracks.android.di.ApplicationScope
import org.owntracks.android.di.CoroutineScopes.IoDispatcher
import org.owntracks.android.model.CommandAction
import org.owntracks.android.model.Parser
import org.owntracks.android.model.messages.MessageBase
import org.owntracks.android.model.messages.MessageCard
import org.owntracks.android.model.messages.MessageClear
Expand All @@ -46,7 +47,6 @@ import org.owntracks.android.preferences.Preferences
import org.owntracks.android.preferences.Preferences.Companion.PREFERENCES_THAT_WIPE_QUEUE_AND_CONTACTS
import org.owntracks.android.preferences.types.ConnectionMode
import org.owntracks.android.services.worker.Scheduler
import org.owntracks.android.support.Parser
import org.owntracks.android.support.interfaces.ConfigurationIncompleteException
import org.owntracks.android.test.CountingIdlingResourceShim
import org.owntracks.android.test.IdlingResourceWithData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import javax.inject.Inject
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import org.owntracks.android.data.waypoints.WaypointsRepo
import org.owntracks.android.model.Parser
import org.owntracks.android.preferences.Preferences
import org.owntracks.android.support.MessageWaypointCollection
import org.owntracks.android.support.Parser
import timber.log.Timber

@HiltViewModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ import org.apache.commons.codec.binary.Base64
import org.apache.hc.core5.net.URIBuilder
import org.owntracks.android.data.waypoints.WaypointsRepo
import org.owntracks.android.di.CoroutineScopes
import org.owntracks.android.model.Parser
import org.owntracks.android.model.Parser.EncryptionException
import org.owntracks.android.model.messages.MessageConfiguration
import org.owntracks.android.model.messages.MessageWaypoints
import org.owntracks.android.preferences.Preferences
import org.owntracks.android.support.Parser
import org.owntracks.android.support.Parser.EncryptionException
import org.owntracks.android.test.SimpleIdlingResource
import timber.log.Timber

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.owntracks.android.support
package org.owntracks.android.model

import com.fasterxml.jackson.core.JsonParseException
import com.fasterxml.jackson.databind.ObjectMapper
Expand All @@ -17,9 +17,7 @@ import org.mockito.Mockito.`when`
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.mock
import org.owntracks.android.location.geofencing.Geofence
import org.owntracks.android.model.BatteryStatus
import org.owntracks.android.model.CommandAction
import org.owntracks.android.model.messages.Clock
import org.owntracks.android.model.Parser.EncryptionException
import org.owntracks.android.model.messages.MessageCard
import org.owntracks.android.model.messages.MessageClear
import org.owntracks.android.model.messages.MessageCmd
Expand All @@ -32,7 +30,6 @@ import org.owntracks.android.model.messages.MessageWaypoint
import org.owntracks.android.preferences.Preferences
import org.owntracks.android.preferences.types.MonitoringMode
import org.owntracks.android.preferences.types.MqttQos
import org.owntracks.android.support.Parser.EncryptionException

class ParserTest {
private val testId = "dummyTestId"
Expand Down Expand Up @@ -819,8 +816,4 @@ class ParserTest {
val parsed = parser.fromJson(msg) as MessageLocation
assertEquals(Instant.parse("2024-02-27T12:30:52Z"), parsed.createdAt)
}

inner class FakeFixedClock : Clock {
override val time: Instant = Instant.ofEpochMilli(25123)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.owntracks.android.model.messages

import org.junit.Assert.assertEquals
import org.junit.Test
import org.owntracks.android.model.FakeFixedClock

class MessageLwtTest {
@Test
fun `an lwt message has a timestamp and created_at which are equal`() {
val messageLwt = MessageLwt(MessageCreatedAtNow(FakeFixedClock()))
assertEquals(25, messageLwt.timestamp)
assert(messageLwt.timestamp == messageLwt.createdAt.epochSecond)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import org.mockito.Mockito.`when`
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.mock
import org.owntracks.android.data.repos.EndpointStateRepo
import org.owntracks.android.model.EncryptionProvider
import org.owntracks.android.model.Parser
import org.owntracks.android.model.messages.MessageCard
import org.owntracks.android.model.messages.MessageCmd
import org.owntracks.android.model.messages.MessageLocation
import org.owntracks.android.preferences.Preferences
import org.owntracks.android.services.MessageProcessor
import org.owntracks.android.support.EncryptionProvider
import org.owntracks.android.support.Parser
import org.owntracks.android.support.interfaces.ConfigurationIncompleteException

class HttpMessageProcessorEndpointTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import org.junit.Before
import org.junit.Test
import org.mockito.kotlin.mock
import org.owntracks.android.location.LocatorPriority
import org.owntracks.android.model.Parser
import org.owntracks.android.model.messages.MessageConfiguration
import org.owntracks.android.preferences.types.ConnectionMode
import org.owntracks.android.preferences.types.MonitoringMode
import org.owntracks.android.preferences.types.MqttProtocolLevel
import org.owntracks.android.preferences.types.MqttQos
import org.owntracks.android.support.Parser
import org.owntracks.android.test.SimpleIdlingResource

class ImportExportTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import kotlin.random.Random
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Test
import org.owntracks.android.model.Parser
import org.owntracks.android.model.messages.MessageLocation
import org.owntracks.android.support.Parser

class BlockingDequeueThatAlsoSometimesPersistsThingsToDiskMaybeTest {
private val parser = Parser(null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import org.junit.Test
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.mock
import org.owntracks.android.data.waypoints.InMemoryWaypointsRepo
import org.owntracks.android.model.Parser
import org.owntracks.android.preferences.InMemoryPreferencesStore
import org.owntracks.android.preferences.Preferences
import org.owntracks.android.preferences.PreferencesStore
import org.owntracks.android.support.Parser
import org.owntracks.android.test.SimpleIdlingResource

@OptIn(ExperimentalCoroutinesApi::class)
Expand Down

0 comments on commit 67a5306

Please sign in to comment.