Index: openacs-4/packages/acs-authentication/tcl/authentication-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-authentication/tcl/authentication-procs.tcl,v diff -u -r1.23 -r1.24 --- openacs-4/packages/acs-authentication/tcl/authentication-procs.tcl 10 Sep 2003 09:09:47 -0000 1.23 +++ openacs-4/packages/acs-authentication/tcl/authentication-procs.tcl 10 Sep 2003 13:13:48 -0000 1.24 @@ -980,7 +980,7 @@ # A user with this email does exist, but he's banned, so we can 'steal' his email address # by setting it to something dummy party::update \ - -user_id $email_party_id \ + -party_id $email_party_id \ -email "dummy-email-$email_party_id" } default { @@ -1004,7 +1004,7 @@ # A user with this username does exist, but he's banned, so we can 'steal' his username # by setting it to something dummy acs_user::update \ - -user_id $usrename_user_id \ + -user_id $username_user_id \ -username "dummy-username-$username_user_id" } default { Index: openacs-4/packages/acs-authentication/tcl/sync-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-authentication/tcl/sync-procs.tcl,v diff -u -r1.8 -r1.9 --- openacs-4/packages/acs-authentication/tcl/sync-procs.tcl 10 Sep 2003 12:42:01 -0000 1.8 +++ openacs-4/packages/acs-authentication/tcl/sync-procs.tcl 10 Sep 2003 13:13:48 -0000 1.9 @@ -53,7 +53,7 @@ return [db_list select_entries { select entry_id from auth_batch_job_entries where job_id = :job_id order by entry_time }] } -ad_proc -public auth::sync::job::get_authority_id_from_job_id { +ad_proc -public auth::sync::job::get_authority_id { {-job_id:required} } { Get the authority_id from a job_id. Cached. @@ -62,10 +62,10 @@ @author Lars Pind (lars@collaboraid.biz) } { - return [util_memoize [list auth::sync::job::get_authority_id_from_job_id_not_cached $job_id]] + return [util_memoize [list auth::sync::job::get_authority_id_not_cached $job_id]] } -ad_proc -private auth::sync::job::get_authority_id_from_job_id_flush { +ad_proc -private auth::sync::job::get_authority_id_flush { {-job_id ""} } { Flush cache @@ -75,13 +75,13 @@ @author Lars Pind (lars@collaboraid.biz) } { if { ![empty_string_p $job_id] } { - util_memoize_flush [list auth::sync::job::get_authority_id_from_job_id_not_cached $job_id] + util_memoize_flush [list auth::sync::job::get_authority_id_not_cached $job_id] } else { - util_memoize_flush_regexp [list auth::sync::job::get_authority_id_from_job_id_not_cached .*] + util_memoize_flush_regexp [list auth::sync::job::get_authority_id_not_cached .*] } } -ad_proc -private auth::sync::job::get_authority_id_from_job_id_seed { +ad_proc -private auth::sync::job::get_authority_id_seed { {-job_id:required} {-authority_id:required} } { @@ -91,10 +91,10 @@ @author Lars Pind (lars@collaboraid.biz) } { - util_memoize_seed [list auth::sync::job::get_authority_id_from_job_id_not_cached $job_id] $authority_id + util_memoize_seed [list auth::sync::job::get_authority_id_not_cached $job_id] $authority_id } -ad_proc -private auth::sync::job::get_authority_id_from_job_id_not_cached { +ad_proc -private auth::sync::job::get_authority_id_not_cached { job_id } { Get the authority_id from a job_id. Not cached. @@ -103,7 +103,7 @@ @author Lars Pind (lars@collaboraid.biz) - @see auth::sync::job::get_authority_id_from_job_id + @see auth::sync::job::get_authority_id } { return [db_string select_auth_id { select authority_id from auth_batch_jobs where job_id = :job_id }] } @@ -145,10 +145,11 @@ values (:job_id, :interactive_p, :snapshot_p, :creation_user, :authority_id) } + } # See the cache, we're going to need it shortly - auth::sync::job::get_authority_id_from_job_id_seed -job_id $job_id -authority_id $authority_id + auth::sync::job::get_authority_id_seed -job_id $job_id -authority_id $authority_id return $job_id } @@ -307,7 +308,7 @@ set entry_id {} set user_id {} - set authority_id [get_authority_id_from_job_id -job_id $job_id] + set authority_id [get_authority_id -job_id $job_id] db_transaction { # We deal with insert/update in a snaphsot sync here @@ -335,6 +336,7 @@ switch $operation { "insert" { # We set email_verified_p to 't', because we trust the email we get from the remote system + array set result [auth::create_local_account \ -authority_id $authority_id \ -username $username \ @@ -411,7 +413,7 @@ } { Deletes the users that weren't included in the snapshot. } { - set authority_id [get_authority_id_from_job_id -job_id $job_id] + set authority_id [get_authority_id -job_id $job_id] set usernames [db_list select_user_ids { select username Index: openacs-4/packages/acs-authentication/tcl/test/sync-test-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-authentication/tcl/test/sync-test-procs.tcl,v diff -u -r1.6 -r1.7 --- openacs-4/packages/acs-authentication/tcl/test/sync-test-procs.tcl 10 Sep 2003 09:09:47 -0000 1.6 +++ openacs-4/packages/acs-authentication/tcl/test/sync-test-procs.tcl 10 Sep 2003 13:13:48 -0000 1.7 @@ -459,8 +459,8 @@ } -aa_register_case job_batch_ims_dummy { - Test a batch job for the local authority +aa_register_case job_batch_ims_example_doc { + Test IMS Enterprise 1.1 batch sync with the XML document from the specification. } { aa_stub acs_sc::invoke { acs_sc::invoke__arg_parser @@ -643,3 +643,250 @@ } +aa_register_case job_batch_ims_test { + Test IMS Enterprise 1.1 batch sync with a constructed document which actually works +} { + aa_stub acs_sc::invoke { + acs_sc::invoke__arg_parser + + if { [string equal $contract GetDocument] && [string equal $operation GetDocument] } { + array set result { + doc_status ok + doc_message {} + document {} + } + + global ims_doc + + set result(document) " + + + $ims_doc(username) + + + $ims_doc(first_names) + $ims_doc(last_name) + + $ims_doc(email) + $ims_doc(url) + +" + + return [array get result] + } else { + acs_sc::invoke_unstubbed \ + -contract $contract \ + -operation $operation \ + -impl $impl \ + -impl_id $impl_id \ + -call_args $call_args \ + -error=$error_p + } + } + + aa_run_with_teardown \ + -rollback \ + -test_code { + + # Create a new dummy authority with the dummy IMS get-document driver and the IMS Enterprise 1.1 process driver. + array set new_auth { + short_name dummy-test + pretty_name dummy-test + enabled_p t + sort_order 999 + auth_impl_id {} + pwd_impl_id {} + forgotten_pwd_url {} + change_pwd_url {} + register_impl_id {} + register_url {} + help_contact_text {} + snapshot_p f + batch_sync_enabled_p f + } + set new_auth(get_doc_impl_id) 1 + set new_auth(process_doc_impl_id) [acs_sc::impl::get_id -owner "acs-authentication" -name "IMS Enterprise 1.1"] + + set new_auth(get_doc_impl_id) [acs_sc::impl::get_id -owner "acs-authentication" -name "HTTPGet"] + + set authority_id [auth::authority::create \ + -array new_auth] + + + global ims_doc + + ##### + # + # Insert + # + ##### + + # Setup dummy variables + set ims_doc(recstatus) 1 + set ims_doc(username) [ad_generate_random_string] + set ims_doc(first_names) [ad_generate_random_string] + set ims_doc(last_name) [ad_generate_random_string] + set ims_doc(email) [string tolower "[ad_generate_random_string]@foo.bar"] + set ims_doc(url) "http://www.[ad_generate_random_string].com" + + set job_id [auth::authority::batch_sync -authority_id $authority_id] + + auth::sync::job::get -job_id $job_id -array job + + aa_equals "Number of actions" $job(num_actions) 1 + aa_equals "Number of problems" $job(num_problems) 0 + aa_log "job.message = '$job(message)'" + aa_log "job.document = '$job(document)'" + + set entry_id [auth::sync::job::get_entries -job_id $job_id] + aa_equals "One entry" [llength $entry_id] 1 + + array unset entry + auth::sync::job::get_entry -entry_id $entry_id -array entry + + aa_log "entry.message = '$entry(message)'" + aa_log "entry.element_messages = '$entry(element_messages)'" + + array unset user + acs_user::get -user_id $entry(user_id) -array user + + foreach varname { username first_names last_name email url } { + aa_equals "$varname" $user($varname) $ims_doc($varname) + } + aa_equals "authority_id" $user(authority_id) $authority_id + aa_false "member_state not banned" [string equal $user(member_state) "banned"] + # saving this for later + set first_user_id $entry(user_id) + + + ##### + # + # Update + # + ##### + + # Setup dummy variables + set ims_doc(recstatus) 2 + # username is unchanged + set ims_doc(first_names) [ad_generate_random_string] + set ims_doc(last_name) [ad_generate_random_string] + set ims_doc(email) [string tolower "[ad_generate_random_string]@foo.bar"] + set ims_doc(url) "http://www.[ad_generate_random_string].com" + + set job_id [auth::authority::batch_sync -authority_id $authority_id] + + auth::sync::job::get -job_id $job_id -array job + + aa_equals "Number of actions" $job(num_actions) 1 + aa_equals "Number of problems" $job(num_problems) 0 + aa_log "job.message = '$job(message)'" + aa_log "job.document = '$job(document)'" + + set entry_id [auth::sync::job::get_entries -job_id $job_id] + aa_equals "One entry" [llength $entry_id] 1 + + array unset entry + auth::sync::job::get_entry -entry_id $entry_id -array entry + + aa_log "entry.message = '$entry(message)'" + aa_log "entry.element_messages = '$entry(element_messages)'" + + array unset user + acs_user::get -user_id $entry(user_id) -array user + + foreach varname { username first_names last_name email url } { + aa_equals "$varname" $user($varname) $ims_doc($varname) + } + aa_false "member_state not banned" [string equal $user(member_state) "banned"] + + ##### + # + # Delete + # + ##### + + # Setup dummy variables + set ims_doc(recstatus) 3 + # username is unchanged + set ims_doc(first_names) [ad_generate_random_string] + set ims_doc(last_name) [ad_generate_random_string] + # email is unchanged + set ims_doc(url) "http://www.[ad_generate_random_string].com" + + set job_id [auth::authority::batch_sync -authority_id $authority_id] + + auth::sync::job::get -job_id $job_id -array job + + aa_equals "Number of actions" $job(num_actions) 1 + aa_equals "Number of problems" $job(num_problems) 0 + aa_log "job.message = '$job(message)'" + aa_log "job.document = '$job(document)'" + + set entry_id [auth::sync::job::get_entries -job_id $job_id] + aa_equals "One entry" [llength $entry_id] 1 + + array unset entry + auth::sync::job::get_entry -entry_id $entry_id -array entry + + aa_log "entry.message = '$entry(message)'" + aa_log "entry.element_messages = '$entry(element_messages)'" + + array unset user + acs_user::get -user_id $entry(user_id) -array user + + foreach varname { username } { + aa_equals "$varname" $user($varname) $ims_doc($varname) + } + aa_equals "member_state" $user(member_state) "banned" + + ##### + # + # Reuse username and email + # + ##### + + # Setup dummy variables + set ims_doc(recstatus) 1 + # same username + set ims_doc(first_names) [ad_generate_random_string] + set ims_doc(last_name) [ad_generate_random_string] + # same email + set ims_doc(url) "http://www.[ad_generate_random_string].com" + + set job_id [auth::authority::batch_sync -authority_id $authority_id] + + auth::sync::job::get -job_id $job_id -array job + + aa_equals "Number of actions" $job(num_actions) 1 + aa_equals "Number of problems" $job(num_problems) 0 + aa_log "job.message = '$job(message)'" + aa_log "job.document = '$job(document)'" + + set entry_id [auth::sync::job::get_entries -job_id $job_id] + aa_equals "One entry" [llength $entry_id] 1 + + array unset entry + auth::sync::job::get_entry -entry_id $entry_id -array entry + + aa_log "entry.message = '$entry(message)'" + aa_log "entry.element_messages = '$entry(element_messages)'" + + array unset user + acs_user::get -user_id $entry(user_id) -array user + foreach varname { username first_names last_name email url } { + aa_equals "$varname" $user($varname) $ims_doc($varname) + } + aa_equals "authority_id" $user(authority_id) $authority_id + aa_false "member_state not banned" [string equal $user(member_state) "banned"] + + # Check that first_user_id has had username/email changed + } +} + + + +aa_register_case job_batch_reuse_username_email { + Test that we can reuse the username and email of deleted users. +} { + # TODO! +}