mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 17:31:14 -05:00
Merge branch 'master' of github.com:alphagov/notifications-api
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from sqlalchemy import UniqueConstraint
|
||||
|
||||
from . import db
|
||||
import datetime
|
||||
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
from app.encryption import (
|
||||
hashpw,
|
||||
@@ -95,6 +96,10 @@ class ApiKey(db.Model):
|
||||
service = db.relationship('Service', backref=db.backref('api_keys', lazy='dynamic'))
|
||||
expiry_date = db.Column(db.DateTime)
|
||||
|
||||
__table_args__ = (
|
||||
UniqueConstraint('service_id', 'name', name='uix_service_to_key_name'),
|
||||
)
|
||||
|
||||
|
||||
TEMPLATE_TYPES = ['sms', 'email', 'letter']
|
||||
|
||||
@@ -123,7 +128,6 @@ class Template(db.Model):
|
||||
|
||||
|
||||
class Job(db.Model):
|
||||
|
||||
__tablename__ = 'jobs'
|
||||
|
||||
id = db.Column(UUID(as_uuid=True), primary_key=True)
|
||||
|
||||
26
migrations/versions/0008_unique_service_to_key_name.py
Normal file
26
migrations/versions/0008_unique_service_to_key_name.py
Normal file
@@ -0,0 +1,26 @@
|
||||
"""empty message
|
||||
|
||||
Revision ID: 0008_unique_service_to_key_name
|
||||
Revises: 0007_change_to_api_keys
|
||||
Create Date: 2016-01-21 16:14:51.773001
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '0008_unique_service_to_key_name'
|
||||
down_revision = '0007_change_to_api_keys'
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
def upgrade():
|
||||
### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_unique_constraint('uix_service_to_key_name', 'api_key', ['service_id', 'name'])
|
||||
### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_constraint('uix_service_to_key_name', 'api_key', type_='unique')
|
||||
### end Alembic commands ###
|
||||
@@ -73,3 +73,16 @@ def test_get_unsigned_secret_returns_key(notify_api,
|
||||
unsigned_api_key = get_unsigned_secret(sample_api_key.id)
|
||||
assert sample_api_key.secret != unsigned_api_key
|
||||
assert unsigned_api_key == _get_secret(sample_api_key.secret)
|
||||
|
||||
|
||||
def test_should_not_allow_duplicate_key_names_per_service(notify_api,
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
sample_api_key):
|
||||
api_key = ApiKey(
|
||||
**{'id': sample_api_key.id + 1, 'service_id': sample_api_key.service_id, 'name': sample_api_key.name})
|
||||
try:
|
||||
save_model_api_key(api_key)
|
||||
fail("should throw IntegrityError")
|
||||
except:
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user