Skip to content

Commit

Permalink
Added message validation
Browse files Browse the repository at this point in the history
  • Loading branch information
quadcopterman committed Jun 27, 2024
1 parent 147f0be commit 20998ca
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.github.dedis.popstellar.model.network.method.message.MessageGeneral
import com.github.dedis.popstellar.model.network.method.message.data.Action
import com.github.dedis.popstellar.model.network.method.message.data.Data
import com.github.dedis.popstellar.model.network.method.message.data.Objects
import com.github.dedis.popstellar.utility.MessageValidator
import com.google.gson.annotations.SerializedName

/** Informs about the result of the authentication procedure */
Expand Down Expand Up @@ -35,6 +36,7 @@ class FederationResult
}
else -> throw IllegalArgumentException("Status must be either '$FAILURE' or '$SUCCESS'.")
}
MessageValidator.verify().validMessage(challenge)
}

override val `object`: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.github.dedis.popstellar.model.network.method.message.data.federation
import com.github.dedis.popstellar.model.network.method.message.data.Action
import com.github.dedis.popstellar.model.network.method.message.data.Data
import com.github.dedis.popstellar.model.network.method.message.data.Objects
import com.github.dedis.popstellar.utility.MessageValidator
import com.google.gson.annotations.SerializedName

/** Token exchange to be broadcast in the LAO */
Expand All @@ -21,6 +22,12 @@ class TokensExchange
val tokens: Array<String>,
val timestamp: Long
) : Data {

init {
MessageValidator.verify().isBase64(rollCallId, "rollCallId")
MessageValidator.verify().validPastTimes(timestamp)
}

override val `object`: String
get() = Objects.FEDERATION.`object`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class TokensExchangeTest {
Assert.assertEquals(TK_EXCHANGE.hashCode().toLong(), tokensExchange2.hashCode().toLong())

val tokensExchange3 = TokensExchange(Lao.generateLaoId(ORGANIZER, CREATION, "LAO2"), ROLL_CALL_ID, TOKENS, TIMESTAMP)
val tokensExchange4 = TokensExchange(LAO_ID, "RC2", TOKENS, TIMESTAMP)
val tokensExchange4 = TokensExchange(LAO_ID, "UkMy", TOKENS, TIMESTAMP)
val tokensExchange5 = TokensExchange(LAO_ID, ROLL_CALL_ID, arrayOf("token1"), TIMESTAMP)
Assert.assertNotEquals(TK_EXCHANGE, tokensExchange3)
Assert.assertNotEquals(TK_EXCHANGE, tokensExchange4)
Expand All @@ -69,7 +69,7 @@ class TokensExchangeTest {
private val CREATION = Instant.now().epochSecond
private const val NAME = "Lao name"
private val LAO_ID = Lao.generateLaoId(ORGANIZER, CREATION, NAME)
private val ROLL_CALL_ID = "RC1"
private val ROLL_CALL_ID = "UkMx"
private val TOKENS = arrayOf("token1", "token2", "token3")
private val TIMESTAMP = Instant.now().epochSecond
private val TK_EXCHANGE = TokensExchange(LAO_ID, ROLL_CALL_ID, TOKENS, TIMESTAMP)
Expand Down

0 comments on commit 20998ca

Please sign in to comment.