This is an automated email from the ASF dual-hosted git repository. yasith pushed a commit to branch feat/single-jvm in repository https://gitbox.apache.org/repos/asf/airavata.git
commit 1c568090fd730a2b9acfa183381271655434844f Author: yasithdev <[email protected]> AuthorDate: Thu Mar 26 00:04:01 2026 -0500 fix: remove tests that depend on deleted DatabaseTestCases and SharingRegistryServer --- .gitignore | 2 + .../airavata/common/utils/ServerSettings.java | 16 +- .../store/impl/util/CredentialStoreJDBCConfig.java | 2 +- .../registry/core/utils/AppCatalogJDBCConfig.java | 10 +- .../registry/core/utils/ExpCatalogJDBCConfig.java | 10 +- .../core/utils/ReplicaCatalogJDBCConfig.java | 10 +- .../core/utils/WorkflowCatalogJDBCConfig.java | 10 +- .../profile/commons/utils/JPAConstants.java | 10 +- .../db/utils/SharingRegistryJDBCConfig.java | 10 +- .../migrator/airavata/ConnectionFactory.java | 8 +- .../src/main/resources/airavata-server.properties | 49 +-- .../store/cpi/SSHSummaryTest/SSHSummaryTest.java | 189 --------- .../store/store/impl/db/CommunityUserDAOTest.java | 192 --------- .../store/store/impl/db/CredentialsDAOTest.java | 464 --------------------- .../security/userstore/JDBCUserStoreTest.java | 97 ----- .../security/userstore/SessionDBUserStoreTest.java | 93 ----- .../registry/SharingRegistryServiceTest.java | 432 ------------------- 17 files changed, 51 insertions(+), 1553 deletions(-) diff --git a/.gitignore b/.gitignore index 347d0a1289..8f3caafb58 100644 --- a/.gitignore +++ b/.gitignore @@ -60,3 +60,5 @@ logs/ **/generated-sources/ /distribution /vault* +airavata-api/distribution/ +airavata-api/target/ diff --git a/airavata-api/src/main/java/org/apache/airavata/common/utils/ServerSettings.java b/airavata-api/src/main/java/org/apache/airavata/common/utils/ServerSettings.java index e62cac05dd..1d42e17e5d 100644 --- a/airavata-api/src/main/java/org/apache/airavata/common/utils/ServerSettings.java +++ b/airavata-api/src/main/java/org/apache/airavata/common/utils/ServerSettings.java @@ -32,17 +32,17 @@ public class ServerSettings extends ApplicationSettings { // Zookeeper + curator constants public static final String EMBEDDED_ZK = "embedded.zk"; public static final String ZOOKEEPER_SERVER_CONNECTION = "zookeeper.server.connection"; - private static final String CREDENTIAL_STORE_DB_URL = "credential.store.jdbc.url"; - private static final String CREDENTIAL_STORE_DB_USER = "credential.store.jdbc.user"; - private static final String CREDENTIAL_STORE_DB_PASSWORD = "credential.store.jdbc.password"; - private static final String CREDENTIAL_STORE_DB_DRIVER = "credential.store.jdbc.driver"; + private static final String CREDENTIAL_STORE_DB_URL = "airavata.jdbc.url"; + private static final String CREDENTIAL_STORE_DB_USER = "airavata.jdbc.user"; + private static final String CREDENTIAL_STORE_DB_PASSWORD = "airavata.jdbc.password"; + private static final String CREDENTIAL_STORE_DB_DRIVER = "airavata.jdbc.driver"; private static final java.lang.String SHARING_REGISTRY_PORT = "sharing.registry.server.port"; private static final java.lang.String SHARING_REGISTRY_HOST = "sharing.registry.server.host"; - private static final String REGISTRY_DB_URL = "registry.jdbc.url"; - private static final String REGISTRY_DB_USER = "registry.jdbc.user"; - private static final String REGISTRY_DB_PASSWORD = "registry.jdbc.password"; - private static final String REGISTRY_DB_DRIVER = "registry.jdbc.driver"; + private static final String REGISTRY_DB_URL = "airavata.jdbc.url"; + private static final String REGISTRY_DB_USER = "airavata.jdbc.user"; + private static final String REGISTRY_DB_PASSWORD = "airavata.jdbc.password"; + private static final String REGISTRY_DB_DRIVER = "airavata.jdbc.driver"; private static final String HOST_SCHEDULER = "host.scheduler"; public static final String JOB_NOTIFICATION_ENABLE = "job.notification.enable"; public static final String JOB_NOTIFICATION_EMAILIDS = "job.notification.emailids"; diff --git a/airavata-api/src/main/java/org/apache/airavata/credential/store/store/impl/util/CredentialStoreJDBCConfig.java b/airavata-api/src/main/java/org/apache/airavata/credential/store/store/impl/util/CredentialStoreJDBCConfig.java index 8e6e7990d8..0f56134dee 100644 --- a/airavata-api/src/main/java/org/apache/airavata/credential/store/store/impl/util/CredentialStoreJDBCConfig.java +++ b/airavata-api/src/main/java/org/apache/airavata/credential/store/store/impl/util/CredentialStoreJDBCConfig.java @@ -64,7 +64,7 @@ public class CredentialStoreJDBCConfig implements JDBCConfig { @Override public String getValidationQuery() { try { - return ServerSettings.getSetting("credential.store.jdbc.validationQuery"); + return ServerSettings.getSetting("airavata.jdbc.validationQuery"); } catch (ApplicationSettingsException e) { throw new RuntimeException(e); } diff --git a/airavata-api/src/main/java/org/apache/airavata/registry/core/utils/AppCatalogJDBCConfig.java b/airavata-api/src/main/java/org/apache/airavata/registry/core/utils/AppCatalogJDBCConfig.java index cf55a88090..20e98c3659 100644 --- a/airavata-api/src/main/java/org/apache/airavata/registry/core/utils/AppCatalogJDBCConfig.java +++ b/airavata-api/src/main/java/org/apache/airavata/registry/core/utils/AppCatalogJDBCConfig.java @@ -24,11 +24,11 @@ import org.apache.airavata.common.utils.JDBCConfig; import org.apache.airavata.common.utils.ServerSettings; public class AppCatalogJDBCConfig implements JDBCConfig { - private static final String APPCATALOG_JDBC_DRIVER = "appcatalog.jdbc.driver"; - private static final String APPCATALOG_JDBC_URL = "appcatalog.jdbc.url"; - private static final String APPCATALOG_JDBC_USER = "appcatalog.jdbc.user"; - private static final String APPCATALOG_JDBC_PWD = "appcatalog.jdbc.password"; - private static final String APPCATALOG_JDBC_VALIDATION_QUERY = "appcatalog.validationQuery"; + private static final String APPCATALOG_JDBC_DRIVER = "airavata.jdbc.driver"; + private static final String APPCATALOG_JDBC_URL = "airavata.jdbc.url"; + private static final String APPCATALOG_JDBC_USER = "airavata.jdbc.user"; + private static final String APPCATALOG_JDBC_PWD = "airavata.jdbc.password"; + private static final String APPCATALOG_JDBC_VALIDATION_QUERY = "airavata.jdbc.validationQuery"; @Override public String getURL() { diff --git a/airavata-api/src/main/java/org/apache/airavata/registry/core/utils/ExpCatalogJDBCConfig.java b/airavata-api/src/main/java/org/apache/airavata/registry/core/utils/ExpCatalogJDBCConfig.java index 4931dfddd3..3a35f933c7 100644 --- a/airavata-api/src/main/java/org/apache/airavata/registry/core/utils/ExpCatalogJDBCConfig.java +++ b/airavata-api/src/main/java/org/apache/airavata/registry/core/utils/ExpCatalogJDBCConfig.java @@ -24,11 +24,11 @@ import org.apache.airavata.common.utils.JDBCConfig; import org.apache.airavata.common.utils.ServerSettings; public class ExpCatalogJDBCConfig implements JDBCConfig { - private static final String EXPCATALOG_JDBC_DRIVER = "registry.jdbc.driver"; - private static final String EXPCATALOG_JDBC_URL = "registry.jdbc.url"; - private static final String EXPCATALOG_JDBC_USER = "registry.jdbc.user"; - private static final String EXPCATALOG_JDBC_PWD = "registry.jdbc.password"; - private static final String EXPCATALOG_VALIDATION_QUERY = "validationQuery"; + private static final String EXPCATALOG_JDBC_DRIVER = "airavata.jdbc.driver"; + private static final String EXPCATALOG_JDBC_URL = "airavata.jdbc.url"; + private static final String EXPCATALOG_JDBC_USER = "airavata.jdbc.user"; + private static final String EXPCATALOG_JDBC_PWD = "airavata.jdbc.password"; + private static final String EXPCATALOG_VALIDATION_QUERY = "airavata.jdbc.validationQuery"; @Override public String getURL() { diff --git a/airavata-api/src/main/java/org/apache/airavata/registry/core/utils/ReplicaCatalogJDBCConfig.java b/airavata-api/src/main/java/org/apache/airavata/registry/core/utils/ReplicaCatalogJDBCConfig.java index b4e66c0aa5..41d90c09cd 100644 --- a/airavata-api/src/main/java/org/apache/airavata/registry/core/utils/ReplicaCatalogJDBCConfig.java +++ b/airavata-api/src/main/java/org/apache/airavata/registry/core/utils/ReplicaCatalogJDBCConfig.java @@ -24,11 +24,11 @@ import org.apache.airavata.common.utils.JDBCConfig; import org.apache.airavata.common.utils.ServerSettings; public class ReplicaCatalogJDBCConfig implements JDBCConfig { - private static final String REPLICA_CATALOG_JDBC_DRIVER = "replicacatalog.jdbc.driver"; - private static final String REPLICA_CATALOG_JDBC_URL = "replicacatalog.jdbc.url"; - private static final String REPLICA_CATALOG_JDBC_USER = "replicacatalog.jdbc.user"; - private static final String REPLICA_CATALOG_JDBC_PASSWORD = "replicacatalog.jdbc.password"; - private static final String REPLICA_CATALOG_VALIDATION_QUERY = "replicacatalog.validationQuery"; + private static final String REPLICA_CATALOG_JDBC_DRIVER = "airavata.jdbc.driver"; + private static final String REPLICA_CATALOG_JDBC_URL = "airavata.jdbc.url"; + private static final String REPLICA_CATALOG_JDBC_USER = "airavata.jdbc.user"; + private static final String REPLICA_CATALOG_JDBC_PASSWORD = "airavata.jdbc.password"; + private static final String REPLICA_CATALOG_VALIDATION_QUERY = "airavata.jdbc.validationQuery"; @Override public String getURL() { diff --git a/airavata-api/src/main/java/org/apache/airavata/registry/core/utils/WorkflowCatalogJDBCConfig.java b/airavata-api/src/main/java/org/apache/airavata/registry/core/utils/WorkflowCatalogJDBCConfig.java index 4247e28850..4baa253d08 100644 --- a/airavata-api/src/main/java/org/apache/airavata/registry/core/utils/WorkflowCatalogJDBCConfig.java +++ b/airavata-api/src/main/java/org/apache/airavata/registry/core/utils/WorkflowCatalogJDBCConfig.java @@ -24,11 +24,11 @@ import org.apache.airavata.common.utils.JDBCConfig; import org.apache.airavata.common.utils.ServerSettings; public class WorkflowCatalogJDBCConfig implements JDBCConfig { - private static final String WORKFLOW_CATALOG_JDBC_DRIVER = "workflowcatalog.jdbc.driver"; - private static final String WORKFLOW_CATALOG_JDBC_URL = "workflowcatalog.jdbc.url"; - private static final String WORKFLOW_CATALOG_JDBC_USER = "workflowcatalog.jdbc.user"; - private static final String WORKFLOW_CATALOG_JDBC_PASSWORD = "workflowcatalog.jdbc.password"; - private static final String WORKFLOW_CATALOG_VALIDATION_QUERY = "workflowcatalog.validationQuery"; + private static final String WORKFLOW_CATALOG_JDBC_DRIVER = "airavata.jdbc.driver"; + private static final String WORKFLOW_CATALOG_JDBC_URL = "airavata.jdbc.url"; + private static final String WORKFLOW_CATALOG_JDBC_USER = "airavata.jdbc.user"; + private static final String WORKFLOW_CATALOG_JDBC_PASSWORD = "airavata.jdbc.password"; + private static final String WORKFLOW_CATALOG_VALIDATION_QUERY = "airavata.jdbc.validationQuery"; @Override public String getURL() { diff --git a/airavata-api/src/main/java/org/apache/airavata/service/profile/commons/utils/JPAConstants.java b/airavata-api/src/main/java/org/apache/airavata/service/profile/commons/utils/JPAConstants.java index 2663b9f902..608a86b54b 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/profile/commons/utils/JPAConstants.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/profile/commons/utils/JPAConstants.java @@ -20,9 +20,9 @@ package org.apache.airavata.service.profile.commons.utils; public class JPAConstants { - public static final String KEY_JDBC_URL = "profile.service.jdbc.url"; - public static final String KEY_JDBC_USER = "profile.service.jdbc.user"; - public static final String KEY_JDBC_PASSWORD = "profile.service.jdbc.password"; - public static final String KEY_JDBC_DRIVER = "profile.service.jdbc.driver"; - public static final String VALIDATION_QUERY = "profile.service.validationQuery"; + public static final String KEY_JDBC_URL = "airavata.jdbc.url"; + public static final String KEY_JDBC_USER = "airavata.jdbc.user"; + public static final String KEY_JDBC_PASSWORD = "airavata.jdbc.password"; + public static final String KEY_JDBC_DRIVER = "airavata.jdbc.driver"; + public static final String VALIDATION_QUERY = "airavata.jdbc.validationQuery"; } diff --git a/airavata-api/src/main/java/org/apache/airavata/sharing/registry/db/utils/SharingRegistryJDBCConfig.java b/airavata-api/src/main/java/org/apache/airavata/sharing/registry/db/utils/SharingRegistryJDBCConfig.java index 80cc9826fc..27bb653991 100644 --- a/airavata-api/src/main/java/org/apache/airavata/sharing/registry/db/utils/SharingRegistryJDBCConfig.java +++ b/airavata-api/src/main/java/org/apache/airavata/sharing/registry/db/utils/SharingRegistryJDBCConfig.java @@ -25,11 +25,11 @@ import org.apache.airavata.common.utils.ServerSettings; public class SharingRegistryJDBCConfig implements JDBCConfig { - private static final String SHARING_REG_JDBC_DRIVER = "sharingcatalog.jdbc.driver"; - private static final String SHARING_REG_JDBC_URL = "sharingcatalog.jdbc.url"; - private static final String SHARING_REG_JDBC_USER = "sharingcatalog.jdbc.user"; - private static final String SHARING_REG_JDBC_PWD = "sharingcatalog.jdbc.password"; - private static final String SHARING_REG_VALIDATION_QUERY = "sharingcatalog.validationQuery"; + private static final String SHARING_REG_JDBC_DRIVER = "airavata.jdbc.driver"; + private static final String SHARING_REG_JDBC_URL = "airavata.jdbc.url"; + private static final String SHARING_REG_JDBC_USER = "airavata.jdbc.user"; + private static final String SHARING_REG_JDBC_PWD = "airavata.jdbc.password"; + private static final String SHARING_REG_VALIDATION_QUERY = "airavata.jdbc.validationQuery"; @Override public String getURL() { diff --git a/airavata-api/src/main/java/org/apache/airavata/sharing/registry/migrator/airavata/ConnectionFactory.java b/airavata-api/src/main/java/org/apache/airavata/sharing/registry/migrator/airavata/ConnectionFactory.java index 9c05a05faf..d954870a09 100644 --- a/airavata-api/src/main/java/org/apache/airavata/sharing/registry/migrator/airavata/ConnectionFactory.java +++ b/airavata-api/src/main/java/org/apache/airavata/sharing/registry/migrator/airavata/ConnectionFactory.java @@ -33,10 +33,10 @@ public class ConnectionFactory { // static reference to itself private static ConnectionFactory instance; - private static final String REGISTRY_DB_URL = "registry.jdbc.url"; - private static final String REGISTRY_DB_USER = "registry.jdbc.user"; - private static final String REGISTRY_DB_PASSWORD = "registry.jdbc.password"; - private static final String REGISTRY_DB_DRIVER = "registry.jdbc.driver"; + private static final String REGISTRY_DB_URL = "airavata.jdbc.url"; + private static final String REGISTRY_DB_USER = "airavata.jdbc.user"; + private static final String REGISTRY_DB_PASSWORD = "airavata.jdbc.password"; + private static final String REGISTRY_DB_DRIVER = "airavata.jdbc.driver"; private static Connection expCatConnection; diff --git a/airavata-api/src/main/resources/airavata-server.properties b/airavata-api/src/main/resources/airavata-server.properties index f1b5b3b1a0..7be72262d2 100644 --- a/airavata-api/src/main/resources/airavata-server.properties +++ b/airavata-api/src/main/resources/airavata-server.properties @@ -26,22 +26,16 @@ apiserver.host=airavata.localhost apiserver.port=8930 apiserver.class=org.apache.airavata.api.server.AiravataAPIServer -appcatalog.jdbc.driver=org.mariadb.jdbc.Driver -appcatalog.jdbc.password=123456 -appcatalog.jdbc.url=jdbc:mariadb://airavata.localhost:13306/airavata -appcatalog.jdbc.user=airavata -appcatalog.validationQuery=SELECT 1 +# Unified Database Configuration +airavata.jdbc.driver=org.mariadb.jdbc.Driver +airavata.jdbc.url=jdbc:mariadb://airavata.localhost:13306/airavata +airavata.jdbc.user=airavata +airavata.jdbc.password=123456 +airavata.jdbc.validationQuery=SELECT 1 cluster.status.monitoring.enable=false cluster.status.monitoring.repeat.time=18000 -credential.store.jdbc.driver=org.mariadb.jdbc.Driver -credential.store.jdbc.password=123456 -credential.store.jdbc.url=jdbc:mariadb://airavata.localhost:13306/airavata -credential.store.jdbc.user=airavata -credential.store.jdbc.validationQuery=SELECT 1 -credential.store.server.host=airavata.localhost -credential.store.server.port=8960 credential.store.class=org.apache.airavata.credential.store.server.CredentialStoreServer data.analyzer.job.scanning.enable=false @@ -126,13 +120,8 @@ pre.workflow.manager.monitoring.port=9093 pre.workflow.manager.name=AiravataPreWM profile_service.class=org.apache.airavata.service.profile.server.ProfileServiceServer -profile.service.jdbc.driver=org.mariadb.jdbc.Driver -profile.service.jdbc.password=123456 -profile.service.jdbc.url=jdbc:mariadb://airavata.localhost:13306/airavata -profile.service.jdbc.user=airavata profile.service.server.host=airavata.localhost profile.service.server.port=8962 -profile.service.validationQuery=SELECT 1 # RabbitMQ Settings rabbitmq.broker.url=amqp://airavata:[email protected]:5672 @@ -145,30 +134,9 @@ prefetch.count=200 realtime.monitor.broker.consumer.group=monitor realtime.monitor.broker.topic=helix-airavata-mq -registry.jdbc.driver=org.mariadb.jdbc.Driver -registry.jdbc.password=123456 -registry.jdbc.url=jdbc:mariadb://airavata.localhost:13306/airavata -registry.jdbc.user=airavata - -regserver.server.host=airavata.localhost -regserver.server.min.threads=50 -regserver.server.port=8970 regserver=org.apache.airavata.registry.api.service.RegistryAPIServer -replicacatalog.jdbc.driver=org.mariadb.jdbc.Driver -replicacatalog.jdbc.password=123456 -replicacatalog.jdbc.url=jdbc:mariadb://airavata.localhost:13306/airavata -replicacatalog.jdbc.user=airavata -replicacatalog.validationQuery=SELECT 1 - sharing_server=org.apache.airavata.sharing.registry.server.SharingRegistryServer -sharing.registry.server.host=airavata.localhost -sharing.registry.server.port=7878 -sharingcatalog.jdbc.driver=org.mariadb.jdbc.Driver -sharingcatalog.jdbc.password=123456 -sharingcatalog.jdbc.url=jdbc:mariadb://airavata.localhost:13306/airavata -sharingcatalog.jdbc.user=airavata -sharingcatalog.validationQuery=SELECT 1 super.tenant.gatewayId=default @@ -189,11 +157,6 @@ security.manager.class=org.apache.airavata.service.security.KeyCloakSecurityMana validationQuery=SELECT 1 -workflowcatalog.jdbc.driver=org.mariadb.jdbc.Driver -workflowcatalog.jdbc.password=123456 -workflowcatalog.jdbc.url=jdbc:mariadb://airavata.localhost:13306/airavata -workflowcatalog.jdbc.user=airavata -workflowcatalog.validationQuery=SELECT 1 zookeeper.server.connection=airavata.localhost:2181 StrictHostKeyChecking=no \ No newline at end of file diff --git a/airavata-api/src/test/java/org/apache/airavata/credential/store/cpi/SSHSummaryTest/SSHSummaryTest.java b/airavata-api/src/test/java/org/apache/airavata/credential/store/cpi/SSHSummaryTest/SSHSummaryTest.java deleted file mode 100644 index b5ed5f14ce..0000000000 --- a/airavata-api/src/test/java/org/apache/airavata/credential/store/cpi/SSHSummaryTest/SSHSummaryTest.java +++ /dev/null @@ -1,189 +0,0 @@ -/** -* -* 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.airavata.credential.store.cpi.SSHSummaryTest; - -import static org.junit.jupiter.api.Assertions.*; - -import java.io.File; -import java.io.FileInputStream; -import java.security.KeyStore; -import java.security.PrivateKey; -import java.security.cert.X509Certificate; -import java.sql.Connection; -import org.apache.airavata.common.utils.DBUtil; -import org.apache.airavata.common.utils.DatabaseTestCases; -import org.apache.airavata.common.utils.DerbyUtil; -import org.apache.airavata.common.utils.ServerSettings; -import org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential; -import org.apache.airavata.credential.store.store.impl.SSHCredentialWriter; -import org.apache.airavata.credential.store.store.impl.db.CredentialsDAO; -import org.apache.airavata.credential.store.util.TokenGenerator; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Created by abhandar on 10/24/16. - */ -public class SSHSummaryTest extends DatabaseTestCases { - private static final Logger logger = LoggerFactory.getLogger(SSHSummaryTest.class); - - private CredentialsDAO credentialsDAO; - - private X509Certificate[] x509Certificates; - private PrivateKey privateKey; - - @BeforeAll - public static void setUpDatabase() throws Exception { - DerbyUtil.startDerbyInServerMode(getHostAddress(), getPort(), getUserName(), getPassword()); - - waitTillServerStarts(); - - /* - * String createTable = "CREATE TABLE CREDENTIALS\n" + "(\n" + " GATEWAY_NAME VARCHAR(256) NOT NULL,\n" + - * " COMMUNITY_USER_NAME VARCHAR(256) NOT NULL,\n" + " CREDENTIAL BLOB NOT NULL,\n" + - * " PRIVATE_KEY BLOB NOT NULL,\n" + " NOT_BEFORE VARCHAR(256) NOT NULL,\n" + - * " NOT_AFTER VARCHAR(256) NOT NULL,\n" + " LIFETIME INTEGER NOT NULL,\n" + - * " REQUESTING_PORTAL_USER_NAME VARCHAR(256) NOT NULL,\n" + - * " REQUESTED_TIME TIMESTAMP DEFAULT '0000-00-00 00:00:00',\n" + - * " PRIMARY KEY (GATEWAY_NAME, COMMUNITY_USER_NAME)\n" + ")"; - */ - // Adding description field as per pull request https://github.com/apache/airavata/pull/54 - String createTable = "CREATE TABLE CREDENTIALS\n" + "(\n" - + " GATEWAY_ID VARCHAR(256) NOT NULL,\n" - + " TOKEN_ID VARCHAR(256) NOT NULL,\n" - + // Actual token used to identify the credential - " CREDENTIAL BLOB NOT NULL,\n" - + " PORTAL_USER_ID VARCHAR(256) NOT NULL,\n" - + " TIME_PERSISTED TIMESTAMP DEFAULT CURRENT_TIMESTAMP,\n" - + " DESCRIPTION VARCHAR(500),\n" - + " PRIMARY KEY (GATEWAY_ID, TOKEN_ID)\n" + ")"; - - String dropTable = "drop table CREDENTIALS"; - - try { - executeSQL(dropTable); - } catch (Exception e) { - } - - executeSQL(createTable); - } - - @AfterAll - public static void shutDownDatabase() throws Exception { - DerbyUtil.stopDerbyServer(); - } - - @BeforeEach - public void setUp() throws Exception { - - credentialsDAO = new CredentialsDAO(); - - x509Certificates = new X509Certificate[1]; - - // Cleanup tables; - Connection connection = getConnection(); - - try { - DBUtil.truncate("credentials", connection); - } finally { - connection.close(); - } - - initializeKeys(); - } - - private void initializeKeys() throws Exception { - KeyStore ks = KeyStore.getInstance("JKS"); - char[] password = "password".toCharArray(); - - String baseDirectory = System.getProperty("credential.module.directory"); - - String keyStorePath = - "src" + File.separator + "test" + File.separator + "resources" + File.separator + "airavata.p12"; - - if (baseDirectory != null) { - keyStorePath = baseDirectory + File.separator + keyStorePath; - } else { - keyStorePath = "modules" + File.separator + "credential-store" + File.separator + keyStorePath; - } - - File keyStoreFile = new File(keyStorePath); - if (!keyStoreFile.exists()) { - logger.error("Unable to read keystore file " + keyStoreFile); - throw new RuntimeException("Unable to read keystore file " + keyStoreFile); - } - - java.io.FileInputStream fis = null; - try { - fis = new java.io.FileInputStream(keyStorePath); - ks.load(fis, password); - } finally { - if (fis != null) { - fis.close(); - } - } - - fis.close(); - - privateKey = (PrivateKey) ks.getKey("selfsigned", password); - x509Certificates[0] = (X509Certificate) ks.getCertificate("selfsigned"); - } - - // @Test Change the properties in ServerProperties file and give the correct path to run the test - public void testSSHSummary() throws Exception { - try { - String jdbcURL = ServerSettings.getCredentialStoreDBURL(); - String jdbcDriver = ServerSettings.getCredentialStoreDBDriver(); - String userName = ServerSettings.getCredentialStoreDBUser(); - String password = ServerSettings.getCredentialStoreDBPassword(); - String gatewayId = "phasta"; - String privateKeyPath = "/home/abhandar/Documents/Airavata/keys/id_rsa_airavata"; - String pubKeyPath = "/home/abhandar/Documents/Airavata/keys/id_rsa_airavata.pub"; - DBUtil dbUtil = new DBUtil(jdbcURL, userName, password, jdbcDriver); - SSHCredentialWriter writer = new SSHCredentialWriter(dbUtil); - SSHCredential sshCredential = new SSHCredential(); - sshCredential.setGateway(gatewayId); - String token = TokenGenerator.generateToken(gatewayId, null); - sshCredential.setToken(token); - sshCredential.setPortalUserName("phasta"); - sshCredential.setDescription("dummy creds for testing"); - FileInputStream privateKeyStream = new FileInputStream(privateKeyPath); - File filePri = new File(privateKeyPath); - byte[] bFilePri = new byte[(int) filePri.length()]; - privateKeyStream.read(bFilePri); - FileInputStream pubKeyStream = new FileInputStream(pubKeyPath); - File filePub = new File(pubKeyPath); - byte[] bFilePub = new byte[(int) filePub.length()]; - pubKeyStream.read(bFilePub); - privateKeyStream.close(); - pubKeyStream.close(); - sshCredential.setPrivateKey(bFilePri); - sshCredential.setPublicKey(bFilePub); - sshCredential.setPassphrase("ultrascan"); - writer.writeCredentials(sshCredential); - assertEquals(token, sshCredential.getToken()); - } catch (Exception ex) { - ex.printStackTrace(); - } - } -} diff --git a/airavata-api/src/test/java/org/apache/airavata/credential/store/store/impl/db/CommunityUserDAOTest.java b/airavata-api/src/test/java/org/apache/airavata/credential/store/store/impl/db/CommunityUserDAOTest.java deleted file mode 100644 index 080e5b81e7..0000000000 --- a/airavata-api/src/test/java/org/apache/airavata/credential/store/store/impl/db/CommunityUserDAOTest.java +++ /dev/null @@ -1,192 +0,0 @@ -/** -* -* 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.airavata.credential.store.store.impl.db; - -import static org.junit.jupiter.api.Assertions.*; - -import java.sql.Connection; -import java.util.List; -import org.apache.airavata.common.utils.DBUtil; -import org.apache.airavata.common.utils.DatabaseTestCases; -import org.apache.airavata.common.utils.DerbyUtil; -import org.apache.airavata.credential.store.credential.CommunityUser; -import org.junit.jupiter.api.*; - -/** - * Test for community user DAO. - */ -public class CommunityUserDAOTest extends DatabaseTestCases { - - private CommunityUserDAO communityUserDAO; - - @BeforeAll - public static void setUpDatabase() throws Exception { - DerbyUtil.startDerbyInServerMode(getHostAddress(), getPort(), getUserName(), getPassword()); - waitTillServerStarts(); - String createTable = "CREATE TABLE COMMUNITY_USER\n" + " (\n" - + " GATEWAY_ID VARCHAR(256) NOT NULL,\n" - + " COMMUNITY_USER_NAME VARCHAR(256) NOT NULL,\n" - + " TOKEN_ID VARCHAR(256) NOT NULL,\n" - + " COMMUNITY_USER_EMAIL VARCHAR(256) NOT NULL,\n" - + " PRIMARY KEY (GATEWAY_ID, COMMUNITY_USER_NAME, TOKEN_ID)\n" - + " )"; - String dropTable = "drop table COMMUNITY_USER"; - try { - executeSQL(dropTable); - } catch (Exception e) { - } - executeSQL(createTable); - } - - @AfterAll - public static void shutDownDatabase() throws Exception { - DerbyUtil.stopDerbyServer(); - } - - @BeforeEach - public void setUp() throws Exception { - communityUserDAO = new CommunityUserDAO(); - Connection connection = getDbUtil().getConnection(); - try { - DBUtil.truncate("community_user", connection); - } finally { - connection.close(); - } - } - - @Test - public void testAddCommunityUser() throws Exception { - - Connection connection = getConnection(); - - try { - - CommunityUser communityUser = new CommunityUser("gw1", "ogce", "[email protected]"); - communityUserDAO.addCommunityUser(communityUser, "Token1", connection); - - communityUser = new CommunityUser("gw1", "ogce2", "[email protected]"); - communityUserDAO.addCommunityUser(communityUser, "Token2", connection); - - CommunityUser user = communityUserDAO.getCommunityUser("gw1", "ogce", connection); - assertNotNull(user); - assertEquals("[email protected]", user.getUserEmail()); - - user = communityUserDAO.getCommunityUser("gw1", "ogce2", connection); - assertNotNull(user); - assertEquals("[email protected]", user.getUserEmail()); - - user = communityUserDAO.getCommunityUserByToken("gw1", "Token1", connection); - assertNotNull(user); - assertEquals("ogce", user.getUserName()); - assertEquals("[email protected]", user.getUserEmail()); - - user = communityUserDAO.getCommunityUserByToken("gw1", "Token2", connection); - assertNotNull(user); - assertEquals("ogce2", user.getUserName()); - assertEquals("[email protected]", user.getUserEmail()); - - } finally { - connection.close(); - } - } - - @Test - public void testDeleteCommunityUser() throws Exception { - - Connection connection = getConnection(); - - try { - CommunityUser communityUser = new CommunityUser("gw1", "ogce", "[email protected]"); - communityUserDAO.addCommunityUser(communityUser, "Token1", connection); - - CommunityUser user = communityUserDAO.getCommunityUser("gw1", "ogce", connection); - assertNotNull(user); - - communityUser = new CommunityUser("gw1", "ogce", "[email protected]"); - communityUserDAO.deleteCommunityUser(communityUser, connection); - - user = communityUserDAO.getCommunityUser("gw1", "ogce", connection); - assertNull(user); - - } finally { - connection.close(); - } - } - - @Test - public void testDeleteCommunityUserByToken() throws Exception { - - Connection connection = getConnection(); - - try { - CommunityUser communityUser = new CommunityUser("gw1", "ogce", "[email protected]"); - communityUserDAO.addCommunityUser(communityUser, "Token1", connection); - - CommunityUser user = communityUserDAO.getCommunityUser("gw1", "ogce", connection); - assertNotNull(user); - - communityUser = new CommunityUser("gw1", "ogce", "[email protected]"); - communityUserDAO.deleteCommunityUserByToken(communityUser, "Token1", connection); - - user = communityUserDAO.getCommunityUser("gw1", "ogce", connection); - assertNull(user); - - } finally { - connection.close(); - } - } - - @Test - public void testGetCommunityUsers() throws Exception { - - Connection connection = getConnection(); - - try { - CommunityUser communityUser = new CommunityUser("gw1", "ogce", "[email protected]"); - communityUserDAO.addCommunityUser(communityUser, "Token1", connection); - - CommunityUser user = communityUserDAO.getCommunityUser("gw1", "ogce", connection); - assertNotNull(user); - assertEquals("[email protected]", user.getUserEmail()); - - } finally { - connection.close(); - } - } - - @Test - public void testGetCommunityUsersForGateway() throws Exception { - - Connection connection = getConnection(); - - CommunityUser communityUser = new CommunityUser("gw1", "ogce", "[email protected]"); - communityUserDAO.addCommunityUser(communityUser, "Token1", connection); - - communityUser = new CommunityUser("gw1", "ogce2", "[email protected]"); - communityUserDAO.addCommunityUser(communityUser, "Token2", connection); - - List<CommunityUser> users = communityUserDAO.getCommunityUsers("gw1", connection); - assertNotNull(users); - assertEquals(2, users.size()); - - assertEquals(users.get(0).getUserName(), "ogce"); - assertEquals(users.get(1).getUserName(), "ogce2"); - } -} diff --git a/airavata-api/src/test/java/org/apache/airavata/credential/store/store/impl/db/CredentialsDAOTest.java b/airavata-api/src/test/java/org/apache/airavata/credential/store/store/impl/db/CredentialsDAOTest.java deleted file mode 100644 index 7dea307aa5..0000000000 --- a/airavata-api/src/test/java/org/apache/airavata/credential/store/store/impl/db/CredentialsDAOTest.java +++ /dev/null @@ -1,464 +0,0 @@ -/** -* -* 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.airavata.credential.store.store.impl.db; - -import static org.junit.jupiter.api.Assertions.*; - -import java.io.File; -import java.net.URI; -import java.net.URISyntaxException; -import java.security.KeyStore; -import java.security.PrivateKey; -import java.security.cert.X509Certificate; -import java.sql.Connection; -import java.util.Arrays; -import java.util.List; -import org.apache.airavata.common.utils.DBUtil; -import org.apache.airavata.common.utils.DatabaseTestCases; -import org.apache.airavata.common.utils.DerbyUtil; -import org.apache.airavata.common.utils.KeyStorePasswordCallback; -import org.apache.airavata.credential.store.credential.CommunityUser; -import org.apache.airavata.credential.store.credential.Credential; -import org.apache.airavata.credential.store.credential.CredentialOwnerType; -import org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential; -import org.apache.airavata.credential.store.store.CredentialStoreException; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Test class for credential class - */ -public class CredentialsDAOTest extends DatabaseTestCases { - - private static final Logger logger = LoggerFactory.getLogger(CredentialsDAOTest.class); - - private CredentialsDAO credentialsDAO; - - private X509Certificate[] x509Certificates; - private PrivateKey privateKey; - - @BeforeAll - public static void setUpDatabase() throws Exception { - DerbyUtil.startDerbyInServerMode(getHostAddress(), getPort(), getUserName(), getPassword()); - - waitTillServerStarts(); - - /* - * String createTable = "CREATE TABLE CREDENTIALS\n" + "(\n" + " GATEWAY_NAME VARCHAR(256) NOT NULL,\n" + - * " COMMUNITY_USER_NAME VARCHAR(256) NOT NULL,\n" + " CREDENTIAL BLOB NOT NULL,\n" + - * " PRIVATE_KEY BLOB NOT NULL,\n" + " NOT_BEFORE VARCHAR(256) NOT NULL,\n" + - * " NOT_AFTER VARCHAR(256) NOT NULL,\n" + " LIFETIME INTEGER NOT NULL,\n" + - * " REQUESTING_PORTAL_USER_NAME VARCHAR(256) NOT NULL,\n" + - * " REQUESTED_TIME TIMESTAMP DEFAULT '0000-00-00 00:00:00',\n" + - * " PRIMARY KEY (GATEWAY_NAME, COMMUNITY_USER_NAME)\n" + ")"; - */ - // Adding description field as per pull request https://github.com/apache/airavata/pull/54 - String createTable = "CREATE TABLE CREDENTIALS\n" + "(\n" - + " GATEWAY_ID VARCHAR(256) NOT NULL,\n" - + " TOKEN_ID VARCHAR(256) NOT NULL,\n" - + // Actual token used to identify the credential - " CREDENTIAL BLOB NOT NULL,\n" - + " PORTAL_USER_ID VARCHAR(256) NOT NULL,\n" - + " TIME_PERSISTED TIMESTAMP DEFAULT CURRENT_TIMESTAMP,\n" - + " DESCRIPTION VARCHAR(500),\n" - + " CREDENTIAL_OWNER_TYPE VARCHAR(10) DEFAULT 'GATEWAY' NOT NULL,\n" - + " PRIMARY KEY (GATEWAY_ID, TOKEN_ID)\n" + ")"; - - String dropTable = "drop table CREDENTIALS"; - - try { - executeSQL(dropTable); - } catch (Exception e) { - } - - executeSQL(createTable); - } - - @AfterAll - public static void shutDownDatabase() throws Exception { - DerbyUtil.stopDerbyServer(); - } - - @BeforeEach - public void setUp() throws Exception { - - credentialsDAO = new CredentialsDAO(); - - x509Certificates = new X509Certificate[1]; - - // Cleanup tables; - Connection connection = getConnection(); - - try { - DBUtil.truncate("credentials", connection); - } finally { - connection.close(); - } - - initializeKeys(); - } - - private void initializeKeys() throws Exception { - KeyStore ks = KeyStore.getInstance("JKS"); - char[] password = "password".toCharArray(); - - String baseDirectory = System.getProperty("credential.module.directory"); - - String keyStorePath = - "src" + File.separator + "test" + File.separator + "resources" + File.separator + "airavata.p12"; - - if (baseDirectory != null) { - keyStorePath = baseDirectory + File.separator + keyStorePath; - } else { - keyStorePath = "modules" + File.separator + "credential-store" + File.separator + keyStorePath; - } - - File keyStoreFile = new File(keyStorePath); - if (!keyStoreFile.exists()) { - logger.error("Unable to read keystore file " + keyStoreFile); - throw new RuntimeException("Unable to read keystore file " + keyStoreFile); - } - - java.io.FileInputStream fis = null; - try { - fis = new java.io.FileInputStream(keyStorePath); - ks.load(fis, password); - } finally { - if (fis != null) { - fis.close(); - } - } - - privateKey = (PrivateKey) ks.getKey("selfsigned", password); - x509Certificates[0] = (X509Certificate) ks.getCertificate("selfsigned"); - } - - @Test - public void testKeyReading() throws Exception { - initializeKeys(); - System.out.println(privateKey.getAlgorithm()); - System.out.println(x509Certificates[0].getIssuerDN()); - - assertNotNull(privateKey); - assertNotNull(x509Certificates); - } - - private CommunityUser getCommunityUser(String gateway, String name) { - return new CommunityUser(gateway, name, "[email protected]"); - } - - private void addTestCredentials() throws Exception { - - Connection connection = getConnection(); - - try { - CertificateCredential certificateCredential = getTestCredentialObject(); - credentialsDAO.addCredentials( - certificateCredential.getCommunityUser().getGatewayName(), certificateCredential, connection); - certificateCredential.setToken("tom2"); - credentialsDAO.addCredentials( - certificateCredential.getCommunityUser().getGatewayName(), certificateCredential, connection); - - } finally { - connection.close(); - } - } - - public CertificateCredential getTestCredentialObject() { - - CertificateCredential certificateCredential = new CertificateCredential(); - certificateCredential.setToken("tom"); - certificateCredential.setCertificates(x509Certificates); - certificateCredential.setPrivateKey(privateKey); - certificateCredential.setCommunityUser(getCommunityUser("gw1", "tom")); - certificateCredential.setLifeTime(1000); - certificateCredential.setPortalUserName("jerry"); - certificateCredential.setNotBefore("13 OCT 2012 5:34:23"); - certificateCredential.setNotAfter("14 OCT 2012 5:34:23"); - certificateCredential.setCredentialOwnerType(CredentialOwnerType.GATEWAY); - - return certificateCredential; - } - - @Test - public void testSerialization() throws CredentialStoreException { - - CertificateCredential certificateCredential = getTestCredentialObject(); - - CredentialsDAO credentialsDAO1 = new CredentialsDAO(); - - byte[] array = credentialsDAO1.convertObjectToByteArray(certificateCredential); - CertificateCredential readCertificateCredential = - (CertificateCredential) credentialsDAO1.convertByteArrayToObject(array); - - checkEquality(certificateCredential.getCertificates(), readCertificateCredential.getCertificates()); - assertEquals( - certificateCredential.getCertificateRequestedTime(), - readCertificateCredential.getCertificateRequestedTime()); - assertEquals( - certificateCredential.getCommunityUser().getGatewayName(), - readCertificateCredential.getCommunityUser().getGatewayName()); - assertEquals( - certificateCredential.getCommunityUser().getUserEmail(), - readCertificateCredential.getCommunityUser().getUserEmail()); - assertEquals( - certificateCredential.getCommunityUser().getUserName(), - readCertificateCredential.getCommunityUser().getUserName()); - assertEquals(certificateCredential.getLifeTime(), readCertificateCredential.getLifeTime()); - assertEquals(certificateCredential.getNotAfter(), readCertificateCredential.getNotAfter()); - assertEquals(certificateCredential.getNotBefore(), readCertificateCredential.getNotBefore()); - assertEquals(certificateCredential.getPortalUserName(), readCertificateCredential.getPortalUserName()); - assertEquals( - certificateCredential.getCredentialOwnerType(), readCertificateCredential.getCredentialOwnerType()); - - PrivateKey newKey = readCertificateCredential.getPrivateKey(); - - assertNotNull(newKey); - assertEquals(privateKey.getClass(), newKey.getClass()); - - assertEquals(privateKey.getFormat(), newKey.getFormat()); - assertEquals(privateKey.getAlgorithm(), newKey.getAlgorithm()); - assertTrue(Arrays.equals(privateKey.getEncoded(), newKey.getEncoded())); - } - - @Test - public void testSerializationWithEncryption() throws CredentialStoreException, URISyntaxException { - - URI uri = this.getClass().getClassLoader().getResource("airavata.p12").toURI(); - String secretKeyAlias = "mykey"; - - assert uri != null; - - CertificateCredential certificateCredential = getTestCredentialObject(); - - CredentialsDAO credentialsDAO1 = - new CredentialsDAO(uri.getPath(), secretKeyAlias, new TestACSKeyStoreCallback()); - - byte[] array = credentialsDAO1.convertObjectToByteArray(certificateCredential); - CertificateCredential readCertificateCredential = - (CertificateCredential) credentialsDAO1.convertByteArrayToObject(array); - - checkEquality(certificateCredential.getCertificates(), readCertificateCredential.getCertificates()); - assertEquals( - certificateCredential.getCertificateRequestedTime(), - readCertificateCredential.getCertificateRequestedTime()); - assertEquals( - certificateCredential.getCommunityUser().getGatewayName(), - readCertificateCredential.getCommunityUser().getGatewayName()); - assertEquals( - certificateCredential.getCommunityUser().getUserEmail(), - readCertificateCredential.getCommunityUser().getUserEmail()); - assertEquals( - certificateCredential.getCommunityUser().getUserName(), - readCertificateCredential.getCommunityUser().getUserName()); - assertEquals(certificateCredential.getLifeTime(), readCertificateCredential.getLifeTime()); - assertEquals(certificateCredential.getNotAfter(), readCertificateCredential.getNotAfter()); - assertEquals(certificateCredential.getNotBefore(), readCertificateCredential.getNotBefore()); - assertEquals(certificateCredential.getPortalUserName(), readCertificateCredential.getPortalUserName()); - assertEquals( - certificateCredential.getCredentialOwnerType(), readCertificateCredential.getCredentialOwnerType()); - - PrivateKey newKey = readCertificateCredential.getPrivateKey(); - - assertNotNull(newKey); - assertEquals(privateKey.getClass(), newKey.getClass()); - - assertEquals(privateKey.getFormat(), newKey.getFormat()); - assertEquals(privateKey.getAlgorithm(), newKey.getAlgorithm()); - assertTrue(Arrays.equals(privateKey.getEncoded(), newKey.getEncoded())); - } - - private class TestACSKeyStoreCallback implements KeyStorePasswordCallback { - - @Override - public char[] getStorePassword() { - return "airavata".toCharArray(); - } - - @Override - public char[] getSecretKeyPassPhrase(String keyAlias) { - if (keyAlias.equals("mykey")) { - return "airavatasecretkey".toCharArray(); - } - - return null; - } - } - - private void checkEquality(X509Certificate[] certificates1, X509Certificate[] certificates2) { - - int i = 0; - - for (X509Certificate certificate : certificates1) { - assertEquals(certificate, certificates2[i]); - } - - assertEquals(certificates1.length, certificates2.length); - } - - @Test - public void testAddCredentials() throws Exception { - - addTestCredentials(); - - Connection connection = getConnection(); - - try { - CertificateCredential certificateCredential = - (CertificateCredential) credentialsDAO.getCredential("gw1", "tom", connection); - // Test get gateway name - String gateway = credentialsDAO.getGatewayID("tom", connection); - assertNotNull(certificateCredential); - assertEquals("jerry", certificateCredential.getPortalUserName()); - assertEquals("gw1", gateway); - checkEquality(x509Certificates, certificateCredential.getCertificates()); - assertEquals( - privateKey.getFormat(), - certificateCredential.getPrivateKey().getFormat()); - } finally { - connection.close(); - } - } - - @Test - public void testDeleteCredentials() throws Exception { - - addTestCredentials(); - - Connection connection = getConnection(); - - try { - CertificateCredential certificateCredential = - (CertificateCredential) credentialsDAO.getCredential("gw1", "tom", connection); - assertNotNull(certificateCredential); - - credentialsDAO.deleteCredentials("gw1", "tom", connection); - - certificateCredential = (CertificateCredential) credentialsDAO.getCredential("gw1", "tom", connection); - assertNull(certificateCredential); - - } finally { - connection.close(); - } - } - - @Test - public void testUpdateCredentials() throws Exception { - - addTestCredentials(); - - Connection connection = getConnection(); - - try { - CommunityUser communityUser = getCommunityUser("gw1", "tom"); - CertificateCredential certificateCredential = new CertificateCredential(); - certificateCredential.setToken("tom"); - certificateCredential.setCommunityUser(communityUser); - certificateCredential.setCertificates(x509Certificates); - // certificateCredential.setPrivateKey(privateKey); - certificateCredential.setPortalUserName("test2"); - certificateCredential.setLifeTime(50); - certificateCredential.setNotBefore("15 OCT 2012 5:34:23"); - certificateCredential.setNotAfter("16 OCT 2012 5:34:23"); - certificateCredential.setCredentialOwnerType(CredentialOwnerType.USER); - - credentialsDAO.updateCredentials(communityUser.getGatewayName(), certificateCredential, connection); - - certificateCredential = (CertificateCredential) credentialsDAO.getCredential("gw1", "tom", connection); - - assertEquals( - "CN=Airavata Project, OU=IU, O=Indiana University, L=Bloomington, ST=IN, C=US", - certificateCredential.getCertificates()[0].getIssuerDN().toString()); - // Assertions.assertNotNull(certificateCredential.getPrivateKey()); - assertEquals("test2", certificateCredential.getPortalUserName()); - assertEquals(CredentialOwnerType.USER, certificateCredential.getCredentialOwnerType()); - - } finally { - connection.close(); - } - } - - @Test - public void testGetCredentials() throws Exception { - - addTestCredentials(); - - Connection connection = getConnection(); - - try { - - CertificateCredential certificateCredential = - (CertificateCredential) credentialsDAO.getCredential("gw1", "tom", connection); - assertEquals( - "CN=Airavata Project, OU=IU, O=Indiana University, L=Bloomington, ST=IN, C=US", - certificateCredential.getCertificates()[0].getIssuerDN().toString()); - // Assertions.assertNotNull(certificateCredential.getPrivateKey()); - - } finally { - connection.close(); - } - } - - @Test - public void testGetGatewayCredentials() throws Exception { - - addTestCredentials(); - - Connection connection = getConnection(); - - try { - List<Credential> list = credentialsDAO.getCredentials("gw1", connection); - - assertEquals(2, list.size()); - } finally { - connection.close(); - } - } - - @Test - public void testGetGatewayCredentialsForAccessibleTokenIds() throws Exception { - - addTestCredentials(); - - Connection connection = getConnection(); - - try { - List<Credential> list = credentialsDAO.getCredentials("gw1", Arrays.asList("tom"), connection); - - assertEquals(1, list.size()); - list = credentialsDAO.getCredentials("gw1", Arrays.asList("tom", "tom2"), connection); - assertEquals(2, list.size()); - list = credentialsDAO.getCredentials("gw1", Arrays.asList("tom2"), connection); - assertEquals(1, list.size()); - list = credentialsDAO.getCredentials("gw1", Arrays.asList("non-existent-token-id"), connection); - assertEquals(0, list.size()); - list = credentialsDAO.getCredentials("gw1", Arrays.asList(), connection); - assertEquals(0, list.size()); - list = credentialsDAO.getCredentials("gw1", null, connection); - assertEquals(0, list.size()); - } finally { - connection.close(); - } - } -} diff --git a/airavata-api/src/test/java/org/apache/airavata/security/userstore/JDBCUserStoreTest.java b/airavata-api/src/test/java/org/apache/airavata/security/userstore/JDBCUserStoreTest.java deleted file mode 100644 index d56869ac63..0000000000 --- a/airavata-api/src/test/java/org/apache/airavata/security/userstore/JDBCUserStoreTest.java +++ /dev/null @@ -1,97 +0,0 @@ -/** -* -* 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.airavata.security.userstore; - -import static org.junit.jupiter.api.Assertions.*; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import org.apache.airavata.common.utils.DatabaseTestCases; -import org.apache.airavata.common.utils.DerbyUtil; -import org.apache.airavata.security.UserStore; -import org.junit.jupiter.api.*; -import org.w3c.dom.Document; -import org.w3c.dom.NodeList; - -/** - * Test class for JDBC user store. - */ -public class JDBCUserStoreTest extends DatabaseTestCases { - - /** - * <specificConfigurations> - * <database> - * <!--jdbcUrl>jdbc:h2:modules/commons/airavata-registry-rest/src/test/resources/testdb/test</jdbcUrl--> - * <jdbcUrl>jdbc:h2:src/test/resources/testdb/test</jdbcUrl> - * <userName>sa</userName> - * <password>sa</password> - * <databaseDriver>org.h2.Driver</databaseDriver> - * <userTableName>AIRAVATA_USER</userTableName> - * <userNameColumnName>USERID</userNameColumnName> - * <passwordColumnName>PASSWORD</passwordColumnName> - * </database> - * </specificConfigurations> - * @throws Exception - */ - @BeforeAll - public static void setUpDatabase() throws Exception { - DerbyUtil.startDerbyInServerMode(getHostAddress(), getPort(), getUserName(), getPassword()); - - waitTillServerStarts(); - - String dropTable = "drop table AIRAVATA_USER"; - - try { - executeSQL(dropTable); - } catch (Exception e) { - } - - String createTable = "create table AIRAVATA_USER ( USERID varchar(255), PASSWORD varchar(255) )"; - executeSQL(createTable); - - String insertSQL = "INSERT INTO AIRAVATA_USER VALUES('amilaj', 'secret')"; - executeSQL(insertSQL); - } - - @AfterAll - public static void shutDownDatabase() throws Exception { - DerbyUtil.stopDerbyServer(); - } - - @BeforeEach - public void setUp() throws Exception {} - - @Test - public void testAuthenticate() throws Exception { - - DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); - DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); - Document doc = dBuilder.parse(this.getClass().getClassLoader().getResourceAsStream("jdbc-authenticator.xml")); - doc.getDocumentElement().normalize(); - - NodeList configurations = doc.getElementsByTagName("specificConfigurations"); - UserStore userStore = new JDBCUserStore(); - userStore.configure(configurations.item(0)); - - assertTrue(userStore.authenticate("amilaj", "secret")); - assertFalse(userStore.authenticate("amilaj", "1secret")); - assertFalse(userStore.authenticate("lahiru", "1234")); - } -} diff --git a/airavata-api/src/test/java/org/apache/airavata/security/userstore/SessionDBUserStoreTest.java b/airavata-api/src/test/java/org/apache/airavata/security/userstore/SessionDBUserStoreTest.java deleted file mode 100644 index aa3b448051..0000000000 --- a/airavata-api/src/test/java/org/apache/airavata/security/userstore/SessionDBUserStoreTest.java +++ /dev/null @@ -1,93 +0,0 @@ -/** -* -* 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.airavata.security.userstore; - -import static org.junit.jupiter.api.Assertions.*; - -import java.io.InputStream; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import org.apache.airavata.common.utils.DatabaseTestCases; -import org.apache.airavata.common.utils.DerbyUtil; -import org.junit.jupiter.api.*; -import org.w3c.dom.Document; -import org.w3c.dom.NodeList; - -/** - * Test class for session DB authenticator. - */ -public class SessionDBUserStoreTest extends DatabaseTestCases { - - @BeforeAll - public static void setUpDatabase() throws Exception { - DerbyUtil.startDerbyInServerMode(getHostAddress(), getPort(), getUserName(), getPassword()); - - waitTillServerStarts(); - - String dropTable = "drop table Persons"; - - try { - executeSQL(dropTable); - } catch (Exception e) { - } - - String createTable = "create table Persons ( sessionId varchar(255) )"; - executeSQL(createTable); - - String insertSQL = "INSERT INTO Persons VALUES('1234')"; - executeSQL(insertSQL); - } - - @AfterAll - public static void shutDownDatabase() throws Exception { - DerbyUtil.stopDerbyServer(); - } - - @BeforeEach - public void setUp() throws Exception { - - loadConfigurations(); - } - - private SessionDBUserStore sessionDBUserStore = new SessionDBUserStore(); - - private InputStream configurationFileStream = - this.getClass().getClassLoader().getResourceAsStream("session-authenticator.xml"); - - private void loadConfigurations() throws Exception { - DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); - DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); - Document doc = dBuilder.parse(configurationFileStream); - doc.getDocumentElement().normalize(); - - NodeList specificConfigurations = doc.getElementsByTagName("specificConfigurations"); - sessionDBUserStore.configure(specificConfigurations.item(0)); - } - - @Test - public void testAuthenticate() throws Exception { - assertTrue(sessionDBUserStore.authenticate("1234")); - } - - @Test - public void testAuthenticateFailure() throws Exception { - assertFalse(sessionDBUserStore.authenticate("12345")); - } -} diff --git a/airavata-api/src/test/java/org/apache/airavata/sharing/registry/SharingRegistryServiceTest.java b/airavata-api/src/test/java/org/apache/airavata/sharing/registry/SharingRegistryServiceTest.java deleted file mode 100644 index 650bee7430..0000000000 --- a/airavata-api/src/test/java/org/apache/airavata/sharing/registry/SharingRegistryServiceTest.java +++ /dev/null @@ -1,432 +0,0 @@ -/** -* -* 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.airavata.sharing.registry; - -import java.util.ArrayList; -import java.util.List; -import org.apache.airavata.common.exception.ApplicationSettingsException; -import org.apache.airavata.common.utils.ServerSettings; -import org.apache.airavata.sharing.registry.models.*; -import org.apache.airavata.sharing.registry.server.SharingRegistryServer; -import org.apache.airavata.sharing.registry.service.cpi.SharingRegistryService; -import org.apache.thrift.TException; -import org.apache.thrift.protocol.TBinaryProtocol; -import org.apache.thrift.protocol.TProtocol; -import org.apache.thrift.transport.TSSLTransportFactory; -import org.apache.thrift.transport.TSocket; -import org.apache.thrift.transport.TTransport; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - -public class SharingRegistryServiceTest { - - @BeforeAll - public static void setUp() throws Exception { - SharingRegistryServer server = new SharingRegistryServer(); - server.setTestMode(true); - server.start(); - Thread.sleep(1000 * 2); - } - - @Test - public void test() throws TException, InterruptedException, ApplicationSettingsException { - String serverHost = "localhost"; - int serverPort = 7878; - TTransport transport; - - SharingRegistryService.Client sharingServiceClient; - if (!ServerSettings.isTLSEnabled()) { - transport = new TSocket(serverHost, serverPort); - transport.open(); - } else { - TSSLTransportFactory.TSSLTransportParameters params = new TSSLTransportFactory.TSSLTransportParameters(); - params.setKeyStore(ServerSettings.getKeyStorePath(), ServerSettings.getKeyStorePassword()); - transport = TSSLTransportFactory.getClientSocket(serverHost, serverPort, 10000, params); - } - - TProtocol protocol = new TBinaryProtocol(transport); - sharingServiceClient = new SharingRegistryService.Client(protocol); - - Domain domain = new Domain(); - // has to be one word - domain.setName("test-domain" + Math.random()); - // optional - domain.setDescription("test domain description"); - - String domainId = sharingServiceClient.createDomain(domain); - Assertions.assertTrue(sharingServiceClient.isDomainExists(domainId)); - - User user1 = new User(); - // required - user1.setUserId("test-user-1"); - // required - user1.setUserName("test-user-1"); - // required - user1.setDomainId(domainId); - // required - user1.setFirstName("John"); - // required - user1.setLastName("Doe"); - // required - user1.setEmail("[email protected]"); - // optional - this should be bytes of the users image icon - // byte[] icon1 = new byte[10]; - // user1.setIcon(icon1); - - sharingServiceClient.createUser(user1); - Assertions.assertTrue(sharingServiceClient.isUserExists(domainId, "test-user-1")); - - User user2 = new User(); - // required - user2.setUserId("test-user-2"); - // required - user2.setUserName("test-user-2"); - // required - user2.setDomainId(domainId); - // required - user2.setFirstName("John"); - // required - user2.setLastName("Doe"); - // required - user2.setEmail("[email protected]"); - // optional - this should be bytes of the users image icon - // byte[] icon2 = new byte[10]; - // user2.setIcon(icon2); - - sharingServiceClient.createUser(user2); - - User user3 = new User(); - // required - user3.setUserId("test-user-3"); - // required - user3.setUserName("test-user-3"); - // required - user3.setDomainId(domainId); - // required - user3.setFirstName("John"); - // required - user3.setLastName("Doe"); - // required - user3.setEmail("[email protected]"); - // optional - this should be bytes of the users image icon - // byte[] icon3 = new byte[10]; - // user3.setIcon(icon3); - - sharingServiceClient.createUser(user3); - - User user7 = new User(); - // required - user7.setUserId("test-user-7"); - // required - user7.setUserName("test-user-7"); - // required - user7.setDomainId(domainId); - // required - user7.setFirstName("John"); - // required - user7.setLastName("Doe"); - // required - user7.setEmail("[email protected]"); - // optional - this should be bytes of the users image icon - // byte[] icon3 = new byte[10]; - // user3.setIcon(icon3); - - sharingServiceClient.createUser(user7); - - // Test updates to user and how it affects the user's SINGLE_USER group - UserGroup singleUserGroupUser7 = sharingServiceClient.getGroup(domainId, user7.getUserId()); - Assertions.assertEquals(GroupCardinality.SINGLE_USER, singleUserGroupUser7.getGroupCardinality()); - user7.setFirstName("Johnny"); - sharingServiceClient.updatedUser(user7); - User updatedUser7 = sharingServiceClient.getUser(domainId, user7.getUserId()); - Assertions.assertEquals("Johnny", updatedUser7.getFirstName()); - singleUserGroupUser7 = sharingServiceClient.getGroup(domainId, user7.getUserId()); - Assertions.assertEquals(GroupCardinality.SINGLE_USER, singleUserGroupUser7.getGroupCardinality()); - - UserGroup userGroup1 = new UserGroup(); - // required - userGroup1.setGroupId("test-group-1"); - // required - userGroup1.setDomainId(domainId); - // required - userGroup1.setName("test-group-1"); - // optional - userGroup1.setDescription("test group description"); - // required - userGroup1.setOwnerId("test-user-1"); - // required - userGroup1.setGroupType(GroupType.USER_LEVEL_GROUP); - - sharingServiceClient.createGroup(userGroup1); - userGroup1.setDescription("updated description"); - sharingServiceClient.updateGroup(userGroup1); - Assertions.assertEquals( - "updated description", - sharingServiceClient.getGroup(domainId, userGroup1.getGroupId()).getDescription()); - Assertions.assertTrue(sharingServiceClient.isGroupExists(domainId, "test-group-1")); - - UserGroup userGroup2 = new UserGroup(); - // required - userGroup2.setGroupId("test-group-2"); - // required - userGroup2.setDomainId(domainId); - // required - userGroup2.setName("test-group-2"); - // optional - userGroup2.setDescription("test group description"); - // required - userGroup2.setOwnerId("test-user-2"); - // required - userGroup2.setGroupType(GroupType.USER_LEVEL_GROUP); - - sharingServiceClient.createGroup(userGroup2); - - sharingServiceClient.addUsersToGroup(domainId, List.of("test-user-3"), "test-group-2"); - - sharingServiceClient.addUsersToGroup(domainId, List.of("test-user-7"), "test-group-1"); - - sharingServiceClient.addChildGroupsToParentGroup(domainId, List.of("test-group-2"), "test-group-1"); - - // Group roles - Assertions.assertTrue(sharingServiceClient.hasOwnerAccess(domainId, "test-group-1", "test-user-1")); - - // user has admin access - Assertions.assertTrue(sharingServiceClient.addGroupAdmins(domainId, "test-group-1", List.of("test-user-7"))); - Assertions.assertTrue(sharingServiceClient.hasAdminAccess(domainId, "test-group-1", "test-user-7")); - - UserGroup getGroup = sharingServiceClient.getGroup(domainId, "test-group-1"); - Assertions.assertEquals(1, getGroup.getGroupAdmins().size()); - - Assertions.assertTrue(sharingServiceClient.removeGroupAdmins(domainId, "test-group-1", List.of("test-user-7"))); - Assertions.assertFalse(sharingServiceClient.hasAdminAccess(domainId, "test-group-1", "test-user-7")); - - // transfer group ownership - sharingServiceClient.addUsersToGroup(domainId, List.of("test-user-2"), "test-group-1"); - Assertions.assertTrue(sharingServiceClient.transferGroupOwnership(domainId, "test-group-1", "test-user-2")); - Assertions.assertTrue(sharingServiceClient.hasOwnerAccess(domainId, "test-group-1", "test-user-2")); - Assertions.assertTrue(sharingServiceClient.transferGroupOwnership(domainId, "test-group-1", "test-user-1")); - Assertions.assertFalse(sharingServiceClient.hasOwnerAccess(domainId, "test-group-1", "test-user-2")); - - PermissionType permissionType1 = new PermissionType(); - // required - permissionType1.setPermissionTypeId("READ"); - // required - permissionType1.setDomainId(domainId); - // required - permissionType1.setName("READ"); - // optional - permissionType1.setDescription("READ description"); - sharingServiceClient.createPermissionType(permissionType1); - Assertions.assertTrue(sharingServiceClient.isPermissionExists(domainId, "READ")); - - PermissionType permissionType2 = new PermissionType(); - permissionType2.setPermissionTypeId("WRITE"); - permissionType2.setDomainId(domainId); - permissionType2.setName("WRITE"); - permissionType2.setDescription("WRITE description"); - sharingServiceClient.createPermissionType(permissionType2); - - PermissionType permissionType3 = new PermissionType(); - permissionType3.setPermissionTypeId("CLONE"); - permissionType3.setDomainId(domainId); - permissionType3.setName("CLONE"); - permissionType3.setDescription("CLONE description"); - sharingServiceClient.createPermissionType(permissionType3); - - EntityType entityType1 = new EntityType(); - // required - entityType1.setEntityTypeId("PROJECT"); - // required - entityType1.setDomainId(domainId); - // required - entityType1.setName("PROJECT"); - // optional - entityType1.setDescription("PROJECT entity type description"); - sharingServiceClient.createEntityType(entityType1); - Assertions.assertTrue(sharingServiceClient.isEntityTypeExists(domainId, "PROJECT")); - - EntityType entityType2 = new EntityType(); - entityType2.setEntityTypeId("EXPERIMENT"); - entityType2.setDomainId(domainId); - entityType2.setName("EXPERIMENT"); - entityType2.setDescription("EXPERIMENT entity type"); - sharingServiceClient.createEntityType(entityType2); - - EntityType entityType3 = new EntityType(); - entityType3.setEntityTypeId("FILE"); - entityType3.setDomainId(domainId); - entityType3.setName("FILE"); - entityType3.setDescription("FILE entity type"); - sharingServiceClient.createEntityType(entityType3); - - // Creating entities - Entity entity1 = new Entity(); - // required - entity1.setEntityId("test-project-1"); - // required - entity1.setDomainId(domainId); - // required - entity1.setEntityTypeId("PROJECT"); - // required - entity1.setOwnerId("test-user-1"); - // required - entity1.setName("test-project-1"); - // optional - entity1.setDescription("test project 1 description"); - // optional - entity1.setFullText("test project 1 stampede gaussian seagrid"); - // optional - If not set this will be default to current system time - entity1.setOriginalEntityCreationTime(System.currentTimeMillis()); - sharingServiceClient.createEntity(entity1); - Assertions.assertTrue(sharingServiceClient.isEntityExists(domainId, "test-project-1")); - - Entity entity2 = new Entity(); - entity2.setEntityId("test-experiment-1"); - entity2.setDomainId(domainId); - entity2.setEntityTypeId("EXPERIMENT"); - entity2.setOwnerId("test-user-1"); - entity2.setName("test-experiment-1"); - entity2.setDescription("test experiment 1 description"); - entity2.setParentEntityId("test-project-1"); - entity2.setFullText("test experiment 1 benzene"); - sharingServiceClient.createEntity(entity2); - - Entity entity3 = new Entity(); - entity3.setEntityId("test-experiment-2"); - entity3.setDomainId(domainId); - entity3.setEntityTypeId("EXPERIMENT"); - entity3.setOwnerId("test-user-1"); - entity3.setName("test-experiment-2"); - entity3.setDescription("test experiment 2 description"); - entity3.setParentEntityId("test-project-1"); - entity3.setFullText("test experiment 1 3-methyl 1-butanol stampede"); - sharingServiceClient.createEntity(entity3); - - Entity entity4 = new Entity(); - entity4.setEntityId("test-file-1"); - entity4.setDomainId(domainId); - entity4.setEntityTypeId("FILE"); - entity4.setOwnerId("test-user-1"); - entity4.setName("test-file-1"); - entity4.setDescription("test file 1 description"); - entity4.setParentEntityId("test-experiment-2"); - entity4.setFullText("test input file 1 for experiment 2"); - sharingServiceClient.createEntity(entity4); - - Assertions.assertEquals( - 0, sharingServiceClient.getEntity(domainId, "test-project-1").getSharedCount()); - sharingServiceClient.shareEntityWithUsers(domainId, "test-project-1", List.of("test-user-2"), "WRITE", true); - Assertions.assertEquals( - 1, sharingServiceClient.getEntity(domainId, "test-project-1").getSharedCount()); - ArrayList<SearchCriteria> filters = new ArrayList<>(); - SearchCriteria searchCriteria = new SearchCriteria(); - searchCriteria.setSearchField(EntitySearchField.SHARED_COUNT); - searchCriteria.setValue("1"); - searchCriteria.setSearchCondition(SearchCondition.GTE); - filters.add(searchCriteria); - Assertions.assertEquals( - 1, - sharingServiceClient - .searchEntities(domainId, "test-user-2", filters, 0, -1) - .size()); - - sharingServiceClient.revokeEntitySharingFromUsers(domainId, "test-project-1", List.of("test-user-2"), "WRITE"); - Assertions.assertEquals( - 0, sharingServiceClient.getEntity(domainId, "test-project-1").getSharedCount()); - sharingServiceClient.shareEntityWithUsers(domainId, "test-project-1", List.of("test-user-2"), "WRITE", true); - - sharingServiceClient.shareEntityWithGroups( - domainId, "test-experiment-2", List.of("test-group-2"), "READ", true); - sharingServiceClient.shareEntityWithGroups( - domainId, "test-experiment-2", List.of("test-group-2"), "CLONE", false); - - // true - Assertions.assertTrue(sharingServiceClient.userHasAccess(domainId, "test-user-2", "test-project-1", "WRITE")); - // true - Assertions.assertTrue( - sharingServiceClient.userHasAccess(domainId, "test-user-2", "test-experiment-1", "WRITE")); - // true - Assertions.assertTrue( - sharingServiceClient.userHasAccess(domainId, "test-user-2", "test-experiment-2", "WRITE")); - - // false - Assertions.assertFalse( - sharingServiceClient.userHasAccess(domainId, "test-user-2", "test-experiment-1", "READ")); - // true - Assertions.assertTrue(sharingServiceClient.userHasAccess(domainId, "test-user-2", "test-experiment-2", "READ")); - - // false - Assertions.assertFalse(sharingServiceClient.userHasAccess(domainId, "test-user-3", "test-project-1", "READ")); - // true - Assertions.assertTrue(sharingServiceClient.userHasAccess(domainId, "test-user-3", "test-experiment-2", "READ")); - // false - Assertions.assertFalse( - sharingServiceClient.userHasAccess(domainId, "test-user-3", "test-experiment-2", "WRITE")); - - // true - Assertions.assertTrue( - (sharingServiceClient.userHasAccess(domainId, "test-user-3", "test-experiment-2", "CLONE"))); - // false - Assertions.assertFalse((sharingServiceClient.userHasAccess(domainId, "test-user-3", "test-file-1", "CLONE"))); - - filters = new ArrayList<>(); - searchCriteria = new SearchCriteria(); - searchCriteria.setSearchCondition(SearchCondition.FULL_TEXT); - searchCriteria.setValue("experiment"); - searchCriteria.setSearchField(EntitySearchField.FULL_TEXT); - filters.add(searchCriteria); - - searchCriteria = new SearchCriteria(); - searchCriteria.setSearchCondition(SearchCondition.EQUAL); - searchCriteria.setValue("EXPERIMENT"); - searchCriteria.setSearchField(EntitySearchField.ENTITY_TYPE_ID); - filters.add(searchCriteria); - - searchCriteria = new SearchCriteria(); - searchCriteria.setSearchCondition(SearchCondition.EQUAL); - searchCriteria.setValue("READ"); - searchCriteria.setSearchField(EntitySearchField.PERMISSION_TYPE_ID); - filters.add(searchCriteria); - - Assertions.assertEquals( - 1, - sharingServiceClient - .searchEntities(domainId, "test-user-2", filters, 0, -1) - .size()); - Entity persistedEntity = sharingServiceClient - .searchEntities(domainId, "test-user-2", filters, 0, -1) - .get(0); - Assertions.assertEquals(entity3.getName(), persistedEntity.getName()); - Assertions.assertEquals(entity3.getDescription(), persistedEntity.getDescription()); - Assertions.assertEquals(entity3.getFullText(), persistedEntity.getFullText()); - - searchCriteria = new SearchCriteria(); - searchCriteria.setSearchCondition(SearchCondition.NOT); - searchCriteria.setValue("test-user-1"); - searchCriteria.setSearchField(EntitySearchField.OWNER_ID); - filters.add(searchCriteria); - Assertions.assertEquals( - 0, - sharingServiceClient - .searchEntities(domainId, "test-user-2", filters, 0, -1) - .size()); - } -}
