1717
1818import static org .junit .Assert .assertArrayEquals ;
1919import static org .junit .Assert .assertEquals ;
20+ import static org .junit .Assert .assertTrue ;
21+ import static org .junit .Assert .fail ;
2022
2123import java .io .IOException ;
2224import java .math .BigInteger ;
4446import com .marklogic .client .DatabaseClient ;
4547import com .marklogic .client .DatabaseClientFactory ;
4648import com .marklogic .client .DatabaseClientFactory .Authentication ;
49+ import com .marklogic .client .FailedRequestException ;
4750import com .marklogic .client .Transaction ;
4851import com .marklogic .client .admin .ExtensionLibrariesManager ;
4952import com .marklogic .client .document .DocumentWriteSet ;
6770public class EvalTest {
6871 private static GregorianCalendar septFirst = new GregorianCalendar (TimeZone .getTimeZone ("CET" ));
6972 private static ExtensionLibrariesManager libMgr ;
73+ private static DatabaseClient adminClient = Common .newAdminClient ();
7074
7175 @ BeforeClass
7276 public static void beforeClass () {
73- Common .connectAdmin ();
74- libMgr = Common .client .newServerConfigManager ().newExtensionLibrariesManager ();
77+ libMgr = adminClient .newServerConfigManager ().newExtensionLibrariesManager ();
7578 Common .connectEval ();
7679
7780 septFirst .set (2014 , Calendar .SEPTEMBER , 1 , 0 , 0 , 0 );
@@ -80,6 +83,7 @@ public static void beforeClass() {
8083 }
8184 @ AfterClass
8285 public static void afterClass () {
86+ adminClient .release ();
8387 Common .release ();
8488 }
8589
@@ -449,5 +453,16 @@ public void test_171() throws Exception{
449453 t1 .rollback ();
450454 }
451455 }
452- }
456+ }
457+
458+ @ Test
459+ public void test_582_need_privilege () throws Exception {
460+ try {
461+ assertEquals ("hello" , adminClient .newServerEval ()
462+ .xquery ("'hello'" ).eval ().next ().getString ());
463+ fail ("a FailedRequestException should have been thrown since rest_admin doesn't have eval privileges" );
464+ } catch (FailedRequestException fre ) {
465+ assertTrue (fre .getMessage ().contains ("SEC-PRIV: Need privilege: http://marklogic.com/xdmp/privileges/xdbc-eval" ));
466+ }
467+ }
453468}
0 commit comments