diff --git a/dialect/api/src/main/java/org/eclipse/daanse/sql/dialect/api/generator/DdlGenerator.java b/dialect/api/src/main/java/org/eclipse/daanse/sql/dialect/api/generator/DdlGenerator.java index fdcc72d..ecf3048 100644 --- a/dialect/api/src/main/java/org/eclipse/daanse/sql/dialect/api/generator/DdlGenerator.java +++ b/dialect/api/src/main/java/org/eclipse/daanse/sql/dialect/api/generator/DdlGenerator.java @@ -1639,6 +1639,16 @@ default boolean supportsUsers() { return false; } + /** + * @return true if {@code grantRole} may name a user where it names a role: the database grants a + * user to another user or role like a role, and the grantee holds the user's privileges. + * PostgreSQL does, where a user is a role that may log in; MySQL from 8.0 does, where + * users and roles are accounts alike. Most databases grant roles only. + */ + default boolean supportsUserAsRole() { + return false; + } + /** One table-rename step of a multi-rename. */ record TableRename(TableReference table, String newName) { } diff --git a/dialect/db/consistency-test/src/test/java/org/eclipse/daanse/sql/dialect/db/consistencytest/UserAsRoleTest.java b/dialect/db/consistency-test/src/test/java/org/eclipse/daanse/sql/dialect/db/consistencytest/UserAsRoleTest.java new file mode 100644 index 0000000..0726710 --- /dev/null +++ b/dialect/db/consistency-test/src/test/java/org/eclipse/daanse/sql/dialect/db/consistencytest/UserAsRoleTest.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2026 Contributors to the Eclipse Foundation. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.daanse.sql.dialect.db.consistencytest; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.stream.Stream; + +import org.eclipse.daanse.sql.dialect.api.Dialect; +import org.eclipse.daanse.sql.dialect.api.DialectInitData; +import org.eclipse.daanse.sql.dialect.db.clickhouse.ClickHouseDialect; +import org.eclipse.daanse.sql.dialect.db.common.AnsiDialect; +import org.eclipse.daanse.sql.dialect.db.derby.DerbyDialect; +import org.eclipse.daanse.sql.dialect.db.duckdb.DuckDbDialect; +import org.eclipse.daanse.sql.dialect.db.h2.H2Dialect; +import org.eclipse.daanse.sql.dialect.db.hive.HiveDialect; +import org.eclipse.daanse.sql.dialect.db.impala.ImpalaDialect; +import org.eclipse.daanse.sql.dialect.db.mariadb.MariaDBDialect; +import org.eclipse.daanse.sql.dialect.db.mssqlserver.MicrosoftSqlServerDialect; +import org.eclipse.daanse.sql.dialect.db.mysql.MySqlDialect; +import org.eclipse.daanse.sql.dialect.db.oracle.OracleDialect; +import org.eclipse.daanse.sql.dialect.db.postgresql.PostgreSqlDialect; +import org.eclipse.daanse.sql.dialect.db.sqlite.SqliteDialect; +import org.junit.jupiter.api.Named; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +/** + * Which dialects grant a user like a role: PostgreSQL, where a user is a role that may log in, and MySQL from 8.0, + * where users and roles are accounts alike. The others grant roles only. + */ +class UserAsRoleTest { + + static Stream dialects() { + return Stream.of(of("postgresql", new PostgreSqlDialect(), true), + of("mysql", new MySqlDialect(), true), + of("mysql 5.7", new MySqlDialect(version(5, 7)), false), + of("mariadb", new MariaDBDialect(), false), + of("oracle", new OracleDialect(), false), + of("mssql", new MicrosoftSqlServerDialect(), false), + of("h2", new H2Dialect(), false), + of("clickhouse", new ClickHouseDialect(), false), + of("derby", new DerbyDialect(), false), + of("hive", new HiveDialect(), false), + of("impala", new ImpalaDialect(), false), + of("ansi", new AnsiDialect(), false), + of("duckdb", new DuckDbDialect(), false), + of("sqlite", new SqliteDialect(), false)); + } + + @ParameterizedTest(name = "{0}") + @MethodSource("dialects") + void grantsAUserLikeARole(Dialect dialect, boolean expected) { + assertThat(dialect.ddlGenerator().supportsUserAsRole()).as("supportsUserAsRole").isEqualTo(expected); + } + + private static Arguments of(String name, Dialect dialect, boolean expected) { + return Arguments.of(Named.of(name, dialect), expected); + } + + private static DialectInitData version(int major, int minor) { + return DialectInitData.ansiDefaults().withVersion(major, minor); + } +} diff --git a/dialect/db/mariadb/src/main/java/org/eclipse/daanse/sql/dialect/db/mariadb/MariaDBDialect.java b/dialect/db/mariadb/src/main/java/org/eclipse/daanse/sql/dialect/db/mariadb/MariaDBDialect.java index c875e8f..f4d0ed3 100644 --- a/dialect/db/mariadb/src/main/java/org/eclipse/daanse/sql/dialect/db/mariadb/MariaDBDialect.java +++ b/dialect/db/mariadb/src/main/java/org/eclipse/daanse/sql/dialect/db/mariadb/MariaDBDialect.java @@ -192,6 +192,12 @@ public boolean supportsUsers() { || dialectVersion.atLeast(new org.eclipse.daanse.sql.dialect.api.DialectVersion(10, 4, 2)); } + /** MariaDB grants a role only, one made with {@code CREATE ROLE}; a user is no role there. */ + @Override + public boolean supportsUserAsRole() { + return false; + } + /** * MariaDB keeps a descending index column from 10.8; before, it took {@code DESC} and ignored it. * A dialect made without a connection takes such a version. diff --git a/dialect/db/mariadb/src/test/java/org/eclipse/daanse/sql/dialect/db/mariadb/container/MariaDBUserAsRoleTest.java b/dialect/db/mariadb/src/test/java/org/eclipse/daanse/sql/dialect/db/mariadb/container/MariaDBUserAsRoleTest.java new file mode 100644 index 0000000..2b4826b --- /dev/null +++ b/dialect/db/mariadb/src/test/java/org/eclipse/daanse/sql/dialect/db/mariadb/container/MariaDBUserAsRoleTest.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2026 Contributors to the Eclipse Foundation. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.daanse.sql.dialect.db.mariadb.container; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.sql.Statement; + +import org.eclipse.daanse.sql.dialect.api.DialectInitData; +import org.eclipse.daanse.sql.dialect.db.mariadb.MariaDBDialect; +import org.junit.jupiter.api.condition.EnabledIfSystemProperty; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; +import org.testcontainers.containers.MariaDBContainer; + +/** + * MariaDB grants a role only, one made with {@code CREATE ROLE}: a user named where a role stands is refused, unlike in + * MySQL. The dialect is built from a live connection. + */ +@EnabledIfSystemProperty(named = "integration.docker", matches = "true") +class MariaDBUserAsRoleTest { + + @ParameterizedTest(name = "mariadb:{0}") + @CsvSource({ "10.6", "11.4" }) + void aUserIsNoRole(String tag) throws Exception { + try (MariaDBContainer db = new MariaDBContainer<>("mariadb:" + tag).withDatabaseName("rt") + .withUsername("rt").withPassword("rt")) { + db.start(); + // root may create roles and users; the container's user may not + try (Connection c = DriverManager.getConnection(db.getJdbcUrl(), "root", db.getPassword()); + Statement st = c.createStatement()) { + MariaDBDialect dialect = new MariaDBDialect(DialectInitData.fromConnection(c)); + + assertThat(dialect.supportsUserAsRole()).as("supportsUserAsRole").isFalse(); + + st.execute(dialect.createUser("rt_user", false).orElseThrow()); + st.execute(dialect.createUser("rt_other", false).orElseThrow()); + assertThatThrownBy(() -> st.execute(dialect.grantRole("rt_user", "rt_other", false))) + .as("a user granted like a role").isInstanceOf(SQLException.class); + + st.execute(dialect.createRole("rt_role", false).orElseThrow()); + st.execute(dialect.grantRole("rt_role", "rt_other", false)); + } + } + } +} diff --git a/dialect/db/mysql/src/main/java/org/eclipse/daanse/sql/dialect/db/mysql/MySqlDialect.java b/dialect/db/mysql/src/main/java/org/eclipse/daanse/sql/dialect/db/mysql/MySqlDialect.java index daba89c..be3fea0 100644 --- a/dialect/db/mysql/src/main/java/org/eclipse/daanse/sql/dialect/db/mysql/MySqlDialect.java +++ b/dialect/db/mysql/src/main/java/org/eclipse/daanse/sql/dialect/db/mysql/MySqlDialect.java @@ -1122,4 +1122,13 @@ protected boolean createOrReplaceRoutine() { public boolean supportsRoles() { return dialectVersion.isUnknownOrAtLeast(8, 0); } + + /** + * MySQL: from 8.0 users and roles are accounts alike, and {@code GRANT 'u' TO 'v'} grants a user + * like a role. + */ + @Override + public boolean supportsUserAsRole() { + return supportsRoles(); + } } diff --git a/dialect/db/mysql/src/test/java/org/eclipse/daanse/sql/dialect/db/mysql/container/MySqlRolesTest.java b/dialect/db/mysql/src/test/java/org/eclipse/daanse/sql/dialect/db/mysql/container/MySqlRolesTest.java index b32da40..0da58f6 100644 --- a/dialect/db/mysql/src/test/java/org/eclipse/daanse/sql/dialect/db/mysql/container/MySqlRolesTest.java +++ b/dialect/db/mysql/src/test/java/org/eclipse/daanse/sql/dialect/db/mysql/container/MySqlRolesTest.java @@ -56,6 +56,7 @@ void roles(String tag, boolean expected) throws Exception { MySqlDialect dialect = new MySqlDialect(DialectInitData.fromConnection(c)); assertThat(dialect.supportsRoles()).as("supportsRoles").isEqualTo(expected); + assertThat(dialect.supportsUserAsRole()).as("supportsUserAsRole").isEqualTo(expected); if (!expected) { assertThat(dialect.createRole("rt_role", false)).as("no role on 5.7").isEmpty(); @@ -90,6 +91,18 @@ void roles(String tag, boolean expected) throws Exception { assertThat(String.join(" ", rows(st, "SHOW GRANTS FOR rt_user"))).as("with the admin option") .contains("GRANT `rt_role`@`%` TO `rt_user`@`%` WITH ADMIN OPTION"); + // a user granted like a role: the grantee holds the user's privileges + st.execute(dialect.grantTablePrivilege("INSERT", ITEMS, "rt_user", false)); + st.execute(dialect.createUser("rt_other", false).orElseThrow()); + st.execute(dialect.grantRole("rt_user", "rt_other", false)); + assertThat(String.join(" ", rows(st, "SHOW GRANTS FOR rt_other"))).as("the user granted like a role") + .contains("GRANT `rt_user`@`%` TO `rt_other`@`%`"); + // MySQL folds what the user holds itself and through its role into one line: SELECT, INSERT + assertThat(String.join(" ", rows(st, "SHOW GRANTS FOR rt_other USING rt_user"))) + .as("the grantee holds the user's privilege") + .contains("INSERT ON `rt`.`items` TO `rt_other`@`%`"); + st.execute(dialect.dropUser("rt_other", false).orElseThrow()); + st.execute(dialect.dropRole("rt_role", false).orElseThrow()); assertThat(rows(st, "SELECT user FROM mysql.user WHERE user = 'rt_role'")).as("dropped").isEmpty(); assertThat(String.join(" ", rows(st, "SHOW GRANTS FOR rt_user"))).as("the grant gone with the role") diff --git a/dialect/db/postgresql/src/main/java/org/eclipse/daanse/sql/dialect/db/postgresql/PostgreSqlDialect.java b/dialect/db/postgresql/src/main/java/org/eclipse/daanse/sql/dialect/db/postgresql/PostgreSqlDialect.java index e16bcb9..34ef6c6 100644 --- a/dialect/db/postgresql/src/main/java/org/eclipse/daanse/sql/dialect/db/postgresql/PostgreSqlDialect.java +++ b/dialect/db/postgresql/src/main/java/org/eclipse/daanse/sql/dialect/db/postgresql/PostgreSqlDialect.java @@ -583,6 +583,12 @@ public boolean supportsUsers() { return true; } + /** PostgreSQL: a user is a role that may log in, and a role is granted to another as any role is. */ + @Override + public boolean supportsUserAsRole() { + return true; + } + /** * PostgreSQL has no {@code CREATE USER IF NOT EXISTS}: with {@code ifNotExists} the statement is a * {@code DO} block that takes an existing role of the name as done. diff --git a/dialect/db/postgresql/src/test/java/org/eclipse/daanse/sql/dialect/db/postgresql/container/PostgreSqlUserAsRoleTest.java b/dialect/db/postgresql/src/test/java/org/eclipse/daanse/sql/dialect/db/postgresql/container/PostgreSqlUserAsRoleTest.java new file mode 100644 index 0000000..882a316 --- /dev/null +++ b/dialect/db/postgresql/src/test/java/org/eclipse/daanse/sql/dialect/db/postgresql/container/PostgreSqlUserAsRoleTest.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2026 Contributors to the Eclipse Foundation. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.daanse.sql.dialect.db.postgresql.container; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.Optional; + +import org.eclipse.daanse.sql.dialect.api.DialectInitData; +import org.eclipse.daanse.sql.dialect.db.postgresql.PostgreSqlDialect; +import org.eclipse.daanse.sql.model.schema.SchemaReference; +import org.eclipse.daanse.sql.model.schema.TableReference; +import org.junit.jupiter.api.condition.EnabledIfSystemProperty; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; +import org.testcontainers.containers.PostgreSQLContainer; + +/** + * PostgreSQL grants a user like a role: a user is a role that may log in, and {@code GRANT "a" TO "b"} makes b hold + * what a holds, its own privileges among it. The dialect is built from a live connection. + */ +@EnabledIfSystemProperty(named = "integration.docker", matches = "true") +class PostgreSqlUserAsRoleTest { + + private static final TableReference ITEMS = new TableReference( + Optional.of(new SchemaReference(Optional.empty(), "public")), "items", TableReference.TYPE_TABLE); + + @ParameterizedTest(name = "postgres:{0}") + @CsvSource({ "12-alpine", "16-alpine" }) + void aUserGrantedLikeARole(String tag) throws Exception { + try (PostgreSQLContainer pg = new PostgreSQLContainer<>("postgres:" + tag)) { + pg.start(); + try (Connection c = pg.createConnection(""); Statement st = c.createStatement()) { + st.execute("CREATE TABLE items(id INT)"); + PostgreSqlDialect dialect = new PostgreSqlDialect(DialectInitData.fromConnection(c)); + + assertThat(dialect.supportsUserAsRole()).as("supportsUserAsRole").isTrue(); + + st.execute(dialect.createUser("rt_user", false).orElseThrow()); + st.execute(dialect.createUser("rt_other", false).orElseThrow()); + st.execute(dialect.grantTablePrivilege("SELECT", ITEMS, "rt_user", false)); + assertThat(holds(st, "rt_other")).as("before the grant").isFalse(); + + st.execute(dialect.grantRole("rt_user", "rt_other", false)); + assertThat(holds(st, "rt_other")).as("the grantee holds the user's privilege").isTrue(); + assertThat(holds(st, "rt_user")).as("the user keeps its own").isTrue(); + + st.execute(dialect.revokeRole("rt_user", "rt_other")); + assertThat(holds(st, "rt_other")).as("revoked").isFalse(); + } + } + } + + private static boolean holds(Statement st, String role) throws SQLException { + try (ResultSet rs = st.executeQuery("SELECT has_table_privilege('" + role + "', 'public.items', 'SELECT')")) { + rs.next(); + return rs.getBoolean(1); + } + } +} diff --git a/jdbc/metadata/src/main/java/org/eclipse/daanse/sql/jdbc/metadata/OracleMetadataProvider.java b/jdbc/metadata/src/main/java/org/eclipse/daanse/sql/jdbc/metadata/OracleMetadataProvider.java index f16a569..940d7d9 100644 --- a/jdbc/metadata/src/main/java/org/eclipse/daanse/sql/jdbc/metadata/OracleMetadataProvider.java +++ b/jdbc/metadata/src/main/java/org/eclipse/daanse/sql/jdbc/metadata/OracleMetadataProvider.java @@ -1717,28 +1717,20 @@ private static boolean isNumericJdbc(java.sql.JDBCType t) { @Override public Optional> getAllRoleMemberships(Connection connection) throws SQLException { - // DBA_ROLE_PRIVS; fallback: own memberships via USER_ROLE_PRIVS. + // With plain read rights: the user's own memberships (USER_ROLE_PRIVS, those of PUBLIC among + // them) and those of the roles it holds, directly or through other roles (ROLE_ROLE_PRIVS). List result = new ArrayList<>(); - try (PreparedStatement ps = connection.prepareStatement( - "SELECT GRANTEE, GRANTED_ROLE, ADMIN_OPTION FROM DBA_ROLE_PRIVS ORDER BY GRANTEE, GRANTED_ROLE"); + try (PreparedStatement ps = connection.prepareStatement(""" + SELECT USERNAME AS GRANTEE, GRANTED_ROLE, ADMIN_OPTION FROM USER_ROLE_PRIVS + UNION + SELECT ROLE AS GRANTEE, GRANTED_ROLE, ADMIN_OPTION FROM ROLE_ROLE_PRIVS + ORDER BY 1, 2"""); ResultSet rs = ps.executeQuery()) { while (rs.next()) { result.add(new org.eclipse.daanse.sql.jdbc.record.schema.RoleMembershipRecord( rs.getString("GRANTEE"), rs.getString("GRANTED_ROLE"), Optional.empty(), Optional.ofNullable(rs.getString("ADMIN_OPTION")))); } - return Optional.of(List.copyOf(result)); - } catch (SQLException e) { - result.clear(); - } - try (PreparedStatement ps = connection.prepareStatement( - "SELECT USERNAME, GRANTED_ROLE, ADMIN_OPTION FROM USER_ROLE_PRIVS ORDER BY GRANTED_ROLE"); - ResultSet rs = ps.executeQuery()) { - while (rs.next()) { - result.add(new org.eclipse.daanse.sql.jdbc.record.schema.RoleMembershipRecord( - rs.getString("USERNAME"), rs.getString("GRANTED_ROLE"), - Optional.empty(), Optional.ofNullable(rs.getString("ADMIN_OPTION")))); - } } return Optional.of(List.copyOf(result)); } @@ -1746,10 +1738,11 @@ public Optional> get @Override public Optional> getAllPrincipals(Connection connection) throws SQLException { - // DBA_USERS/DBA_ROLES need elevated rights; without them: empty. + // With plain read rights: ALL_USERS names every user to every user; the roles are those the + // user holds, directly or through other roles. List result = new ArrayList<>(); try (PreparedStatement ps = connection.prepareStatement( - "SELECT USERNAME FROM DBA_USERS ORDER BY USERNAME"); + "SELECT USERNAME FROM ALL_USERS ORDER BY USERNAME"); ResultSet rs = ps.executeQuery()) { while (rs.next()) { result.add(new org.eclipse.daanse.sql.jdbc.record.schema.DatabasePrincipalRecord(rs.getString("USERNAME"), org.eclipse.daanse.sql.jdbc.api.schema.DatabasePrincipal.KIND_USER)); @@ -1757,15 +1750,31 @@ public Optional> } catch (SQLException e) { return Optional.empty(); } - try (PreparedStatement ps = connection.prepareStatement( - "SELECT ROLE FROM DBA_ROLES ORDER BY ROLE"); + for (String role : roleNames(connection)) { + result.add(new org.eclipse.daanse.sql.jdbc.record.schema.DatabasePrincipalRecord(role, + org.eclipse.daanse.sql.jdbc.api.schema.DatabasePrincipal.KIND_ROLE)); + } + return Optional.of(List.copyOf(result)); + } + + /** + * The roles the current user holds: granted to it or to PUBLIC (USER_ROLE_PRIVS), and those + * granted to these roles in turn (ROLE_ROLE_PRIVS, which shows the roles the user has access to). + */ + private static List roleNames(Connection connection) throws SQLException { + List roles = new ArrayList<>(); + try (PreparedStatement ps = connection.prepareStatement(""" + SELECT GRANTED_ROLE AS ROLE FROM USER_ROLE_PRIVS + UNION + SELECT ROLE FROM ROLE_ROLE_PRIVS + UNION + SELECT GRANTED_ROLE AS ROLE FROM ROLE_ROLE_PRIVS + ORDER BY 1"""); ResultSet rs = ps.executeQuery()) { while (rs.next()) { - result.add(new org.eclipse.daanse.sql.jdbc.record.schema.DatabasePrincipalRecord(rs.getString("ROLE"), org.eclipse.daanse.sql.jdbc.api.schema.DatabasePrincipal.KIND_ROLE)); + roles.add(rs.getString("ROLE")); } - } catch (SQLException e) { - return Optional.empty(); } - return Optional.of(List.copyOf(result)); + return roles; } } diff --git a/jdbc/metadata/src/test/java/org/eclipse/daanse/sql/jdbc/metadata/OracleMetadataContractTest.java b/jdbc/metadata/src/test/java/org/eclipse/daanse/sql/jdbc/metadata/OracleMetadataContractTest.java index 29e88f6..b040da3 100644 --- a/jdbc/metadata/src/test/java/org/eclipse/daanse/sql/jdbc/metadata/OracleMetadataContractTest.java +++ b/jdbc/metadata/src/test/java/org/eclipse/daanse/sql/jdbc/metadata/OracleMetadataContractTest.java @@ -10,6 +10,7 @@ package org.eclipse.daanse.sql.jdbc.metadata; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.tuple; import java.sql.Connection; import java.sql.DriverManager; @@ -19,6 +20,8 @@ import java.util.Locale; import org.eclipse.daanse.sql.jdbc.api.MetadataProvider; +import org.eclipse.daanse.sql.jdbc.api.schema.DatabasePrincipal; +import org.eclipse.daanse.sql.jdbc.api.schema.RoleMembership; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledIfSystemProperty; import org.testcontainers.oracle.OracleContainer; @@ -124,4 +127,35 @@ protected List afterStock() { void theSequencesOfOracleItselfAreRead() throws SQLException { assertThat(provider().getAllSequences(connection(), null, "SYS")).isNotEmpty(); } + + /** + * The container's user reads with plain rights, from views every user may read: every user, the + * roles it holds, also one it holds through another role, and the memberships among them; a role it does not hold + * stays unseen. It reads in a session of its own, which has the roles granted before it began. + */ + @Test + void usersRolesAndMembershipsAreReadWithPlainReadRights() throws SQLException { + try (var s = system.createStatement()) { + s.execute("CREATE ROLE R_PARENT"); + s.execute("CREATE ROLE R_CHILD"); + s.execute("CREATE ROLE R_OTHER"); + s.execute("GRANT R_PARENT TO R_CHILD WITH ADMIN OPTION"); + s.execute("GRANT R_CHILD TO " + sales()); + } + try (Connection reader = DriverManager.getConnection(container.getJdbcUrl(), container.getUsername(), + container.getPassword())) { + List principals = provider().getAllPrincipals(reader).orElseThrow(); + assertThat(principals).as("the users and roles") + .extracting(DatabasePrincipal::name, DatabasePrincipal::kind) + .contains(tuple(sales(), DatabasePrincipal.KIND_USER), tuple("STOCK", DatabasePrincipal.KIND_USER), + tuple("SYSTEM", DatabasePrincipal.KIND_USER), tuple("R_CHILD", DatabasePrincipal.KIND_ROLE), + tuple("R_PARENT", DatabasePrincipal.KIND_ROLE)) + .doesNotContain(tuple("R_OTHER", DatabasePrincipal.KIND_ROLE)); + + List memberships = provider().getAllRoleMemberships(reader).orElseThrow(); + assertThat(memberships).as("the memberships") + .extracting(RoleMembership::grantee, RoleMembership::role, m -> m.adminOption().orElse(null)) + .contains(tuple(sales(), "R_CHILD", "NO"), tuple("R_CHILD", "R_PARENT", "YES")); + } + } }