X Tutup
Skip to content

Commit 3af49a1

Browse files
authored
Revert "integration: move to Python3 (letsencrypt#4313)" (letsencrypt#4323)
This reverts commit 796a7aa. People's tests have been breaking on `docker-compose up` with the following output: ``` ImportError: No module named requests ``` Fixes letsencrypt#4322
1 parent 0d9b48e commit 3af49a1

File tree

13 files changed

+164
-162
lines changed

13 files changed

+164
-162
lines changed

docker-compose.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: '3'
22
services:
33
boulder:
44
# To minimize fetching this should be the same version used below
5-
image: letsencrypt/boulder-tools-go${TRAVIS_GO_VERSION:-1.12}:2019-06-28
5+
image: letsencrypt/boulder-tools-go${TRAVIS_GO_VERSION:-1.12}:2019-04-08
66
environment:
77
FAKE_DNS: 10.77.77.77
88
PKCS11_PROXY_SOCKET: tcp://boulder-hsm:5657
@@ -55,7 +55,7 @@ services:
5555
working_dir: /go/src/github.com/letsencrypt/boulder
5656
bhsm:
5757
# To minimize fetching this should be the same version used above
58-
image: letsencrypt/boulder-tools-go${TRAVIS_GO_VERSION:-1.12}:2019-06-28
58+
image: letsencrypt/boulder-tools-go${TRAVIS_GO_VERSION:-1.12}:2019-04-08
5959
environment:
6060
PKCS11_DAEMON_SOCKET: tcp://0.0.0.0:5657
6161
command: /usr/local/bin/pkcs11-daemon /usr/lib/softhsm/libsofthsm2.so
@@ -77,7 +77,7 @@ services:
7777
logging:
7878
driver: none
7979
netaccess:
80-
image: letsencrypt/boulder-tools-go${TRAVIS_GO_VERSION:-1.12}:2019-06-28
80+
image: letsencrypt/boulder-tools-go${TRAVIS_GO_VERSION:-1.12}:2019-04-08
8181
environment:
8282
GO111MODULE: "on"
8383
GOFLAGS: "-mod=vendor"

test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ if [[ "$RUN" =~ "integration" ]] ; then
110110
args+=("--skip-setup")
111111
fi
112112

113-
source ${CERTBOT_PATH:-/certbot}/${VENV_NAME:-venv3}/bin/activate
113+
source ${CERTBOT_PATH:-/certbot}/${VENV_NAME:-venv}/bin/activate
114114
DIRECTORY=http://boulder:4000/directory \
115-
python3 test/integration-test.py "${args[@]}"
115+
python2 test/integration-test.py "${args[@]}"
116116
fi
117117

118118
# Test that just ./start.py works, which is a proxy for testing that

test/boulder-tools/Dockerfile.tmpl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@ RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH"
99
WORKDIR $GOPATH
1010

1111
ADD build.sh /tmp/build.sh
12-
ADD requirements.txt /tmp/requirements.txt
1312
RUN /tmp/build.sh

test/boulder-tools/build.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ git clone https://github.com/certbot/certbot /certbot
5151
cd /certbot
5252
./letsencrypt-auto --os-packages-only
5353
./tools/venv3.py
54-
source venv3/bin/activate
55-
pip install -r /tmp/requirements.txt
5654
cd -
5755

5856
# Install pkcs11-proxy. Checked out commit was master HEAD at time

test/challtestsrv.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import requests
1+
import urllib2
22
import json
33

44
class ChallTestServer:
@@ -39,14 +39,14 @@ def __init__(self, url=None):
3939
self._baseURL = url
4040

4141
def _postURL(self, url, body):
42-
return requests.post(
42+
return urllib2.urlopen(
4343
url,
44-
data=json.dumps(body)).text
44+
data=json.dumps(body)).read()
4545

4646
def _URL(self, path):
4747
urlPath = self._paths.get(path, None)
4848
if urlPath is None:
49-
raise(Exception("No challenge test server URL path known for {0}".format(path)))
49+
raise Exception("No challenge test server URL path known for {0}".format(path))
5050
return self._baseURL + urlPath
5151

5252
def _clear_request_history(self, host, typ):

test/chisel.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import sys
1515
import threading
1616
import time
17-
import requests
17+
import urllib2
1818

1919
from cryptography import x509
2020
from cryptography.hazmat.backends import default_backend
@@ -73,9 +73,9 @@ def update_email(client, email):
7373
email.
7474
"""
7575
if client is None:
76-
raise(NoClientError("update_email requires a valid acme.Client argument"))
76+
raise NoClientError("update_email requires a valid acme.Client argument")
7777
if email is None:
78-
raise(EmailRequiredError("update_email requires an email argument"))
78+
raise EmailRequiredError("update_email requires an email argument")
7979
if not email.startswith("mailto:"):
8080
email = "mailto:"+ email
8181
acct = client.account
@@ -86,7 +86,7 @@ def get_chall(authz, typ):
8686
for chall_body in authz.body.challenges:
8787
if isinstance(chall_body.chall, typ):
8888
return chall_body
89-
raise(Exception("No %s challenge found" % typ))
89+
raise Exception("No %s challenge found" % typ)
9090

9191
class ValidationError(Exception):
9292
"""An error that occurs during challenge validation."""
@@ -110,9 +110,9 @@ def issue(client, authzs, cert_output=None):
110110
csr = OpenSSL.crypto.X509Req()
111111
csr.add_extensions([
112112
OpenSSL.crypto.X509Extension(
113-
'subjectAltName'.encode(),
113+
'subjectAltName',
114114
critical=False,
115-
value=(', '.join('DNS:' + d for d in domains)).encode()
115+
value=', '.join('DNS:' + d for d in domains).encode()
116116
),
117117
])
118118
csr.set_pubkey(pkey)
@@ -126,21 +126,19 @@ def issue(client, authzs, cert_output=None):
126126
# If we get a PollError, pick the first failed authz and turn it into a more
127127
# useful ValidationError that contains details we can look for in tests.
128128
for authz in error.updated:
129-
r = requests.get(authz.uri)
130-
r.raise_for_status()
131-
updated_authz = r.json()
129+
updated_authz = json.loads(urllib2.urlopen(authz.uri).read())
132130
domain = authz.body.identifier.value,
133131
for c in updated_authz['challenges']:
134132
if 'error' in c:
135133
err = c['error']
136-
raise(ValidationError(domain, err['type'], err['detail']))
134+
raise ValidationError(domain, err['type'], err['detail'])
137135
# If none of the authz's had an error, just re-raise.
138136
raise
139137
if cert_output is not None:
140138
pem = OpenSSL.crypto.dump_certificate(OpenSSL.crypto.FILETYPE_PEM,
141139
cert_resource.body)
142140
with open(cert_output, 'w') as f:
143-
f.write(pem.decode())
141+
f.write(pem)
144142
return cert_resource
145143

146144
def http_01_answer(client, chall_body):
@@ -225,7 +223,7 @@ def auth_and_issue(domains, chall_type="dns-01", email=None, cert_output=None, c
225223
elif chall_type == "tls-alpn-01":
226224
cleanup = do_tlsalpn_challenges(client, authzs)
227225
else:
228-
raise(Exception("invalid challenge type %s" % chall_type))
226+
raise Exception("invalid challenge type %s" % chall_type)
229227

230228
try:
231229
cert_resource = issue(client, authzs, cert_output)
@@ -252,15 +250,15 @@ def expect_problem(problem_type, func):
252250
else:
253251
raise
254252
if not ok:
255-
raise(Exception('Expected %s, got no error' % problem_type))
253+
raise Exception('Expected %s, got no error' % problem_type)
256254

257255
if __name__ == "__main__":
258256
domains = sys.argv[1:]
259257
if len(domains) == 0:
260-
print(__doc__)
258+
print __doc__
261259
sys.exit(0)
262260
try:
263261
auth_and_issue(domains)
264-
except messages.Error as e:
265-
print(e)
262+
except messages.Error, e:
263+
print e
266264
sys.exit(1)

test/chisel2.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import signal
1616
import threading
1717
import time
18+
import urllib2
1819

1920
from cryptography.hazmat.backends import default_backend
2021
from cryptography.hazmat.primitives.asymmetric import rsa
@@ -59,14 +60,14 @@ def make_client(email=None):
5960
client.net.account = client.new_account(messages.NewRegistration.from_data(email=email,
6061
terms_of_service_agreed=True))
6162
else:
62-
raise(Exception("Unrecognized terms of service URL %s" % tos))
63+
raise Exception("Unrecognized terms of service URL %s" % tos)
6364
return client
6465

6566
def get_chall(authz, typ):
6667
for chall_body in authz.body.challenges:
6768
if isinstance(chall_body.chall, typ):
6869
return chall_body
69-
raise(Exception("No %s challenge found" % typ.typ))
70+
raise Exception("No %s challenge found" % typ.typ)
7071

7172
def make_csr(domains):
7273
key = OpenSSL.crypto.PKey()
@@ -99,7 +100,7 @@ def auth_and_issue(domains, chall_type="dns-01", email=None, cert_output=None, c
99100
elif chall_type == "tls-alpn-01":
100101
cleanup = do_tlsalpn_challenges(client, authzs)
101102
else:
102-
raise(Exception("invalid challenge type %s" % chall_type))
103+
raise Exception("invalid challenge type %s" % chall_type)
103104

104105
try:
105106
order = client.poll_and_finalize(order)
@@ -171,27 +172,27 @@ def expect_problem(problem_type, func):
171172
if e.typ == problem_type:
172173
ok = True
173174
else:
174-
raise(Exception("Expected %s, got %s" % (problem_type, error.__str__())))
175+
raise Exception("Expected %s, got %s" % (problem_type, error.__str__()))
175176
except acme_errors.ValidationError as e:
176177
for authzr in e.failed_authzrs:
177178
for chall in authzr.body.challenges:
178179
error = chall.error
179180
if error and error.typ == problem_type:
180181
ok = True
181182
elif error:
182-
raise(Exception("Expected %s, got %s" % (problem_type, error.__str__())))
183+
raise Exception("Expected %s, got %s" % (problem_type, error.__str__()))
183184
if not ok:
184-
raise(Exception('Expected %s, got no error' % problem_type))
185+
raise Exception('Expected %s, got no error' % problem_type)
185186

186187
if __name__ == "__main__":
187188
# Die on SIGINT
188189
signal.signal(signal.SIGINT, signal.SIG_DFL)
189190
domains = sys.argv[1:]
190191
if len(domains) == 0:
191-
print(__doc__)
192+
print __doc__
192193
sys.exit(0)
193194
try:
194195
auth_and_issue(domains)
195-
except messages.Error as e:
196-
print(e)
196+
except messages.Error, e:
197+
print e
197198
sys.exit(1)

test/helpers.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
#!/usr/bin/env python2.7
12
import base64
23
import os
3-
import urllib
4+
import urllib2
45
import time
56
import re
67
import random
78
import json
8-
import requests
99
import socket
1010
import tempfile
1111
import shutil
@@ -38,20 +38,20 @@ def random_domain():
3838
return "rand.%x.xyz" % random.randrange(2**32)
3939

4040
def run(cmd, **kwargs):
41-
return subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, **kwargs).decode()
41+
return subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, **kwargs)
4242

4343
def fetch_ocsp(request_bytes, url):
4444
"""Fetch an OCSP response using POST, GET, and GET with URL encoding.
4545
4646
Returns a tuple of the responses.
4747
"""
48-
ocsp_req_b64 = base64.b64encode(request_bytes).decode()
48+
ocsp_req_b64 = base64.b64encode(request_bytes)
4949

5050
# Make the OCSP request three different ways: by POST, by GET, and by GET with
5151
# URL-encoded parameters. All three should have an identical response.
52-
get_response = requests.get("%s/%s" % (url, ocsp_req_b64)).content
53-
get_encoded_response = requests.get("%s/%s" % (url, urllib.parse.quote(ocsp_req_b64, safe = ""))).content
54-
post_response = requests.post("%s/" % (url), data=request_bytes).content
52+
get_response = urllib2.urlopen("%s/%s" % (url, ocsp_req_b64)).read()
53+
get_encoded_response = urllib2.urlopen("%s/%s" % (url, urllib2.quote(ocsp_req_b64, safe = ""))).read()
54+
post_response = urllib2.urlopen("%s/" % (url), request_bytes).read()
5555

5656
return (post_response, get_response, get_encoded_response)
5757

@@ -61,13 +61,13 @@ def make_ocsp_req(cert_file, issuer_file):
6161
# First generate the OCSP request in DER form
6262
run("openssl ocsp -no_nonce -issuer %s -cert %s -reqout %s" % (
6363
issuer_file, cert_file, ocsp_req_file))
64-
with open(ocsp_req_file, mode='rb') as f:
64+
with open(ocsp_req_file) as f:
6565
ocsp_req = f.read()
6666
return ocsp_req
6767

6868
def ocsp_verify(cert_file, issuer_file, ocsp_response):
6969
ocsp_resp_file = os.path.join(tempdir, "ocsp.resp")
70-
with open(ocsp_resp_file, "wb") as f:
70+
with open(ocsp_resp_file, "w") as f:
7171
f.write(ocsp_response)
7272
output = run("openssl ocsp -no_nonce -issuer %s -cert %s \
7373
-verify_other %s -CAfile test/test-root.pem \
@@ -76,8 +76,8 @@ def ocsp_verify(cert_file, issuer_file, ocsp_response):
7676
# also look for the string "Response Verify Failure"
7777
verify_failure = "Response Verify Failure"
7878
if re.search(verify_failure, output):
79-
print(output)
80-
raise(Exception("OCSP verify failure"))
79+
print output
80+
raise Exception("OCSP verify failure")
8181
return output
8282

8383
def verify_ocsp(cert_file, issuer_file, url, status):
@@ -87,28 +87,28 @@ def verify_ocsp(cert_file, issuer_file, url, status):
8787
# Verify all responses are the same
8888
for resp in responses:
8989
if resp != responses[0]:
90-
raise(Exception("OCSP responses differed: %s vs %s" %(
91-
base64.b64encode(responses[0]), base64.b64encode(resp))))
90+
raise Exception("OCSP responses differed: %s vs %s" %(
91+
base64.b64encode(responses[0]), base64.b64encode(resp)))
9292

9393
# Check response is for the correct certificate and is correct
9494
# status
9595
resp = responses[0]
9696
verify_output = ocsp_verify(cert_file, issuer_file, resp)
9797
if not re.search("%s: %s" % (cert_file, status), verify_output):
98-
print(verify_output)
99-
raise(Exception("OCSP response wasn't '%s'" % status))
98+
print verify_output
99+
raise Exception("OCSP response wasn't '%s'" % status)
100100

101101
def reset_akamai_purges():
102-
requests.post("http://localhost:6789/debug/reset-purges", data="{}")
102+
urllib2.urlopen("http://localhost:6789/debug/reset-purges", "{}")
103103

104104
def verify_akamai_purge():
105105
deadline = time.time() + 0.25
106106
while True:
107107
time.sleep(0.05)
108108
if time.time() > deadline:
109-
raise(Exception("Timed out waiting for Akamai purge"))
110-
response = requests.get("http://localhost:6789/debug/get-purges")
111-
purgeData = response.json()
109+
raise Exception("Timed out waiting for Akamai purge")
110+
response = urllib2.urlopen("http://localhost:6789/debug/get-purges")
111+
purgeData = json.load(response)
112112
if len(purgeData["V3"]) is not 1:
113113
continue
114114
break
@@ -142,7 +142,7 @@ def waitport(port, prog, perTickCheck=None):
142142
return True
143143
except socket.error as e:
144144
if e.errno == errno.ECONNREFUSED:
145-
print("Waiting for debug port %d (%s)" % (port, prog))
145+
print "Waiting for debug port %d (%s)" % (port, prog)
146146
else:
147147
raise
148-
raise(Exception("timed out waiting for debug port %d (%s)" % (port, prog)))
148+
raise Exception("timed out waiting for debug port %d (%s)" % (port, prog))

0 commit comments

Comments
 (0)
X Tutup