Skip to content

Commit

Permalink
PROD-972 Add group version increment to onPolicyUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghost-in-a-Jar committed Jul 15, 2024
1 parent e9694ee commit e90559b
Showing 1 changed file with 40 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1164,7 +1164,7 @@ class ResourceServiceSpec
val policies =
policyDAO.listAccessPolicies(resource, samRequestContext).unsafeRunSync().map(_.copy(email = WorkbenchEmail("[email protected]")))

assert(policies.contains(newPolicy))
assert(policies.contains(newPolicy.copy(version = 2)))
}

it should "should add a memberPolicy as a member when specified through policy identifiers" in {
Expand Down Expand Up @@ -1285,6 +1285,13 @@ class ResourceServiceSpec
)
).thenReturn(IO.unit)

when(
mockDirectoryDAO.updateGroupUpdatedDateAndVersionWithSession(
any[WorkbenchGroupIdentity],
any[SamRequestContext]
)
).thenReturn(IO.unit)

runAndWait(
resourceService.overwritePolicy(
defaultResourceType,
Expand Down Expand Up @@ -1325,6 +1332,12 @@ class ResourceServiceSpec
// function calls that should pass but what they return does not matter
when(mockAccessPolicyDAO.overwritePolicy(ArgumentMatchers.eq(accessPolicy), any[SamRequestContext])).thenReturn(IO.pure(accessPolicy))
when(mockCloudExtensions.onGroupUpdate(ArgumentMatchers.eq(Seq(policyId)), ArgumentMatchers.eq(Set(member)), any[SamRequestContext])).thenReturn(IO.unit)
when(
mockDirectoryDAO.updateGroupUpdatedDateAndVersionWithSession(
any[WorkbenchGroupIdentity],
any[SamRequestContext]
)
).thenReturn(IO.unit)

// overwrite policy with no members
runAndWait(
Expand Down Expand Up @@ -1412,7 +1425,7 @@ class ResourceServiceSpec
val policies =
policyDAO.listAccessPolicies(resource, samRequestContext).unsafeRunSync().map(_.copy(email = WorkbenchEmail("[email protected]")))

assert(policies.contains(newPolicy))
assert(policies.contains(newPolicy.copy(version = 2)))
}

it should "fail if any members are not test.firecloud.org accounts" in {
Expand Down Expand Up @@ -1486,7 +1499,7 @@ class ResourceServiceSpec
val policies =
policyDAO.listAccessPolicies(resource, samRequestContext).unsafeRunSync().map(_.copy(email = WorkbenchEmail("[email protected]")))

assert(policies.contains(newPolicy))
assert(policies.contains(newPolicy.copy(version = 2)))
}

it should "call CloudExtensions.onGroupUpdate when members change" in {
Expand Down Expand Up @@ -1516,6 +1529,12 @@ class ResourceServiceSpec
// function calls that should pass but what they return does not matter
when(mockAccessPolicyDAO.overwritePolicyMembers(ArgumentMatchers.eq(policyId), ArgumentMatchers.eq(Set.empty), any[SamRequestContext])).thenReturn(IO.unit)
when(mockCloudExtensions.onGroupUpdate(ArgumentMatchers.eq(Seq(policyId)), ArgumentMatchers.eq(Set(member)), any[SamRequestContext])).thenReturn(IO.unit)
when(
mockDirectoryDAO.updateGroupUpdatedDateAndVersionWithSession(
any[WorkbenchGroupIdentity],
any[SamRequestContext]
)
).thenReturn(IO.unit)

// overwrite policy members with empty set
runAndWait(resourceService.overwritePolicyMembers(policyId, Set.empty, samRequestContext))
Expand Down Expand Up @@ -1576,7 +1595,7 @@ class ResourceServiceSpec

val policies = policyDAO.listAccessPolicies(resource, samRequestContext).unsafeRunSync()

assert(policies.contains(newPolicy))
assert(policies.contains(newPolicy.copy(version = 2)))
}

it should "fail when given an invalid action" in {
Expand Down Expand Up @@ -2107,6 +2126,13 @@ class ResourceServiceSpec
IO.pure(LazyList(AccessPolicy(policyId, Set.empty, WorkbenchEmail(""), Set.empty, Set.empty, Set.empty, false))),
IO.pure(LazyList(AccessPolicy(policyId, Set(member), WorkbenchEmail(""), Set.empty, Set.empty, Set.empty, false)))
)
when(
mockDirectoryDAO.updateGroupUpdatedDateAndVersionWithSession(
any[WorkbenchGroupIdentity],
any[SamRequestContext]
)
).thenReturn(IO.unit)

runAndWait(resourceService.addSubjectToPolicy(policyId, member, samRequestContext))

verify(mockCloudExtensions, Mockito.timeout(500))
Expand Down Expand Up @@ -2164,6 +2190,13 @@ class ResourceServiceSpec
IO.pure(LazyList(AccessPolicy(policyId, Set.empty, WorkbenchEmail(""), Set.empty, Set.empty, Set.empty, false))),
IO.pure(LazyList(AccessPolicy(policyId, Set(member), WorkbenchEmail(""), Set.empty, Set.empty, Set.empty, false)))
)
when(
mockDirectoryDAO.updateGroupUpdatedDateAndVersionWithSession(
any[WorkbenchGroupIdentity],
any[SamRequestContext]
)
).thenReturn(IO.unit)

runAndWait(resourceService.removeSubjectFromPolicy(policyId, member, samRequestContext))

verify(mockCloudExtensions, Mockito.timeout(1000))
Expand Down Expand Up @@ -3122,7 +3155,9 @@ class ResourceServiceSpec

returnedPolicies should contain theSameElementsAs Set(expectedPolicy)

policyDAO.loadPolicy(testPolicyId, samRequestContext).unsafeRunSync().map(_.copy(email = WorkbenchEmail(""))) shouldBe Some(expectedPolicy)
policyDAO.loadPolicy(testPolicyId, samRequestContext).unsafeRunSync().map(_.copy(email = WorkbenchEmail(""))) shouldBe Some(
expectedPolicy.copy(version = 2)
)
}

it should "validate admin policies" in {
Expand Down

0 comments on commit e90559b

Please sign in to comment.