Klaus Demo ~jonashaag/klaus / 3fd1a0c
Cleanup tests Jonas Haag 7 years ago
1 changed file(s) with 58 addition(s) and 44 deletion(s). Raw diff Collapse all Expand all
5454 with testserver():
5555 assert can_reach_site_unauthorized()
5656 assert can_reach_site_authorized()
57 assert_cannot_clone()
57
58 assert not can_clone_unauthorized()
59 assert not can_clone_authorized()
60
5861 assert not can_push_unauthorized()
5962 assert not can_push_authorized()
6063
6669 testserver(use_smarthttp=True, htdigest_file=open(HTDIGEST_FILE), disable_push=True)
6770 ]:
6871 with server:
72 assert can_reach_site_unauthorized()
73 assert can_reach_site_authorized()
74
6975 assert can_clone_unauthorized()
76 assert can_clone_authorized()
77
7078 assert not can_push_unauthorized()
7179 assert not can_push_authorized()
7280
7381
7482 def test_smarthttp_push_no_require_browser_auth():
7583 with testserver(use_smarthttp=True, htdigest_file=open(HTDIGEST_FILE)):
84 assert can_reach_site_unauthorized()
85 assert can_reach_site_authorized()
86
7687 assert can_clone_unauthorized()
88 assert can_clone_authorized()
89
7790 assert not can_push_unauthorized()
7891 assert can_push_authorized()
7992
8295 with testserver_require_auth():
8396 assert not can_reach_site_unauthorized()
8497 assert can_reach_site_authorized()
98
8599 assert not can_clone_unauthorized()
86100 assert not can_clone_authorized()
101
87102 assert not can_push_unauthorized()
88103 assert not can_push_authorized()
89104
90105
91106 def test_smarthttp_require_browser_auth():
92107 with testserver_require_auth(use_smarthttp=True, disable_push=True):
108 assert not can_reach_site_unauthorized()
109 assert can_reach_site_authorized()
110
93111 assert not can_clone_unauthorized()
94112 assert can_clone_authorized()
113
95114 assert not can_push_unauthorized()
96115 assert not can_push_authorized()
97116
98117
99118 def test_smarthttp_push_require_browser_auth():
100119 with testserver_require_auth(use_smarthttp=True):
120 assert not can_reach_site_unauthorized()
121 assert can_reach_site_authorized()
122
101123 assert not can_clone_unauthorized()
102124 assert can_clone_authorized()
125
103126 assert not can_push_unauthorized()
104127 assert can_push_authorized()
105
106
107 def assert_cannot_clone():
108 assert "git clone" not in GET_unauthorized(TEST_REPO_URL).content
109 assert 404 == GET_unauthorized(TEST_REPO_URL + "info/refs?service=git-upload-pack").status_code
110 assert 128 == subprocess.call(["git", "clone", AUTHORIZED_TEST_REPO_URL])
111
112
113 def assert_cannot_push_authorized(expected_status):
114 assert expected_status == GET_authorized(TEST_REPO_URL + "info/refs?service=git-receive-pack").status_code
115 assert expected_status == GET_authorized(TEST_REPO_URL + "git-receive-pack").status_code
116 assert 128 == subprocess.call(["git", "push", AUTHORIZED_TEST_REPO_URL, "master"], cwd=TEST_REPO)
117
118
119 def assert_cannot_push_unauthorized(expected_status):
120 assert expected_status == GET_unauthorized(TEST_REPO_URL + "info/refs?service=git-receive-pack").status_code
121 assert expected_status == GET_unauthorized(TEST_REPO_URL + "git-receive-pack").status_code
122 # XXX 'git push' asks for a new username/password and blocks
123 # assert 128 == subprocess.call(["git", "push", UNAUTHORIZED_TEST_REPO_URL, "master"], cwd=TEST_REPO)
124
125
126 # Clone
127 def can_clone_unauthorized():
128 tmp = tempfile.mkdtemp()
129 try:
130 return subprocess.call(["git", "clone", UNAUTHORIZED_TEST_REPO_URL, tmp]) == 0
131 finally:
132 shutil.rmtree(tmp, ignore_errors=True)
133
134 def can_clone_authorized():
135 tmp = tempfile.mkdtemp()
136 try:
137 return subprocess.call(["git", "clone", AUTHORIZED_TEST_REPO_URL, tmp]) == 0
138 finally:
139 shutil.rmtree(tmp, ignore_errors=True)
140
141
142 # Push
143 def can_push_unauthorized():
144 return subprocess.call(["git", "push", UNAUTHORIZED_TEST_REPO_URL, "master"], cwd=TEST_REPO) == 0
145
146 def can_push_authorized():
147 return subprocess.call(["git", "push", AUTHORIZED_TEST_REPO_URL, "master"], cwd=TEST_REPO) == 0
148128
149129
150130 # Reach
153133
154134 def can_reach_site_authorized():
155135 return GET_authorized(TEST_REPO_URL).status_code == 200
136
137
138 # Clone
139 def can_clone_unauthorized():
140 return _can_clone(GET_unauthorized, UNAUTHORIZED_TEST_REPO_URL)
141
142 def can_clone_authorized():
143 return _can_clone(GET_authorized, AUTHORIZED_TEST_REPO_URL)
144
145 def _can_clone(get, url):
146 tmp = tempfile.mkdtemp()
147 try:
148 return any([
149 "git clone" in get(TEST_REPO_URL).content,
150 get(TEST_REPO_URL + "info/refs?service=git-upload-pack").status_code == 200,
151 subprocess.call(["git", "clone", url, tmp]) == 0,
152 ])
153 finally:
154 shutil.rmtree(tmp, ignore_errors=True)
155
156
157 # Push
158 def can_push_unauthorized():
159 return _can_push(GET_unauthorized, UNAUTHORIZED_TEST_REPO_URL)
160
161 def can_push_authorized():
162 return _can_push(GET_authorized, AUTHORIZED_TEST_REPO_URL)
163
164 def _can_push(get, url):
165 return any([
166 get(TEST_REPO_URL + "info/refs?service=git-receive-pack").status_code == 200,
167 get(TEST_REPO_URL + "git-receive-pack").status_code == 200,
168 subprocess.call(["git", "push", url, "master"], cwd=TEST_REPO) == 0,
169 ])