_acs-tcl__ad_page_contract_filters (private)

 _acs-tcl__ad_page_contract_filters

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

Partial Call Graph (max 5 caller/called nodes):
%3 aa_false aa_false (public) aa_log aa_log (public) aa_log_result aa_log_result (public) aa_section aa_section (public) aa_true aa_true (public) _acs-tcl__ad_page_contract_filters _acs-tcl__ad_page_contract_filters _acs-tcl__ad_page_contract_filters->aa_false _acs-tcl__ad_page_contract_filters->aa_log _acs-tcl__ad_page_contract_filters->aa_log_result _acs-tcl__ad_page_contract_filters->aa_section _acs-tcl__ad_page_contract_filters->aa_true

Testcases:
No testcase defined.
Source code:
        
        set _aa_export {}
        set body_count 1
        foreach testcase_body {{
        aa_section {Filters without format spec}

        dict set cases integer { "1" 1 "a" 0 "1.2" 0 "'" 0 }
        dict set cases naturalnum { "1" 1 0 1 "-1" 0 "a" 0 "1.2" 0 "'" 0 }
        dict set cases float { "1" 1 "1.0" 1 "a" 0 "-1.0" 1 "1,0" 0 }
        dict set cases negative_float { "1" 1 "-1.0" 1 "-a" 0 "-1,0" 0 }
        dict set cases object_id {
            "1" 1 "a" 0 "1.2" 0 "'" 0 -1 1 "0x0" 0
            "-2147483648" 1 "2147483647" 1 "-2147483649" 0 "2147483648" 0
        }
        dict set cases boolean {
            "1" 1 "-1" 0 "a" 0 "0" 1 "true" 1 "f" 1 "TRUE" 1 "ok" 0 "nok" 0
        }

        dict set cases word {red 1 " " 0 "hello_world" 1 {$a} 0 a1 1 <p> 0 "a.b" 0 "-flag" 0 "1,2" 0 "r: -1" 0}
        dict set cases token {red 1 " " 1 "hello_world" 1 {$a} 0 a1 1 <p> 0 "a.b" 1 "-flag" 1 "1,2" 1 "r: -1" 1}
        dict set cases safetclchars {red 1 " " 1 "hello world" 1 {$a} 0 a1 1 <p> 1 "a.b" 1 "-flag" 1 "1,2" 1 "r: -1" 1 {a[b]c} 0 x\\y 0}

        dict set cases sql_identifier  {red 1 " " 0 "hello_world" 1 {$a} 0 a1 1 <p> 0 "a.b" 0 "-flag" 0 "1,2" 0 "r: -1" 0}
        dict set cases email { {philip@mit.edu} 1 {Philip Greenspun <philip@mit.edu>} 0 }
        dict set cases localurl { . 1 ./index 1 https://o-p-e-n-a-c-s.org/ 0 }

        dict set cases html { "'" 1 "<p>" 1 }
        dict set cases nohtml { "a" 1 "<p>" 0 }
        dict set cases allhtml { "a" 1 "<p>" 1 "<script>alert('ciao');</script>" 1}

        dict set cases printable { "a" 1 "a b" 1 "a\x00b" 0 "name\xc0\x80.jpg" 0}

        dict set cases date {
            {day 1 month 1 year 2010} 1
            {day 60 month 1 year 2010} 0
            {day 31 month 11 year 2010} 0
            {day 30 month 11 year <evil>} 0
            {day "" month "" year ""} 1
        }

        dict set cases time {
            {ampm am time 00:00:00} 0
            {ampm am time 01:00:00} 1
            {ampm pm time 01:00:00} 1
            {ampm stuff time 01:00:00} 0
            {ampm "" time 01:00:00} 0
            {ampm am time 13:00:00} 0
            {ampm am time 12:67:00} 0
            {ampm am time 12:00:100} 0
        }

        dict set cases time24 {
            {time 00:00:00} 1
            {time 01:00:00} 1
            {time 13:00:00} 1
            {time 12:67:00} 0
            {time 12:00:100} 0
            {time 24:00:00} 0
            {time 23:59:59} 1
            {time 23:61:59} 0
        }

        dict set cases path {
            $path 0
            \\root\path 0
            ../test/path 1
            /my-test/path 1
            ?wheremypath? 0
        }

        close [ad_opentmpfile tmpfilename]
        dict set cases tmpfile [list  $tmpfilename 1  /etc/passwd 0  /home/nsadmin/somefile.txt 0  bogusstring 0]

        dict set cases phone {
            "(800) 888-8888" 1
            "800-888-8888" 1
            "800.888.8888" 1
            "8008888888" 1
            "(800) 888-8888 extension 405" 1
            "(800) 888-8888abcd" 1
            "" 1
            "1-800-888-8888" 0
            "10-10-220 800.888.8888" 0
            "abcd(800) 888-8888" 0
        }

        foreach filter [dict keys $cases] {
            foreach { value result } [dict get $cases $filter] {
                if {[regexp {[^[:print:]]} $value]} {
                    #
                    # Use ns_urlencode to avoid error messages, when
                    # invalid strings are added to the DB. We should
                    # probably export NaviServer's
                    # DStringAppendPrintable for such cases.
                    #
                    set print_value [ns_urlencode $value]
                } else {
                    set print_value $value
                }
                if {$filter in {"date" "time" "time24"}} {
                    #
                    # This filter passes an array
                    #
                    array set value_array $value
                    if { $result } {
                        aa_true "'[ns_quotehtml $print_value]' is $filter"  [ad_page_contract_filter_invoke $filter dummy value_array]
                    } else {
                        aa_false "'[ns_quotehtml $print_value]' is NOT $filter"  [ad_page_contract_filter_invoke $filter dummy value_array]
                    }
                    unset value_array
                } else {
                    if { $result } {
                        aa_true "'[ns_quotehtml $print_value]' is $filter"  [ad_page_contract_filter_invoke $filter dummy value]
                    } else {
                        aa_false "'[ns_quotehtml $print_value]' is NOT $filter"  [ad_page_contract_filter_invoke $filter dummy value]
                    }
                }
            }
        }

        set cases {}

        aa_section {Filters with format spec}

        dict set cases clock {
             1234 "%s" 1
             2022-01-01 "%s" 0
             2022-01-01 "%Y-%m-%d" 1
             2022-01-01 {"%Y-%m-%d" "%s"} 1
        }

        dict set cases object_type [list  9999999999999999999999 acs_object 0  [db_string q {select min(object_id) from acs_objects}] acs_object 1  [db_string q {select min(object_id) from acs_objects where object_type <> 'user'}] user 0  [db_string q {select min(object_id) from acs_objects where object_type = 'user'}] user 1  [db_string q {select min(object_id) from acs_objects where object_type <> 'user'}] {user acs_object} 1  [db_string q {select min(object_id) - 1 from acs_objects}] {user acs_object} 0  ]

        dict set cases oneof {
             1234 {1234 5} 1
             2022-01-01 {1234 6} 0
             "apple" {"banana" "mango" "apple"} 1
        }

        dict set cases range {
            1 {-1 10} 1
            1 {-2 0} 0
            0001 {-1000 10000} 1
            42 {0 1} 0
        }

        dict set cases string_length {
            abcd {max 2} 0
            abcd {min 2} 1
            abcd {max 6} 1
            a {min 2} 0
        }

        dict set cases string_length_range {
            abcd {0 2} 0
            abcd {2 100} 1
            abcd {0 6} 1
            a {2 5} 0
        }

        foreach filter [dict keys $cases] {
            foreach { value formats result } [dict get $cases $filter] {
                if {[regexp {[^[:print:]]} $value]} {
                    #
                    # Use ns_urlencode to avoid error messages, when
                    # invalid strings are added to the DB. We should
                    # probably export NaviServer's
                    # DStringAppendPrintable for such cases.
                    #
                    set print_value [ns_urlencode $value]
                } else {
                    set print_value $value
                }
                if { $result } {
                    aa_true "'[ns_quotehtml $print_value]' is $filter ($formats)"  [ad_page_contract_filter_invoke $filter dummy value [list $formats]]
                } else {
                    aa_false "'[ns_quotehtml $print_value]' is NOT $filter ($formats)"  [ad_page_contract_filter_invoke $filter dummy value [list $formats]]
                }
            }
        }

    }} {
          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" "ad_page_contract_filters (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: