From: Jorge Pereira Date: Tue, 20 Apr 2021 09:27:58 +0000 (-0300) Subject: Fix SQL tests checking properly the query results (#4064) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d8626c17363b83d6329f5321ea67c84ca548ed59;p=thirdparty%2Ffreeradius-server.git Fix SQL tests checking properly the query results (#4064) Use macros, so the tests don't have huge lines of text --- diff --git a/src/tests/modules/sql/acct_0_start.unlang b/src/tests/modules/sql/acct_0_start.unlang index 5df65d15e1a..c3a225acc79 100644 --- a/src/tests/modules/sql/acct_0_start.unlang +++ b/src/tests/modules/sql/acct_0_start.unlang @@ -1,15 +1,8 @@ # -# Clear out old data +# Clear out old data. We don't care if the deletion deletes any rows. # -update { - &Tmp-String-0 := "%{sql:DELETE FROM radacct WHERE AcctSessionId = '00000000'}" -} -if (!&Tmp-String-0) { - test_fail -} -else { - test_pass -} + +"%{sql:${delete_from_radacct} '00000000'}" sql.accounting if (ok) { @@ -19,22 +12,10 @@ else { test_fail } -update { - &Tmp-Integer-0 := "%{sql:SELECT count(*) FROM radacct WHERE AcctSessionId = '00000000'}" -} -if (!&Tmp-Integer-0 || (&Tmp-Integer-0 != 1)) { +if ("%{sql:SELECT count(*) FROM radacct WHERE AcctSessionId = '00000000'}" != "1") { test_fail } -else { - test_pass -} -update { - &Tmp-Integer-0 := "%{sql:SELECT acctsessiontime FROM radacct WHERE AcctSessionId = '00000000'}" -} -if (!&Tmp-Integer-0 || (&Tmp-Integer-0 != 0)) { +if ("%{sql:SELECT acctsessiontime FROM radacct WHERE AcctSessionId = '00000000'}" != "0") { test_fail } -else { - test_pass -} diff --git a/src/tests/modules/sql/acct_1_update.unlang b/src/tests/modules/sql/acct_1_update.unlang index 9e1d4bd201a..12362e09bb8 100644 --- a/src/tests/modules/sql/acct_1_update.unlang +++ b/src/tests/modules/sql/acct_1_update.unlang @@ -9,23 +9,10 @@ else { test_fail } -update { - &Tmp-Integer-0 := "%{sql:SELECT count(*) FROM radacct WHERE AcctSessionId = '00000001'}" -} -if (!&Tmp-Integer-0 || (&Tmp-Integer-0 != 1)) { +if ("%{sql:SELECT count(*) FROM radacct WHERE AcctSessionId = '00000001'}" != "1") { test_fail } -else { - test_pass -} -update { - &Tmp-Integer-0 := "%{sql:SELECT acctsessiontime FROM radacct WHERE AcctSessionId = '00000001'}" -} -if (!&Tmp-Integer-0 || (&Tmp-Integer-0 != 30)) { - test_fail -} -else { +if ("%{sql:SELECT acctsessiontime FROM radacct WHERE AcctSessionId = '00000001'}" != "30") { test_pass } - diff --git a/src/tests/modules/sql/acct_2_stop.unlang b/src/tests/modules/sql/acct_2_stop.unlang index 59bd1346532..cf51d50c9e7 100644 --- a/src/tests/modules/sql/acct_2_stop.unlang +++ b/src/tests/modules/sql/acct_2_stop.unlang @@ -9,32 +9,14 @@ else { test_fail } -update { - &Tmp-Integer-0 := "%{sql:SELECT count(*) FROM radacct WHERE AcctSessionId = '00000002'}" -} -if (!&Tmp-Integer-0 || (&Tmp-Integer-0 != 1)) { +if("%{sql:SELECT count(*) FROM radacct WHERE AcctSessionId = '00000002'}" != "1") { test_fail } -else { - test_pass -} -update { - &Tmp-Integer-0 := "%{sql:SELECT acctsessiontime FROM radacct WHERE AcctSessionId = '00000002'}" -} -if (!&Tmp-Integer-0 || (&Tmp-Integer-0 != 120)) { +if("%{sql:SELECT acctsessiontime FROM radacct WHERE AcctSessionId = '00000002'}" != "120") { test_fail } -else { - test_pass -} -update { - &Tmp-String-0 := "%{sql:SELECT AcctTerminateCause FROM radacct WHERE AcctSessionId = '00000002'}" -} -if (!&Tmp-String-0 || (&Tmp-String-0 != 'User-Request')) { +if("%{sql:SELECT AcctTerminateCause FROM radacct WHERE AcctSessionId = '00000002'}" != 'User-Request') { test_fail } -else { - test_pass -} diff --git a/src/tests/modules/sql/acct_start_conflict.unlang b/src/tests/modules/sql/acct_start_conflict.unlang index 79dae7f3905..45da5fdf84a 100644 --- a/src/tests/modules/sql/acct_start_conflict.unlang +++ b/src/tests/modules/sql/acct_start_conflict.unlang @@ -5,15 +5,7 @@ # # Clear out old data # -update { - &Tmp-String-0 := "%{sql:DELETE FROM radacct WHERE AcctSessionId = '00000003'}" -} -if (!&Tmp-String-0) { - test_fail -} -else { - test_pass -} +"%{sql:delete_from_radacct '00000003'}" # # Insert the Accounting-Request start @@ -29,28 +21,16 @@ else { # # Check the database has at least one row # -update { - &Tmp-Integer-0 := "%{sql:SELECT count(*) FROM radacct WHERE AcctSessionId = '00000003'}" -} -if (!&Tmp-Integer-0 || (&Tmp-Integer-0 != 1)) { +if ("%{sql:SELECT count(*) FROM radacct WHERE AcctSessionId = '00000003'}" != "1") { test_fail } -else { - test_pass -} # # Check acctsessiontime matches the value in the request # -update { - &Tmp-Integer-0 := "%{sql:SELECT acctsessiontime FROM radacct WHERE AcctSessionId = '00000003'}" -} -if (!&Tmp-Integer-0 || (&Tmp-Integer-0 != 0)) { +if ("%{sql:SELECT acctsessiontime FROM radacct WHERE AcctSessionId = '00000003'}" != "0") { test_fail } -else { - test_pass -} # # Change acctsessiontime and verify it's updated @@ -65,12 +45,7 @@ if (ok) { else { test_fail } -update { - &Tmp-String-0 := "%{sql:SELECT connectinfo_start FROM radacct WHERE AcctSessionId = '00000003'}" -} -if (!&Tmp-Integer-0 || (&Tmp-String-0 != 'updated')) { + +if ("%{sql:SELECT connectinfo_start FROM radacct WHERE AcctSessionId = '00000003'}" != 'updated') { test_fail } -else { - test_pass -} diff --git a/src/tests/modules/sql/acct_update_no_start.unlang b/src/tests/modules/sql/acct_update_no_start.unlang index c2e2cc7784e..2ec432a3d84 100644 --- a/src/tests/modules/sql/acct_update_no_start.unlang +++ b/src/tests/modules/sql/acct_update_no_start.unlang @@ -1,41 +1,19 @@ # # Clear out old data # -update { - &Tmp-String-0 := "%{sql:DELETE FROM radacct WHERE AcctSessionId = '00000004'}" -} -if (!&Tmp-String-0) { - test_fail -} -else { - test_pass -} +"%{sql:${delete_from_radacct} '00000004'}" sql.accounting -if (ok) { - test_pass -} -else { +if (!ok) { test_fail } -update { - &Tmp-Integer-0 := "%{sql:SELECT count(*) FROM radacct WHERE AcctSessionId = '00000004'}" -} -if (!&Tmp-Integer-0 || (&Tmp-Integer-0 != 1)) { +if ("%{sql:SELECT count(*) FROM radacct WHERE AcctSessionId = '00000004'}" != "1") { test_fail } -else { - test_pass -} -update { - &Tmp-Integer-0 := "%{sql:SELECT acctsessiontime FROM radacct WHERE AcctSessionId = '00000004'}" -} -if (!&Tmp-Integer-0 || (&Tmp-Integer-0 != 30)) { +if ("%{sql:SELECT acctsessiontime FROM radacct WHERE AcctSessionId = '00000004'}" != "30") { test_fail } -else { - test_pass -} +test_pass diff --git a/src/tests/modules/sql/auth.unlang b/src/tests/modules/sql/auth.unlang index 3afdf3617cf..5c973d078e0 100644 --- a/src/tests/modules/sql/auth.unlang +++ b/src/tests/modules/sql/auth.unlang @@ -1,38 +1,21 @@ # # Clear out old data # -update { - &Tmp-String-0 := "%{sql:DELETE FROM radcheck WHERE username = 'user_auth'}" -} -if (!&Tmp-String-0) { - test_fail -} +"%{sql:${delete_from_radcheck} 'user_auth'}" -update { - &Tmp-String-0 := "%{sql:INSERT INTO radcheck (username, attribute, op, value) VALUES ('user_auth', 'NAS-IP-Address', '==', '1.2.3.4')}" -} -if (!&Tmp-String-0) { +if ("%{sql:${insert_into_radcheck} ('user_auth', 'NAS-IP-Address', '==', '1.2.3.4')}" != "1") { test_fail } -update { - &Tmp-String-0 := "%{sql:INSERT INTO radcheck (username, attribute, op, value) VALUES ('user_auth', 'Password.Cleartext', ':=', 'password')}" -} -if (!&Tmp-String-0) { +if ("%{sql:${insert_into_radcheck} ('user_auth', 'Password.Cleartext', ':=', 'password')}" != "1") { test_fail } -update { - &Tmp-String-0 := "%{sql:DELETE FROM radreply WHERE username = 'user_auth'}" -} -if (!&Tmp-String-0) { +if ("%{sql:${delete_from_radreply} 'user_auth'}" != "1") { test_fail } -update { - &Tmp-String-0 := "%{sql:INSERT INTO radreply (username, attribute, op, value) VALUES ('user_auth', 'Idle-Timeout', ':=', '3600')}" -} -if (!&Tmp-String-0) { +if ("%{sql:${insert_into_radreply} ('user_auth', 'Idle-Timeout', ':=', '3600')}" != "1") { test_fail } diff --git a/src/tests/modules/sql/reject.unlang b/src/tests/modules/sql/reject.unlang index c0657a82d83..1c68fd724a4 100644 --- a/src/tests/modules/sql/reject.unlang +++ b/src/tests/modules/sql/reject.unlang @@ -1,38 +1,24 @@ # # Clear out old data # -update { - &Tmp-String-0 := "%{sql:DELETE FROM radcheck WHERE username = 'user_reject'}" -} -if (!&Tmp-String-0) { - test_fail -} +"%{sql:${delete_from_radcheck} 'user_reject'}" -update { - &Tmp-String-0 := "%{sql:INSERT INTO radcheck (username, attribute, op, value) VALUES ('user_reject', 'NAS-IP-Address', '==', '1.2.3.4')}" -} -if (!&Tmp-String-0) { +# +# Add in the check items. +# +if ("%{sql:${insert_into_radcheck} ('user_reject', 'NAS-IP-Address', '==', '1.2.3.4')}" != "1") { test_fail } -update { - &Tmp-String-0 := "%{sql:INSERT INTO radcheck (username, attribute, op, value) VALUES ('user_reject', 'Password.Cleartext', ':=', 'wrong-password')}" -} -if (!&Tmp-String-0) { +if ("%{sql:${insert_into_radcheck} ('user_reject', 'Password.Cleartext', ':=', 'wrong-password')}" != "1") { test_fail } -update { - &Tmp-String-0 := "%{sql:DELETE FROM radreply WHERE username = 'user_reject'}" -} -if (!&Tmp-String-0) { +if ("%{sql:${delete_from_radreply} 'user_reject'}" != "1") { test_fail } -update { - &Tmp-String-0 := "%{sql:INSERT INTO radreply (username, attribute, op, value) VALUES ('user_reject', 'Reply-Message', ':=', 'Authentication failed')}" -} -if (!&Tmp-String-0) { +if ("%{sql:${insert_into_radreply} ('user_reject', 'Reply-Message', ':=', 'Authentication failed')}" != "1") { test_fail } diff --git a/src/tests/modules/unit_test_module.conf b/src/tests/modules/unit_test_module.conf index 0faedcde526..5bd631d07f1 100644 --- a/src/tests/modules/unit_test_module.conf +++ b/src/tests/modules/unit_test_module.conf @@ -12,6 +12,7 @@ security { allow_vulnerable_openssl = yes } +delete_from_radacct = "DELETE FROM radcheck WHERE AcctSessionId =" delete_from_radcheck = "DELETE FROM radcheck WHERE username =" delete_from_radreply = "DELETE FROM radreply WHERE username =" insert_into_radcheck = "INSERT INTO radcheck (username, attribute, op, value) VALUES"