Changeset 107515 for trunk/base/tests


Ignore:
Timestamp:
Jul 2, 2013, 12:22:03 AM (7 years ago)
Author:
cal@…
Message:

trace test: fix to correctly test trace mode

Previously, this test tested privilege separation rather than trace mode,
because the location the Portfiles tried to access was in the trace sandbox.

This test helped uncover a series of problems in trace mode I have fixed
locally and will commit shortly.

Location:
trunk/base/tests/test/trace
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/base/tests/test/trace/Makefile

    r107032 r107515  
    22
    33.PHONY: test
     4
     5PWD=$(shell dirname `pwd`)
    46
    57$(bindir)/port:
     
    911test:
    1012        @PORTSRC=$(PORTSRC) $(bindir)/port clean > /dev/null
    11         @touch delete-trace
    12         @touch rename-trace
    13         @mkdir -p rmdir-trace
    14         @rm -f create-trace
    15         @rm -f create-trace-modenv
    16         @rm -rf mkdir-trace
     13        @mkdir -p ../tracetesttmp
     14        @chown $(RUNUSR) ../tracetesttmp
     15        @sudo -u $(RUNUSR) touch ../tracetesttmp/delete-trace
     16        @sudo -u $(RUNUSR) touch ../tracetesttmp/rename-trace
     17        @sudo -u $(RUNUSR) mkdir -p ../tracetesttmp/rmdir-trace
    1718        @rm -f /tmp/hello-trace
    18         @rm -f link-trace
    19         @ln -s /usr/include/unistd.h /tmp/link-trace2
    20         @-PORTSRC=$(PORTSRC) $(bindir)/port -t test > output 2>&1 || (cat output; exit 1)
    21         @rm -f link-trace
     19        @ln -sf /usr/include/unistd.h /tmp/link-trace2
     20        @chown -h $(RUNUSR) /tmp/link-trace2
     21        @PORTSRC=$(PORTSRC) $(bindir)/port -t test > output 2>&1 || (cat output; exit 1)
    2222        @rm -f /tmp/link-trace2
    23         @rm -f delete-trace
    24         @rm -f rename-trace
    25         @rm -f rename-new-trace
    26         @rm -f create-trace
    27         @rm -f create-trace-modenv
    28         @rm -rf mkdir-trace
    29         @rm -rf rmdir-trace
    3023        @rm -f /tmp/hello-trace
    31         @sed -e "s|${PWD}|PWD|g" < output > output.sed
     24        @rm -rf ../tracetesttmp
     25        @sed -e "s|$(PWD)|PWD|g" < output > output.sed
    3226        @diff -u master output.sed 2>&1 | tee difference
    3327        @if [ -s difference ]; then \
  • trunk/base/tests/test/trace/Portfile

    r79489 r107515  
     1# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
    12# $Id$
    23
    3 PortSystem 1.0
    4 name            trace
    5 version         1
    6 categories      test
    7 maintainers     pguyot@kallisys.net
    8 description     Test port for -t
    9 homepage        http://www.macports.org/
    10 platforms       darwin
     4PortSystem          1.0
     5name                trace
     6version             1
     7categories          test
     8maintainers         pguyot@kallisys.net
     9description         Test port for -t
     10homepage            http://www.macports.org/
     11platforms           darwin
    1112
    12 long_description ${description}
     13long_description    ${description}
    1314
    1415distfiles
    15 use_configure no
    16 build           {}
    17 destroot        {
    18         system "touch ${destroot}${prefix}/lib/${name}"
     16use_configure       no
     17build {}
     18destroot {
     19    system "touch ${destroot}${prefix}/lib/${name}"
    1920}
    2021
    2122test {
    22         catch {system "touch create-trace"}
    23         catch {system "rm delete-trace"}
    24         system "touch /tmp/hello-trace"
    25         system "rm /tmp/hello-trace"
    26         system "ln -s /usr/include/ link-trace"
    27         system "rm /tmp/link-trace2"
    28         catch {system "mkdir mkdir-trace"}
    29         catch {system "rmdir rmdir-trace"}
    30         catch {system "mv rename-trace rename-new-trace"}
    31         catch {system "DYLD_INSERT_LIBRARIES= touch create-trace-modenv"}
    32         system "mkdir -p /usr/bin"
     23    proc fails {operation} {
     24        if {![catch $operation]} {
     25            ui_error "Operation ${operation} succeeded although it should have failed!"
     26            error "test failure"
     27        }
     28    }
     29    # the port directory is outside of the sandbox; make sure files can't be
     30    # created, deleted or symlinked into place here
     31    fails {system "touch ../tracetesttmp/create-trace"}
     32    fails {system "rm ../tracetesttmp/delete-trace"}
     33    fails {system "ln -s /usr/include/ ../tracetesttmp/link-trace"}
     34    # we also don't want mkdir or rmdir here
     35    fails {system "mkdir ../tracetesttmp/mkdir-trace"}
     36    fails {system "rmdir ../tracetesttmp/rmdir-trace"}
     37    # renaming should also be prohibited
     38    fails {system "mv ../tracetesttmp/rename-trace ../tracetesttmp/rename-new-trace"}
     39
     40    # test access to /tmp
     41    system "touch /tmp/hello-trace"
     42    system "rm /tmp/hello-trace"
     43    system "rm /tmp/link-trace2"
     44
     45    # overwriting DYLD_INSERT_LIBRARIES should not allow escaping the sandbox (due to env restoring)
     46    fails {system "DYLD_INSERT_LIBRARIES= touch ../tracetesttmp/create-trace-modenv"}
     47
     48    # if the directories already exist, mkdir -p should succeed.
     49    system "mkdir -p /usr/bin"
    3350}
Note: See TracChangeset for help on using the changeset viewer.