4747import org .labkey .test .util .Log4jUtils ;
4848import org .labkey .test .util .PermissionsHelper ;
4949import org .labkey .test .util .PortalHelper ;
50+ import org .labkey .test .util .SearchHelper ;
5051import org .labkey .test .util .UIUserHelper ;
5152
5253import java .io .BufferedReader ;
6465import static org .junit .Assert .assertFalse ;
6566import static org .junit .Assert .assertTrue ;
6667import static org .junit .Assert .fail ;
68+ import static org .labkey .test .util .PasswordUtil .getUsername ;
6769import static org .labkey .test .util .PermissionsHelper .AUTHOR_ROLE ;
6870import static org .labkey .test .util .PermissionsHelper .EDITOR_ROLE ;
6971import static org .labkey .test .util .PermissionsHelper .FOLDER_ADMIN_ROLE ;
7072import static org .labkey .test .util .PermissionsHelper .PROJECT_ADMIN_ROLE ;
71- import static org .labkey .test .util .PasswordUtil .getUsername ;
7273
7374@ Category ({Daily .class , Hosting .class })
7475@ BaseWebDriverTest .ClassTimeout (minutes = 9 )
@@ -79,21 +80,18 @@ public class AuditLogTest extends BaseWebDriverTest
7980 public static final String QUERY_UPDATE_EVENT = "Query update events" ;
8081 public static final String PROJECT_AUDIT_EVENT = "Project and Folder events" ;
8182 public static final String ASSAY_AUDIT_EVENT = "Link to Study events" ;
83+ public static final String COMMENT_COLUMN = "Comment" ;
8284
8385 private static final String AUDIT_TEST_USER = "audit_user1@auditlog.test" ;
8486 private static final String AUDIT_TEST_USER2 = "audit_user2@auditlog.test" ;
8587 private static final String AUDIT_TEST_USER3 = "audit_user3@auditlog.test" ;
86-
8788 private static final String AUDIT_SECURITY_GROUP = "Testers" ;
88-
8989 private static final String AUDIT_TEST_PROJECT = "AuditVerifyTest" ;
9090 private static final String AUDIT_DETAILED_TEST_PROJECT = "AuditDetailedLogTest" ;
9191 private static final String AUDIT_TEST_SUBFOLDER = "AuditVerifyTest_Subfolder" ;
9292 private static final String AUDIT_PROPERTY_EVENTS_PROJECT = "AuditDomainPropertyEvents" ;
93-
94- final String DOMAIN_PROPERTY_LOG_NAME = "Domain property events" ;
95-
96- public static final String COMMENT_COLUMN = "Comment" ;
93+ private static final String DOMAIN_PROPERTY_LOG_NAME = "Domain property events" ;
94+ private static final String SEARCH_TERM = "doesn't matter" ;
9795
9896 private final ApiPermissionsHelper permissionsHelper = new ApiPermissionsHelper (this );
9997 private final AuditLogHelper _auditLogHelper = new AuditLogHelper (this );
@@ -377,19 +375,37 @@ protected void canSeeAuditLogTest()
377375 createUserWithPermissions (AUDIT_TEST_USER , AUDIT_TEST_PROJECT , EDITOR_ROLE );
378376 createUserWithPermissions (AUDIT_TEST_USER2 , AUDIT_TEST_PROJECT , PROJECT_ADMIN_ROLE );
379377
378+ // Do a search to ensure an audit entry in /home
379+ clickProject ("Home" );
380+ new SearchHelper (this ).searchFor (SEARCH_TERM );
381+ goToProjectHome ();
382+
380383 // signed in as an admin so we should see rows here
381- verifyAuditQueries (true );
384+ verifyAuditQueries (true , getProjectName () );
382385
383386 // signed in as an editor should not show any rows for audit query links
384387 impersonate (AUDIT_TEST_USER );
385- verifyAuditQueries (false );
388+ verifyAuditQueries (false , getProjectName ());
389+ verifyAuditQueries (false , "Home" );
390+ stopImpersonating ();
391+
392+ // Grant the "See Audit Log Events" folder role to our audit user in the project and verify we see audit
393+ // information in this project but not /Home. We pass the fully qualified classnames in the next few calls to
394+ // disambiguate the root role from the folder role.
395+ permissionsHelper .addMemberToRole (AUDIT_TEST_USER , "org.labkey.api.security.roles.CanSeeAuditLogFolderRole" , PermissionsHelper .MemberType .user , getProjectName ());
396+ impersonate (AUDIT_TEST_USER );
397+ verifyAuditQueries (true , getProjectName ());
398+ verifyAuditQueries (false , "Home" );
386399 stopImpersonating ();
400+ permissionsHelper .removeUserRoleAssignment (AUDIT_TEST_USER , "org.labkey.api.security.roles.CanSeeAuditLogFolderRole" , getProjectName ());
387401
388- // now grant CanSeeAuditLog permission to our audit user and verify
389- // we see audit information
390- permissionsHelper .setSiteRoleUserPermissions (AUDIT_TEST_USER , "See Audit Log Events " );
402+ // Grant the "See Audit Log Events" root role to our audit user and verify we see audit information in this
403+ // project and in /Home
404+ permissionsHelper .setSiteRoleUserPermissions (AUDIT_TEST_USER , "org.labkey.api.security.roles.CanSeeAuditLogRole " );
391405 impersonate (AUDIT_TEST_USER );
392- verifyAuditQueries (true );
406+ verifyAuditQueries (true , getProjectName ());
407+ ExecuteQueryPage .beginAt (this , "Home" , "auditLog" , "SearchAuditEvent" );
408+ verifyAuditQueryEvent (this , "Query" , SEARCH_TERM , 1 );
393409
394410 // cleanup
395411 stopImpersonating ();
@@ -482,7 +498,7 @@ public void testDetailedQueryUpdateAuditLog() throws IOException, CommandExcepti
482498 //then create model (which has detailed audit log level)
483499 InsertRowsCommand insertCmd2 = new InsertRowsCommand ("vehicle" , "models" );
484500 rowMap = new HashMap <>();
485- rowMap .put ("manufacturerId" , resp1 .getRows ().get ( 0 ).get ("rowid" ));
501+ rowMap .put ("manufacturerId" , resp1 .getRows ().getFirst ( ).get ("rowid" ));
486502 rowMap .put ("name" , "Soul" );
487503 insertCmd2 .addRow (rowMap );
488504 insertCmd2 .execute (cn , AUDIT_DETAILED_TEST_PROJECT );
@@ -535,17 +551,17 @@ protected void verifyListAuditLogQueries(Visibility v)
535551 verifyAuditQueryEvent (this , "List" , "Child List" , 1 , canSeeChild (v ));
536552 }
537553
538- protected void verifyAuditQueries (boolean canSeeAuditLog )
554+ protected void verifyAuditQueries (boolean canSeeAuditLog , String containerPath )
539555 {
540- ExecuteQueryPage .beginAt (this , getProjectName () , "auditLog" , "ContainerAuditEvent" );
556+ ExecuteQueryPage .beginAt (this , containerPath , "auditLog" , "ContainerAuditEvent" );
541557 if (canSeeAuditLog )
542558 verifyAuditQueryEvent (this , COMMENT_COLUMN , AUDIT_TEST_PROJECT + " was created" , 1 );
543559 else
544560 assertTextPresent ("No data to show." );
545561
546- ExecuteQueryPage .beginAt (this , getProjectName () , "auditLog" , "GroupAuditEvent" );
562+ ExecuteQueryPage .beginAt (this , containerPath , "auditLog" , "GroupAuditEvent" );
547563 if (canSeeAuditLog )
548- verifyAuditQueryEvent (this , COMMENT_COLUMN , "The user " + AUDIT_TEST_USER + " was assigned to the security role Editor." , 1 );
564+ verifyAuditQueryEvent (this , COMMENT_COLUMN , "The user " + AUDIT_TEST_USER + " was assigned to the security role Editor." , 4 );
549565 else
550566 assertTextPresent ("No data to show." );
551567 }
0 commit comments