Skip to content

Conversation

onsriahi14
Copy link
Contributor

@onsriahi14 onsriahi14 commented May 12, 2024

This PR defines :

  • FederationInit message
  • FederationExpect Message
  • FederationChallengeRequest message
  • FederationChallenge message
  • FederationResult message
  • Their respective JsonReader and JsonWriter
    It also includes examples of each message and some unit tests

@onsriahi14 onsriahi14 requested a review from a team as a code owner May 12, 2024 12:01
@onsriahi14 onsriahi14 requested review from t1b00 and removed request for a team May 12, 2024 12:01
Copy link

Pull reviewers stats

Stats of the last 30 days for popstellar:

User Total reviews Time to review Total comments
K1li4nL
🥇
9
▀▀
4d 5h 54m
36
▀▀▀
arnauds5
🥈
7
3d 22h 51m
21
▀▀
t1b00
🥉
4
18h 56m
8
pierluca
3
10d 21h 31m
11
simone-kalbermatter
3
1d 15h 1m
2
matteosz
3
4d 1h 36m
2
Tyratox
2
13d 22h 35m
13
1florentin
2
8d 13h 48m
6
MariemBaccari
2
1d 5h 39m
0
ljankoschek
2
18m
0
onsriahi14
2
9h 31m
0
DanielTavaresA
2
8d 4h 48m
5
quadcopterman
2
3d 22h 58m
0
Kaz-ookid
2
15d 1h 34m
▀▀
6
4xiom5
1
12d 4h 52m
0
sgueissa
1
25m
0
osm-alt
1
6d 1h 13m
11
⚡️ Pull request stats

Base automatically changed from work-federation-protocol to master May 13, 2024 11:48
Copy link
Collaborator

@DanielTavaresA DanielTavaresA left a 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"
Copy link
Collaborator

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

Comment on lines 489 to 493
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"

Copy link
Collaborator

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"

Comment on lines 519 to 522
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"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same remark as federationExpect

Comment on lines 569 to 572
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"
Copy link
Collaborator

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]])
Copy link
Collaborator

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]
}

Comment on lines 31 to 33
case challenge_request extends ActionType("challenge_request")
case challenge extends ActionType("challenge")
case federation_result extends ActionType("federation_result")
Copy link
Collaborator

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")
Copy link
Collaborator

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.
Copy link
Collaborator

@DanielTavaresA DanielTavaresA left a 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)
}
Copy link
Collaborator

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

Copy link
Contributor

@K1li4nL K1li4nL left a 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

Copy link

Quality Gate Passed Quality Gate passed for 'PoP - PoPCHA-Web-Client'

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

Copy link
Contributor

@K1li4nL K1li4nL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM !

Copy link

Copy link

Quality Gate Passed Quality Gate passed for 'PoP - Be1-Go'

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

Copy link

Quality Gate Passed Quality Gate passed for 'PoP - Fe1-Web'

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

Copy link

Quality Gate Passed Quality Gate passed for 'PoP - Fe2-Android'

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

@onsriahi14 onsriahi14 enabled auto-merge May 17, 2024 10:07
Copy link
Collaborator

@DanielTavaresA DanielTavaresA left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work ! LGTM

@onsriahi14 onsriahi14 added this pull request to the merge queue May 17, 2024
Merged via the queue into master with commit abf0af1 May 17, 2024
@onsriahi14 onsriahi14 deleted the work-be2-ons-authentication-protocol-messages branch May 17, 2024 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants