fixed bug 796619

This commit is contained in:
Alex Meade 2011-06-13 10:10:45 -04:00
parent 91e34d37d2
commit 67e11fa809
2 changed files with 71 additions and 1 deletions

View File

@ -176,7 +176,8 @@ def revoke_certs_by_project(project_id):
def revoke_certs_by_user_and_project(user_id, project_id): def revoke_certs_by_user_and_project(user_id, project_id):
"""Revoke certs for user in project.""" """Revoke certs for user in project."""
admin = context.get_admin_context() admin = context.get_admin_context()
for cert in db.certificate_get_all_by_user(admin, user_id, project_id): for cert in db.certificate_get_all_by_user_and_project(admin,
user_id, project_id):
revoke_cert(cert['project_id'], cert['file_name']) revoke_cert(cert['project_id'], cert['file_name'])

View File

@ -16,7 +16,10 @@
Tests for Crypto module. Tests for Crypto module.
""" """
import mox
from nova import crypto from nova import crypto
from nova import db
from nova import test from nova import test
@ -46,3 +49,69 @@ class SymmetricKeyTestCase(test.TestCase):
plain = decrypt(cipher_text) plain = decrypt(cipher_text)
self.assertEquals(plain_text, plain) self.assertEquals(plain_text, plain)
class RevokeCertsTest(test.TestCase):
def test_revoke_certs_by_user_and_project(self):
user_id = 'test_user'
project_id = 2
file_name = 'test_file'
certificates = [{"user_id": user_id, "project_id": project_id,
"file_name": file_name}]
self.mox.StubOutWithMock(db, 'certificate_get_all_by_user_and_project')
db.certificate_get_all_by_user_and_project(mox.IgnoreArg(), \
user_id, project_id).AndReturn(certificates)
self.mox.StubOutWithMock(crypto, 'revoke_cert')
crypto.revoke_cert(project_id, mox.IgnoreArg())
self.mox.ReplayAll()
crypto.revoke_certs_by_user_and_project(user_id, project_id)
self.mox.VerifyAll()
def test_revoke_certs_by_user(self):
user_id = 'test_user'
project_id = 2
file_name = 'test_file'
certificates = [{"user_id": user_id, "project_id": project_id,
"file_name": file_name}]
self.mox.StubOutWithMock(db, 'certificate_get_all_by_user')
db.certificate_get_all_by_user(mox.IgnoreArg(), \
user_id).AndReturn(certificates)
self.mox.StubOutWithMock(crypto, 'revoke_cert')
crypto.revoke_cert(project_id, mox.IgnoreArg())
self.mox.ReplayAll()
crypto.revoke_certs_by_user(user_id)
self.mox.VerifyAll()
def test_revoke_certs_by_project(self):
user_id = 'test_user'
project_id = 2
file_name = 'test_file'
certificates = [{"user_id": user_id, "project_id": project_id,
"file_name": file_name}]
self.mox.StubOutWithMock(db, 'certificate_get_all_by_project')
db.certificate_get_all_by_project(mox.IgnoreArg(), \
project_id).AndReturn(certificates)
self.mox.StubOutWithMock(crypto, 'revoke_cert')
crypto.revoke_cert(project_id, mox.IgnoreArg())
self.mox.ReplayAll()
crypto.revoke_certs_by_project(project_id)
self.mox.VerifyAll()