Esempio n. 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));
  }
Esempio n. 2
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());
  }
Esempio n. 3
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());
 }
Esempio n. 4
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());
  }