Handle duplicate creation of CA with same UUID.
This commit is contained in:
parent
c81af303b0
commit
f3b217435a
@ -1,6 +1,7 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
from sqlalchemy.ext.declarative import declarative_base
|
from sqlalchemy.ext.declarative import declarative_base
|
||||||
|
from sqlalchemy.exc import IntegrityError
|
||||||
import falcon
|
import falcon
|
||||||
import sshpubkeys
|
import sshpubkeys
|
||||||
import uuid
|
import uuid
|
||||||
@ -28,7 +29,10 @@ def createAuthority(session, auth_id):
|
|||||||
user_key=RSA.generate(2048).exportKey('PEM'),
|
user_key=RSA.generate(2048).exportKey('PEM'),
|
||||||
host_key=RSA.generate(2048).exportKey('PEM'))
|
host_key=RSA.generate(2048).exportKey('PEM'))
|
||||||
session.add(auth)
|
session.add(auth)
|
||||||
session.commit()
|
try:
|
||||||
|
session.commit()
|
||||||
|
except IntegrityError:
|
||||||
|
raise falcon.HTTPConflict("This certificate authority already exists.")
|
||||||
return auth
|
return auth
|
||||||
|
|
||||||
class UserCert(Base):
|
class UserCert(Base):
|
||||||
|
@ -52,6 +52,17 @@ def test_post_authority(client):
|
|||||||
#auth = session.query(Authority).get(auth_id)
|
#auth = session.query(Authority).get(auth_id)
|
||||||
#assert auth is not None
|
#assert auth is not None
|
||||||
|
|
||||||
|
@pytest.mark.dependency(depends=['test_post_authority'])
|
||||||
|
def test_post_authority_duplicate(client):
|
||||||
|
body = {
|
||||||
|
'auth_id': auth_id,
|
||||||
|
}
|
||||||
|
response = client.simulate_post(
|
||||||
|
'/authorities',
|
||||||
|
body=json.dumps(body)
|
||||||
|
)
|
||||||
|
assert response.status == falcon.HTTP_CONFLICT
|
||||||
|
|
||||||
def test_post_no_body(client):
|
def test_post_no_body(client):
|
||||||
for path in ['/authorities', '/usercerts', '/hosttokens',
|
for path in ['/authorities', '/usercerts', '/hosttokens',
|
||||||
'/hostcerts', '/novavendordata']:
|
'/hostcerts', '/novavendordata']:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user