Index: openacs-4/packages/acs-authentication/tcl/test/authentication-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-authentication/tcl/test/authentication-procs.tcl,v diff -u -r1.1.2.5 -r1.1.2.6 --- openacs-4/packages/acs-authentication/tcl/test/authentication-procs.tcl 5 Oct 2021 14:32:59 -0000 1.1.2.5 +++ openacs-4/packages/acs-authentication/tcl/test/authentication-procs.tcl 5 Oct 2021 15:08:59 -0000 1.1.2.6 @@ -213,6 +213,59 @@ } } +aa_register_case \ + -cats {api} \ + -procs { + auth::get_user_id + } \ + auth__get_user_id { + Test auth::get_user_id + } { + # We will just mess about with the ad_conn variables used + # inside the proc to simulate a few possible situations. + set prev_untrusted_user_id [ad_conn untrusted_user_id] + set prev_account_status [ad_conn account_status] + set prev_auth_level [ad_conn auth_level] + + set user_id [ad_conn user_id] + + set bogus_user [db_string get_bogus_user { + select max(user_id) + 1 from users + }] + + aa_run_with_teardown \ + -rollback \ + -test_code { + foreach { + untrusted_user_id account_status auth_level + wanted_level wanted_account_status + expected_result + } [list \ + 0 whatever none 1234 whatever 0 \ + $user_id ok ok ok ok $user_id \ + $user_id ok ok secure ok [expr {[security::https_available_p] ? 0 : $user_id}] \ + $user_id ok secure secure ok $user_id \ + $user_id ok secure secure whatever $user_id \ + $bogus_user ok secure secure ok $bogus_user \ + $bogus_user ko secure secure ok 0 \ + ] { + ad_conn -set untrusted_user_id $untrusted_user_id + ad_conn -set account_status $account_status + ad_conn -set auth_level $auth_level + + set v [auth::get_user_id \ + -level $wanted_level \ + -account_status $wanted_account_status] + aa_equals "For user '$untrusted_user_id', level '$wanted_level', account_status '$wanted_account_status' the result should be '$expected_result'" \ + $v $expected_result + } + } -teardown_code { + ad_conn -set untrusted_user_id $prev_untrusted_user_id + ad_conn -set account_status $prev_account_status + ad_conn -set auth_level $prev_auth_level + } + } + # Local variables: # mode: tcl # tcl-indent-level: 4