Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ Require-Bundle: org.eclipse.core.runtime,
org.jkiss.dbeaver.ext.generic,
org.eclipse.lsp4j,
org.eclipse.lsp4j.jsonrpc
Export-Package: io.cloudbeaver.test.platform
Export-Package: io.cloudbeaver.test.platform,
io.cloudbeaver.test.platform.util
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
import io.cloudbeaver.model.rm.lock.RMLockTest;
import io.cloudbeaver.model.session.WebSessionProjectTest;
import io.cloudbeaver.model.session.WebSessionTest;
import io.cloudbeaver.test.platform.admin.AdminCreateUserTest;
import io.cloudbeaver.test.platform.admin.AdminLastLoginTimeTest;
import io.cloudbeaver.test.platform.sql.*;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.platform.suite.api.SelectClasses;
Expand All @@ -40,7 +43,14 @@
NoSessionTest.class,
WebSessionTest.class,
WebSessionProjectTest.class,
WebNavigatorNodeInfoTest.class
WebNavigatorNodeInfoTest.class,
AdminCreateUserTest.class,
AdminLastLoginTimeTest.class,
GenerateSQLResultSetTest.class,
RowIdResultSetTest.class,
GroupingEndpointTest.class,
ForeignKeyNavigationEndpointTest.class,
DataFilterConstraintsTest.class
}
)
public class CEServerTestSuite {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2026 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.cloudbeaver.test.platform;

import io.cloudbeaver.CloudbeaverMockTest;
import io.cloudbeaver.WebSessionGlobalProjectImpl;
import io.cloudbeaver.app.CEAppStarter;
import io.cloudbeaver.model.WebConnectionInfo;
import io.cloudbeaver.model.session.BaseWebSession;
import io.cloudbeaver.model.session.WebSession;
import io.cloudbeaver.server.WebAppUtils;
import io.cloudbeaver.test.WebGQLClient;
import io.cloudbeaver.test.platform.util.GraphQLTestClientWrapper;
import io.cloudbeaver.test.platform.util.WebDBTestUtils;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.DBPDataSourceContainer;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCSession;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.LoggingProgressMonitor;
import org.junit.jupiter.api.BeforeEach;

public abstract class CloudbeaverDBTest extends CloudbeaverMockTest {

protected final WebGQLClient client = CEAppStarter.createClient();
protected DBPDataSourceContainer databaseContainer;
protected static JDBCSession databaseSession;
protected final DBRProgressMonitor monitor = new LoggingProgressMonitor();

protected final GraphQLTestClientWrapper clientWrapper = new GraphQLTestClientWrapper(client);
protected WebSessionGlobalProjectImpl globalProject;
protected WebConnectionInfo webConnectionInfo;
protected WebSession webSession;

@BeforeEach
public void init() throws Exception {
String sessionId = clientWrapper.openSession();
webSession = resolveWebSession(sessionId);
globalProject = webSession.getGlobalProject();
if (globalProject == null) {
throw new DBException("Global project is not configured");
}
databaseContainer = WebDBTestUtils.createH2DataSource(monitor, globalProject);
globalProject.getDataSourceRegistry().addDataSource(databaseContainer);
databaseSession = DBUtils.openUtilSession(monitor, databaseContainer, "Internal database session");
databaseSession.enableLogging(false);
webConnectionInfo = globalProject.addConnection(databaseContainer);
}

private static WebSession resolveWebSession(String sessionId) throws DBException {
var sessionManager = WebAppUtils.getWebApplication().getSessionManager();
BaseWebSession session = sessionId == null ? null : sessionManager.getSession(sessionId);
if (session instanceof WebSession ws) {
return ws;
}
return (WebSession) sessionManager.getAllActiveSessions().stream()
.findFirst()
.orElseThrow(() -> new DBException("No active web session"));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2026 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.cloudbeaver.test.platform.admin;

import io.cloudbeaver.CloudbeaverMockTest;
import io.cloudbeaver.app.CEAppStarter;
import io.cloudbeaver.test.WebGQLClient;
import org.jkiss.dbeaver.model.data.json.JSONUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.Map;

public class AdminCreateUserTest extends CloudbeaverMockTest {

private static final String GQL_CREATE_USER = """
query createUser($userId: ID!, $enabled: Boolean!, $authRole: String) {
result: createUser(userId: $userId, enabled: $enabled, authRole: $authRole) { userId }
}""";

private static final String GQL_DELETE_USER = """
query deleteUser($userId: ID!) {
result: deleteUser(userId: $userId)
}""";

@Test
public void testCreateUserTrimsUserName() throws Exception {
WebGQLClient adminClient = CEAppStarter.createClient();
CEAppStarter.authenticateTestUser(adminClient);

String expectedUserId = "trim-user-test";
String paddedUserName = " " + expectedUserId + " ";
try {
Map<String, Object> created = adminClient.sendQuery(
GQL_CREATE_USER,
Map.of("userId", paddedUserName, "enabled", true, "authRole", "user")
);
Assertions.assertNotNull(created);
Assertions.assertEquals(expectedUserId, JSONUtils.getString(created, "userId"));
} finally {
adminClient.sendQuery(GQL_DELETE_USER, Map.of("userId", expectedUserId));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2026 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.cloudbeaver.test.platform.admin;

import io.cloudbeaver.CloudbeaverMockTest;
import io.cloudbeaver.app.CEAppStarter;
import io.cloudbeaver.auth.provider.local.LocalAuthProvider;
import io.cloudbeaver.test.WebGQLClient;
import org.jkiss.dbeaver.model.auth.SMAuthStatus;
import org.jkiss.dbeaver.model.data.json.JSONUtils;
import org.jkiss.utils.SecurityUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.Map;

public class AdminLastLoginTimeTest extends CloudbeaverMockTest {

private static final String TEST_USER_ID = "last-login-test-user";
private static final String TEST_USER_PASSWORD = SecurityUtils.makeDigest("12345");

private static final String GQL_CREATE_USER = """
query createUser($userId: ID!, $enabled: Boolean!, $authRole: String) {
result: createUser(userId: $userId, enabled: $enabled, authRole: $authRole) { userId }
}""";

private static final String GQL_DELETE_USER = """
query deleteUser($userId: ID!) {
result: deleteUser(userId: $userId)
}""";

private static final String GQL_SET_USER_CREDENTIALS = """
query setUserCredentials($userId: ID!, $providerId: ID!, $credentials: Object!) {
result: setUserCredentials(userId: $userId, providerId: $providerId, credentials: $credentials)
}""";

private static final String GQL_ADMIN_USER_INFO = """
query adminUserInfo($userId: ID!) {
result: adminUserInfo(userId: $userId) {
userId
lastLoginTime
}
}""";

@Test
public void testLastLoginTimePopulatedAfterAuthentication() throws Exception {

// GIVEN
WebGQLClient adminClient = CEAppStarter.createClient();
CEAppStarter.authenticateTestUser(adminClient);

try {
Map<String, Object> created = adminClient.sendQuery(
GQL_CREATE_USER,
Map.of("userId", TEST_USER_ID, "enabled", true, "authRole", "user")
);
Assertions.assertNotNull(created);
Assertions.assertEquals(TEST_USER_ID, JSONUtils.getString(created, "userId"));

adminClient.sendQuery(
GQL_SET_USER_CREDENTIALS,
Map.of(
"userId", TEST_USER_ID,
"providerId", LocalAuthProvider.PROVIDER_ID,
"credentials", Map.of("password", TEST_USER_PASSWORD)
)
);

Map<String, Object> beforeLogin = adminClient.sendQuery(
GQL_ADMIN_USER_INFO,
Map.of("userId", TEST_USER_ID)
);
Assertions.assertNotNull(beforeLogin);
Assertions.assertEquals(TEST_USER_ID, JSONUtils.getString(beforeLogin, "userId"));
Assertions.assertNull(
JSONUtils.getString(beforeLogin, "lastLoginTime"),
"lastLoginTime should be null before the first successful authentication"
);

WebGQLClient userClient = CEAppStarter.createClient();
Map<String, Object> authInfo = userClient.sendQuery(
WebGQLClient.GQL_AUTHENTICATE,
Map.of(
"provider", LocalAuthProvider.PROVIDER_ID,
"credentials", Map.of(
LocalAuthProvider.CRED_USER, TEST_USER_ID,
LocalAuthProvider.CRED_PASSWORD, TEST_USER_PASSWORD
)
)
);
Assertions.assertNotNull(authInfo);
Assertions.assertEquals(SMAuthStatus.SUCCESS.name(), JSONUtils.getString(authInfo, "authStatus"));

// WHEN
Map<String, Object> afterLogin = adminClient.sendQuery(
GQL_ADMIN_USER_INFO,
Map.of("userId", TEST_USER_ID)
);

// THEN
Assertions.assertNotNull(afterLogin);
Assertions.assertEquals(TEST_USER_ID, JSONUtils.getString(afterLogin, "userId"));
String lastLoginTime = JSONUtils.getString(afterLogin, "lastLoginTime");
Assertions.assertNotNull(
lastLoginTime,
"lastLoginTime must be returned for an authenticated user"
);
Assertions.assertFalse(
lastLoginTime.isBlank(),
"lastLoginTime must not be empty"
);
} finally {
adminClient.sendQuery(GQL_DELETE_USER, Map.of("userId", TEST_USER_ID));
}
}
}
Loading
Loading