Skip to content

DatabasePermission.Equals() only compares Permission property, ignores State property #2391

@coderabbitai

Description

@coderabbitai

Description

The DatabasePermission.Equals() method has a bug where it only compares the Permission property and ignores the State property. This causes incorrect equality comparisons when two instances have the same Permission but different State values.

Current Behavior

When comparing two DatabasePermission instances:

  • Instance 1: State = 'Deny', Permission = 'select'
  • Instance 2: State = 'Grant', Permission = 'select'

The comparison returns true (equal) when it should return false (not equal).

Expected Behavior

The Equals() method should compare both the State and Permission properties to determine equality.

Impact

  • Tests currently assert the buggy behavior rather than the correct behavior
  • Future developers may not realize this is incorrect behavior
  • The bug becomes harder to track and fix over time

Affected Files

  • source/Classes/DatabasePermission.ps1 (or similar location for the class implementation)
  • tests/Unit/Classes/DatabasePermission.Tests.ps1 (lines 158-161)

Suggested Fix

  1. Update the Equals() method to compare both State and Permission properties
  2. Ensure GetHashCode() also covers both fields consistently
  3. Revert the test assertion to the correct expectation (Should -BeFalse)
  4. Add/adjust unit tests to cover both equal and not-equal cases

References

Metadata

Metadata

Assignees

Labels

bugThe issue is a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions