Skip to content

Commit

Permalink
updated migration tests to include revoked_token table
Browse files Browse the repository at this point in the history
  • Loading branch information
heartsucker committed Apr 23, 2019
1 parent bd78d77 commit b2d91ce
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions securedrop/tests/migrations/migration_b58139cfdc8c.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ def check_upgrade(self):
and without being able to inject this config, the checksum function won't succeed. The above
`load_data` function provides data that can be manually verified by checking the `rqworker`
log file in `/tmp/`.
The other part of the migration, creating a table, cannot be tested regardless.
'''
pass

Expand All @@ -175,9 +177,15 @@ def load_data(self):
self.create_submission(checksum=True)
self.create_reply(checksum=True)

# add a revoked token for enable a foreign key connection
self.add_revoked_token()

def check_downgrade(self):
'''
Verify that the checksum column is now gone.
The dropping of the revoked_tokens table cannot be checked. If the migration completes,
then it wokred correctly.
'''
with self.app.app_context():
sql = "SELECT * FROM submissions"
Expand All @@ -197,3 +205,13 @@ def check_downgrade(self):
submission['checksum']
except NoSuchColumnError:
pass

def add_revoked_token(self):
params = {
'journalist_id': self.journalist_id,
'token': 'abc123',
}
sql = '''INSERT INTO revoked_tokens (journalist_id, token)
VALUES (:journalist_id, :token)
'''
db.engine.execute(text(sql), **params)

0 comments on commit b2d91ce

Please sign in to comment.