11/*
2+ * Elemental
3+ * Copyright (C) 2024, Evolved Binary Ltd
4+ *
5+ 6+ * https://www.evolvedbinary.com | https://www.elemental.xyz
7+ *
8+ * This library is free software; you can redistribute it and/or
9+ * modify it under the terms of the GNU Lesser General Public
10+ * License as published by the Free Software Foundation; version 2.1.
11+ *
12+ * This library is distributed in the hope that it will be useful,
13+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+ * Lesser General Public License for more details.
16+ *
17+ * You should have received a copy of the GNU Lesser General Public
18+ * License along with this library; if not, write to the Free Software
19+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20+ *
21+ * NOTE: Parts of this file contain code from 'The eXist-db Authors'.
22+ * The original license header is included below.
23+ *
24+ * =====================================================================
25+ *
226 * eXist-db Open Source Native XML Database
327 * Copyright (C) 2001 The eXist-db Authors
428 *
3357import org .exist .xmldb .EXistResource ;
3458import org .exist .xmldb .UserManagementService ;
3559import org .exist .xmldb .XmldbURI ;
36- import org .junit .AfterClass ;
37- import org .junit .BeforeClass ;
38- import org .junit .ClassRule ;
39- import org .junit .Test ;
60+ import org .junit .*;
61+ import org .junit .runner .RunWith ;
62+ import org .junit .runners .Parameterized ;
63+ import org .junit .runners .Parameterized .Parameter ;
64+ import org .junit .runners .Parameterized .Parameters ;
4065import org .xmldb .api .DatabaseManager ;
4166import org .xmldb .api .base .Collection ;
4267import org .xmldb .api .base .XMLDBException ;
4368import org .xmldb .api .modules .BinaryResource ;
4469
4570import javax .annotation .Nullable ;
4671import java .io .IOException ;
72+ import java .util .Arrays ;
4773
4874import static org .apache .http .HttpStatus .SC_OK ;
4975import static org .junit .Assert .assertEquals ;
5076
77+ @ RunWith (Parameterized .class )
5178public class LoginModuleTest {
5279
53- private static String XQUERY = "import module namespace login= \" http://exist-db.org/xquery/login \" " +
54- "at \" resource:org/exist/xquery/modules/persistentlogin/login.xql \" ;" +
55- " login:set-user(' org.exist.login', (), false())," +
56- "sm:id()/(descendant::sm:effective,descendant::sm:real)[1]/sm:username/string()" ;
80+ @ Parameters
81+ public static Iterable <? extends Object > loginDomains () {
82+ return Arrays . asList ( "xyz.elemental. login" , " org.exist.login" );
83+ }
5784
5885 @ ClassRule
59- public static final ExistWebServer existWebServer = new ExistWebServer (true , false , true );
86+ public static final ExistWebServer EXIST_WEB_SERVER = new ExistWebServer (true , false , true );
6087
6188 private final static String XQUERY_FILENAME = "test-login.xql" ;
6289
63- private static Collection root ;
64- private static HttpClient client ;
90+ private Collection root ;
91+ private HttpClient client ;
92+
93+ @ Parameter
94+ public String loginDomain ;
95+
96+ @ Before
97+ public void setup () throws XMLDBException {
98+ final String xquery = "import module namespace login=\" http://exist-db.org/xquery/login\" " +
99+ "at \" resource:org/exist/xquery/modules/persistentlogin/login.xql\" ;" +
100+ "login:set-user('" + loginDomain + "', (), false())," +
101+ "sm:id()/(descendant::sm:effective,descendant::sm:real)[1]/sm:username/string()" ;
65102
66- @ BeforeClass
67- public static void beforeClass () throws XMLDBException {
68- root = DatabaseManager .getCollection ("xmldb:exist://localhost:" + existWebServer .getPort () + "/xmlrpc" + XmldbURI .ROOT_COLLECTION , TestUtils .ADMIN_DB_USER , TestUtils .ADMIN_DB_PWD );
103+ root = DatabaseManager .getCollection ("xmldb:exist://localhost:" + EXIST_WEB_SERVER .getPort () + "/xmlrpc" + XmldbURI .ROOT_COLLECTION , TestUtils .ADMIN_DB_USER , TestUtils .ADMIN_DB_PWD );
69104 final BinaryResource res = root .createResource (XQUERY_FILENAME , BinaryResource .class );
70105 ((EXistResource ) res ).setMimeType ("application/xquery" );
71- res .setContent (XQUERY );
106+ res .setContent (xquery );
72107 root .storeResource (res );
73108 final UserManagementService ums = root .getService (UserManagementService .class );
74109 ums .chmod (res , 0777 );
@@ -77,8 +112,8 @@ public static void beforeClass() throws XMLDBException {
77112 client = HttpClientBuilder .create ().setDefaultCookieStore (store ).build ();
78113 }
79114
80- @ AfterClass
81- public static void afterClass () throws XMLDBException {
115+ @ After
116+ public void cleanup () throws XMLDBException {
82117 final BinaryResource res = (BinaryResource )root .getResource (XQUERY_FILENAME );
83118 root .removeResource (res );
84119 }
@@ -98,11 +133,11 @@ public void loginAndLogout() throws IOException {
98133 doGet ("logout=true" , TestUtils .GUEST_DB_USER );
99134 }
100135
101- private void doGet (@ Nullable String params , String expected ) throws IOException {
102- final HttpGet httpGet = new HttpGet ("http://localhost:" + existWebServer .getPort () + "/rest" + XmldbURI .ROOT_COLLECTION + '/' + XQUERY_FILENAME +
136+ private void doGet (@ Nullable final String params , final String expected ) throws IOException {
137+ final HttpGet httpGet = new HttpGet ("http://localhost:" + EXIST_WEB_SERVER .getPort () + "/rest" + XmldbURI .ROOT_COLLECTION + '/' + XQUERY_FILENAME +
103138 (params == null ? "" : "?" + params ));
104- HttpResponse response = client .execute (httpGet );
105- HttpEntity entity = response .getEntity ();
139+ final HttpResponse response = client .execute (httpGet );
140+ final HttpEntity entity = response .getEntity ();
106141 final String responseBody = EntityUtils .toString (entity );
107142 assertEquals (responseBody , SC_OK , response .getStatusLine ().getStatusCode ());
108143 assertEquals (expected , responseBody );
0 commit comments