_acs-authentication__sync_batch_ims_test (private)

 _acs-authentication__sync_batch_ims_test

Defined in packages/acs-authentication/tcl/test/sync-test-procs.tcl

Partial Call Graph (max 5 caller/called nodes):
%3 aa_equals aa_equals (public) aa_false aa_false (public) aa_log aa_log (public) aa_log_result aa_log_result (public) aa_run_with_teardown aa_run_with_teardown (public) _acs-authentication__sync_batch_ims_test _acs-authentication__sync_batch_ims_test _acs-authentication__sync_batch_ims_test->aa_equals _acs-authentication__sync_batch_ims_test->aa_false _acs-authentication__sync_batch_ims_test->aa_log _acs-authentication__sync_batch_ims_test->aa_log_result _acs-authentication__sync_batch_ims_test->aa_run_with_teardown

Testcases:
No testcase defined.
Source code:
        
        set _aa_export {}
        set body_count 1
        foreach testcase_body {{
    aa_stub acs_sc::invoke {

        if { $contract eq "auth_sync_retrieve" && $operation eq "GetDocument" } {
            array set result {
                doc_status ok
                doc_message {}
                document {}
            }

            global ims_doc

            set result(document) "<enterprise>
  <person recstatus=\"$ims_doc(recstatus)\">
    <sourcedid>
      <id>$ims_doc(username)</id>
    </sourcedid>
    <name>
      <fn>$ims_doc(first_names) $ims_doc(last_name)</fn>
      <n>
        <given>$ims_doc(first_names)</given>
        <family>$ims_doc(last_name)</family>
      </n>
    </name>
    <email>$ims_doc(email)</email>
    <url>$ims_doc(url)</url>
  </person>
</enterprise>"

            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 {}
                batch_sync_enabled_p f
            }

            set new_auth(process_doc_impl_id) [acs_sc::impl::get_id -owner "acs-authentication" -name "IMS_Enterprise_v_1p1"]
            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
            #
            #####

            aa_log "--- Insert test ---"

            # 1 = insert operation
            set ims_doc(recstatus) 1

            # dummy user variables
            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)'"

            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)'"

            set user [acs_user::get -user_id $entry(user_id)]

            foreach varname { username first_names last_name email url } {
                aa_equals "$varname" [dict get $user $varname$ims_doc($varname)
            }
            aa_equals "authority_id" [dict get $user authority_id] $authority_id
            aa_false "member_state not banned" {[dict get $user member_state] eq "banned"}
            # saving this for later
            set first_user_id $entry(user_id)


            #####
            #
            # Update
            #
            #####

            aa_log "--- Update test ---"

            # 2 = update operation
            set ims_doc(recstatus) 2

            # dummy user variables
            # 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)'"

            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)'"

            set user [acs_user::get -user_id $entry(user_id)]

            foreach varname { username first_names last_name email url } {
                aa_equals "$varname" [dict get $user $varname$ims_doc($varname)
            }
            aa_false "member_state not banned" {[dict get $user member_state] eq "banned"}

            #####
            #
            # Delete
            #
            #####

            aa_log "--- Delete test ---"

            # 3 = delete operation
            set ims_doc(recstatus) 3

            # user variables stay the same, we are deleting

            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)'"

            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)'"
            aa_log "entry.user_id = '$entry(user_id)'"

            set user_info [acs_user::get_user_info -user_id $entry(user_id)]
            aa_equals "username"     [dict get $user_info username]     $ims_doc(username)
            aa_equals "member_state" [dict get $user_info member_state] "banned"

            #####
            #
            # Reuse username and email. This should fail, as we don't
            # allow 'stealing' usernames from banned users.
            #
            #####

            aa_log "--- Reuse username/email of a deleted user test ---"

            # 1 = insert operation
            set ims_doc(recstatus) 1

            # attributes of the previously deletes user
            set old_doc [array get ims_doc]

            # dummy user variables
            # 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

            # operation has failed because user exists already
            aa_equals "Number of actions" $job(num_actions) 1
            aa_equals "Number of problems" $job(num_problems) 1
            aa_log "job.message = '$job(message)'"

            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)'"
            aa_log "entry.user_id = '$entry(user_id)'"

            # all attributes remained the same
            set user [acs_user::get -user_id $entry(user_id)]
            foreach varname { username email first_names last_name url } {
                aa_true "$varname" {[dict get $user $varname] eq [dict get $old_doc $varname]}
            }
            aa_equals "authority_id" [dict get $user authority_id] $authority_id
            # previously deleted user keeps being banned
            aa_true "member_state is still banned" {[dict get $user member_state] eq "banned"}

            # Check that first_user_id has had username/email changed

            #####
            #
            # Test GetElements
            #
            #####

            aa_log "--- GetElements test ---"

            set desired_elements [ad_generate_random_string]

            auth::driver::set_parameter_value  -authority_id $authority_id  -impl_id [acs_sc::impl::get_id -owner "acs-authentication" -name "IMS_Enterprise_v_1p1"]  -parameter Elements  -value $desired_elements

            set elements [auth::sync::GetElements -authority_id $authority_id]

            aa_equals "Elements are '$desired_elements'" $elements $desired_elements

        }
}} {
          aa_log "Running testcase body $body_count"
          set ::__aa_test_indent [info level]
          set catch_val [catch $testcase_body msg]
          if {$catch_val != 0 && $catch_val != 2} {
              aa_log_result "fail" "sync_batch_ims_test (body $body_count): Error during execution: $msg, stack trace: \n$::errorInfo"
          }
          incr body_count
        }
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: