You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by br...@apache.org on 2013/01/26 00:22:21 UTC

svn commit: r1438760 - /subversion/trunk/subversion/tests/cmdline/svnauthz_tests.py

Author: breser
Date: Fri Jan 25 23:22:21 2013
New Revision: 1438760

URL: http://svn.apache.org/viewvc?rev=1438760&view=rev
Log:
Split up the svnauthz tests more so file tests always run.

* subversion/tests/cmdline/svnauthz_tests.py
  (svnauthz_validate_test): Split into ...
  (svnauthz_validate_file_test, svnauthz_validate_repo_test): these new
    functions.
  (svnauthz_accessof_test): Split into ...
  (svnauthz_accessof_file_test, svnauthz_accessof_repo_test): these new
    functions.
  (svnauthz_accessof_is_test): Split into ...
  (svnauthz_accessof_is_file_test, svnauthz_accessof_is_repo_test): these new
    functions.
  (svnauthz_compat_mode_test): Split into ...
  (svnauthz_compat_mode_file_test, svnauthz_compat_mode_repo_test): these new
    functions.
  (test_list): Adjust for the function changes.
    

Modified:
    subversion/trunk/subversion/tests/cmdline/svnauthz_tests.py

Modified: subversion/trunk/subversion/tests/cmdline/svnauthz_tests.py
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/cmdline/svnauthz_tests.py?rev=1438760&r1=1438759&r2=1438760&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/cmdline/svnauthz_tests.py (original)
+++ subversion/trunk/subversion/tests/cmdline/svnauthz_tests.py Fri Jan 25 23:22:21 2013
@@ -83,9 +83,36 @@ def verify_logfile(logfilename, expected
 # the library tests for the config file parser and the authz
 # parser already validate various failures that return errors.
 
+def svnauthz_validate_file_test(sbox):
+  "test 'svnauthz validate' on files"
+
+  # build an authz file
+  (authz_fd, authz_path) = tempfile.mkstemp()
+  authz_content = "[/]\n* = rw\n"
+  svntest.main.file_write(authz_path, authz_content)
+  
+  # Valid authz file
+  svntest.actions.run_and_verify_svnauthz("Valid authz file", None, None,
+                                          0, False, "validate", authz_path)
+
+  # Invalid authz file, expect exit code 1, we found the file loaded it
+  # but found an error
+  svntest.main.file_write(authz_path, 'x\n')
+  svntest.actions.run_and_verify_svnauthz("Invalid authz file", None, None,
+                                          1, False, "validate", authz_path)
+
+  # Non-existant authz file
+  # exit code 2, operational error since we can't test the file.
+  os.close(authz_fd)
+  os.remove(authz_path)
+  svntest.actions.run_and_verify_svnauthz("Non-existant authz file", None,
+                                          None, 2, False, "validate",
+                                          authz_path)
+
 @SkipUnless(svntest.main.is_ra_type_file)
-def svnauthz_validate_test(sbox):
-  "test 'svnauthz validate' on files and urls"
+def svnauthz_validate_repo_test(sbox):
+  "test 'svnauthz validate' on urls"
+
   sbox.build()
   wc_dir = sbox.wc_dir
   repo_url = sbox.repo_url
@@ -105,33 +132,17 @@ def svnauthz_validate_test(sbox):
                                            expected_status, None, wc_dir):
     raise svntest.Failure
 
-  # Valid authz file (use the wc copy to validate the file)
-  svntest.actions.run_and_verify_svnauthz("Valid authz file", None, None,
-                                          0, False, "validate", authz_path)
-
   # Valid authz url (file stored in repo)
   authz_url = repo_url + '/A/authz'
   svntest.actions.run_and_verify_svnauthz("Valid authz url", None, None,
                                           0, False, "validate", authz_url)
 
-  # Invalid authz file (use the already existing iota file from greek tree)
-  # exit code 1, we found the file loaded it but found an error
-  iota_path = os.path.join(wc_dir, 'iota')
-  svntest.actions.run_and_verify_svnauthz("Invalid authz file", None, None,
-                                          1, False, "validate", iota_path)
-
   # Invalid authz url (again use the iota file in the repo)
-  # exit code 1, we found the file loaded it but found an error
+  # expect exit code 1, we found the file loaded it but found an error
   iota_url = repo_url + '/iota'
   svntest.actions.run_and_verify_svnauthz("Invalid authz url", None, None,
                                           1, False, "validate", iota_url)
 
-  # Non-existant authz file
-  # exit code 2, operational error since we can't test the file.
-  svntest.actions.run_and_verify_svnauthz("Non-existant authz file", None,
-                                          None, 2, False, "validate",
-                                          os.path.join(wc_dir, "zilch"))
-
   # Non-existant authz url
   # TODO: This should be exit code 2 but svnauthz is misbehaving and
   # returning 1 for now.
@@ -197,32 +208,16 @@ def svnauthz_validate_txn_test(sbox):
   expected_data = svntest.verify.ExpectedOutput("Exit 2\n", match_all=False)
   verify_logfile(logfilepath, expected_data)
 
+def svnauthz_accessof_file_test(sbox):
+  "test 'svnauthz accessof' on files"
 
-@SkipUnless(svntest.main.is_ra_type_file)
-def svnauthz_accessof_test(sbox):
-  "test 'svnauthz accessof' on files and urls"
-
-  sbox.build()
-  wc_dir = sbox.wc_dir
-  repo_url = sbox.repo_url
-
+  # build an authz file
+  (authz_fd, authz_path) = tempfile.mkstemp()
   authz_content = "[/]\ngroucho = \ngallagher = rw\n* = r\n" + \
       "[/bios]\n* = rw\n" + \
       "[comedy:/jokes]\ngroucho = rw\n" + \
       "[slapstick:/jokes]\n* =\n"
-
-  # build an authz file and commit it to the repo
-  authz_path = os.path.join(wc_dir, 'A', 'authz')
   svntest.main.file_write(authz_path, authz_content)
-  svntest.main.run_svn(None, 'add', authz_path)
-  expected_output = wc.State(wc_dir, {'A/authz' : Item(verb='Adding')})
-  expected_status = svntest.actions.get_virginal_state(wc_dir, 1)
-  expected_status.add({
-    'A/authz'            :  Item(status='  ', wc_rev=2),
-  })
-  if svntest.actions.run_and_verify_commit(wc_dir, expected_output,
-                                           expected_status, None, wc_dir):
-    raise svntest.Failure
 
   # Anonymous access with no path, and no repository should be rw
   # since it returns the highest level of access granted anywhere.
@@ -263,19 +258,12 @@ def svnauthz_accessof_test(sbox):
                                           "--username", "groucho",
                                           "--repository", "comedy")
 
-  # Redo the last test on a URL, we don't redo all the iterations since
-  # all the actual validation is basically the same no matter the source
-  # of the file.
-  authz_url = repo_url + "/A/authz"
-  svntest.actions.run_and_verify_svnauthz("User access on path with repo",
-                                          ["rw\n"], None, 0, False, "accessof",
-                                          authz_url, "--path", "/jokes",
-                                          "--username", "groucho",
-                                          "--repository", "comedy")
+  os.close(authz_fd)
+  os.remove(authz_path)
 
 @SkipUnless(svntest.main.is_ra_type_file)
-def svnauthz_accessof_is_test(sbox):
-  "test 'svnauthz accessof --is' on files and urls"
+def svnauthz_accessof_repo_test(sbox):
+  "test 'svnauthz accessof' on urls"
 
   sbox.build()
   wc_dir = sbox.wc_dir
@@ -299,6 +287,57 @@ def svnauthz_accessof_is_test(sbox):
                                            expected_status, None, wc_dir):
     raise svntest.Failure
 
+  # Anonymous access with no path, and no repository should be rw
+  # since it returns the highest level of access granted anywhere.
+  # So /bios being rw for everyone means this will be rw.
+  authz_url = repo_url + "/A/authz"
+  svntest.actions.run_and_verify_svnauthz("Anonymous access", ["rw\n"], None,
+                                          0, False, "accessof", authz_url)
+
+  # Anonymous access on /jokes should be r, no repo so won't match
+  # the slapstick:/jokes section.
+  svntest.actions.run_and_verify_svnauthz("Anonymous access on path",
+                                          ["r\n"], None, 0, False, "accessof",
+                                          authz_url, "--path", "/jokes")
+
+  # Anonymous access on /jokes on slapstick repo should be no
+  svntest.actions.run_and_verify_svnauthz("Anonymous access on path with repo",
+                                          ["no\n"], None, 0, False, "accessof",
+                                          authz_url, "--path", "/jokes",
+                                          "--repository", "slapstick")
+
+  # User access with no path, and no repository should be rw
+  # since it returns the h ighest level of access anywhere.
+  # So /bios being rw for everyone means this will be rw.
+  svntest.actions.run_and_verify_svnauthz("User access", ["rw\n"], None,
+                                          0, False, "accessof", authz_url,
+                                          "--username", "groucho")
+
+  # User groucho specified on /jokes with no repo, will not match any of the
+  # repo specific sections, so is r since everyone has read access.
+  svntest.actions.run_and_verify_svnauthz("User access on path", ["r\n"], None,
+                                          0, False, "accessof", authz_url,
+                                          "--path", "/jokes", "--username",
+                                          "groucho")
+
+  # User groucho specified on /jokes with the repo comedy will be rw 
+  svntest.actions.run_and_verify_svnauthz("User access on path with repo",
+                                          ["rw\n"], None, 0, False, "accessof",
+                                          authz_url, "--path", "/jokes",
+                                          "--username", "groucho",
+                                          "--repository", "comedy")
+ 
+def svnauthz_accessof_is_file_test(sbox):
+  "test 'svnauthz accessof --is' on files"
+
+  # build an authz file
+  (authz_fd, authz_path) = tempfile.mkstemp()
+  authz_content = "[/]\ngroucho = \ngallagher = rw\n* = r\n" + \
+      "[/bios]\n* = rw\n" + \
+      "[comedy:/jokes]\ngroucho = rw\n" + \
+      "[slapstick:/jokes]\n* =\n"
+  svntest.main.file_write(authz_path, authz_content)
+
   # Test an invalid --is option, should get an error message and exit code
   # of 2.
   expected_output = svntest.verify.RegexOutput(
@@ -424,10 +463,153 @@ def svnauthz_accessof_is_test(sbox):
                                           "--repository", "comedy", "--is",
                                           "no")
 
-  # Redo the last test on a URL, we don't redo all the iterations since
-  # all the actual validation is basically the same no matter the source
-  # of the file.
+  # Add an invalid line to the authz file
+  svntest.main.file_append(authz_path, "x\n")
+  # Check that --is returns 1 when the syntax is invalid with a file..
+  expected_out = svntest.verify.RegexOutput(
+      ".*Error while parsing config file:",
+      match_all=False
+  )
+  svntest.actions.run_and_verify_svnauthz("--is with invalid authz file",
+                                          None, expected_out, 1, False, 
+                                          "accessof", authz_path, "--path",
+                                          "/jokes", "--username", "groucho",
+                                          "--repository", "comedy", "--is",
+                                          "rw")
+
+  os.close(authz_fd)
+  os.remove(authz_path)
+
+@SkipUnless(svntest.main.is_ra_type_file)
+def svnauthz_accessof_is_repo_test(sbox):
+  "test 'svnauthz accessof --is' on files and urls"
+
+  sbox.build()
+  wc_dir = sbox.wc_dir
+  repo_url = sbox.repo_url
+
+  authz_content = "[/]\ngroucho = \ngallagher = rw\n* = r\n" + \
+      "[/bios]\n* = rw\n" + \
+      "[comedy:/jokes]\ngroucho = rw\n" + \
+      "[slapstick:/jokes]\n* =\n"
+
+  # build an authz file and commit it to the repo
+  authz_path = os.path.join(wc_dir, 'A', 'authz')
+  svntest.main.file_write(authz_path, authz_content)
+  svntest.main.run_svn(None, 'add', authz_path)
+  expected_output = wc.State(wc_dir, {'A/authz' : Item(verb='Adding')})
+  expected_status = svntest.actions.get_virginal_state(wc_dir, 1)
+  expected_status.add({
+    'A/authz'            :  Item(status='  ', wc_rev=2),
+  })
+  if svntest.actions.run_and_verify_commit(wc_dir, expected_output,
+                                           expected_status, None, wc_dir):
+    raise svntest.Failure
+
+  # Test an invalid --is option, should get an error message and exit code
+  # of 2.
   authz_url = repo_url + "/A/authz"
+  expected_output = svntest.verify.RegexOutput(
+      ".*'x' is not a valid argument for --is", match_all=False
+  )
+  svntest.actions.run_and_verify_svnauthz("--is x fails", None,
+                                          expected_output, 2, False,
+                                          "accessof", authz_url, "--is", "x")
+
+  # Anonymous access with no path, and no repository should be rw
+  # since it returns the highest level of access granted anywhere.
+  # So /bios being rw for everyone means this will be rw.
+  # Test --is rw returns 0.
+  svntest.actions.run_and_verify_svnauthz("Anonymous access --is rw", None,
+                                          None, 0, False, "accessof",
+                                          authz_url, "--is", "rw")
+  # Test --is r returns 3.
+  svntest.actions.run_and_verify_svnauthz("Anonymous access --is r", None,
+                                          None, 3, False, "accessof",
+                                          authz_url, "--is", "r")
+  # Test --is no returns 3.
+  svntest.actions.run_and_verify_svnauthz("Anonymous access --is no", None,
+                                          None, 3, False, "accessof",
+                                          authz_url, "--is", "no")
+
+  # Anonymous access on /jokes should be r, no repo so won't match
+  # the slapstick:/jokes section.
+  # Test --is r returns 0.
+  svntest.actions.run_and_verify_svnauthz("Anonymous access on path --is r",
+                                          None, None, 0, False, "accessof",
+                                          authz_url, "--path", "/jokes",
+                                          "--is", "r")
+  # Test --is rw returns 3.
+  svntest.actions.run_and_verify_svnauthz("Anonymous access on path --is r",
+                                          None, None, 3, False, "accessof",
+                                          authz_url, "--path", "/jokes",
+                                          "--is", "rw")
+  # Test --is no returns 3.
+  svntest.actions.run_and_verify_svnauthz("Anonymous access on path --is r",
+                                          None, None, 3, False, "accessof",
+                                          authz_url, "--path", "/jokes",
+                                          "--is", "no")
+
+  # Anonymous access on /jokes on slapstick repo should be no
+  # Test --is no returns 0.
+  svntest.actions.run_and_verify_svnauthz("Anon access on path w/ repo --is no",
+                                          None, None, 0, False, "accessof",
+                                          authz_url, "--path", "/jokes",
+                                          "--repository", "slapstick",
+                                          "--is", "no")
+  # Test --is rw returns 3.
+  svntest.actions.run_and_verify_svnauthz("Anon access on path w/ repo --is no",
+                                          None, None, 3, False, "accessof",
+                                          authz_url, "--path", "/jokes",
+                                          "--repository", "slapstick",
+                                          "--is", "rw")
+  # Test --is r returns 3.
+  svntest.actions.run_and_verify_svnauthz("Anon access on path w/ repo --is no",
+                                          None, None, 3, False, "accessof",
+                                          authz_url, "--path", "/jokes",
+                                          "--repository", "slapstick",
+                                          "--is", "r")
+
+  # User access with no path, and no repository should be rw
+  # since it returns the h ighest level of access anywhere.
+  # So /bios being rw for everyone means this will be rw.
+  # Test --is rw returns 0.
+  svntest.actions.run_and_verify_svnauthz("User access --is rw", None, None,
+                                          0, False, "accessof", authz_url,
+                                          "--username", "groucho", "--is",
+                                          "rw")
+  # Test --is r returns 3.
+  svntest.actions.run_and_verify_svnauthz("User access --is r", None, None,
+                                          3, False, "accessof", authz_url,
+                                          "--username", "groucho", "--is",
+                                          "r")
+  # Test --is no returns 3.
+  svntest.actions.run_and_verify_svnauthz("User access --is no", None, None,
+                                          3, False, "accessof", authz_url,
+                                          "--username", "groucho", "--is",
+                                          "no")
+
+  # User groucho specified on /jokes with no repo, will not match any of the
+  # repo specific sections, so is r since everyone has read access.
+  # Test --is r returns 0.
+  svntest.actions.run_and_verify_svnauthz("User access on path --is r", None,
+                                          None, 0, False, "accessof",
+                                          authz_url, "--path", "/jokes",
+                                          "--username", "groucho", "--is", "r")
+  # Test --is rw returns 3.
+  svntest.actions.run_and_verify_svnauthz("User access on path --is rw", None,
+                                          None, 3, False, "accessof",
+                                          authz_url, "--path", "/jokes",
+                                          "--username", "groucho",
+                                          "--is", "rw")
+  # Test --is no returns 3.
+  svntest.actions.run_and_verify_svnauthz("User access on path --is no", None,
+                                          None, 3, False, "accessof",
+                                          authz_url, "--path", "/jokes",
+                                          "--username", "groucho",
+                                          "--is", "no")
+
+  # User groucho specified on /jokes with the repo comedy will be rw 
   # Test --is rw returns 0.
   svntest.actions.run_and_verify_svnauthz("User access on path w/ repo --is rw",
                                           None, None, 0, False, "accessof",
@@ -458,19 +640,11 @@ def svnauthz_accessof_is_test(sbox):
                                            expected_status, None, wc_dir):
     raise svntest.Failure
 
-  # Check that --is returns 1 when the syntax is invalid with a file..
+  # Check that --is returns 1 when the syntax is invalid with a url.
   expected_out = svntest.verify.RegexOutput(
       ".*Error while parsing config file:",
       match_all=False
   )
-  svntest.actions.run_and_verify_svnauthz("--is with invalid authz file",
-                                          None, expected_out, 1, False, 
-                                          "accessof", authz_path, "--path",
-                                          "/jokes", "--username", "groucho",
-                                          "--repository", "comedy", "--is",
-                                          "rw")
-
-  # Check that --is returns 1 when the syntax is invalid with a url.
   svntest.actions.run_and_verify_svnauthz("--is with invalid authz url",
                                           None, expected_out, 1, False,
                                           "accessof", authz_url, "--path",
@@ -547,16 +721,13 @@ def svnauthz_accessof_txn_test(sbox):
   expected_data = svntest.verify.ExpectedOutput('Exit 2\n', match_all=False)
   verify_logfile(logfilepath, expected_data)
 
-@SkipUnless(svntest.main.is_ra_type_file)
-def svnauthz_compat_mode_test(sbox):
-  "test 'svnauthz-validate' compatability mode"
-  sbox.build()
-  wc_dir = sbox.wc_dir
-  repo_url = sbox.repo_url
+def svnauthz_compat_mode_file_test(sbox):
+  "test 'svnauthz-validate' compatability mode file"
+ 
 
   # Create an authz file 
+  (authz_fd, authz_path) = tempfile.mkstemp()
   authz_content = "[/]\n* = rw\n"
-  authz_path = os.path.join(wc_dir, 'A/authz')
   svntest.main.file_write(authz_path, authz_content)
 
   # Check a valid file.
@@ -564,6 +735,37 @@ def svnauthz_compat_mode_test(sbox):
                                           None, None, 0, True,
                                           authz_path)
 
+  # Check an invalid file.
+  svntest.main.file_append(authz_path, "x\n")
+  svntest.actions.run_and_verify_svnauthz("svnauthz-validate on invalid file",
+                                          None, None, 1, True,
+                                          authz_path)
+
+  # Remove the file.
+  os.close(authz_fd)
+  os.remove(authz_path)
+
+  # Check a non-existant file.
+  svntest.actions.run_and_verify_svnauthz(
+      "svnauthz-validate on non-existant file", None, None, 2, True,
+      authz_path
+  )
+
+
+@SkipUnless(svntest.main.is_ra_type_file)
+def svnauthz_compat_mode_repo_test(sbox):
+  "test 'svnauthz-validate' compatability mode url"
+
+  sbox.build()
+  wc_dir = sbox.wc_dir
+  repo_url = sbox.repo_url
+
+  # Create an authz file 
+  authz_content = "[/]\n* = rw\n"
+  authz_path = os.path.join(wc_dir, 'A/authz')
+  svntest.main.file_write(authz_path, authz_content)
+  authz_url = repo_url + '/A/authz'
+
   # Commit the file and check a URL
   svntest.main.run_svn(None, 'add', authz_path)
   expected_output = wc.State(wc_dir, {'A/authz' : Item(verb='Adding')})
@@ -576,18 +778,24 @@ def svnauthz_compat_mode_test(sbox):
     raise svntest.Failure
   svntest.actions.run_and_verify_svnauthz("svnauthz-validate on url",
                                           None, None, 0, True,
-                                          repo_url + '/A/authz')
+                                          authz_url)
 
-  # Check an invalid file.
+  # Check an invalid url.
   svntest.main.file_append(authz_path, "x\n")
+  expected_output = wc.State(wc_dir, {'A/authz' : Item(verb='Sending')})
+  expected_status.tweak('A/authz', status='  ', wc_rev=3)
+  if svntest.actions.run_and_verify_commit(wc_dir, expected_output,
+                                           expected_status, None, wc_dir):
+    raise svntest.Failure
   svntest.actions.run_and_verify_svnauthz("svnauthz-validate on invalid file",
                                           None, None, 1, True,
                                           authz_path)
 
-  # Check a non-existant file.
+  # Check a non-existant url.
+  # TODO: Exit code really should be 2 but it's 1 right now.
   svntest.actions.run_and_verify_svnauthz(
-      "svnauthz-validate on non-existant file", None, None, 2, True,
-      os.path.join(wc_dir, "zlich")
+      "svnauthz-validate on non-existant file", None, None, 1, True,
+      repo_url + "/zilch"
   )
 
 ########################################################################
@@ -596,12 +804,16 @@ def svnauthz_compat_mode_test(sbox):
 
 # list all tests here, starting with None:
 test_list = [ None,
-              svnauthz_validate_test,
+              svnauthz_validate_file_test,
+              svnauthz_validate_repo_test,
               svnauthz_validate_txn_test,
-              svnauthz_accessof_test,
-              svnauthz_accessof_is_test,
+              svnauthz_accessof_file_test,
+              svnauthz_accessof_repo_test,
+              svnauthz_accessof_is_file_test,
+              svnauthz_accessof_is_repo_test,
               svnauthz_accessof_txn_test,
-              svnauthz_compat_mode_test,
+              svnauthz_compat_mode_file_test,
+              svnauthz_compat_mode_repo_test,
              ]
 
 if __name__ == '__main__':