Changeset 146728 for trunk/base


Ignore:
Timestamp:
Mar 16, 2016, 9:20:02 AM (4 years ago)
Author:
cal@…
Message:

port1.0/tests: Do not req. root for activate_start

The activate_start test needs root privileges if we don't mock the
elevateToRoot function. Let's mock the function to avoid this requirement. The
same work should be continued for the currently failing activate_main test.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/base/src/port1.0/tests/portactivate.test

    r118559 r146728  
    2020
    2121
    22 test activate_start {
    23     Activate start unit test.
    24     Requires root for setting euid.
    25 } -constraints {
    26     root
    27 } -setup {
     22set activate_start_fixture_setup {
     23    global prefix
     24
     25    set _save_prefix ${prefix}
     26    file mkdir ${pwd}/tmpdir
     27    set prefix ${pwd}/tmpdir
     28
     29    rename getuid _save_getuid
     30    rename geteuid _save_geteuid
     31
     32    set fake_uid 0
     33    set fake_euid 0
     34    set elevateToRootCalls [list]
     35
     36    proc getuid {} {
     37        global fake_uid
     38        return ${fake_uid}
     39    }
     40    proc geteuid {} {
     41        global fake_euid
     42        return ${fake_euid}
     43    }
     44
     45    proc elevateToRoot {phase} {
     46        global elevateToRootCalls
     47        lappend elevateToRootCalls $phase
     48    }
     49}
     50set activate_start_fixture_cleanup {
     51    rename getuid ""
     52    rename geteuid ""
     53
     54    rename _save_getuid getuid
     55    rename _save_geteuid geteuid
     56
     57    file delete -force ${pwd}/tmpdir
     58}
     59
     60test activate_start_elevate {
     61    Test portactivate::activate_start to make sure it elevates to root if necessary
     62} -setup $activate_start_fixture_setup -cleanup $activate_start_fixture_cleanup -body {
    2863    # file writable $prefix is used to determine whether privilege escalation
    2964    # is needed, so set prefix to a directory unwritable for this user
    3065    set prefix /usr/bin
     66    set fake_uid 0
     67    set fake_euid 500
    3168
    32     # elevateToRoot uses $euid and $egid as the IDs to set
    33     set euid 0
    34     set egid 0
     69    portactivate::activate_start
    3570
    36 } -body {
    37     # drop privileges; the code won't attempt to elevate privileges without
    38     # that
    39     seteuid 333
    40     if {[catch {portactivate::activate_start args}] != 0} {
    41         return "FAIL: couldn't elevate privileges"
    42     }
     71    return ${elevateToRootCalls}
     72} -result [list "activate"] -errorOutput ""
    4373
    44     # when uid == 0 and euid == 0, the code will not attempt to elevate
    45     # privileges
    46     seteuid 0
    47     if {[catch {portactivate::activate_start args}] != 0} {
    48         return "FAIL: couldn't elevate privileges"
    49     }
    50     return "Activate_start successful."
    51 } -result "Activate_start successful."
     74test activate_start_noelevate {
     75    Test portactivate::activate_start to make sure that it does not elevate to root if it cannot
     76} -setup $activate_start_fixture_setup -cleanup $activate_start_fixture_cleanup -body {
     77    set fake_uid 500
     78    set fake_euid 500
     79
     80    portactivate::activate_start
     81
     82    return ${elevateToRootCalls}
     83} -result [list] -errorOutput ""
    5284
    5385
     
    101133
    102134    mportclose $mport
    103 } -result "Port activate successful."
     135} -result "Port activate successful." -errorOutput ""
    104136
    105137
Note: See TracChangeset for help on using the changeset viewer.