22
33import org .apache .commons .collections4 .IteratorUtils ;
44import org .apache .commons .io .FileUtils ;
5+ import org .jetbrains .annotations .Nullable ;
56import org .junit .BeforeClass ;
67import org .junit .Test ;
78import org .junit .experimental .categories .Category ;
89import org .labkey .test .BaseWebDriverTest ;
910import org .labkey .test .Locator ;
11+ import org .labkey .test .Locators ;
1012import org .labkey .test .TestTimeoutException ;
13+ import org .labkey .test .WebTestHelper ;
1114import org .labkey .test .categories .Git ;
1215import org .labkey .test .pages .core .admin .ShowAdminPage ;
1316import org .labkey .test .pages .core .admin .ShowAuditLogPage ;
1417import org .labkey .test .params .list .IntListDefinition ;
18+ import org .labkey .test .util .AbstractDataRegionExportOrSignHelper ;
1519import org .labkey .test .util .ApiPermissionsHelper ;
20+ import org .labkey .test .util .DataRegionExportHelper ;
1621import org .labkey .test .util .DataRegionTable ;
17- import org .labkey .test .util .PermissionsHelper ;
22+ import org .labkey .test .util .SummaryStatisticsHelper ;
23+ import org .openqa .selenium .By ;
24+ import org .openqa .selenium .support .ui .ExpectedConditions ;
1825
1926import java .io .File ;
2027import java .util .Arrays ;
2128import java .util .List ;
2229
2330import static org .junit .Assert .assertTrue ;
31+ import static org .labkey .test .util .PermissionsHelper .TROUBLESHOOTER_ROLE ;
2432
2533@ Category ({Git .class })
2634@ BaseWebDriverTest .ClassTimeout (minutes = 4 )
2735public class TroubleshooterRoleTest extends BaseWebDriverTest
2836{
29- protected static final String TROUBLESHOOTER = "troubleshooter@troubleshooter.test" ;
37+ protected static final String TROUBLESHOOTER_USER = "troubleshooter@troubleshooter.test" ;
3038 protected int _troubleShooterId ;
3139
3240 @ BeforeClass
@@ -39,30 +47,30 @@ public static void setupProject()
3947 @ Override
4048 protected void doCleanup (boolean afterTest ) throws TestTimeoutException
4149 {
42- _userHelper .deleteUsers (false , TROUBLESHOOTER );
50+ _userHelper .deleteUsers (false , TROUBLESHOOTER_USER );
4351 _containerHelper .deleteProject (getProjectName (), afterTest );
4452 }
4553
4654 protected void doSetup ()
4755 {
48- _troubleShooterId = _userHelper .createUser (TROUBLESHOOTER ).getUserId ();
56+ _troubleShooterId = _userHelper .createUser (TROUBLESHOOTER_USER ).getUserId ();
4957 ApiPermissionsHelper apiPermissionsHelper = new ApiPermissionsHelper (this );
50- apiPermissionsHelper .addMemberToRole (TROUBLESHOOTER , getRole (), PermissionsHelper . MemberType . user , "/" );
58+ apiPermissionsHelper .addMemberToRole (_troubleShooterId , getRole (), "/" );
5159 _containerHelper .createProject (getProjectName ());
5260 }
5361
5462 protected String getRole ()
5563 {
56- return "Troubleshooter" ;
64+ return TROUBLESHOOTER_ROLE ;
5765 }
5866
5967 @ Test
6068 public void testAuditLogsIsAccessible () throws Exception
6169 {
62- // Ensure that there is at least on event to see
70+ // Ensure that there is at least one event to see
6371 new IntListDefinition ("AuditList" , "id" ).create (createDefaultConnection (), getProjectName ());
6472
65- impersonate (TROUBLESHOOTER );
73+ impersonate (TROUBLESHOOTER_USER );
6674 ShowAdminPage showAdminPage = goToAdminConsole ().goToSettingsSection ();
6775
6876 log ("Verifying audit log link is present" );
@@ -82,7 +90,7 @@ public void testAuditLogsIsAccessible() throws Exception
8290 @ Test
8391 public void testAdminConsoleVisibility ()
8492 {
85- impersonate (TROUBLESHOOTER );
93+ impersonate (TROUBLESHOOTER_USER );
8694
8795 log ("Verify permissions from troubleshooter" );
8896 verifySitePermissionSetting (false );
@@ -93,20 +101,19 @@ public void testAdminConsoleVisibility()
93101 verifySitePermissionSetting (true );
94102 }
95103
96- /**
97- * Issue 47508: auditLog table visibility is inconsistent
98- * Assert broken behavior to prompt a test update once issue is fixed.
99- */
104+ // Verify fix for Issue 47508 / GitHub Issue #26: auditLog table visibility is inconsistent
100105 @ Test
101106 public void testAllAuditTableVisibility ()
102107 {
103- impersonate (TROUBLESHOOTER );
108+ impersonate (TROUBLESHOOTER_USER );
104109 ShowAdminPage showAdminPage = goToAdminConsole ().goToSettingsSection ();
105110
106- log ("Verify the export file is non empty " );
111+ log ("Verify \" Group and role \" audit event table is viewable " );
107112 ShowAuditLogPage auditLogPage = showAdminPage .clickAuditLog ();
108113 auditLogPage .selectView ("Group and role events" );
109- assertTextPresent ("You do not have permission to see this data." );
114+ assertTextNotPresent ("You do not have permission to see this data." );
115+ DataRegionTable logTable = auditLogPage .getLogTable ();
116+ assertTrue (logTable .getDataRowCount () > 0 );
110117 }
111118
112119 protected void verifySitePermissionSetting (boolean canSave )
@@ -132,6 +139,60 @@ protected void verifySitePermissionSetting(boolean canSave)
132139 isElementPresent (Locator .button ("Save and Finish" )));
133140 }
134141
142+ // Verifications for GitHub Issue #785 - Troubleshooters should have read access in the root (but not elsewhere)
143+ @ Test
144+ public void testQueryAccessInRoot ()
145+ {
146+ goToAdminConsole ();
147+ impersonate (TROUBLESHOOTER_USER );
148+ testQueryAccess ();
149+ stopImpersonating ();
150+
151+ goToAdminConsole ();
152+ impersonateRole (TROUBLESHOOTER_ROLE );
153+ testQueryAccess ();
154+ stopImpersonating ();
155+ }
156+
157+ private void testQueryAccess ()
158+ {
159+ // Verify that Troubleshooters can access the schema browser and view an arbitrary query in the root
160+ goToSchemaBrowser (null , false );
161+ DataRegionTable dataRegionTable = viewQueryData ("core" , "Modules" );
162+ dataRegionTable .showAll ();
163+ int rowCount = dataRegionTable .getDataRowCount ();
164+ assertTrue (rowCount > 6 );
165+
166+ // Verify that basic summary statistics work
167+ dataRegionTable .setSummaryStatistic ("Name" , SummaryStatisticsHelper .BASE_STAT_COUNT , String .valueOf (rowCount ));
168+
169+ // Verify that exports using POST work
170+ DataRegionExportHelper exportHelper = new DataRegionExportHelper (dataRegionTable );
171+ exportHelper .exportExcel (AbstractDataRegionExportOrSignHelper .ExcelFileType .XLSX );
172+ exportHelper .exportScript (DataRegionExportHelper .ScriptExportType .JAVA );
173+
174+ // Troubleshooters should NOT have read access outside the root
175+ goToProjectHome ();
176+ assertTextPresent ("User does not have permission to perform this operation." );
177+ goToSchemaBrowser (getProjectName (), true );
178+ }
179+
180+ // Troubleshooters don't get the "Go To Module" menu item, so can't use goToSchemaBrowser()
181+ public void goToSchemaBrowser (@ Nullable String container , boolean expectPermissionError )
182+ {
183+ beginAt (WebTestHelper .buildRelativeUrl ("query" , container ,"begin" ));
184+
185+ if (expectPermissionError )
186+ {
187+ assertTextPresent ("User does not have permission to perform this operation." );
188+ }
189+ else
190+ {
191+ shortWait ().until (ExpectedConditions .visibilityOfElementLocated (By .cssSelector ("div.lk-sb-instructions" )));
192+ waitForElement (Locators .pageSignal ("queryTreeRendered" ));
193+ }
194+ }
195+
135196 @ Override
136197 protected String getProjectName ()
137198 {
0 commit comments