Skip to content

Conversation

@paul-fresquet
Copy link
Contributor

@paul-fresquet paul-fresquet commented Dec 2, 2025

Summary

Complete implementation of protocol version validation to block connections between clients with incompatible versions.

Main Changes

Member-side validation

  • Early validation in OnPublicKeyCheckDataAskedAsync
  • Send InformProtocolVersionIncompatible notification when incompatible

SignalR notification flow

  • New InformProtocolVersionIncompatibleParameters class
  • New SignalR method and Azure Function endpoint
  • Client-side handler in HubPushHandler2

Server-side validation

  • Added IsProtocolVersionIncompatible in StartTrustCheckResult
  • Validation in StartTrustCheckCommandHandler

Integration tests

  • MockServerFacade and FakeHubPushHandler test helpers
  • 4 test scenarios covering all version compatibility cases

paul-fresquet and others added 30 commits November 30, 2025 08:36
- Add MockServerFacade and FakeHubPushHandler test helpers
- Add ProtocolVersion_IntegrationTests with 3 test scenarios:
  * Server returns protocol version incompatible
  * Server returns success
  * Joiner with incompatible version sends notification
- Mock IPublicKeysManager and ITrustProcessPublicKeysRepository to avoid blocking on async operations
# Conflicts:
#	tests/ByteSync.Client.UnitTests/Services/Communications/PublicKeysTrusterTests.cs
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements comprehensive protocol version validation to prevent connections between clients with incompatible protocol versions. The implementation spans server-side validation, client-side validation, SignalR notification infrastructure, and extensive test coverage.

Key Changes

  • Server-side validation: Added IsProtocolVersionIncompatible flag to StartTrustCheckResult and implemented version checking in StartTrustCheckCommandHandler to validate both joiner and member protocol versions before initiating trust checks
  • Member-side validation: Added early validation in PublicKeysTruster.OnPublicKeyCheckDataAskedAsync to check joiner's protocol version and send notification if incompatible
  • SignalR notification flow: Created InformProtocolVersionIncompatibleParameters class, new SignalR method in IHubByteSyncPush, Azure Function endpoint in TrustFunction, and client-side handler in HubPushHandler2 and PublicKeyCheckDataPushReceiver

Reviewed changes

Copilot reviewed 26 out of 26 changed files in this pull request and generated 15 comments.

Show a summary per file
File Description
src/ByteSync.Common/Business/Sessions/Cloud/Connections/StartTrustCheckResult.cs Added IsProtocolVersionIncompatible property to indicate version incompatibility
src/ByteSync.Common/Business/Sessions/Cloud/Connections/InformProtocolVersionIncompatibleParameters.cs New parameter class for protocol version incompatibility notifications
src/ByteSync.Common/Interfaces/Hub/IHubByteSyncPush.cs Added InformProtocolVersionIncompatible method to SignalR interface
src/ByteSync.ServerCommon/Commands/Trusts/StartTrustCheckCommandHandler.cs Implemented server-side validation logic for protocol versions
src/ByteSync.ServerCommon/Commands/Trusts/InformProtocolVersionIncompatibleRequest.cs New request class for MediatR command
src/ByteSync.ServerCommon/Commands/Trusts/InformProtocolVersionIncompatibleCommandHandler.cs Handler to forward incompatibility notifications to joiner
src/ByteSync.Functions/Http/TrustFunction.cs New Azure Function endpoint for protocol version notifications
src/ByteSync.Client/Business/Communications/PublicKeysTrusting/JoinerTrustProcessData.cs Added tracking for incompatible members and early termination logic
src/ByteSync.Client/Services/Communications/TrustProcessPublicKeysRepository.cs Added methods to set and check protocol version incompatibility
src/ByteSync.Client/Services/Communications/PublicKeysTruster.cs Implemented member-side validation and joiner-side incompatibility handling
src/ByteSync.Client/Services/Communications/Api/TrustApiClient.cs Added client method to call protocol incompatibility endpoint
src/ByteSync.Client/Services/Communications/SignalR/HubPushHandler2.cs Added SignalR subject for incompatibility notifications
src/ByteSync.Client/Services/Communications/PushReceivers/PublicKeyCheckDataPushReceiver.cs Subscribed to and handled incompatibility notifications
src/ByteSync.Client/Interfaces/Controls/Communications/ITrustProcessPublicKeysRepository.cs Added interface methods for protocol version tracking
src/ByteSync.Client/Interfaces/Controls/Communications/Http/ITrustApiClient.cs Added interface method for incompatibility notification
src/ByteSync.Client/Interfaces/Controls/Communications/SignalR/IHubPushHandler2.cs Added interface property for incompatibility subject
tests/ByteSync.ServerCommon.Tests/Commands/Trusts/StartTrustCheckCommandHandlerTests.cs Added 4 comprehensive test scenarios covering all version compatibility cases
tests/ByteSync.ServerCommon.Tests/Commands/Trusts/InformProtocolVersionIncompatibleCommandHandlerTests.cs New test file with 2 tests for the incompatibility command handler
tests/ByteSync.Functions.UnitTests/Http/TrustFunctionTests.cs New test for Azure Function endpoint
tests/ByteSync.Client.UnitTests/Services/Communications/PublicKeysTrusterTests.cs Added 6 unit tests for protocol version validation scenarios
tests/ByteSync.Client.UnitTests/Services/Communications/Api/TrustApiClientTests.cs New test file for TrustApiClient incompatibility method
tests/ByteSync.Client.UnitTests/Services/Communications/PushReceivers/PublicKeyCheckDataPushReceiverTests.cs New test for push receiver incompatibility handling
tests/ByteSync.Client.IntegrationTests/Scenarios/SessionConnection/ProtocolVersion_IntegrationTests.cs New integration test file with 4 end-to-end test scenarios
tests/ByteSync.Client.IntegrationTests/TestHelpers/Server/MockServerFacade.cs New test helper for mocking server behavior
tests/ByteSync.Client.IntegrationTests/TestHelpers/Server/FakeHubPushHandler.cs New test helper for fake SignalR push handler
Comments suppressed due to low confidence (1)

src/ByteSync.ServerCommon/Commands/Trusts/InformProtocolVersionIncompatibleCommandHandler.cs:21

  • This assignment to client is useless, since its value is never read.
        var client = request.Client;

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

{
var sessionId = "test-session-123";
var joinerInstanceId = "joiner-instance-id";
var memberInstanceId = "joiner-instance-id";
Copy link

Copilot AI Dec 3, 2025

Choose a reason for hiding this comment

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

The memberInstanceId is incorrectly set to the same value as joinerInstanceId ("joiner-instance-id"). This appears to be a copy-paste error. The member and joiner should have different instance IDs. The verification on line 153 expects MemberClientInstanceId to be different from JoinerClientInstanceId.

Suggested fix:

var memberInstanceId = "member-instance-id";

Also, the member instance ID is set up on line 71 in the Setup method as "joiner-instance-id", which should probably be updated to match the corrected variable name.

Suggested change
var memberInstanceId = "joiner-instance-id";
var memberInstanceId = "member-instance-id";

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in commit d8805ac. Corrected the joiner/member instance IDs to be distinct values.

…ionSource for robust async test - Remove unused 'client' variable in InformProtocolVersionIncompatibleCommandHandler - Remove extra blank lines at end of files - Refactor foreach with implicit filtering to use explicit .Where() - Fix joiner/member instance ID confusion in integration test
@sonarqubecloud
Copy link

sonarqubecloud bot commented Dec 3, 2025

@paul-fresquet paul-fresquet merged commit 5b177e3 into master Dec 3, 2025
44 of 45 checks passed
@paul-fresquet paul-fresquet deleted the feature/protocol-version-validation-member branch December 3, 2025 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants