use of org.cloudfoundry.identity.uaa.approval.Approval in project uaa by cloudfoundry.
the class ApprovalsAdminEndpointsTests method attemptingToCreateAnApprovalWithADifferentStatusUpdatesApproval.
@Test
void attemptingToCreateAnApprovalWithADifferentStatusUpdatesApproval() {
addApproval(marissa.getId(), "uaa.user", 6000, APPROVED);
addApproval(marissa.getId(), "uaa.admin", 12000, DENIED);
addApproval(marissa.getId(), "openid", 6000, APPROVED);
addApproval(marissa.getId(), "openid", 18000, DENIED);
List<Approval> updatedApprovals = endpoints.getApprovals(userIdFilter(marissa.getId()), 1, 100);
assertEquals(3, updatedApprovals.size());
assertTrue(updatedApprovals.contains(new Approval().setUserId(marissa.getId()).setClientId("c1").setScope("uaa.user").setExpiresAt(Approval.timeFromNow(6000)).setStatus(APPROVED)));
assertTrue(updatedApprovals.contains(new Approval().setUserId(marissa.getId()).setClientId("c1").setScope("uaa.admin").setExpiresAt(Approval.timeFromNow(12000)).setStatus(DENIED)));
assertTrue(updatedApprovals.contains(new Approval().setUserId(marissa.getId()).setClientId("c1").setScope("openid").setExpiresAt(Approval.timeFromNow(18000)).setStatus(DENIED)));
}
use of org.cloudfoundry.identity.uaa.approval.Approval in project uaa by cloudfoundry.
the class JdbcApprovalStoreTests method canRefreshApproval.
// TODO: Understand this test. Do we need this test?
// @Test
// void refreshApprovalCallsGetZoneId() {
// Approval app = jdbcApprovalStore.getApprovals("u1", "c1", defaultZoneId).iterator().next();
// IdentityZone spy = spy(IdentityZoneHolder.get());
// IdentityZoneHolder.set(spy);
// jdbcApprovalStore.refreshApproval(app, defaultZoneId);
// verify(spy, times(1)).getId();
// }
@Test
void canRefreshApproval() {
Approval app = jdbcApprovalStore.getApprovals("u1", "c1", defaultZoneId).iterator().next();
Date now = new Date();
jdbcApprovalStore.refreshApproval(new Approval().setUserId(app.getUserId()).setClientId(app.getClientId()).setScope(app.getScope()).setExpiresAt(now).setStatus(APPROVED), defaultZoneId);
app = jdbcApprovalStore.getApprovals("u1", "c1", defaultZoneId).iterator().next();
assertThat((int) Math.abs(now.getTime() / 1000d - app.getExpiresAt().getTime() / 1000d), lessThan(2));
}
use of org.cloudfoundry.identity.uaa.approval.Approval in project uaa by cloudfoundry.
the class JdbcApprovalStoreTests method addApproval.
private static void addApproval(final JdbcApprovalStore jdbcApprovalStore, final String userId, final String clientId, final String scope, final long expiresIn, final ApprovalStatus status, final String zoneId) {
Date expiresAt = new Timestamp(new Date().getTime() + expiresIn);
Date lastUpdatedAt = new Date();
Approval newApproval = new Approval().setUserId(userId).setClientId(clientId).setScope(scope).setExpiresAt(expiresAt).setStatus(status).setLastUpdatedAt(lastUpdatedAt);
jdbcApprovalStore.addApproval(newApproval, zoneId);
}
use of org.cloudfoundry.identity.uaa.approval.Approval in project uaa by cloudfoundry.
the class JdbcApprovalStoreTests method canRevokeSingleApproval.
@Test
void canRevokeSingleApproval() {
List<Approval> approvals = jdbcApprovalStore.getApprovalsForUser("u1", defaultZoneId);
assertEquals(2, approvals.size());
Approval toRevoke = approvals.get(0);
assertTrue(jdbcApprovalStore.revokeApproval(toRevoke, defaultZoneId));
List<Approval> approvalsAfterRevoke = jdbcApprovalStore.getApprovalsForUser("u1", defaultZoneId);
assertEquals(1, approvalsAfterRevoke.size());
assertFalse(approvalsAfterRevoke.contains(toRevoke));
}
use of org.cloudfoundry.identity.uaa.approval.Approval in project uaa by cloudfoundry.
the class JdbcApprovalStoreTests method addingAndUpdatingAnApprovalPublishesEvents.
@Test
void addingAndUpdatingAnApprovalPublishesEvents() {
UaaTestAccounts testAccounts = UaaTestAccounts.standard(null);
Approval approval = new Approval().setUserId(testAccounts.getUserName()).setClientId("app").setScope("cloud_controller.read").setExpiresAt(Approval.timeFromNow(1000)).setStatus(ApprovalStatus.APPROVED);
eventPublisher.clearEvents();
MockAuthentication authentication = new MockAuthentication();
SecurityContextHolder.getContext().setAuthentication(authentication);
jdbcApprovalStore.addApproval(approval, defaultZoneId);
assertEquals(1, eventPublisher.getEventCount());
ApprovalModifiedEvent addEvent = eventPublisher.getLatestEvent();
assertEquals(approval, addEvent.getSource());
assertEquals(authentication, addEvent.getAuthentication());
assertEquals("{\"scope\":\"cloud_controller.read\",\"status\":\"APPROVED\"}", addEvent.getAuditEvent().getData());
approval.setStatus(DENIED);
eventPublisher.clearEvents();
jdbcApprovalStore.addApproval(approval, defaultZoneId);
assertEquals(1, eventPublisher.getEventCount());
ApprovalModifiedEvent modifyEvent = eventPublisher.getLatestEvent();
assertEquals(approval, modifyEvent.getSource());
assertEquals(authentication, modifyEvent.getAuthentication());
assertEquals("{\"scope\":\"cloud_controller.read\",\"status\":\"DENIED\"}", addEvent.getAuditEvent().getData());
}
Aggregations