raise 400 when failing to create users

This commit is contained in:
MinRK
2014-09-25 14:49:06 -07:00
parent 2c8af78141
commit e2f12f7071
3 changed files with 11 additions and 1 deletions

View File

@@ -88,8 +88,10 @@ class UserAPIHandler(BaseUserHandler):
try:
self.authenticator.add_user(user)
except Exception:
self.log.error("Failed to create user: %s" % name, exc_info=True)
self.db.delete(user)
self.db.commit()
raise web.HTTPError(400, "Failed to create user: %s" % name)
self.write(json.dumps(self.user_model(user)))
self.set_status(201)

View File

@@ -48,7 +48,7 @@ class MockSpawner(LocalProcessSpawner):
class MockPAMAuthenticator(PAMAuthenticator):
def system_user_exists(self, user):
# skip the add-system-user bit
return True
return not user.name.startswith('dne')
def authenticate(self, *args, **kwargs):
with mock.patch('simplepam.authenticate', mock_authenticate):

View File

@@ -102,6 +102,14 @@ def test_add_user(app):
assert user.name == name
assert not user.admin
def test_add_user_bad(app):
db = app.db
name = 'dne_newuser'
r = api_request(app, 'users', name, method='post')
assert r.status_code == 400
user = find_user(db, name)
assert user is None
def test_add_admin(app):
db = app.db
name = 'newadmin'