opensecuritycontroller / osc-core

A software-defined security orchestration solution
https://www.opensecuritycontroller.org/
Apache License 2.0
43 stars 29 forks source link

Adding multiple security group members (SGM) of the same type to the security group entity does not work #366

Open emanoelxavier opened 7 years ago

emanoelxavier commented 7 years ago

Expected Behavior

From within OSC code calling SecurityGroup.addSecurityGroupMember with members of the same type should work as expected: new and different members should be added. This issue does not seem to reflect directly on OSC APIs or UI but it does affect unit testing and it could have other not yet found side effects.

Actual Behavior

From within OSC code calling SecurityGroup.addSecurityGroupMember with members of the same type does not work. Only the first member gets added, this is happening because the type of the security members collection is TreeSet which uses compareTo to identify if elements are the same. Currently the SecurityGroupMember implements compareTo using the type only, thus adding elements of the same type does not work. This does not seem to be affecting any behavior on the APIs or UIs, the reason seems because the persistence framework instantiates the set of SGMs with a different collection other than TreeSet this affects the unit tests though.

Steps to Reproduce

Since this is currently only affecting unit tests the repro steps involve removing the workaround added for the unit tests and running them:

  1. Run the unit tests AllocateDAIWithSGIMembersTaskTest
  2. Observe the unit tests are passing
  3. Remove the workaround/TODO on UpdateDAIToSGIMembersTaskTest.newSGM which is currently mocking the compareTo method of the SGM
  4. Rerun the unit tests AllocateDAIWithSGIMembersTaskTest and observe that they will now fail due to the TreeSet issue.

Additional Information

Once the TreeSet issue is addressed, i.e.: use a HashSet then the tests should pass without the need for any workaround.

Status

emanoelxavier commented 7 years ago

@arvindn05 fyi

emanoelxavier commented 7 years ago

@opensecuritycontroller/osc_triage fyi