コード例 #1
0
  /**
   * Tests {@link SecurityManager#canCommentToActivity(PortalContainer, Identity,
   * ExoSocialActivity)}.
   */
  public void testCanCommentToActivity() {
    createActivities(demoIdentity, demoIdentity, 1);
    ExoSocialActivity demoActivity = activityManager.getActivities(demoIdentity).get(0);
    boolean demoCommentToDemoActivity =
        SecurityManager.canCommentToActivity(getContainer(), demoIdentity, demoActivity);
    assertTrue("demoCommentToDemoActivity must be true", demoCommentToDemoActivity);

    connectIdentities(maryIdentity, demoIdentity, false);
    boolean maryCommentToDemoActivity =
        SecurityManager.canCommentToActivity(getContainer(), maryIdentity, demoActivity);
    assertFalse("maryCommentToDemoActivity must be false", maryCommentToDemoActivity);
    connectIdentities(maryIdentity, demoIdentity, true);
    maryCommentToDemoActivity =
        SecurityManager.canCommentToActivity(getContainer(), maryIdentity, demoActivity);
    assertTrue("maryCommentToDemoActivity must be true", maryCommentToDemoActivity);

    createSpaces(1);
    Space createdSpace = tearDownSpaceList.get(0);
    Identity spaceIdentity =
        identityManager.getOrCreateIdentity(
            SpaceIdentityProvider.NAME, createdSpace.getPrettyName(), false);
    tearDownIdentityList.add(spaceIdentity);
    createActivities(spaceIdentity, spaceIdentity, 1);
    ExoSocialActivity spaceActivity = activityManager.getActivities(spaceIdentity).get(0);
    boolean demoCommentToSpaceActivity =
        SecurityManager.canCommentToActivity(getContainer(), demoIdentity, spaceActivity);
    assertTrue("demoCommentToSpaceActivity must be true", demoCommentToSpaceActivity);
    boolean maryCommentToSpaceActivity =
        SecurityManager.canCommentToActivity(getContainer(), maryIdentity, spaceActivity);
    assertTrue("maryCommentToSpaceActivity must be true", maryCommentToSpaceActivity);

    boolean johnCommentToSpaceActivity =
        SecurityManager.canCommentToActivity(getContainer(), johnIdentity, spaceActivity);
    assertFalse("johnCommentToSpaceActivity must be false", johnCommentToSpaceActivity);
  }
コード例 #2
0
  /**
   * Tests {@link SecurityManager#canDeleteActivity(PortalContainer, Identity, ExoSocialActivity)}.
   */
  public void testCanDeleteActivity() {
    createActivities(demoIdentity, demoIdentity, 2);
    ExoSocialActivity demoActivity = activityManager.getActivities(demoIdentity).get(1);
    boolean demoDeleteDemoActivity =
        SecurityManager.canDeleteActivity(getContainer(), demoIdentity, demoActivity);
    assertTrue("demoDeleteDemoActivity must be true", demoDeleteDemoActivity);

    boolean maryDeleteDemoActivity =
        SecurityManager.canDeleteActivity(getContainer(), maryIdentity, demoActivity);
    assertFalse("maryDeleteDemoActivity must be false", maryDeleteDemoActivity);

    // demo connects to john
    createActivities(johnIdentity, johnIdentity, 1);
    connectIdentities(demoIdentity, johnIdentity, false);
    ExoSocialActivity johnActivity = activityManager.getActivities(johnIdentity).get(0);
    boolean demoDeleteJohnActivity =
        SecurityManager.canDeleteActivity(getContainer(), demoIdentity, johnActivity);
    assertFalse("demoDeleteDemoActivity must be false", demoDeleteJohnActivity);

    connectIdentities(demoIdentity, johnIdentity, true);
    createActivities(demoIdentity, johnIdentity, 1);
    demoActivity = activityManager.getActivities(johnIdentity).get(0); // newest
    demoDeleteDemoActivity =
        SecurityManager.canDeleteActivity(getContainer(), demoIdentity, demoActivity);
    assertTrue("demoDeleteDemoActivity must be true", demoDeleteDemoActivity);
    boolean johnDeleteDemoActivity =
        SecurityManager.canDeleteActivity(getContainer(), johnIdentity, demoActivity);
    assertTrue("johnDeleteDemoActivity must be true", johnDeleteDemoActivity);

    // demo, mary, john on a space
    createSpaces(1);
    Space createdSpace = tearDownSpaceList.get(0);
    Identity spaceIdentity =
        identityManager.getOrCreateIdentity(
            SpaceIdentityProvider.NAME, createdSpace.getPrettyName(), false);
    tearDownIdentityList.add(spaceIdentity);
    createActivities(spaceIdentity, spaceIdentity, 1);
    ExoSocialActivity spaceActivity = activityManager.getActivities(spaceIdentity).get(0);
    boolean demoDeleteSpaceActivity =
        SecurityManager.canDeleteActivity(getContainer(), demoIdentity, spaceActivity);
    assertTrue("demoDeleteDemoActivity must be true", demoDeleteSpaceActivity);
    boolean maryDeleteSpaceActivity =
        SecurityManager.canDeleteActivity(getContainer(), maryIdentity, spaceActivity);
    assertFalse("maryDeleteSpaceActivity must be false", maryDeleteSpaceActivity);
    boolean johnDeleteSpaceActivity =
        SecurityManager.canDeleteActivity(getContainer(), johnIdentity, spaceActivity);
    assertFalse("johnDeleteSpaceActivity must be false", johnDeleteSpaceActivity);
    createActivities(demoIdentity, spaceIdentity, 1);
    ExoSocialActivity demoToSpaceActivity = activityManager.getActivities(spaceIdentity).get(0);
    boolean demoDeleteDemoToSpaceActivity =
        SecurityManager.canDeleteActivity(getContainer(), demoIdentity, demoToSpaceActivity);
    assertTrue("demoDeleteDemoToSpaceActivity must be true", demoDeleteDemoToSpaceActivity);
    boolean maryDeleteDemoToSpaceActivity =
        SecurityManager.canDeleteActivity(getContainer(), maryIdentity, demoToSpaceActivity);
    assertFalse("maryDeleteDemoToSpaceActivity must be false", maryDeleteDemoToSpaceActivity);
    boolean johnDeleteDemoToSpaceActivity =
        SecurityManager.canDeleteActivity(getContainer(), johnIdentity, demoToSpaceActivity);
    assertFalse("johnDeleteDemoToSpaceActivity must be false", johnDeleteDemoToSpaceActivity);
  }
コード例 #3
0
  /**
   * Tests {@link SecurityManager#canDeleteComment(PortalContainer, Identity, ExoSocialActivity)}.
   */
  public void testCanDeleteComment() {
    createActivities(demoIdentity, demoIdentity, 1);
    ExoSocialActivity demoActivity = activityManager.getActivities(demoIdentity).get(0);
    createComment(demoActivity, demoIdentity, 1);
    ExoSocialActivity demoComment = activityManager.getComments(demoActivity).get(0);

    boolean demoDeleteDemoComment =
        SecurityManager.canDeleteComment(getContainer(), demoIdentity, demoComment);
    assertTrue("demoDeleteDemoComment must be true", demoDeleteDemoComment);

    // BUG #3: TODO FIX THIS
    boolean maryDeleteDemoComment =
        SecurityManager.canDeleteComment(getContainer(), maryIdentity, demoComment);
    assertFalse("maryDeleteDemoComment must be false", maryDeleteDemoComment);

    connectIdentities(maryIdentity, demoIdentity, true);
    createActivities(maryIdentity, demoIdentity, 1);
    ExoSocialActivity maryActivity = activityManager.getActivities(demoIdentity).get(0);
    createComment(maryActivity, demoIdentity, 1);
    createComment(maryActivity, maryIdentity, 1);
    List<ExoSocialActivity> comments = activityManager.getComments(maryActivity);
    assertEquals(2, comments.size());

    // BUG of ActivityManager, FIX IT and change these lines below following its changes.
    /*
    assertTrue("comments.get(0).getPostedTime() > comments.get(1).getPostedTime() must return true",
               comments.get(0).getPostedTime() > comments.get(1).getPostedTime());
    */
    assertTrue(
        "comments.get(0).getPostedTime() < comments.get(1).getPostedTime() must return true",
        comments.get(0).getPostedTime() < comments.get(1).getPostedTime()); // must >
    ExoSocialActivity demoCommentMaryActivity = comments.get(0); // must be 1
    ExoSocialActivity maryCommentMaryActivity = comments.get(1); // must be 0

    boolean demoDeleteMaryCommentMaryActivity =
        SecurityManager.canDeleteComment(getContainer(), demoIdentity, maryCommentMaryActivity);

    assertTrue("demoDeleteMaryCommentMaryActivity must be true", demoDeleteMaryCommentMaryActivity);

    boolean johnDeleteDemoCommentMaryActivity =
        SecurityManager.canDeleteComment(getContainer(), johnIdentity, demoCommentMaryActivity);
    assertFalse(
        "johnDeleteDemoCommentMaryActivity must be false", johnDeleteDemoCommentMaryActivity);

    createSpaces(1);
    Space createdSpace = tearDownSpaceList.get(0);
    Identity spaceIdentity =
        identityManager.getOrCreateIdentity(
            SpaceIdentityProvider.NAME, createdSpace.getPrettyName(), false);
    createActivities(spaceIdentity, spaceIdentity, 1);
    ExoSocialActivity spaceActivity = activityManager.getActivities(spaceIdentity).get(0);

    createComment(spaceActivity, maryIdentity, 1);
    createComment(spaceActivity, demoIdentity, 1);
    List<ExoSocialActivity> spaceActivityComments = activityManager.getComments(spaceActivity);
    ExoSocialActivity maryCommentSpaceActivity =
        spaceActivityComments.get(0); // must be demo's comment
    ExoSocialActivity demoCommentSpaceActivity =
        spaceActivityComments.get(1); // must be mary's comment

    boolean maryDeleteDemoCommentSpaceActivity =
        SecurityManager.canDeleteComment(getContainer(), maryIdentity, demoCommentSpaceActivity);
    assertFalse(
        "maryDeleteDemoCommentSpaceActivity must be false", maryDeleteDemoCommentSpaceActivity);

    boolean demoDeleteMaryCommentSpaceActivity =
        SecurityManager.canDeleteComment(getContainer(), demoIdentity, maryCommentSpaceActivity);
    assertTrue(
        "demoDeleteMaryCommentSpaceActivity must be true", demoDeleteMaryCommentSpaceActivity);
  }
コード例 #4
0
 /**
  * Tests {@link SecurityManager#canAccessActivity(PortalContainer, Identity, ExoSocialActivity)}.
  */
 public void testCanAccessActivity() {
   createActivities(demoIdentity, demoIdentity, 2);
   ExoSocialActivity activity = activityManager.getActivities(demoIdentity).get(0);
   assertTrue(SecurityManager.canAccessActivity(getContainer(), johnIdentity, activity));
 }