changeset 36536:74c033b9d579

test-acl: mock up util.getuser() to trust $LOGNAME on Windows The test relies on POSIX-like getuser() behavior, so we can't use windows.getuser().
author Yuya Nishihara <yuya@tcha.org>
date Tue, 27 Feb 2018 22:37:57 +0900
parents db33c5bc781f
children 165cf86365ff
files tests/test-acl.t
diffstat 1 files changed, 27 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/tests/test-acl.t	Thu Mar 01 04:50:22 2018 -0500
+++ b/tests/test-acl.t	Tue Feb 27 22:37:57 2018 +0900
@@ -21,6 +21,15 @@
   >     echo
   > }
 
+  > cat > posixgetuser.py <<'EOF'
+  > import getpass
+  > from mercurial import pycompat, util
+  > def posixgetuser():
+  >     return pycompat.fsencode(getpass.getuser())
+  > if not pycompat.isposix:
+  >     util.getuser = posixgetuser  # forcibly trust $LOGNAME
+  > EOF
+
   > init_config()
   > {
   >     cat > fakegroups.py <<EOF
@@ -41,6 +50,7 @@
   > sources = push
   > [extensions]
   > f=`pwd`/fakegroups.py
+  > posixgetuser=$TESTTMP/posixgetuser.py
   > EOF
   > }
 
@@ -72,6 +82,10 @@
   3 files updated, 0 files merged, 0 files removed, 0 files unresolved
 
   $ config=b/.hg/hgrc
+  $ cat >> "$config" <<EOF
+  > [extensions]
+  > posixgetuser=$TESTTMP/posixgetuser.py
+  > EOF
 
 Extension disabled for lack of a hook
 
@@ -1126,6 +1140,7 @@
   [acl]
   sources = push
   [extensions]
+  posixgetuser=$TESTTMP/posixgetuser.py
   [acl.allow]
   ** = fred
   """
@@ -1206,6 +1221,7 @@
   [acl]
   sources = push
   [extensions]
+  posixgetuser=$TESTTMP/posixgetuser.py
   [acl.allow]
   ** = fred
   [acl.deny]
@@ -1287,6 +1303,7 @@
   [acl]
   sources = push
   [extensions]
+  posixgetuser=$TESTTMP/posixgetuser.py
   [acl.allow]
   ** = @group1
   """
@@ -1368,6 +1385,7 @@
   [acl]
   sources = push
   [extensions]
+  posixgetuser=$TESTTMP/posixgetuser.py
   [acl.allow]
   ** = @group1
   [acl.deny]
@@ -1491,6 +1509,7 @@
   [acl]
   sources = push
   [extensions]
+  posixgetuser=$TESTTMP/posixgetuser.py
   """
   pushing to ../b
   query 1; heads
@@ -1573,6 +1592,7 @@
   [acl]
   sources = push
   [extensions]
+  posixgetuser=$TESTTMP/posixgetuser.py
   [acl.deny.branches]
   foobar = *
   """
@@ -1651,6 +1671,7 @@
   [acl]
   sources = push
   [extensions]
+  posixgetuser=$TESTTMP/posixgetuser.py
   [acl.allow.branches]
   """
   pushing to ../b
@@ -1723,6 +1744,7 @@
   [acl]
   sources = push
   [extensions]
+  posixgetuser=$TESTTMP/posixgetuser.py
   [acl.allow.branches]
   * = george
   """
@@ -1790,6 +1812,7 @@
   [acl]
   sources = push
   [extensions]
+  posixgetuser=$TESTTMP/posixgetuser.py
   [acl.allow.branches]
   * = george
   """
@@ -1878,6 +1901,7 @@
   [acl]
   sources = push
   [extensions]
+  posixgetuser=$TESTTMP/posixgetuser.py
   [acl.allow.branches]
   foobar = astro
   * = george
@@ -1965,6 +1989,7 @@
   [acl]
   sources = push
   [extensions]
+  posixgetuser=$TESTTMP/posixgetuser.py
   [acl.deny.branches]
   foobar = astro
   default = astro
@@ -2039,6 +2064,7 @@
   [acl]
   sources = push
   [extensions]
+  posixgetuser=$TESTTMP/posixgetuser.py
   [acl.deny.branches]
   default = !astro
   """
@@ -2121,6 +2147,7 @@
   [acl]
   sources = push
   [extensions]
+  posixgetuser=$TESTTMP/posixgetuser.py
   [acl.deny.branches]
   default = !astro
   """