Example #1
0
  @Test
  public void addSameApprovalRepeatedlyUpdatesExpiry() {
    assertTrue(
        dao.addApproval(
            new Approval()
                .setUserId("u2")
                .setClientId("c2")
                .setScope("dash.user")
                .setExpiresAt(Approval.timeFromNow(6000))
                .setStatus(APPROVED)));
    Approval app = dao.getApprovals("u2", "c2").iterator().next();
    assertEquals(
        Math.round(app.getExpiresAt().getTime() / 1000),
        Math.round((new Date().getTime() + 6000) / 1000));

    assertTrue(
        dao.addApproval(
            new Approval()
                .setUserId("u2")
                .setClientId("c2")
                .setScope("dash.user")
                .setExpiresAt(Approval.timeFromNow(8000))
                .setStatus(APPROVED)));
    app = dao.getApprovals("u2", "c2").iterator().next();
    assertEquals(
        Math.round(app.getExpiresAt().getTime() / 1000),
        Math.round((new Date().getTime() + 8000) / 1000));
  }
Example #2
0
 @Override
 public AuditEvent getAuditEvent() {
   Approval source = getSource();
   return createAuditRecord(
       source.getUserId(),
       AuditEventType.ApprovalModifiedEvent,
       getOrigin(getAuthentication()),
       getData(source));
 }
Example #3
0
  @Test
  public void canRefreshApproval() {
    Approval app = dao.getApprovals("u1", "c1").iterator().next();
    Date now = new Date();

    dao.refreshApproval(
        new Approval()
            .setUserId(app.getUserId())
            .setClientId(app.getClientId())
            .setScope(app.getScope())
            .setExpiresAt(now)
            .setStatus(APPROVED));
    app = dao.getApprovals("u1", "c1").iterator().next();
    assertEquals(Math.round(now.getTime() / 1000), Math.round(app.getExpiresAt().getTime() / 1000));
  }
Example #4
0
 @Test
 public void canAddApproval() {
   assertTrue(
       dao.addApproval(
           new Approval()
               .setUserId("u2")
               .setClientId("c2")
               .setScope("dash.user")
               .setExpiresAt(Approval.timeFromNow(12000))
               .setStatus(APPROVED)));
   List<Approval> apps = dao.getApprovals("u2", "c2");
   assertEquals(1, apps.size());
   Approval app = apps.iterator().next();
   assertEquals("dash.user", app.getScope());
   assertTrue(app.getExpiresAt().after(new Date()));
   assertEquals(APPROVED, app.getStatus());
 }
Example #5
0
  @Test
  public void testAddingAndUpdatingAnApprovalPublishesEvents() throws Exception {
    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);

    dao.addApproval(approval);

    Assert.assertEquals(1, eventPublisher.getEventCount());

    ApprovalModifiedEvent addEvent = eventPublisher.getLatestEvent();
    Assert.assertEquals(approval, addEvent.getSource());
    Assert.assertEquals(authentication, addEvent.getAuthentication());
    Assert.assertEquals(
        "{\"scope\":\"cloud_controller.read\",\"status\":\"APPROVED\"}",
        addEvent.getAuditEvent().getData());

    approval.setStatus(DENIED);

    eventPublisher.clearEvents();
    dao.addApproval(approval);

    Assert.assertEquals(1, eventPublisher.getEventCount());

    ApprovalModifiedEvent modifyEvent = eventPublisher.getLatestEvent();
    Assert.assertEquals(approval, modifyEvent.getSource());
    Assert.assertEquals(authentication, modifyEvent.getAuthentication());
    Assert.assertEquals(
        "{\"scope\":\"cloud_controller.read\",\"status\":\"DENIED\"}",
        addEvent.getAuditEvent().getData());
  }
Example #6
0
  @Test
  @Ignore // this test has issues
  public void addSameApprovalDifferentStatusRepeatedlyOnlyUpdatesStatus() {
    assertTrue(
        dao.addApproval(
            new Approval()
                .setUserId("u2")
                .setClientId("c2")
                .setScope("dash.user")
                .setExpiresAt(Approval.timeFromNow(6000))
                .setStatus(APPROVED)));
    Approval app = dao.getApprovals("u2", "c2").iterator().next();
    assertEquals(
        Math.round(app.getExpiresAt().getTime() / 1000),
        Math.round((new Date().getTime() + 6000) / 1000));

    assertTrue(
        dao.addApproval(
            new Approval()
                .setUserId("u2")
                .setClientId("c2")
                .setScope("dash.user")
                .setExpiresAt(Approval.timeFromNow(8000))
                .setStatus(DENIED)));
    app = dao.getApprovals("u2", "c2").iterator().next();
    assertEquals(
        Math.round(app.getExpiresAt().getTime() / 1000),
        Math.round((new Date().getTime() + 6000) / 1000));
    assertEquals(DENIED, app.getStatus());
  }
Example #7
0
 public ApprovalModifiedEventData(Approval approval) {
   scope = approval.getScope();
   status = approval.getStatus();
 }