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 ;
73+ import static org .labkey .test .util .PermissionsHelper .SEE_AUDIT_LOG_FOLDER_ROLE ;
74+ import static org .labkey .test .util .PermissionsHelper .SEE_AUDIT_LOG_SITE_ROLE ;
7275
7376@ Category ({Daily .class , Hosting .class })
7477@ BaseWebDriverTest .ClassTimeout (minutes = 9 )
@@ -79,21 +82,18 @@ public class AuditLogTest extends BaseWebDriverTest
7982 public static final String QUERY_UPDATE_EVENT = "Query update events" ;
8083 public static final String PROJECT_AUDIT_EVENT = "Project and Folder events" ;
8184 public static final String ASSAY_AUDIT_EVENT = "Link to Study events" ;
85+ public static final String COMMENT_COLUMN = "Comment" ;
8286
8387 private static final String AUDIT_TEST_USER = "audit_user1@auditlog.test" ;
8488 private static final String AUDIT_TEST_USER2 = "audit_user2@auditlog.test" ;
8589 private static final String AUDIT_TEST_USER3 = "audit_user3@auditlog.test" ;
86-
8790 private static final String AUDIT_SECURITY_GROUP = "Testers" ;
88-
8991 private static final String AUDIT_TEST_PROJECT = "AuditVerifyTest" ;
9092 private static final String AUDIT_DETAILED_TEST_PROJECT = "AuditDetailedLogTest" ;
9193 private static final String AUDIT_TEST_SUBFOLDER = "AuditVerifyTest_Subfolder" ;
9294 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" ;
95+ private static final String DOMAIN_PROPERTY_LOG_NAME = "Domain property events" ;
96+ private static final String SEARCH_TERM = "doesn't matter" ;
9797
9898 private final ApiPermissionsHelper permissionsHelper = new ApiPermissionsHelper (this );
9999 private final AuditLogHelper _auditLogHelper = new AuditLogHelper (this );
@@ -377,19 +377,37 @@ protected void canSeeAuditLogTest()
377377 createUserWithPermissions (AUDIT_TEST_USER , AUDIT_TEST_PROJECT , EDITOR_ROLE );
378378 createUserWithPermissions (AUDIT_TEST_USER2 , AUDIT_TEST_PROJECT , PROJECT_ADMIN_ROLE );
379379
380+ // Do a search to ensure an audit entry in /home
381+ clickProject ("Home" );
382+ new SearchHelper (this ).searchFor (SEARCH_TERM );
383+ goToProjectHome ();
384+
380385 // signed in as an admin so we should see rows here
381- verifyAuditQueries (true );
386+ verifyAuditQueries (true , getProjectName () );
382387
383388 // signed in as an editor should not show any rows for audit query links
384389 impersonate (AUDIT_TEST_USER );
385- verifyAuditQueries (false );
390+ verifyAuditQueries (false , getProjectName ());
391+ verifyAuditQueries (false , "Home" );
392+ stopImpersonating ();
393+
394+ // Grant the "See Audit Log Events" folder role to our audit user in the project and verify we see audit
395+ // information in this project but not /Home. We pass the fully qualified classnames in the next few calls to
396+ // disambiguate the root role from the folder role.
397+ permissionsHelper .addMemberToRole (AUDIT_TEST_USER , SEE_AUDIT_LOG_FOLDER_ROLE , PermissionsHelper .MemberType .user , getProjectName ());
398+ impersonate (AUDIT_TEST_USER );
399+ verifyAuditQueries (true , getProjectName ());
400+ verifyAuditQueries (false , "Home" );
386401 stopImpersonating ();
402+ permissionsHelper .removeUserRoleAssignment (AUDIT_TEST_USER , SEE_AUDIT_LOG_FOLDER_ROLE , getProjectName ());
387403
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" );
404+ // Grant the "See Audit Log Events" root role to our audit user and verify we see audit information in this
405+ // project and in /Home
406+ permissionsHelper .setSiteRoleUserPermissions (AUDIT_TEST_USER , SEE_AUDIT_LOG_SITE_ROLE );
391407 impersonate (AUDIT_TEST_USER );
392- verifyAuditQueries (true );
408+ verifyAuditQueries (true , getProjectName ());
409+ ExecuteQueryPage .beginAt (this , "Home" , "auditLog" , "SearchAuditEvent" );
410+ verifyAuditQueryEvent (this , "Query" , SEARCH_TERM , 1 );
393411
394412 // cleanup
395413 stopImpersonating ();
@@ -482,7 +500,7 @@ public void testDetailedQueryUpdateAuditLog() throws IOException, CommandExcepti
482500 //then create model (which has detailed audit log level)
483501 InsertRowsCommand insertCmd2 = new InsertRowsCommand ("vehicle" , "models" );
484502 rowMap = new HashMap <>();
485- rowMap .put ("manufacturerId" , resp1 .getRows ().get ( 0 ).get ("rowid" ));
503+ rowMap .put ("manufacturerId" , resp1 .getRows ().getFirst ( ).get ("rowid" ));
486504 rowMap .put ("name" , "Soul" );
487505 insertCmd2 .addRow (rowMap );
488506 insertCmd2 .execute (cn , AUDIT_DETAILED_TEST_PROJECT );
@@ -535,17 +553,17 @@ protected void verifyListAuditLogQueries(Visibility v)
535553 verifyAuditQueryEvent (this , "List" , "Child List" , 1 , canSeeChild (v ));
536554 }
537555
538- protected void verifyAuditQueries (boolean canSeeAuditLog )
556+ protected void verifyAuditQueries (boolean canSeeAuditLog , String containerPath )
539557 {
540- ExecuteQueryPage .beginAt (this , getProjectName () , "auditLog" , "ContainerAuditEvent" );
558+ ExecuteQueryPage .beginAt (this , containerPath , "auditLog" , "ContainerAuditEvent" );
541559 if (canSeeAuditLog )
542560 verifyAuditQueryEvent (this , COMMENT_COLUMN , AUDIT_TEST_PROJECT + " was created" , 1 );
543561 else
544562 assertTextPresent ("No data to show." );
545563
546- ExecuteQueryPage .beginAt (this , getProjectName () , "auditLog" , "GroupAuditEvent" );
564+ ExecuteQueryPage .beginAt (this , containerPath , "auditLog" , "GroupAuditEvent" );
547565 if (canSeeAuditLog )
548- verifyAuditQueryEvent (this , COMMENT_COLUMN , "The user " + AUDIT_TEST_USER + " was assigned to the security role Editor." , 1 );
566+ verifyAuditQueryEvent (this , COMMENT_COLUMN , "The user " + AUDIT_TEST_USER + " was assigned to the security role Editor." , 4 );
549567 else
550568 assertTextPresent ("No data to show." );
551569 }
0 commit comments