Skip to content

Commit 098ff22

Browse files
authored
Merge pull request #321 from pretendWhale/2.1.1
2.1.1
2 parents 799c5b1 + 49f8840 commit 098ff22

File tree

4 files changed

+27
-20
lines changed

4 files changed

+27
-20
lines changed

Changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# CHANGELOG
22
All notable changes to this project will be documented here.
33

4+
## [v2.1.1]
5+
- Remove the requirement for clients to send unique user name (#318)
6+
47
## [v2.1.0]
58
- Add R tester (#310)
69

client/autotest_client/__init__.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ def _check_rate_limit(user_name):
8484

8585
def _authorize_user():
8686
api_key = request.headers.get("Api-Key")
87-
user_name = (_redis_connection().hgetall("autotest:users") or {}).get(api_key)
87+
user_name = (_redis_connection().hgetall("autotest:user_credentials") or {}).get(api_key)
8888
if user_name is None:
8989
abort(make_response(jsonify(message="Unauthorized"), 401))
9090
_check_rate_limit(user_name)
91-
return user_name
91+
return api_key
9292

9393

9494
def _authorize_settings(user, settings_id=None, **_kw):
@@ -175,19 +175,13 @@ def _f(*args, **kwargs):
175175
@app.route("/register", methods=["POST"])
176176
def register():
177177
# non-secure registration
178-
user_name = request.json["user_name"]
179178
auth_type = request.json.get("auth_type")
180179
credentials = request.json.get("credentials")
181-
users = _redis_connection().hgetall("autotest:users") or {}
182-
if user_name in users:
183-
abort(make_response(jsonify(message="User already exists"), 400))
184180
key = base64.b64encode(os.urandom(24)).decode("utf-8")
185-
while key in users:
186-
key = base64.b64encode(os.urandom(24)).decode("utf-8")
187181
data = {"auth_type": auth_type, "credentials": credentials}
188-
_redis_connection().hset("autotest:users", key=key, value=user_name)
189-
_redis_connection().hset("autotest:user_credentials", key=user_name, value=json.dumps(data))
190-
return {"user_name": user_name, "api_key": key}
182+
while not _redis_connection().hsetnx("autotest:user_credentials", key=key, value=json.dumps(data)):
183+
key = base64.b64encode(os.urandom(24)).decode("utf-8")
184+
return {"api_key": key}
191185

192186

193187
@app.route("/reset_credentials", methods=["PUT"])

client/autotest_client/tests/test_flask_app.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import autotest_client
22
import pytest
33
import fakeredis
4+
import json
45

56

67
@pytest.fixture
@@ -27,11 +28,20 @@ def fake_redis_db(monkeypatch, fake_redis_conn):
2728

2829

2930
class TestRegister:
30-
def test_no_username(self, client):
31-
resp = client.post("/register")
32-
assert resp.status_code == 500
33-
assert resp.json['message'] == "'NoneType' object is not subscriptable"
34-
35-
def test_with_username(self, client, fake_redis_conn):
36-
client.post("/register", json={"user_name": "test"})
37-
assert "test" in fake_redis_conn.hgetall("autotest:users").values()
31+
32+
@pytest.fixture
33+
def credentials(self):
34+
return {'auth_type': 'test', 'credentials': '12345'}
35+
36+
@pytest.fixture
37+
def response(self, client, credentials):
38+
return client.post("/register", json=credentials)
39+
40+
def test_status(self, response):
41+
assert response.status_code == 200
42+
43+
def test_api_key_set(self, response):
44+
assert response.json['api_key']
45+
46+
def test_credentials_set(self, response, fake_redis_conn, credentials):
47+
assert json.loads(fake_redis_conn.hget('autotest:user_credentials', response.json['api_key'])) == credentials

server/autotest_server/testers/jupyter/lib/jupyter_pytest_plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def pytest_collect_file(self, parent, path):
6363

6464

6565
class IpynbFile(pytest.File):
66-
TEST_PATTERN = re.compile(r"(?i)^\s*#+\s*(test\w*)\s*$")
66+
TEST_PATTERN = re.compile(r"(?i)^\s*#+\s*(test.*?)\s*$")
6767

6868
def collect(self):
6969
mod = importer.import_from_path(self.fspath)

0 commit comments

Comments
 (0)