-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathConnectionConfigTest.java
More file actions
151 lines (125 loc) · 5.43 KB
/
Copy pathConnectionConfigTest.java
File metadata and controls
151 lines (125 loc) · 5.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package org.utplsql.cli;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.ValueSource;
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());
}
@Test
void parseCredentialsIsNotExternalAuthentication() {
ConnectionConfig info = new ConnectionConfig("test/pw@MY_TNS_ALIAS");
assertFalse(info.isExternalAuthentication());
assertEquals("test/pw@MY_TNS_ALIAS", info.getConnectString());
}
@Test
void parseExternalAuthentication() {
ConnectionConfig info = new ConnectionConfig("/@MY_TNS_ALIAS");
assertNull(info.getUser());
assertNull(info.getPassword());
assertEquals("MY_TNS_ALIAS", info.getConnect());
assertTrue(info.isExternalAuthentication());
assertFalse(info.isSysDba());
assertEquals("/@MY_TNS_ALIAS", info.getConnectString());
}
@Test
void parseExternalAuthenticationWithTnsAdminInUrl() {
ConnectionConfig info = new ConnectionConfig("/@MY_TNS_ALIAS?TNS_ADMIN=/home/me/oracle/network/admin");
assertNull(info.getUser());
assertNull(info.getPassword());
assertEquals("MY_TNS_ALIAS?TNS_ADMIN=/home/me/oracle/network/admin", info.getConnect());
assertTrue(info.isExternalAuthentication());
}
@Test
void parseExternalAuthenticationWithEzConnect() {
ConnectionConfig info = new ConnectionConfig("/@//my.local.host:1521/service");
assertEquals("//my.local.host:1521/service", info.getConnect());
assertTrue(info.isExternalAuthentication());
}
@ParameterizedTest
@ValueSource(strings = {
"/pw@MY_TNS_ALIAS", // password without user
"test/@MY_TNS_ALIAS", // user without password
"@MY_TNS_ALIAS",
"test@MY_TNS_ALIAS",
"MY_TNS_ALIAS"
})
void rejectInvalidConnectString(String connectString) {
assertThrows(IllegalArgumentException.class, () -> new ConnectionConfig(connectString));
}
@Test
void parseUnquotedPasswordWithAt() {
ConnectionConfig info = new ConnectionConfig("test/p@ss@w0rd@MY_TNS_ALIAS");
assertEquals("test", info.getUser());
assertEquals("p@ss@w0rd", info.getPassword());
assertEquals("MY_TNS_ALIAS", info.getConnect());
}
@ParameterizedTest
@CsvSource(delimiter = '|', value = {
"test/pw@my.local.host/service | ****/****@my.local.host/service",
"test/pw@//my.local.host:1521/service | ****/****@//my.local.host:1521/service",
"sys as sysdba/pw@MY_TNS_ALIAS | ****/****@MY_TNS_ALIAS",
"test/\"p@ssw0rd=\"@MY_TNS_ALIAS | ****/****@MY_TNS_ALIAS",
"\"User/Mine@=\"/pw@MY_TNS_ALIAS | ****/****@MY_TNS_ALIAS",
"test/p@ss@MY_TNS_ALIAS | ****/****@MY_TNS_ALIAS",
"/@MY_TNS_ALIAS | /@MY_TNS_ALIAS"
})
void maskCredentials(String connectString, String expected) {
assertEquals(expected, ConnectionConfig.maskCredentials(connectString));
assertEquals(expected, new ConnectionConfig(connectString).getMaskedConnectString());
}
@ParameterizedTest
@ValueSource(strings = {
"run",
"--debug",
"-p=app.test_pkg",
"-f=ut_documentation_reporter",
"MY_TNS_ALIAS"
})
void maskCredentialsLeavesOtherValuesUnchanged(String value) {
assertEquals(value, ConnectionConfig.maskCredentials(value));
}
@Test
void maskCredentialsOfNull() {
assertNull(ConnectionConfig.maskCredentials(null));
}
}