-
Notifications
You must be signed in to change notification settings - Fork 8
Add federation authentication protocol messages + tests + examples in Scala #1851
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add federation authentication protocol messages + tests + examples in Scala #1851
Conversation
…ion-protocol-implementation
…ion-protocol-implementation
…ion-protocol-messages
Pull reviewers statsStats of the last 30 days for popstellar:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First part of my review. Overall good code, just small inconsistencies between jsonRPC and scala.
|
||
implicit object FederationChallengeFormat extends JsonFormat[FederationChallenge] { | ||
final private val PARAM_CHALLENGE_VALUE: String = "value" | ||
final private val PARAM_CHALLENGE_VALID_UNTIL: String = "validUntil" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This field should match the one in the jsonRPC description : "valid_until". If not, when trying to parse a received message, an error will be thrown
final private val PARAM_ID: String = "laoId" | ||
final private val PARAM_SERVER_ADDRESS: String = "serverAddress" | ||
final private val PARAM_OTHER_ORGANIZER: String = "other_organizer" | ||
final private val PARAM_CHALLENGE: String = "challenge" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same remark as previously. The PARAM should match some keys in the RPC message defined. But once you extracted them, you can use them as you want in your object "FederationExpect". "laoId" -> "lao_id", "serverAddress" -> "server_address", "other_organizer" -> "public_key"
final private val PARAM_ID: String = "laoId" | ||
final private val PARAM_SERVER_ADDRESS: String = "serverAddress" | ||
final private val PARAM_OTHER_ORGANIZER: String = "other_organizer" | ||
final private val PARAM_CHALLENGE: String = "challenge" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same remark as federationExpect
final private val PARAM_STATUS: String = "status" | ||
final private val PARAM_REASON: String = "reason" | ||
final private val PARAM_ORGANIZER: String = "organizer" | ||
final private val PARAM_CHALLENGE_MESSAGE = "challenge_message" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same remark as before.
case JsString(r) => r | ||
} | ||
|
||
val organizer = jsObj.fields.get(PARAM_ORGANIZER).flatMap(_.convertTo[Option[PublicKey]]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit : can't the same logic as reason be applied here ?
val organizer = jsObj.fields.get(PARAM_ORGANIZER).collect {
case key @ JsString(_) => key.convertTo[PublicKey]
}
case challenge_request extends ActionType("challenge_request") | ||
case challenge extends ActionType("challenge") | ||
case federation_result extends ActionType("federation_result") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I am not mistaken, string should match actions from jsonRPC format. "federation_result" -> "result"
other_organizer: PublicKey, | ||
challenge: Message | ||
) extends MessageData { | ||
require(serverAddress.matches("^(ws|wss):\\/\\/.*(:\\\\d{0,5})?\\/.*$"), s"This is an invalid server address") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentionned during meeting, using "require" doesn't allow to handle errors gracefully. As you have this pattern on your jsonRPC, you could assume that if a message reaches here, it has the right format. Or you could try to handle it gracefully and return an error/default value in case of wrong format.
…tern check since having it in json schemas ensures that messages have the right format at this level.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one suggestion about tests to avoid finding bugs latter on. This suggestion applies to all tests about messages. After that LGTM
val request_challenge_ = FederationChallengeRequest.buildFromJson(CHALLENGE_REQUEST.toJson.toString) | ||
|
||
request_challenge_ should equal(CHALLENGE_REQUEST) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To test that your implementation works with the json examples you could add the json in the /util/examples/json and use readJsonFromPath. That way you can be sure that your implementation is correct with the messages defined in the protocol. Because a subtle bug could be that you are building from a json that you created, so your implementation work to read and write with object within the app, but not for the outside world. You can find some examples in other tests that use readJsonFromPath
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me overall, two issues I believe could be important otherwise a couple nitpicks
be2-scala/src/main/scala/ch/epfl/pop/model/network/method/message/data/ActionType.scala
Show resolved
Hide resolved
...c/main/scala/ch/epfl/pop/model/network/method/message/data/federation/FederationResult.scala
Outdated
Show resolved
Hide resolved
be2-scala/src/main/scala/ch/epfl/pop/model/objects/Base16Data.scala
Outdated
Show resolved
Hide resolved
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM !
|
|
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work ! LGTM
This PR defines :
It also includes examples of each message and some unit tests