Skip to content

Commit 0b8fa5c

Browse files
test
Adding an additional validation that a non-session owner cannot change ownership and that a session owner cannot change ownership to a non-session owner when the NetworkObject in question has the SessionOwner permissions set.
1 parent 75fb258 commit 0b8fa5c

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

com.unity.netcode.gameobjects/Tests/Runtime/DistributedAuthority/OwnershipPermissionsTests.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,24 @@ public IEnumerator ValidateOwnershipPermissionsTest()
371371
AssertOnTimeout($"[Targeted Owner] Client-{firstInstance.NetworkManager.LocalClientId} did not get the right request response: {daHostInstanceHelper.OwnershipRequestResponseStatus} Expecting: {NetworkObject.OwnershipRequestResponseStatus.CannotRequest}!");
372372

373373
// Try changing the ownership explicitly
374-
daHostInstance.ChangeOwnership(m_ClientNetworkManagers[0].LocalClientId);
374+
// Get the cloned daHostInstance instance on a client side
375+
var clientInstance = m_ClientNetworkManagers[2].SpawnManager.SpawnedObjects[daHostInstance.NetworkObjectId];
376+
377+
// Get the client instance of the OwnershipPermissionsTestHelper component
378+
var clientInstanceHelper = clientInstance.GetComponent<OwnershipPermissionsTestHelper>();
379+
380+
// Have the client attempt to change ownership
381+
clientInstance.ChangeOwnership(m_ClientNetworkManagers[2].LocalClientId);
382+
383+
// Verify the client side gets a permission failure status of NetworkObject.OwnershipPermissionsFailureStatus.SessionOwnerOnly
384+
Assert.IsTrue(clientInstanceHelper.OwnershipPermissionsFailureStatus == NetworkObject.OwnershipPermissionsFailureStatus.SessionOwnerOnly,
385+
$"Expected {clientInstance.name} to return {NetworkObject.OwnershipPermissionsFailureStatus.SessionOwnerOnly} but its permission failure" +
386+
$" status is {clientInstanceHelper.OwnershipPermissionsFailureStatus}!");
387+
388+
// Have the session owner attempt to change ownership to a non-session owner
389+
daHostInstance.ChangeOwnership(m_ClientNetworkManagers[2].LocalClientId);
390+
391+
// Verify the session owner cannot assign a SessionOwner permission NetworkObject to a non-sessionowner client
375392
Assert.IsTrue(daHostInstanceHelper.OwnershipPermissionsFailureStatus == NetworkObject.OwnershipPermissionsFailureStatus.SessionOwnerOnly,
376393
$"Expected {daHostInstance.name} to return {NetworkObject.OwnershipPermissionsFailureStatus.SessionOwnerOnly} but its permission failure" +
377394
$" status is {daHostInstanceHelper.OwnershipPermissionsFailureStatus}!");

0 commit comments

Comments
 (0)