Skip to content

Commit 757a339

Browse files
committed
Added tests for WALLET connections.
Removed dependencies on depreciated MojoRule Removed transitive vulnerabilities from plexus-utils (dependency update)
1 parent ea123b3 commit 757a339

3 files changed

Lines changed: 205 additions & 209 deletions

File tree

‎pom.xml‎

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,24 @@
8282
</distributionManagement>
8383

8484

85+
<dependencyManagement>
86+
<dependencies>
87+
<!-- Versions without known vulnerabilities of transitive dependencies -->
88+
<!-- plexus-utils: from maven-core (provided) and maven-compat (test), CVE-2025-67030 -->
89+
<dependency>
90+
<groupId>org.codehaus.plexus</groupId>
91+
<artifactId>plexus-utils</artifactId>
92+
<version>3.6.1</version>
93+
</dependency>
94+
<!-- assertj-core: from itf-assertj (test), CVE-2026-24400 -->
95+
<dependency>
96+
<groupId>org.assertj</groupId>
97+
<artifactId>assertj-core</artifactId>
98+
<version>3.27.7</version>
99+
</dependency>
100+
</dependencies>
101+
</dependencyManagement>
102+
85103
<dependencies>
86104
<!-- Maven API - provided by the Maven runtime -->
87105
<dependency>
@@ -99,7 +117,7 @@
99117
<dependency>
100118
<groupId>org.apache.maven.shared</groupId>
101119
<artifactId>maven-shared-utils</artifactId>
102-
<version>3.4.2</version>
120+
<version>3.5.0</version>
103121
</dependency>
104122

105123
<dependency>
@@ -128,12 +146,6 @@
128146
<version>${junit.version}</version>
129147
<scope>test</scope>
130148
</dependency>
131-
<dependency>
132-
<groupId>org.junit.vintage</groupId>
133-
<artifactId>junit-vintage-engine</artifactId>
134-
<version>${junit.version}</version>
135-
<scope>test</scope>
136-
</dependency>
137149

138150
<dependency>
139151
<groupId>com.soebes.itf.jupiter.extension</groupId>
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
package org.utplsql.maven.plugin;
2+
3+
import oracle.security.pki.OracleSecretStore;
4+
import oracle.security.pki.OracleWallet;
5+
import org.apache.maven.api.plugin.testing.Basedir;
6+
import org.apache.maven.api.plugin.testing.InjectMojo;
7+
import org.apache.maven.api.plugin.testing.MojoParameter;
8+
import org.apache.maven.api.plugin.testing.MojoTest;
9+
import org.junit.jupiter.api.AfterEach;
10+
import org.junit.jupiter.api.Test;
11+
import org.junit.jupiter.api.io.TempDir;
12+
13+
import java.nio.file.Files;
14+
import java.nio.file.Path;
15+
16+
import static org.utplsql.maven.plugin.UtPlsqlMojoTest.UNIT_TESTS;
17+
18+
/**
19+
* Tests of the database connection configuration.
20+
* <p>
21+
* Unlike {@link UtPlsqlMojoTest}, no connection is given as mojo parameters,
22+
* so the mojo falls back to the dbUrl, dbUser and dbPass system properties.
23+
*/
24+
@MojoTest
25+
@MojoParameter(name = "targetDir", value = "target/unit-tests")
26+
class UtPlsqlMojoConnectionTest {
27+
28+
private static final String WALLET_TNS_ALIAS = "UTPLSQL_MAVEN_WALLET";
29+
30+
@TempDir
31+
Path tempDir;
32+
33+
@AfterEach
34+
void clearSystemProperties() {
35+
System.clearProperty("dbUrl");
36+
System.clearProperty("dbUser");
37+
System.clearProperty("dbPass");
38+
}
39+
40+
/**
41+
* DB configuration from System Properties
42+
* <p>
43+
* Given : a pom.xml without dbUrl, dbUser and dbPass configured
44+
* When : pom is read
45+
* Then : System Properties must be used to configure database
46+
*/
47+
@Test
48+
@Basedir(UNIT_TESTS + "db_config_using_system_properties")
49+
void db_config_using_system_properties(@InjectMojo(goal = "test", pom = "pom.xml") UtPlsqlMojo utPlsqlMojo) throws Exception {
50+
System.setProperty("dbUrl", "jdbc:oracle:thin:@//localhost:1521/FREEPDB1");
51+
System.setProperty("dbUser", "UT3");
52+
System.setProperty("dbPass", "ut3");
53+
54+
utPlsqlMojo.execute();
55+
}
56+
57+
/**
58+
* Connection using Oracle Wallet (Secure External Password Store)
59+
* <p>
60+
* Given : a pom.xml without dbUser and dbPass and a dbUrl pointing to a TNS alias stored in an Oracle Wallet
61+
* When : tests are run
62+
* Then : credentials are taken from the wallet
63+
*/
64+
@Test
65+
@Basedir(UNIT_TESTS + "wallet_connection")
66+
void wallet_connection_without_credentials(@InjectMojo(goal = "test", pom = "pom.xml") UtPlsqlMojo utPlsqlMojo) throws Exception {
67+
System.setProperty("dbUrl", walletDbUrl());
68+
69+
utPlsqlMojo.execute();
70+
}
71+
72+
/**
73+
* Connection using Oracle Wallet with empty credentials
74+
* <p>
75+
* Given : a dbUrl pointing to a TNS alias stored in an Oracle Wallet and empty dbUser and dbPass (e.g. -DdbUser= -DdbPass=)
76+
* When : tests are run
77+
* Then : empty credentials are ignored and credentials are taken from the wallet
78+
*/
79+
@Test
80+
@Basedir(UNIT_TESTS + "wallet_connection")
81+
void wallet_connection_with_empty_credentials(@InjectMojo(goal = "test", pom = "pom.xml") UtPlsqlMojo utPlsqlMojo) throws Exception {
82+
System.setProperty("dbUrl", walletDbUrl());
83+
System.setProperty("dbUser", "");
84+
System.setProperty("dbPass", "");
85+
86+
utPlsqlMojo.execute();
87+
}
88+
89+
/**
90+
* Creates an auto-login Oracle Wallet holding the UT3 credentials for {@link #WALLET_TNS_ALIAS},
91+
* with tnsnames.ora and ojdbc.properties next to it, so no Oracle client tooling (mkstore/orapki) is needed.
92+
*
93+
* @return JDBC URL of the TNS alias, with the generated directory as TNS_ADMIN
94+
*/
95+
private String walletDbUrl() throws Exception {
96+
Path tnsAdmin = Files.createDirectories(tempDir.resolve("tns_admin"));
97+
98+
OracleWallet wallet = new OracleWallet();
99+
wallet.create("Wallet_Pwd_123".toCharArray());
100+
OracleSecretStore secretStore = wallet.getSecretStore();
101+
secretStore.createCredential(WALLET_TNS_ALIAS.toCharArray(), "UT3".toCharArray(), "ut3".toCharArray());
102+
wallet.setSecretStore(secretStore);
103+
wallet.saveAs(tnsAdmin.toString());
104+
wallet.createSSO();
105+
wallet.saveSSO();
106+
107+
Files.writeString(tnsAdmin.resolve("tnsnames.ora"),
108+
WALLET_TNS_ALIAS + " = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))"
109+
+ "(CONNECT_DATA = (SERVICE_NAME = FREEPDB1)))\n");
110+
// ${TNS_ADMIN} is resolved by the JDBC driver, the same way as in wallets downloaded for Oracle Autonomous Database
111+
Files.writeString(tnsAdmin.resolve("ojdbc.properties"),
112+
"oracle.net.wallet_location=(SOURCE=(METHOD=FILE)(METHOD_DATA=(DIRECTORY=${TNS_ADMIN})))\n");
113+
114+
return "jdbc:oracle:thin:@" + WALLET_TNS_ALIAS + "?TNS_ADMIN=" + tnsAdmin.toAbsolutePath().toString().replace('\\', '/');
115+
}
116+
}

0 commit comments

Comments
 (0)