Skip to content

Commit 3c0aa9a

Browse files
committed
refactor: replace hardcoded credentials with test utility functions and remove unused code
1 parent d1d0a1b commit 3c0aa9a

File tree

15 files changed

+112
-191
lines changed

15 files changed

+112
-191
lines changed

.github/workflows/enterprise.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,6 @@ jobs:
7575
TD_VERSION=3.9.9.9 cargo nextest run -p taos-ws-sys test_taos_get_client_info_injected -- --ignored
7676
TD_VERSION="$(printf '\xff\xfe')" cargo nextest run -p taos-ws-sys test_taos_get_client_info_default
7777
78-
# - name: Setup tmate session
79-
# uses: mxschmitt/action-tmate@v3
80-
# timeout-minutes: 300
81-
8278
- name: Generate code coverage
8379
env:
8480
TDENGINE_CLOUD_URL: ${{ secrets.TDENGINE_CLOUD_URL }}

taos-query/src/common/opts.rs

Lines changed: 0 additions & 120 deletions
This file was deleted.

taos-query/src/util/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ mod inline_write;
99

1010
pub mod req_id;
1111

12+
#[cfg(feature = "test")]
13+
pub mod test_utils;
1214
#[cfg(feature = "test")]
1315
pub mod totp;
1416
#[cfg(feature = "test")]

taos-query/src/util/test_utils.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use std::env;
2+
3+
pub fn test_username() -> String {
4+
env::var("TEST_USERNAME").unwrap_or_else(|_| "root".to_string())
5+
}
6+
7+
pub fn test_password() -> String {
8+
env::var("TEST_PASSWORD").unwrap_or_else(|_| "taosdata".to_string())
9+
}

taos-ws-sys/src/old_ws/tmq.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,7 @@ mod tests {
11321132

11331133
let consumer = ws_tmq_consumer_new(
11341134
conf,
1135-
b"tmq+ws://root:taosdata@localhost:6041\0" as *const u8 as *const c_char,
1135+
b"tmq+ws://localhost:6041\0" as *const u8 as *const c_char,
11361136
std::ptr::null_mut(),
11371137
0,
11381138
);

taos-ws-sys/src/ws/mod.rs

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,8 +1014,8 @@ pub fn test_connect() -> *mut TAOS {
10141014
unsafe {
10151015
let taos = taos_connect(
10161016
c"localhost".as_ptr(),
1017-
c"root".as_ptr(),
1018-
c"taosdata".as_ptr(),
1017+
ptr::null(),
1018+
ptr::null(),
10191019
ptr::null(),
10201020
6041,
10211021
);
@@ -1056,6 +1056,7 @@ mod tests {
10561056
use std::ptr;
10571057

10581058
use faststr::FastStr;
1059+
use taos_query::util::test_utils::{test_password, test_username};
10591060

10601061
use super::*;
10611062
use crate::ws::error::{taos_errno, taos_errstr};
@@ -1064,10 +1065,13 @@ mod tests {
10641065
#[test]
10651066
fn test_taos_connect() {
10661067
unsafe {
1068+
let user = CString::new(test_username()).unwrap();
1069+
let pass = CString::new(test_password()).unwrap();
1070+
10671071
let taos = taos_connect(
10681072
c"localhost".as_ptr(),
1069-
c"root".as_ptr(),
1070-
c"taosdata".as_ptr(),
1073+
user.as_ptr(),
1074+
pass.as_ptr(),
10711075
ptr::null(),
10721076
6041,
10731077
);
@@ -1098,10 +1102,13 @@ mod tests {
10981102
#[test]
10991103
fn test_taos_connect_unable_to_establish_connection() {
11001104
unsafe {
1105+
let user = CString::new(test_username()).unwrap();
1106+
let pass = CString::new(test_password()).unwrap();
1107+
11011108
let taos = taos_connect(
11021109
c"invalid_host".as_ptr(),
1103-
c"root".as_ptr(),
1104-
c"taosdata".as_ptr(),
1110+
user.as_ptr(),
1111+
pass.as_ptr(),
11051112
ptr::null(),
11061113
6041,
11071114
);
@@ -1335,12 +1342,23 @@ mod tests {
13351342
assert!(!taos.is_null());
13361343
taos_close(taos);
13371344

1338-
let taos = taos_connect_with_dsn(c"ws://root:taosdata@localhost:6041".as_ptr());
1345+
let dsn = CString::new(format!(
1346+
"ws://{}:{}@localhost:6041",
1347+
test_username(),
1348+
test_password()
1349+
))
1350+
.unwrap();
1351+
let taos = taos_connect_with_dsn(dsn.as_ptr());
13391352
assert!(!taos.is_null());
13401353
taos_close(taos);
13411354

1342-
let taos =
1343-
taos_connect_with_dsn(c"ws://root:taosdata@localhost:6041?read_timeout=1".as_ptr());
1355+
let dsn = CString::new(format!(
1356+
"ws://{}:{}@localhost:6041?read_timeout=1",
1357+
test_username(),
1358+
test_password()
1359+
))
1360+
.unwrap();
1361+
let taos = taos_connect_with_dsn(dsn.as_ptr());
13441362
assert!(!taos.is_null());
13451363
taos_close(taos);
13461364

@@ -1417,7 +1435,11 @@ mod tests {
14171435

14181436
unsafe {
14191437
let dsn = build_dsn_from_options(&opts as *const _).unwrap();
1420-
assert!(dsn.starts_with("ws://root:taosdata@localhost:6041/"));
1438+
assert!(dsn.starts_with(&format!(
1439+
"ws://{}:{}@localhost:6041/",
1440+
test_username(),
1441+
test_password()
1442+
)));
14211443
}
14221444
}
14231445

@@ -1436,7 +1458,11 @@ mod tests {
14361458

14371459
unsafe {
14381460
let dsn = build_dsn_from_options(&opts as *const _).unwrap();
1439-
assert!(dsn.starts_with("ws://root:taosdata@localhost:6041/"));
1461+
assert!(dsn.starts_with(&format!(
1462+
"ws://{}:{}@localhost:6041/",
1463+
test_username(),
1464+
test_password()
1465+
)));
14401466
}
14411467
}
14421468

@@ -1510,11 +1536,14 @@ mod tests {
15101536
],
15111537
);
15121538

1539+
let user = test_username();
1540+
let pass = test_password();
1541+
15131542
let opts = make_options(&[
15141543
(IP, "localhost"),
15151544
(PORT, "6041"),
1516-
(USER, "root"),
1517-
(PASS, "taosdata"),
1545+
(USER, &user),
1546+
(PASS, &pass),
15181547
(DB, "test_1765508846"),
15191548
]);
15201549
let taos = taos_connect_with(&opts as *const _);
@@ -1767,12 +1796,15 @@ mod tests {
17671796
],
17681797
);
17691798

1799+
let user = test_username();
1800+
let pass = test_password();
1801+
17701802
unsafe {
17711803
let opts = make_options(&[
17721804
(IP, "localhost"),
17731805
(PORT, "6445"),
1774-
(USER, "root"),
1775-
(PASS, "taosdata"),
1806+
(USER, &user),
1807+
(PASS, &pass),
17761808
(DB, "test_1765519301"),
17771809
(WS_TLS_MODE, "3"),
17781810
(WS_TLS_VERSION, "TLSv1.3,TLSv1.2"),

taos-ws-sys/src/ws/query.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2101,8 +2101,8 @@ mod tests {
21012101

21022102
let taos = taos_connect(
21032103
c"localhost".as_ptr(),
2104-
c"root".as_ptr(),
2105-
c"taosdata".as_ptr(),
2104+
ptr::null(),
2105+
ptr::null(),
21062106
c"test_1737102411".as_ptr(),
21072107
6041,
21082108
);
@@ -3159,8 +3159,8 @@ mod tests {
31593159
unsafe {
31603160
let taos = taos_connect(
31613161
c"[::1]".as_ptr(),
3162-
c"root".as_ptr(),
3163-
c"taosdata".as_ptr(),
3162+
ptr::null(),
3163+
ptr::null(),
31643164
ptr::null(),
31653165
6041,
31663166
);

taos-ws-sys/src/ws/stmt2.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1973,8 +1973,8 @@ mod tests {
19731973
unsafe {
19741974
let taos = taos_connect(
19751975
c"localhost".as_ptr(),
1976-
c"root".as_ptr(),
1977-
c"taosdata".as_ptr(),
1976+
ptr::null(),
1977+
ptr::null(),
19781978
ptr::null(),
19791979
8818,
19801980
);
@@ -2098,8 +2098,8 @@ mod tests {
20982098
let taos = unsafe {
20992099
taos_connect(
21002100
c"localhost".as_ptr(),
2101-
c"root".as_ptr(),
2102-
c"taosdata".as_ptr(),
2101+
ptr::null(),
2102+
ptr::null(),
21032103
ptr::null(),
21042104
8819,
21052105
)
@@ -2232,8 +2232,8 @@ mod tests {
22322232
unsafe {
22332233
let taos = taos_connect(
22342234
c"localhost".as_ptr(),
2235-
c"root".as_ptr(),
2236-
c"taosdata".as_ptr(),
2235+
ptr::null(),
2236+
ptr::null(),
22372237
ptr::null(),
22382238
8821,
22392239
);

0 commit comments

Comments
 (0)