[146728] trunk/base/src/port1.0/tests/portactivate.test
cal at macports.org
cal at macports.org
Wed Mar 16 02:20:02 PDT 2016
Revision: 146728
https://trac.macports.org/changeset/146728
Author: cal at macports.org
Date: 2016-03-16 02:20:02 -0700 (Wed, 16 Mar 2016)
Log 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.
Modified Paths:
--------------
trunk/base/src/port1.0/tests/portactivate.test
Modified: trunk/base/src/port1.0/tests/portactivate.test
===================================================================
--- trunk/base/src/port1.0/tests/portactivate.test 2016-03-16 07:48:43 UTC (rev 146727)
+++ trunk/base/src/port1.0/tests/portactivate.test 2016-03-16 09:20:02 UTC (rev 146728)
@@ -19,38 +19,70 @@
macports_worker_init
-test activate_start {
- Activate start unit test.
- Requires root for setting euid.
-} -constraints {
- root
-} -setup {
+set activate_start_fixture_setup {
+ global prefix
+
+ set _save_prefix ${prefix}
+ file mkdir ${pwd}/tmpdir
+ set prefix ${pwd}/tmpdir
+
+ rename getuid _save_getuid
+ rename geteuid _save_geteuid
+
+ set fake_uid 0
+ set fake_euid 0
+ set elevateToRootCalls [list]
+
+ proc getuid {} {
+ global fake_uid
+ return ${fake_uid}
+ }
+ proc geteuid {} {
+ global fake_euid
+ return ${fake_euid}
+ }
+
+ proc elevateToRoot {phase} {
+ global elevateToRootCalls
+ lappend elevateToRootCalls $phase
+ }
+}
+set activate_start_fixture_cleanup {
+ rename getuid ""
+ rename geteuid ""
+
+ rename _save_getuid getuid
+ rename _save_geteuid geteuid
+
+ file delete -force ${pwd}/tmpdir
+}
+
+test activate_start_elevate {
+ Test portactivate::activate_start to make sure it elevates to root if necessary
+} -setup $activate_start_fixture_setup -cleanup $activate_start_fixture_cleanup -body {
# file writable $prefix is used to determine whether privilege escalation
# is needed, so set prefix to a directory unwritable for this user
set prefix /usr/bin
+ set fake_uid 0
+ set fake_euid 500
- # elevateToRoot uses $euid and $egid as the IDs to set
- set euid 0
- set egid 0
+ portactivate::activate_start
-} -body {
- # drop privileges; the code won't attempt to elevate privileges without
- # that
- seteuid 333
- if {[catch {portactivate::activate_start args}] != 0} {
- return "FAIL: couldn't elevate privileges"
- }
+ return ${elevateToRootCalls}
+} -result [list "activate"] -errorOutput ""
- # when uid == 0 and euid == 0, the code will not attempt to elevate
- # privileges
- seteuid 0
- if {[catch {portactivate::activate_start args}] != 0} {
- return "FAIL: couldn't elevate privileges"
- }
- return "Activate_start successful."
-} -result "Activate_start successful."
+test activate_start_noelevate {
+ Test portactivate::activate_start to make sure that it does not elevate to root if it cannot
+} -setup $activate_start_fixture_setup -cleanup $activate_start_fixture_cleanup -body {
+ set fake_uid 500
+ set fake_euid 500
+ portactivate::activate_start
+ return ${elevateToRootCalls}
+} -result [list] -errorOutput ""
+
+
test activate_main {
Activate main unit test.
} -constraints {
@@ -100,7 +132,7 @@
array set macports::channels $oldchannels
mportclose $mport
-} -result "Port activate successful."
+} -result "Port activate successful." -errorOutput ""
cleanupTests
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/macports-changes/attachments/20160316/486d37f6/attachment.html>
More information about the macports-changes
mailing list