Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Feature/connect as sysdba #133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions 15 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ To connect using TNS, you need to have the ORACLE_HOME environment variable set.
The file tnsnames.ora must exist in path %ORACLE_HOME%/network/admin
The file tnsnames.ora must contain valid TNS entries.

In case you use a username containing `/` or a password containing `@` you should encapsulate it with double quotes `"`:
```
utplsql run "my/Username"/"myP@ssword"@connectstring
```

### run
`utplsql run <ConnectionURL> [<options>]`

Expand Down Expand Up @@ -227,6 +232,16 @@ UT_XUNIT_REPORTER:
Provides outcomes in a format conforming with JUnit 4 and above as defined in: https://gist.github.com/kuzuha/232902acab1344d6b578
```

## Using utPLSQL-cli as sysdba

Since 3.1.3 it is possible to run utPLSQL-cli as sysdba by running

```
utplsql run "sys as sysdba"/pw@connectstring
```

It is, however, __not recommended__ to run utPLSQL with sysdba privileges.

## Enabling Color Outputs on Windows

To enable color outputs on Windows cmd you need to install an open-source utility called [ANSICON](http://adoxa.altervista.org/ansicon/).
Expand Down
22 changes: 19 additions & 3 deletions 22 src/main/java/org/utplsql/cli/ConnectionConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,26 @@ public class ConnectionConfig {
private final String connect;

public ConnectionConfig( String connectString ) {
Matcher m = Pattern.compile("^([^/]+)/([^@]+)@(.*)$").matcher(connectString);
Matcher m = Pattern.compile("^(\".+\"|[^/]+)/(\".+\"|[^@]+)@(.*)$").matcher(connectString);
if ( m.find() ) {
user = m.group(1);
password = m.group(2);
user = stripEnclosingQuotes(m.group(1));
password = stripEnclosingQuotes(m.group(2));
connect = m.group(3);
}
else
throw new IllegalArgumentException("Not a valid connectString: '" + connectString + "'");
}

private String stripEnclosingQuotes( String value ) {
if ( value.length() > 1
&& value.startsWith("\"")
&& value.endsWith("\"")) {
return value.substring(1, value.length()-1);
} else {
return value;
}
}

public String getConnect() {
return connect;
}
Expand All @@ -35,4 +45,10 @@ public String getPassword() {
public String getConnectString() {
return user + "/" + password + "@" + connect;
}

public boolean isSysDba() {
return user != null &&
(user.toLowerCase().endsWith(" as sysdba")
|| user.toLowerCase().endsWith(" as sysoper"));
}
}
7 changes: 7 additions & 0 deletions 7 src/main/java/org/utplsql/cli/DataSourceProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public static DataSource getDataSource(ConnectionInfo info, int maxConnections )
requireOjdbc();

ConnectionConfig config = new ConnectionConfig(info.getConnectionString());
warnIfSysDba(config);

HikariDataSource pds = new TestedDataSourceProvider(config).getDataSource();
pds.setAutoCommit(false);
Expand All @@ -43,4 +44,10 @@ private static void requireOjdbc() {
throw new RuntimeException("Can't run utPLSQL-cli without Oracle JDBC driver");
}
}

private static void warnIfSysDba(ConnectionConfig config) {
if ( config.isSysDba() ) {
System.out.println("WARNING: You are connecting to the database as SYSDBA or SYSOPER, which is NOT RECOMMENDED and can put your database at risk!");
}
}
}
2 changes: 1 addition & 1 deletion 2 src/main/java/org/utplsql/cli/RunCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public class RunCommand implements ICommand {
private ReporterFactory reporterFactory;
private ReporterManager reporterManager;

private ConnectionInfo getConnectionInfo() {
ConnectionInfo getConnectionInfo() {
return connectionInfoList.get(0);
}

Expand Down
57 changes: 57 additions & 0 deletions 57 src/test/java/org/utplsql/cli/ConnectionConfigTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package org.utplsql.cli;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

public class ConnectionConfigTest {

@Test
void parse() {
ConnectionConfig info = new ConnectionConfig("test/pw@my.local.host/service");

assertEquals("test", info.getUser());
assertEquals("pw", info.getPassword());
assertEquals("my.local.host/service", info.getConnect());
assertFalse(info.isSysDba());
}

@Test
void parseSysDba() {
ConnectionConfig info = new ConnectionConfig("sys as sysdba/pw@my.local.host/service");

assertEquals("sys as sysdba", info.getUser());
assertEquals("pw", info.getPassword());
assertEquals("my.local.host/service", info.getConnect());
assertTrue(info.isSysDba());
}
@Test
void parseSysOper() {
ConnectionConfig info = new ConnectionConfig("myOperUser as sysoper/passw0rd@my.local.host/service");

assertEquals("myOperUser as sysoper", info.getUser());
assertEquals("passw0rd", info.getPassword());
assertEquals("my.local.host/service", info.getConnect());
assertTrue(info.isSysDba());
}

@Test
void parseSpecialCharsPW() {
ConnectionConfig info = new ConnectionConfig("test/\"p@ssw0rd=\"@my.local.host/service");

assertEquals("test", info.getUser());
assertEquals("p@ssw0rd=", info.getPassword());
assertEquals("my.local.host/service", info.getConnect());
assertFalse(info.isSysDba());
}

@Test
void parseSpecialCharsUser() {
ConnectionConfig info = new ConnectionConfig("\"User/Mine@=\"/pw@my.local.host/service");

assertEquals("User/Mine@=", info.getUser());
assertEquals("pw", info.getPassword());
assertEquals("my.local.host/service", info.getConnect());
assertFalse(info.isSysDba());
}
}
8 changes: 8 additions & 0 deletions 8 src/test/java/org/utplsql/cli/DataSourceProviderIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ void connectToDatabase() throws SQLException {
assertNotNull(dataSource);
}

//@Test
void connectAsSysdba() throws SQLException {
ConnectionConfig config = new ConnectionConfig("sys as sysdba/oracle@localhost:1522/ORCLPDB1");
DataSource dataSource = new TestedDataSourceProvider(config).getDataSource();

assertNotNull(dataSource);
}

@Test
void initNlsLang() throws SQLException {
System.setProperty("NLS_LANG", "BRAZILIAN PORTUGUESE_BRAZIL.WE8ISO8859P1");
Expand Down
26 changes: 14 additions & 12 deletions 26 src/test/java/org/utplsql/cli/RunCommandIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.utplsql.api.reporter.CoreReporters;

import java.nio.file.Paths;
import java.sql.SQLException;

import static org.junit.jupiter.api.Assertions.assertEquals;

Expand All @@ -13,6 +14,14 @@
*/
class RunCommandIT extends AbstractFileOutputTest {

private void assertValidReturnCode(int returnCode) throws SQLException {
// Only expect failure-exit-code to work on several framework versions
if (OptionalFeatures.FAIL_ON_ERROR.isAvailableFor(TestHelper.getFrameworkVersion()))
assertEquals(2, returnCode);
else
assertEquals(0, returnCode);
}

@Test
void run_Default() throws Exception {

Expand All @@ -23,21 +32,18 @@ void run_Default() throws Exception {
"-c",
"--failure-exit-code=2");

// Only expect failure-exit-code to work on several framework versions
if (OptionalFeatures.FAIL_ON_ERROR.isAvailableFor(TestHelper.getFrameworkVersion()))
assertEquals(2, result);
else
assertEquals(0, result);
assertValidReturnCode(result);
}

@Test
void run_Debug() throws Exception {

int result = TestHelper.runApp("run",
TestHelper.getConnectionString(),
"--debug");
"--debug",
"--failure-exit-code=2");

assertEquals(1, result);
assertValidReturnCode(result);
}

@Test
Expand All @@ -55,11 +61,7 @@ void run_MultipleReporters() throws Exception {
"-c",
"--failure-exit-code=2");

// Only expect failure-exit-code to work on several framework versions
if (OptionalFeatures.FAIL_ON_ERROR.isAvailableFor(TestHelper.getFrameworkVersion()))
assertEquals(2, result);
else
assertEquals(0, result);
assertValidReturnCode(result);
}


Expand Down
7 changes: 7 additions & 0 deletions 7 src/test/java/org/utplsql/cli/RunCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,11 @@ void reporterOptions_TwoReporters() {
assertTrue(reporterOptions2.outputToScreen());
}

@Test
void connectionString_asSysdba() {
RunCommand runCmd = TestHelper.createRunCommand("sys as sysdba/mypass@connectstring/service");

assertEquals("sys as sysdba/mypass@connectstring/service",
runCmd.getConnectionInfo().getConnectionString());
}
}
12 changes: 12 additions & 0 deletions 12 src/test/java/org/utplsql/cli/TestHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,16 @@ static Version getFrameworkVersion() throws SQLException {
static String getConnectionString() {
return sUser + "/" + sPass + "@" + sUrl;
}

static String getUser() {
return sUser;
}

static String getPass() {
return sPass;
}

static String getUrl() {
return sUrl;
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.