summaryrefslogtreecommitdiff
path: root/subversion/tests/cmdline/redirect_tests.py
blob: 3262c1ba901c557a66a8b8f8aa8095d7163ab4d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#!/usr/bin/env python
#
#  redirect_tests.py:  Test ra_dav handling of server-side redirects
#
#  Subversion is a tool for revision control.
#  See http://subversion.apache.org for more information.
#
# ====================================================================
#    Licensed to the Apache Software Foundation (ASF) under one
#    or more contributor license agreements.  See the NOTICE file
#    distributed with this work for additional information
#    regarding copyright ownership.  The ASF licenses this file
#    to you under the Apache License, Version 2.0 (the
#    "License"); you may not use this file except in compliance
#    with the License.  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing,
#    software distributed under the License is distributed on an
#    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
#    KIND, either express or implied.  See the License for the
#    specific language governing permissions and limitations
#    under the License.
######################################################################

# General modules
import os, re

# Our testing module
import svntest

# (abbreviations)
Skip = svntest.testcase.Skip_deco
SkipUnless = svntest.testcase.SkipUnless_deco
XFail = svntest.testcase.XFail_deco
Issues = svntest.testcase.Issues_deco
Issue = svntest.testcase.Issue_deco
Wimp = svntest.testcase.Wimp_deco

# Regular expression which matches the redirection notification
redirect_regex = re.compile(r"^Redirecting to URL '.*'")

# Generic UUID-matching regular expression
uuid_regex = re.compile(r"[a-fA-F0-9]{8}(-[a-fA-F0-9]{4}){3}-[a-fA-F0-9]{12}")


def verify_url(wc_path, url, wc_path_is_file=False):
  # check that we have a Repository Root and Repository UUID
  name = os.path.basename(wc_path)
  expected = {'Path' : re.escape(wc_path),
              'URL' : url,
              'Repository Root' : '.*',
              'Revision' : '.*',
              'Node Kind' : 'directory',
              'Repository UUID' : uuid_regex,
             }
  if wc_path_is_file:
    expected.update({'Name' : name,
                     'Node Kind' : 'file',
                     })
  svntest.actions.run_and_verify_info([expected], wc_path)


######################################################################
# Tests
#
#   Each test must return on success or raise on failure.

#----------------------------------------------------------------------
@SkipUnless(svntest.main.is_ra_type_dav)
def temporary_redirect(sbox):
  "temporary redirect should error out"

  sbox.build(create_wc=False)
  wc_dir = sbox.add_wc_path("my")
  co_url = sbox.redirected_root_url(temporary=True)

  # Try various actions against the repository, expecting an error
  # that indicates that some relocation has occurred.
  exit_code, out, err = svntest.main.run_svn('.*moved temporarily.*',
                                             'info', co_url)
  exit_code, out, err = svntest.main.run_svn('.*moved temporarily.*',
                                             'co', co_url, wc_dir)
  exit_code, out, err = svntest.main.run_svn('.*moved temporarily.*',
                                             'mkdir', '-m', 'MKDIR',
                                             co_url + '/newdir')
  exit_code, out, err = svntest.main.run_svn('.*moved temporarily.*',
                                             'delete', '-m', 'DELETE',
                                             co_url + '/iota')

#----------------------------------------------------------------------
@SkipUnless(svntest.main.is_ra_type_dav)
def redirected_checkout(sbox):
  "redirected checkout"

  sbox.build(create_wc=False)
  wc_dir = sbox.add_wc_path("my")
  co_url = sbox.redirected_root_url()

  # Checkout the working copy via its redirect URL
  exit_code, out, err = svntest.main.run_svn(None, 'co', co_url, wc_dir)
  if err:
    raise svntest.Failure
  if not redirect_regex.match(out[0]):
    raise svntest.Failure

  # Verify that we have the expected URL.
  verify_url(wc_dir, sbox.repo_url)

#----------------------------------------------------------------------
@SkipUnless(svntest.main.is_ra_type_dav)
def redirected_update(sbox):
  "redirected update"

  sbox.build()
  wc_dir = sbox.wc_dir
  relocate_url = sbox.redirected_root_url()

  # Relocate (by cheating) the working copy to the redirect URL.  When
  # we then update, we'll expect to find ourselves automagically back
  # to the original URL.  (This is because we can't easily introduce a
  # redirect to the Apache configuration from the test suite here.)
  svntest.actions.no_relocate_validation()
  exit_code, out, err = svntest.main.run_svn(None, 'sw', '--relocate',
                                             sbox.repo_url, relocate_url,
                                             wc_dir)
  svntest.actions.do_relocate_validation()

  # Now update the working copy.
  exit_code, out, err = svntest.main.run_svn(None, 'up', wc_dir)
  if err:
    raise svntest.Failure
  if not re.match("^Updating '.*':", out[0]):
    raise svntest.Failure
  if not redirect_regex.match(out[1]):
    raise svntest.Failure

  # Verify that we have the expected URL.
  verify_url(wc_dir, sbox.repo_url)

#----------------------------------------------------------------------
@SkipUnless(svntest.main.is_ra_type_dav)
def redirected_nonroot_update(sbox):
  "redirected update of non-repos-root wc"

  sbox.build(create_wc=False)
  wc_dir = sbox.wc_dir
  checkout_url = sbox.repo_url + '/A'
  relocate_url = sbox.redirected_root_url() + '/A'

  # Checkout a subdir of the repository root.
  exit_code, out, err = svntest.main.run_svn(None, 'co',
                                             checkout_url, wc_dir)
  if err:
    raise svntest.Failure
  
  # Relocate (by cheating) the working copy to the redirect URL.  When
  # we then update, we'll expect to find ourselves automagically back
  # to the original URL.  (This is because we can't easily introduce a
  # redirect to the Apache configuration from the test suite here.)
  svntest.actions.no_relocate_validation()
  exit_code, out, err = svntest.main.run_svn(None, 'sw', '--relocate',
                                             checkout_url, relocate_url,
                                             wc_dir)
  svntest.actions.do_relocate_validation()

  # Now update the working copy.
  exit_code, out, err = svntest.main.run_svn(None, 'up', wc_dir)
  if err:
    raise svntest.Failure
  if not re.match("^Updating '.*':", out[0]):
    raise svntest.Failure
  if not redirect_regex.match(out[1]):
    raise svntest.Failure

  # Verify that we have the expected URL.
  verify_url(wc_dir, checkout_url)

#----------------------------------------------------------------------

########################################################################
# Run the tests

# list all tests here, starting with None:
test_list = [ None,
              temporary_redirect,
              redirected_checkout,
              redirected_update,
              redirected_nonroot_update,
             ]

if __name__ == '__main__':
  svntest.main.run_tests(test_list)
  # NOTREACHED


### End of file.