Patchwork test-acl: mock up util.getuser() to trust $LOGNAME on Windows

login
register
mail settings
Submitter Yuya Nishihara
Date Feb. 27, 2018, 2:57 p.m.
Message ID <27a69d7c94488b6a21ce.1519743445@mimosa>
Download mbox | patch
Permalink /patch/28467/
State Accepted
Headers show

Comments

Yuya Nishihara - Feb. 27, 2018, 2:57 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1519738677 -32400
#      Tue Feb 27 22:37:57 2018 +0900
# Node ID 27a69d7c94488b6a21ce4ddbcdb183ce335714e1
# Parent  1a1f7b96d833af5a29d6d75580d083511ff388f6
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().
Matt Harbison - Feb. 28, 2018, 2:50 a.m.
On Tue, 27 Feb 2018 09:57:25 -0500, Yuya Nishihara <yuya@tcha.org> wrote:

> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1519738677 -32400
> #      Tue Feb 27 22:37:57 2018 +0900
> # Node ID 27a69d7c94488b6a21ce4ddbcdb183ce335714e1
> # Parent  1a1f7b96d833af5a29d6d75580d083511ff388f6
> test-acl: mock up util.getuser() to trust $LOGNAME on Windows

Works for me, thanks.
Augie Fackler - March 1, 2018, 7:17 p.m.
On Tue, Feb 27, 2018 at 11:57:25PM +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1519738677 -32400
> #      Tue Feb 27 22:37:57 2018 +0900
> # Node ID 27a69d7c94488b6a21ce4ddbcdb183ce335714e1
> # Parent  1a1f7b96d833af5a29d6d75580d083511ff388f6
> test-acl: mock up util.getuser() to trust $LOGNAME on Windows

queued, thanks

Patch

diff --git a/tests/test-acl.t b/tests/test-acl.t
--- a/tests/test-acl.t
+++ b/tests/test-acl.t
@@ -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 @@  fred is always allowed
   [acl]
   sources = push
   [extensions]
+  posixgetuser=$TESTTMP/posixgetuser.py
   [acl.allow]
   ** = fred
   """
@@ -1206,6 +1221,7 @@  no one is allowed inside foo/Bar/
   [acl]
   sources = push
   [extensions]
+  posixgetuser=$TESTTMP/posixgetuser.py
   [acl.allow]
   ** = fred
   [acl.deny]
@@ -1287,6 +1303,7 @@  OS-level groups
   [acl]
   sources = push
   [extensions]
+  posixgetuser=$TESTTMP/posixgetuser.py
   [acl.allow]
   ** = @group1
   """
@@ -1368,6 +1385,7 @@  OS-level groups
   [acl]
   sources = push
   [extensions]
+  posixgetuser=$TESTTMP/posixgetuser.py
   [acl.allow]
   ** = @group1
   [acl.deny]
@@ -1491,6 +1509,7 @@  No branch acls specified
   [acl]
   sources = push
   [extensions]
+  posixgetuser=$TESTTMP/posixgetuser.py
   """
   pushing to ../b
   query 1; heads
@@ -1573,6 +1592,7 @@  Branch acl deny test
   [acl]
   sources = push
   [extensions]
+  posixgetuser=$TESTTMP/posixgetuser.py
   [acl.deny.branches]
   foobar = *
   """
@@ -1651,6 +1671,7 @@  Branch acl empty allow test
   [acl]
   sources = push
   [extensions]
+  posixgetuser=$TESTTMP/posixgetuser.py
   [acl.allow.branches]
   """
   pushing to ../b
@@ -1723,6 +1744,7 @@  Branch acl allow other
   [acl]
   sources = push
   [extensions]
+  posixgetuser=$TESTTMP/posixgetuser.py
   [acl.allow.branches]
   * = george
   """
@@ -1790,6 +1812,7 @@  Branch acl allow other
   [acl]
   sources = push
   [extensions]
+  posixgetuser=$TESTTMP/posixgetuser.py
   [acl.allow.branches]
   * = george
   """
@@ -1878,6 +1901,7 @@  push foobar into the remote
   [acl]
   sources = push
   [extensions]
+  posixgetuser=$TESTTMP/posixgetuser.py
   [acl.allow.branches]
   foobar = astro
   * = george
@@ -1965,6 +1989,7 @@  Branch acl conflicting deny
   [acl]
   sources = push
   [extensions]
+  posixgetuser=$TESTTMP/posixgetuser.py
   [acl.deny.branches]
   foobar = astro
   default = astro
@@ -2039,6 +2064,7 @@  User 'astro' must not be denied
   [acl]
   sources = push
   [extensions]
+  posixgetuser=$TESTTMP/posixgetuser.py
   [acl.deny.branches]
   default = !astro
   """
@@ -2121,6 +2147,7 @@  Non-astro users must be denied
   [acl]
   sources = push
   [extensions]
+  posixgetuser=$TESTTMP/posixgetuser.py
   [acl.deny.branches]
   default = !astro
   """