Skip to content

Commit d4514ca

Browse files
authored
Merge pull request #154 from evolvedbinary/6.x.x/hotfix/login-module-test
[6.x.x] Added a test to the Persistent Login Module for an Elemental login domain
2 parents 25bea11 + 981cbc4 commit d4514ca

2 files changed

Lines changed: 58 additions & 21 deletions

File tree

extensions/modules/persistentlogin/pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
<include>src/test/resources-filtered/conf.xml</include>
117117
<include>src/test/resources/log4j2.xml</include>
118118
<include>src/test/resources/standalone-webapp/WEB-INF/web.xml</include>
119+
<include>src/test/java/org/exist/xquery/modules/persistentlogin/LoginModuleTest.java</include>
119120
</includes>
120121
</licenseSet>
121122

@@ -129,6 +130,7 @@
129130
<exclude>src/test/resources-filtered/conf.xml</exclude>
130131
<exclude>src/test/resources/log4j2.xml</exclude>
131132
<exclude>src/test/resources/standalone-webapp/WEB-INF/web.xml</exclude>
133+
<exclude>src/test/java/org/exist/xquery/modules/persistentlogin/LoginModuleTest.java</exclude>
132134
</excludes>
133135
</licenseSet>
134136

extensions/modules/persistentlogin/src/test/java/org/exist/xquery/modules/persistentlogin/LoginModuleTest.java

Lines changed: 56 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
11
/*
2+
* Elemental
3+
* Copyright (C) 2024, Evolved Binary Ltd
4+
*
5+
* admin@evolvedbinary.com
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
*
@@ -34,42 +58,53 @@
3458
import org.exist.xmldb.EXistResource;
3559
import org.exist.xmldb.UserManagementService;
3660
import org.exist.xmldb.XmldbURI;
37-
import org.junit.AfterClass;
38-
import org.junit.BeforeClass;
39-
import org.junit.ClassRule;
40-
import org.junit.Test;
61+
import org.junit.*;
62+
import org.junit.runner.RunWith;
63+
import org.junit.runners.Parameterized;
64+
import org.junit.runners.Parameterized.Parameter;
65+
import org.junit.runners.Parameterized.Parameters;
4166
import org.xmldb.api.DatabaseManager;
4267
import org.xmldb.api.base.Collection;
4368
import org.xmldb.api.base.XMLDBException;
4469
import org.xmldb.api.modules.BinaryResource;
4570

4671
import javax.annotation.Nullable;
4772
import java.io.IOException;
73+
import java.util.Arrays;
4874

4975
import static org.apache.http.HttpStatus.SC_OK;
5076
import static org.junit.Assert.assertEquals;
5177

78+
@RunWith(Parameterized.class)
5279
public class LoginModuleTest {
5380

54-
private static String XQUERY = "import module namespace login=\"http://exist-db.org/xquery/login\" " +
55-
"at \"resource:org/exist/xquery/modules/persistentlogin/login.xql\";" +
56-
"login:set-user('org.exist.login', (), false())," +
57-
"sm:id()/(descendant::sm:effective,descendant::sm:real)[1]/sm:username/string()";
81+
@Parameters
82+
public static Iterable<? extends Object> loginDomains() {
83+
return Arrays.asList("xyz.elemental.login", "org.exist.login");
84+
}
5885

5986
@ClassRule
60-
public static final ExistWebServer existWebServer = new ExistWebServer(true, false, true);
87+
public static final ExistWebServer EXIST_WEB_SERVER = new ExistWebServer(true, false, true);
6188

6289
private final static String XQUERY_FILENAME = "test-login.xql";
6390

64-
private static Collection root;
65-
private static HttpClient client;
91+
private Collection root;
92+
private HttpClient client;
93+
94+
@Parameter
95+
public String loginDomain;
96+
97+
@Before
98+
public void setup() throws XMLDBException {
99+
final String xquery = "import module namespace login=\"http://exist-db.org/xquery/login\" " +
100+
"at \"resource:org/exist/xquery/modules/persistentlogin/login.xql\";" +
101+
"login:set-user('" + loginDomain + "', (), false())," +
102+
"sm:id()/(descendant::sm:effective,descendant::sm:real)[1]/sm:username/string()";
66103

67-
@BeforeClass
68-
public static void beforeClass() throws XMLDBException {
69-
root = DatabaseManager.getCollection("xmldb:exist://localhost:" + existWebServer.getPort() + "/xmlrpc" + XmldbURI.ROOT_COLLECTION, TestUtils.ADMIN_DB_USER, TestUtils.ADMIN_DB_PWD);
104+
root = DatabaseManager.getCollection("xmldb:exist://localhost:" + EXIST_WEB_SERVER.getPort() + "/xmlrpc" + XmldbURI.ROOT_COLLECTION, TestUtils.ADMIN_DB_USER, TestUtils.ADMIN_DB_PWD);
70105
final BinaryResource res = (BinaryResource)root.createResource(XQUERY_FILENAME, "BinaryResource");
71106
((EXistResource) res).setMimeType("application/xquery");
72-
res.setContent(XQUERY);
107+
res.setContent(xquery);
73108
root.storeResource(res);
74109
final UserManagementService ums = (UserManagementService)root.getService("UserManagementService", "1.0");
75110
ums.chmod(res, 0777);
@@ -78,8 +113,8 @@ public static void beforeClass() throws XMLDBException {
78113
client = HttpClientBuilder.create().setDefaultCookieStore(store).build();
79114
}
80115

81-
@AfterClass
82-
public static void afterClass() throws XMLDBException {
116+
@After
117+
public void cleanup() throws XMLDBException {
83118
final BinaryResource res = (BinaryResource)root.getResource(XQUERY_FILENAME);
84119
root.removeResource(res);
85120
}
@@ -99,11 +134,11 @@ public void loginAndLogout() throws IOException {
99134
doGet("logout=true", TestUtils.GUEST_DB_USER);
100135
}
101136

102-
private void doGet(@Nullable String params, String expected) throws IOException {
103-
final HttpGet httpGet = new HttpGet("http://localhost:" + existWebServer.getPort() + "/rest" + XmldbURI.ROOT_COLLECTION + '/' + XQUERY_FILENAME +
137+
private void doGet(@Nullable final String params, final String expected) throws IOException {
138+
final HttpGet httpGet = new HttpGet("http://localhost:" + EXIST_WEB_SERVER.getPort() + "/rest" + XmldbURI.ROOT_COLLECTION + '/' + XQUERY_FILENAME +
104139
(params == null ? "" : "?" + params));
105-
HttpResponse response = client.execute(httpGet);
106-
HttpEntity entity = response.getEntity();
140+
final HttpResponse response = client.execute(httpGet);
141+
final HttpEntity entity = response.getEntity();
107142
final String responseBody = EntityUtils.toString(entity);
108143
assertEquals(responseBody, SC_OK, response.getStatusLine().getStatusCode());
109144
assertEquals(expected, responseBody);

0 commit comments

Comments
 (0)