]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Fix SQL tests checking properly the query results (#4064)
authorJorge Pereira <jpereira@users.noreply.github.com>
Tue, 20 Apr 2021 09:27:58 +0000 (06:27 -0300)
committerGitHub <noreply@github.com>
Tue, 20 Apr 2021 09:27:58 +0000 (05:27 -0400)
Use  macros, so the tests don't have huge lines of text

src/tests/modules/sql/acct_0_start.unlang
src/tests/modules/sql/acct_1_update.unlang
src/tests/modules/sql/acct_2_stop.unlang
src/tests/modules/sql/acct_start_conflict.unlang
src/tests/modules/sql/acct_update_no_start.unlang
src/tests/modules/sql/auth.unlang
src/tests/modules/sql/reject.unlang
src/tests/modules/unit_test_module.conf

index 5df65d15e1aab184ea98779980cd301894ab5a70..c3a225acc7921ac07dd9983d595f60e7b7f98c76 100644 (file)
@@ -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
-}
index 9e1d4bd201a22dddf8bfe9c028ad4600317e2a2a..12362e09bb8bfc592a5c7c0b86048735ca1eb33a 100644 (file)
@@ -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
 }
-
index 59bd1346532bf42bf9f49eda53652ec51ee3b9a3..cf51d50c9e73e0cb2a8cc95286338c2ce2ffba87 100644 (file)
@@ -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
-}
index 79dae7f39052cd4d06d2fa0ead48b28b8cf9c6e2..45da5fdf84a6e8f917fd4da4f742f093e32d3a05 100644 (file)
@@ -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
-}
index c2e2cc7784ebb0b36da3dd5d7bdd781f705e5686..2ec432a3d8410fd9ab6df677297eb455f5dde387 100644 (file)
@@ -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
index 3afdf3617cfdfe02af7d97934bc771e22a50e7dd..5c973d078e040c8a920e63ca9b21b679ecd145a5 100644 (file)
@@ -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
 }
 
index c0657a82d8309fb33aee5fc2d7036a791ef3cc0f..1c68fd724a4415014c8f1f7b491faa12262d6ae1 100644 (file)
@@ -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
 }
 
index 0faedcde526eea6327f147c63c3d2b39f593ac22..5bd631d07f1b6d03ba8b0ec70b541f9b78cbb0a2 100644 (file)
@@ -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"