Skip to content

Commit b38a8e0

Browse files
authored
Expand "See Audit Log Events" test (#2905)
1 parent 31319bc commit b38a8e0

3 files changed

Lines changed: 44 additions & 20 deletions

File tree

src/org/labkey/test/tests/AbstractAssayTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import static org.labkey.test.params.FieldDefinition.DOMAIN_TRICKY_CHARACTERS;
3737
import static org.labkey.test.util.PermissionsHelper.EDITOR_ROLE;
3838
import static org.labkey.test.util.PermissionsHelper.READER_ROLE;
39+
import static org.labkey.test.util.PermissionsHelper.SEE_AUDIT_LOG_SITE_ROLE;
3940

4041
/**
4142
* @deprecated TODO: Move shared functionality to a Helper class
@@ -209,8 +210,8 @@ protected void setupEnvironment()
209210

210211
//add a PI user to that group
211212
permissionsHelper.addUserToProjGroup(TEST_ASSAY_USR_PI1, getProjectName(), TEST_ASSAY_GRP_PIS);
212-
// give the PI user "CanSeeAuditLog" permission
213-
permissionsHelper.setSiteRoleUserPermissions(TEST_ASSAY_USR_PI1, "See Audit Log Events");
213+
// give the PI user site "CanSeeAuditLog" permission
214+
permissionsHelper.setSiteRoleUserPermissions(TEST_ASSAY_USR_PI1, SEE_AUDIT_LOG_SITE_ROLE);
214215

215216
//add a lab tech user to the Users group
216217
permissionsHelper.addUserToProjGroup(TEST_ASSAY_USR_TECH1, getProjectName(), TEST_ASSAY_GRP_USERS);

src/org/labkey/test/tests/AuditLogTest.java

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import org.labkey.test.util.Log4jUtils;
4848
import org.labkey.test.util.PermissionsHelper;
4949
import org.labkey.test.util.PortalHelper;
50+
import org.labkey.test.util.SearchHelper;
5051
import org.labkey.test.util.UIUserHelper;
5152

5253
import java.io.BufferedReader;
@@ -64,11 +65,13 @@
6465
import static org.junit.Assert.assertFalse;
6566
import static org.junit.Assert.assertTrue;
6667
import static org.junit.Assert.fail;
68+
import static org.labkey.test.util.PasswordUtil.getUsername;
6769
import static org.labkey.test.util.PermissionsHelper.AUTHOR_ROLE;
6870
import static org.labkey.test.util.PermissionsHelper.EDITOR_ROLE;
6971
import static org.labkey.test.util.PermissionsHelper.FOLDER_ADMIN_ROLE;
7072
import 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
}

src/org/labkey/test/util/PermissionsHelper.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ public abstract class PermissionsHelper
4747
public static final String AUTHOR_ROLE = "Author";
4848
public static final String SUBMITTER_ROLE = "Submitter";
4949

50+
// These two roles have the same friendly name; disambiguate using their fully qualified class names
51+
public static final String SEE_AUDIT_LOG_SITE_ROLE = "org.labkey.api.security.roles.CanSeeAuditLogRole";
52+
public static final String SEE_AUDIT_LOG_FOLDER_ROLE = "org.labkey.api.security.roles.CanSeeAuditLogFolderRole";
53+
54+
// TODO: Should "See Audit Log" roles be added here?
5055
public static final Set<String> AUDIT_LOG_VIEWER_ROLES = Set.of(SITE_ADMIN_ROLE, APP_ADMIN_ROLE, PROJECT_ADMIN_ROLE, FOLDER_ADMIN_ROLE);
5156

5257
public static boolean canSeeAuditLogs(String roleName)

0 commit comments

Comments
 (0)