예제 #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));
  }
예제 #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());
  }
예제 #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));
  }
예제 #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());
 }