0 | 0 |
import os
|
|
1 |
import re
|
1 | 2 |
import subprocess
|
2 | 3 |
import tempfile
|
3 | 4 |
import shutil
|
|
33 | 34 |
def options_test(make_app_args, expected_permissions):
|
34 | 35 |
def test():
|
35 | 36 |
with serve(**make_app_args):
|
36 | |
for action, permitted in expected_permissions.items():
|
37 | |
if action.endswith('auth'):
|
38 | |
actions = [action]
|
|
37 |
for check, permitted in expected_permissions.items():
|
|
38 |
if check in globals():
|
|
39 |
checks = [check]
|
|
40 |
elif check.endswith('auth'):
|
|
41 |
checks = ['can_%s' % check]
|
39 | 42 |
else:
|
40 | |
actions = [action + '_unauth', action + '_auth']
|
41 | |
for action in actions:
|
42 | |
funcname = 'can_%s' % action
|
43 | |
assert globals()[funcname]() == permitted
|
|
43 |
checks = ['can_%s_unauth' % check, 'can_%s_auth' % check]
|
|
44 |
for check in checks:
|
|
45 |
assert globals()[check]() == permitted
|
44 | 46 |
return test
|
45 | 47 |
|
46 | 48 |
|
|
71 | 73 |
test_smart_auth_disable_push = options_test(
|
72 | 74 |
{'require_browser_auth': True, 'use_smarthttp': True, 'disable_push': True, 'htdigest_file': open(HTDIGEST_FILE)},
|
73 | 75 |
{'reach_auth': True, 'reach_unauth': False, 'clone_auth': True, 'clone_unauth': False, 'push': False}
|
|
76 |
)
|
|
77 |
|
|
78 |
test_ctags_disabled = options_test(
|
|
79 |
{},
|
|
80 |
{'ctags_tags_and_branches': False, 'ctags_all': False}
|
|
81 |
)
|
|
82 |
test_ctags_tags_and_branches = options_test(
|
|
83 |
{'ctags_policy': 'tags-and-branches'},
|
|
84 |
{'ctags_tags_and_branches': True, 'ctags_all': False}
|
|
85 |
)
|
|
86 |
test_ctags_all = options_test(
|
|
87 |
{'ctags_policy': 'ALL'},
|
|
88 |
{'ctags_tags_and_branches': True, 'ctags_all': True}
|
74 | 89 |
)
|
75 | 90 |
|
76 | 91 |
|
|
116 | 131 |
])
|
117 | 132 |
|
118 | 133 |
|
|
134 |
# Ctags
|
|
135 |
def ctags_tags_and_branches():
|
|
136 |
return all(
|
|
137 |
_ctags_enabled(ref, f)
|
|
138 |
for ref in ["master", "tag1"] for f in ["test.c", "test.js"]
|
|
139 |
)
|
|
140 |
|
|
141 |
|
|
142 |
def ctags_all():
|
|
143 |
all_refs = re.findall('href=".+/commit/([a-z0-9]{40})/">',
|
|
144 |
requests.get(UNAUTH_TEST_REPO_URL).content)
|
|
145 |
assert len(all_refs) == 3
|
|
146 |
return all(
|
|
147 |
_ctags_enabled(ref, f)
|
|
148 |
for ref in all_refs for f in ["test.c", "test.js"]
|
|
149 |
)
|
|
150 |
|
|
151 |
def _ctags_enabled(ref, filename):
|
|
152 |
response = requests.get(UNAUTH_TEST_REPO_URL + "blob/%s/%s" % (ref, filename))
|
|
153 |
href = '<a href="/%sblob/%s/%s#L-1">' % (TEST_REPO_URL, ref, filename)
|
|
154 |
return href in response.content
|
|
155 |
|
|
156 |
|
119 | 157 |
def _GET_unauth(url=""):
|
120 | 158 |
return requests.get(UNAUTH_TEST_SERVER + url, auth=requests.auth.HTTPDigestAuth("invalid", "password"))
|
121 | 159 |
|