tests/test-acl
branchstable
changeset 12795 3cb0559e44d0
parent 12793 469850088fc1
parent 12794 6bf8d48bec8e
child 12796 bc69ba99e34b
equal deleted inserted replaced
12793:469850088fc1 12795:3cb0559e44d0
     1 #!/bin/sh
       
     2 
       
     3 do_push()
       
     4 {
       
     5     user=$1
       
     6     shift
       
     7 
       
     8     echo "Pushing as user $user"
       
     9     echo 'hgrc = """'
       
    10     sed -e 1,2d b/.hg/hgrc | grep -v fakegroups.py
       
    11     echo '"""'
       
    12     if test -f acl.config; then
       
    13 	echo 'acl.config = """'
       
    14 	cat acl.config
       
    15 	echo '"""'
       
    16     fi
       
    17     # On AIX /etc/profile sets LOGNAME read-only. So
       
    18     #  LOGNAME=$user hg --cws a --debug push ../b
       
    19     # fails with "This variable is read only."
       
    20     # Use env to work around this.
       
    21     env LOGNAME=$user hg --cwd a --debug push ../b
       
    22     hg --cwd b rollback
       
    23     hg --cwd b --quiet tip
       
    24     echo
       
    25 }
       
    26 
       
    27 init_config()
       
    28 {
       
    29 cat > fakegroups.py <<EOF
       
    30 from hgext import acl
       
    31 def fakegetusers(ui, group):
       
    32     try:
       
    33         return acl._getusersorig(ui, group)
       
    34     except:
       
    35         return ["fred", "betty"]
       
    36 acl._getusersorig = acl._getusers
       
    37 acl._getusers = fakegetusers
       
    38 EOF
       
    39 
       
    40 rm -f acl.config
       
    41 cat > $config <<EOF
       
    42 [hooks]
       
    43 pretxnchangegroup.acl = python:hgext.acl.hook
       
    44 [acl]
       
    45 sources = push
       
    46 [extensions]
       
    47 f=`pwd`/fakegroups.py
       
    48 EOF
       
    49 }
       
    50 
       
    51 hg init a
       
    52 cd a
       
    53 mkdir foo foo/Bar quux
       
    54 echo 'in foo' > foo/file.txt
       
    55 echo 'in foo/Bar' > foo/Bar/file.txt
       
    56 echo 'in quux' > quux/file.py
       
    57 hg add -q
       
    58 hg ci -m 'add files' -d '1000000 0'
       
    59 echo >> foo/file.txt
       
    60 hg ci -m 'change foo/file' -d '1000001 0'
       
    61 echo >> foo/Bar/file.txt
       
    62 hg ci -m 'change foo/Bar/file' -d '1000002 0'
       
    63 echo >> quux/file.py
       
    64 hg ci -m 'change quux/file' -d '1000003 0'
       
    65 hg tip --quiet
       
    66 
       
    67 cd ..
       
    68 hg clone -r 0 a b
       
    69 
       
    70 echo '[extensions]' >> $HGRCPATH
       
    71 echo 'acl =' >> $HGRCPATH
       
    72 
       
    73 config=b/.hg/hgrc
       
    74 
       
    75 echo
       
    76 
       
    77 echo 'Extension disabled for lack of a hook'
       
    78 do_push fred
       
    79 
       
    80 echo '[hooks]' >> $config
       
    81 echo 'pretxnchangegroup.acl = python:hgext.acl.hook' >> $config
       
    82 
       
    83 echo 'Extension disabled for lack of acl.sources'
       
    84 do_push fred
       
    85 
       
    86 echo 'No [acl.allow]/[acl.deny]'
       
    87 echo '[acl]' >> $config
       
    88 echo 'sources = push' >> $config
       
    89 do_push fred
       
    90 
       
    91 echo 'Empty [acl.allow]'
       
    92 echo '[acl.allow]' >> $config
       
    93 do_push fred
       
    94 
       
    95 echo 'fred is allowed inside foo/'
       
    96 echo 'foo/** = fred' >> $config
       
    97 do_push fred
       
    98 
       
    99 echo 'Empty [acl.deny]'
       
   100 echo '[acl.deny]' >> $config
       
   101 do_push barney
       
   102 
       
   103 echo 'fred is allowed inside foo/, but not foo/bar/ (case matters)'
       
   104 echo 'foo/bar/** = fred' >> $config
       
   105 do_push fred
       
   106 
       
   107 echo 'fred is allowed inside foo/, but not foo/Bar/'
       
   108 echo 'foo/Bar/** = fred' >> $config
       
   109 do_push fred
       
   110 
       
   111 echo 'barney is not mentioned => not allowed anywhere'
       
   112 do_push barney
       
   113 
       
   114 echo 'barney is allowed everywhere'
       
   115 echo '[acl.allow]' >> $config
       
   116 echo '** = barney' >> $config
       
   117 do_push barney
       
   118 
       
   119 echo 'wilma can change files with a .txt extension'
       
   120 echo '**/*.txt = wilma' >> $config
       
   121 do_push wilma
       
   122 
       
   123 echo 'file specified by acl.config does not exist'
       
   124 echo '[acl]' >> $config
       
   125 echo 'config = ../acl.config' >> $config
       
   126 do_push barney
       
   127 
       
   128 echo 'betty is allowed inside foo/ by a acl.config file'
       
   129 echo '[acl.allow]' >> acl.config
       
   130 echo 'foo/** = betty' >> acl.config
       
   131 do_push betty
       
   132 
       
   133 echo 'acl.config can set only [acl.allow]/[acl.deny]'
       
   134 echo '[hooks]' >> acl.config
       
   135 echo 'changegroup.acl = false' >> acl.config
       
   136 do_push barney
       
   137 
       
   138 # asterisk
       
   139 
       
   140 init_config
       
   141 
       
   142 echo 'asterisk test'
       
   143 echo '[acl.allow]' >> $config
       
   144 echo "** = fred" >> $config
       
   145 echo "fred is always allowed"
       
   146 do_push fred
       
   147 
       
   148 echo '[acl.deny]' >> $config
       
   149 echo "foo/Bar/** = *" >> $config
       
   150 echo "no one is allowed inside foo/Bar/"
       
   151 do_push fred
       
   152 
       
   153 # Groups
       
   154 
       
   155 init_config
       
   156 
       
   157 echo 'OS-level groups'
       
   158 echo '[acl.allow]' >> $config
       
   159 echo "** = @group1" >> $config
       
   160 echo "@group1 is always allowed"
       
   161 do_push fred
       
   162 
       
   163 echo '[acl.deny]' >> $config
       
   164 echo "foo/Bar/** = @group1" >> $config
       
   165 echo "@group is allowed inside anything but foo/Bar/"
       
   166 do_push fred
       
   167 
       
   168 echo 'Invalid group'
       
   169 # Disable the fakegroups trick to get real failures
       
   170 grep -v fakegroups $config > config.tmp
       
   171 mv config.tmp $config
       
   172 echo '[acl.allow]' >> $config
       
   173 echo "** = @unlikelytoexist" >> $config
       
   174 do_push fred 2>&1 | grep unlikelytoexist
       
   175 
       
   176 true