Skip to content

Commit 6b3c06a

Browse files
committed
test(protocol): Introduce account management test
Refs: #141
1 parent e08593e commit 6b3c06a

File tree

2 files changed

+53
-9
lines changed

2 files changed

+53
-9
lines changed

automatoes/protocol.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ def get_registration(self, account: Account):
131131
"""
132132
headers = {'Content-Type': "application/jose+json"}
133133
response = self.post_as_get(account.uri, headers=headers,
134-
kid=self.account.uri,
135-
key=account.key, uri=account.uri)
134+
kid=account.uri, key=account.key,
135+
uri=account.uri)
136136
if str(response.status_code).startswith("2"):
137137
return _json(response)
138138
raise AcmeError(response)
@@ -154,8 +154,8 @@ def new_account(self, account: Account, contacts: list,
154154
}
155155
headers = {'Content-Type': "application/jose+json"}
156156
path = self.peasant.directory()['newAccount']
157-
response = self.post_as_get(path, data=payload, headers=headers,
158-
key=account.key, uri=path)
157+
response = self.post(path, data=payload, headers=headers,
158+
key=account.key, uri=path)
159159

160160
uri = response.headers.get("Location")
161161

@@ -172,11 +172,11 @@ def new_account(self, account: Account, contacts: list,
172172
raise AcmeError(response)
173173

174174
def terms_from_directory(self):
175-
response = self.get_directory()
176-
if response.status_code == 200:
177-
if "meta" in response.json():
178-
if "termsOfService" in response.json()['meta']:
179-
return response.json()['meta']['termsOfService']
175+
# TODO: Check how to trigger an error here
176+
directory = self.peasant.directory()
177+
if "meta" in directory:
178+
if "termsOfService" in directory['meta']:
179+
return directory['meta']['termsOfService']
180180
return None
181181

182182

tests/account_management_test.py

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Copyright 2019-2025 Flavio Garcia
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from automatoes.crypto import generate_rsa_key
16+
from automatoes.model import Account
17+
from cartola import security
18+
from tests import get_protocol, get_transport, PEEBLE_URL
19+
from tornado import testing
20+
21+
22+
class AccountTestCase(testing.AsyncTestCase):
23+
""" Test letsencrypt nonce
24+
"""
25+
26+
@testing.gen_test
27+
async def test_new_acount(self):
28+
protocol = get_protocol(get_transport())
29+
contact = "candango_{}_{}@candango.org".format(
30+
security.random_string(5, False, False),
31+
security.random_string(5, False, False)
32+
)
33+
# To check against the get_registration method after
34+
# TODO: check against more than one emails in the contacts
35+
peeble_term = ("data:text/plain,Do%20what%20thou%20wilt")
36+
account = Account(key=generate_rsa_key(4096))
37+
response = protocol.new_account(account, [contact], True)
38+
self.assertEqual(peeble_term, response.terms)
39+
self.assertEqual("valid", response.contents['status'])
40+
account.uri = response.uri
41+
self.assertEqual(PEEBLE_URL, "/".join(response.uri.split("/")[0:3]))
42+
self.assertEqual("my-account", "/".join(response.uri.split("/")[3:4]))
43+
self.assertIsInstance(response.uri.split("/")[4:5][0], str)
44+
protocol.get_registration(account)

0 commit comments

Comments
 (0)