You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@syncope.apache.org by "ilgrosso (via GitHub)" <gi...@apache.org> on 2024/08/21 16:14:22 UTC
[PR] [SYNCOPE-1827] Only JPA with JSON support available, PostgreSQL the default option [syncope]
ilgrosso opened a new pull request, #820:
URL: https://github.com/apache/syncope/pull/820
Missing:
- [ ] archetype
- [ ] docs
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@syncope.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [SYNCOPE-1827] Only JPA with JSON support available, PostgreSQL the default option [syncope]
Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #820:
URL: https://github.com/apache/syncope/pull/820#discussion_r1731391165
##########
core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/AbstractTest.java:
##########
@@ -18,22 +18,194 @@
*/
package org.apache.syncope.core.persistence.jpa;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.fail;
+
+import io.zonky.test.db.postgres.embedded.EmbeddedPostgres;
import jakarta.persistence.EntityManager;
-import java.util.Optional;
+import java.io.InputStream;
+import java.util.Map;
+import java.util.Properties;
+import java.util.function.Supplier;
+import java.util.stream.Stream;
import org.apache.syncope.core.persistence.api.entity.AnyUtilsFactory;
import org.apache.syncope.core.persistence.api.entity.EntityFactory;
-import org.apache.syncope.core.persistence.api.entity.PlainAttr;
-import org.apache.syncope.core.persistence.api.entity.PlainAttrValue;
-import org.apache.syncope.core.persistence.jpa.dao.JPAPlainAttrValueDAO;
-import org.apache.syncope.core.persistence.jpa.dao.repo.PlainSchemaRepoExtImpl;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.test.context.DynamicPropertyRegistry;
+import org.springframework.test.context.DynamicPropertySource;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
+import org.testcontainers.containers.MariaDBContainer;
+import org.testcontainers.containers.MySQLContainer;
+import org.testcontainers.oracle.OracleContainer;
@SpringJUnitConfig(classes = { MasterDomain.class, PersistenceTestContext.class })
-@DirtiesContext
public abstract class AbstractTest {
+ private static String JDBC_DRIVER;
+
+ private static String DATABASE_PLATFORM;
+
+ private static String ORM = "META-INF/spring-orm.xml";
+
+ private static String INDEXES = "classpath:META-INF/indexes.xml";
+
+ private static String VIEWS = "classpath:META-INF/views.xml";
+
+ private static Supplier<Object> JDBC_URL_SUPPLIER;
+
+ private static Supplier<Object> JDBC2_URL_SUPPLIER;
+
+ private static Supplier<Object> DB_USER_SUPPLIER = () -> "syncope";
+
+ private static Supplier<Object> DB_PWD_SUPPLIER = () -> "syncope";
+
+ private static Supplier<Object> DB2_USER_SUPPLIER = () -> "syncope";
+
+ private static Supplier<Object> DB2_PWD_SUPPLIER = () -> "syncope";
+
+ private static boolean classExists(final String name) {
+ try {
+ Class.forName(name, false, AbstractTest.class.getClassLoader());
+ return true;
+ } catch (ClassNotFoundException e) {
+ // ignore
+ return false;
+ }
+ }
+
+ static {
+ String dockerMySQLVersion = null;
+ String dockerMariaDBVersion = null;
+ String dockerOracleVersion = null;
+ try (InputStream propStream = AbstractTest.class.getResourceAsStream("/test.properties")) {
+ Properties props = new Properties();
+ props.load(propStream);
+
+ dockerMySQLVersion = props.getProperty("docker.mysql.version");
+ dockerMariaDBVersion = props.getProperty("docker.mariadb.version");
+ dockerOracleVersion = props.getProperty("docker.oracle.version");
+ } catch (Exception e) {
+ fail("Could not load /test.properties", e);
+ }
+ assertNotNull(dockerMySQLVersion);
+ assertNotNull(dockerMariaDBVersion);
+ assertNotNull(dockerOracleVersion);
+
+ if (classExists("org.postgresql.Driver")) {
+ JDBC_DRIVER = "org.postgresql.Driver";
+ DATABASE_PLATFORM = "org.apache.openjpa.jdbc.sql.PostgresDictionary";
+ ORM = "META-INF/spring-orm.xml";
+ INDEXES = "classpath:META-INF/indexes.xml";
+ VIEWS = "classpath:META-INF/views.xml";
+
+ try {
+ EmbeddedPostgres pg = EmbeddedPostgres.builder().start();
+ JdbcTemplate jdbcTemplate = new JdbcTemplate(pg.getPostgresDatabase());
+ Stream.of("syncope", "syncopetwo").forEach(key -> {
+ jdbcTemplate.execute("CREATE DATABASE " + key);
+
+ jdbcTemplate.execute("CREATE USER " + key + " WITH PASSWORD '" + key + "'");
Review Comment:
## Query built by concatenation with a possibly-untrusted string
Query built by concatenation with [this expression](1), which may be untrusted.
[Show more details](https://github.com/apache/syncope/security/code-scanning/1628)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@syncope.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [SYNCOPE-1827] Only JPA with JSON support available, PostgreSQL the default option [syncope]
Posted by "ilgrosso (via GitHub)" <gi...@apache.org>.
ilgrosso merged PR #820:
URL: https://github.com/apache/syncope/pull/820
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@syncope.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [SYNCOPE-1827] Only JPA with JSON support available, PostgreSQL the default option [syncope]
Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #820:
URL: https://github.com/apache/syncope/pull/820#discussion_r1725388445
##########
fit/persistence-embedded/src/main/java/org/apache/syncope/fit/persistence/embedded/EmbeddedPostgreSQLContext.java:
##########
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.syncope.fit.persistence.embedded;
+
+import io.zonky.test.db.postgres.embedded.EmbeddedPostgres;
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Stream;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+import org.springframework.context.annotation.Bean;
+import org.springframework.jndi.JndiObjectFactoryBean;
+
+public class EmbeddedPostgreSQLContext {
+
+ private static final Logger LOG = LoggerFactory.getLogger(EmbeddedPostgreSQLContext.class);
+
+ @Value("${embedded.databases:syncope}")
+ private String[] embeddedDatabases;
+
+ @ConditionalOnClass(name = "org.postgresql.Driver")
+ @Bean(name = "MasterDataSource")
+ public JndiObjectFactoryBean masterDataSource() {
+ LOG.info("Creating embedded databases: {}", List.of(embeddedDatabases));
+
+ try {
+ EmbeddedPostgres pg = EmbeddedPostgres.builder().setPort(5432).start();
+
+ Stream.of(embeddedDatabases).forEach(key -> {
+ try (Connection conn = pg.getPostgresDatabase().getConnection();
+ Statement stmt = conn.createStatement()) {
+
+ ResultSet resultSet = stmt.executeQuery(
+ "SELECT COUNT(*) FROM pg_database WHERE datname = '" + key + "'");
+ resultSet.next();
+ if (resultSet.getInt(1) <= 0) {
+ stmt.execute("CREATE DATABASE " + key);
+ } else {
+ LOG.info("Database {} exists", key);
+ }
+
+ resultSet = stmt.executeQuery("SELECT COUNT(*) FROM pg_user WHERE usename = '" + key + "'");
+ resultSet.next();
+ if (resultSet.getInt(1) <= 0) {
+ stmt.execute("CREATE USER " + key + " WITH PASSWORD '" + key + "'");
Review Comment:
## Query built by concatenation with a possibly-untrusted string
Query built by concatenation with [this expression](1), which may be untrusted.
[Show more details](https://github.com/apache/syncope/security/code-scanning/1627)
##########
fit/persistence-embedded/src/main/java/org/apache/syncope/fit/persistence/embedded/EmbeddedPostgreSQLContext.java:
##########
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.syncope.fit.persistence.embedded;
+
+import io.zonky.test.db.postgres.embedded.EmbeddedPostgres;
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Stream;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+import org.springframework.context.annotation.Bean;
+import org.springframework.jndi.JndiObjectFactoryBean;
+
+public class EmbeddedPostgreSQLContext {
+
+ private static final Logger LOG = LoggerFactory.getLogger(EmbeddedPostgreSQLContext.class);
+
+ @Value("${embedded.databases:syncope}")
+ private String[] embeddedDatabases;
+
+ @ConditionalOnClass(name = "org.postgresql.Driver")
+ @Bean(name = "MasterDataSource")
+ public JndiObjectFactoryBean masterDataSource() {
+ LOG.info("Creating embedded databases: {}", List.of(embeddedDatabases));
+
+ try {
+ EmbeddedPostgres pg = EmbeddedPostgres.builder().setPort(5432).start();
+
+ Stream.of(embeddedDatabases).forEach(key -> {
+ try (Connection conn = pg.getPostgresDatabase().getConnection();
+ Statement stmt = conn.createStatement()) {
+
+ ResultSet resultSet = stmt.executeQuery(
+ "SELECT COUNT(*) FROM pg_database WHERE datname = '" + key + "'");
Review Comment:
## Query built by concatenation with a possibly-untrusted string
Query built by concatenation with [this expression](1), which may be untrusted.
[Show more details](https://github.com/apache/syncope/security/code-scanning/1625)
##########
fit/persistence-embedded/src/main/java/org/apache/syncope/fit/persistence/embedded/EmbeddedPostgreSQLContext.java:
##########
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.syncope.fit.persistence.embedded;
+
+import io.zonky.test.db.postgres.embedded.EmbeddedPostgres;
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Stream;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+import org.springframework.context.annotation.Bean;
+import org.springframework.jndi.JndiObjectFactoryBean;
+
+public class EmbeddedPostgreSQLContext {
+
+ private static final Logger LOG = LoggerFactory.getLogger(EmbeddedPostgreSQLContext.class);
+
+ @Value("${embedded.databases:syncope}")
+ private String[] embeddedDatabases;
+
+ @ConditionalOnClass(name = "org.postgresql.Driver")
+ @Bean(name = "MasterDataSource")
+ public JndiObjectFactoryBean masterDataSource() {
+ LOG.info("Creating embedded databases: {}", List.of(embeddedDatabases));
+
+ try {
+ EmbeddedPostgres pg = EmbeddedPostgres.builder().setPort(5432).start();
+
+ Stream.of(embeddedDatabases).forEach(key -> {
+ try (Connection conn = pg.getPostgresDatabase().getConnection();
+ Statement stmt = conn.createStatement()) {
+
+ ResultSet resultSet = stmt.executeQuery(
+ "SELECT COUNT(*) FROM pg_database WHERE datname = '" + key + "'");
+ resultSet.next();
+ if (resultSet.getInt(1) <= 0) {
+ stmt.execute("CREATE DATABASE " + key);
+ } else {
+ LOG.info("Database {} exists", key);
+ }
+
+ resultSet = stmt.executeQuery("SELECT COUNT(*) FROM pg_user WHERE usename = '" + key + "'");
Review Comment:
## Query built by concatenation with a possibly-untrusted string
Query built by concatenation with [this expression](1), which may be untrusted.
[Show more details](https://github.com/apache/syncope/security/code-scanning/1626)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@syncope.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org