class TestVerfierDB(unittest.TestCase): def setUp(self): self.engine = create_engine('sqlite://') VerfierMain.metadata.create_all(self.engine, checkfirst=True) self.session = SessionManager().make_session(self.engine) self.populate_agent() def populate_agent(self): self.session.add(VerfierMain(**test_data)) self.session.commit() def test_add_agent(self): agent = self.session.query(VerfierMain).filter_by( agent_id=agent_id).first() self.assertEqual(agent.v, 'cf0B779EA1dkHVWfTxQuSLHNFeutYeSmVWe7JOFWzXg=') self.assertEqual(agent.port, 9002) self.assertEqual( agent.tpm_policy, '{"22": ["0000000000000000000000000000000000000001", "0000000000000000000000000000000000000000000000000000000000000001", "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", "ffffffffffffffffffffffffffffffffffffffff", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"], "15": ["0000000000000000000000000000000000000000", "0000000000000000000000000000000000000000000000000000000000000000", "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"], "mask": "0x408400"}' ) self.assertEqual( agent.revocation_key, '-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDs1onKjLZHDnqu\nnrsCb5aZohK2FU+jjU4NT23x1UzYzpFU9wBZ0avj+HeFYbQiAKanSbS7PvhjJMdE\naWMgRMgigr2K1xx+ZhBu4zTPFMy11msxMIL/HPROSYx/9wUZrhf4z/rBsuppFVs3\nKfKmQHuptjZX+D+m+nANO8WOILyW2+5YO5FNw1XJ3gVO6elJJ/CzQcYWIioONuTM\nQ+g8OQc+yTZruwedcSpOX56GpBImWUKXzTz3zoX7AlYxjEBjT86rxoBVXo3ZIwYx\n+mJk7NADN2qvLSXxTnLBxISHdsUDBP5DfurFQPhZC5oARN6/Y4zPESnhm8iwlG5o\n2ZjxVzphAgMBAAECggEBAKVKudImUJTY8yBp4aS6koXYymxQBUvlM8MwW1A7iK2L\nxXxi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NNflf0YdDFVniFUyq9vfbq2drJSnMiy8Dvju0j5PC\n+MALz22fsNoIV2h6gz0i1lXiyVgpoAhYCbbPv0wO6iHKPBzH3Onv6BKrVMy1pnzh\n6QsfbhjzBfFg1Zxp/h1tBqA=\n-----END PRIVATE KEY-----\n' ) self.assertEqual(agent.accept_tpm_hash_algs, ['sha512', 'sha384', 'sha256', 'sha1']) def test_count_agents(self): agent = self.session.query(VerfierMain.agent_id).count() self.assertEqual(agent, 1) def test_set_operation_state(self): self.session.query(VerfierMain).filter(agent_id == agent_id).update( {'operational_state': TENANT_FAILED}) self.session.commit() agent = self.session.query(VerfierMain).filter_by( agent_id=agent_id).first() self.assertEqual(agent.operational_state, 10) def test_delete_agent(self): agent = self.session.query(VerfierMain).filter_by( agent_id=agent_id).first() self.session.query(VerfierMain).filter_by(agent_id=agent_id).delete() self.session.commit() agent = self.session.query(VerfierMain).filter_by( agent_id=agent_id).first() self.assertIsNone(agent) def tearDown(self): self.session.close()
class TestRegistrarDB(unittest.TestCase): def setUp(self): self.engine = create_engine('sqlite://') RegistrarMain.metadata.create_all(self.engine, checkfirst=True) self.session = SessionManager().make_session(self.engine) self.populate_agent() def populate_agent(self): self.session.add(RegistrarMain(**test_data)) self.session.commit() def test_add_agent(self): agent = self.session.query(RegistrarMain).filter_by( agent_id=agent_id).first() self.assertEqual( agent.ek, """-----BEGIN PUBLIC KEY----- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0dLxdAABVJO6qxamjCMh yhWZgiFHZHnPEe0tMFyK3fNVr/w8lX9r+QOLxLmkT0IdgsEYtGZGefbD+qQl4O1s k25823Xzu5tEF8966rTdkfsv8CRrNaBLwWlnt/n+qjIoU3xZJMmR+mFfqTc3a6zV mPOYJstFtM8r4b9HPCUq6Mte/J3Wx4FxI9R4UrCUyiAeH++0QapIxuEGsVIYs92n GyvFQYBZFRU6cIt33iaqTrRCICJp+YblMnw54YJGAH2vTVQf6/fLAnQt5L1UfmTy R/ZA6advx8soekSBOIAW7XmV8Xp9mSquIHZdSXMJlcn/B35PU3BdkUtIYm5JuGGt PQIDAQAB -----END PUBLIC KEY-----""") self.assertEqual( agent.aik, """-----BEGIN PUBLIC KEY----- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0dLxdAABVJO6qxamjCMh yhWZgiFHZHnPEe0tMFyK3fNVr/w8lX9r+QOLxLmkT0IdgsEYtGZGefbD+qQl4O1s k25823Xzu5tEF8966rTdkfsv8CRrNaBLwWlnt/n+qjIoU3xZJMmR+mFfqTc3a6zV mPOYJstFtM8r4b9HPCUq6Mte/J3Wx4FxI9R4UrCUyiAeH++0QapIxuEGsVIYs92n GyvFQYBZFRU6cIt33iaqTrRCICJp+YblMnw54YJGAH2vTVQf6/fLAnQt5L1UfmTy R/ZA6advx8soekSBOIAW7XmV8Xp9mSquIHZdSXMJlcn/B35PU3BdkUtIYm5JuGGt PQIDAQAB -----END PUBLIC KEY-----""") self.assertEqual( agent.ekcert, """-----BEGIN CERTIFICATE----- MIIEnzCCA4egAwIBAgIEMV64bDANBgkqhkiG9w0BAQUFADBtMQswCQYDVQQGEwJE RTEQMA4GA1UECBMHQmF2YXJpYTEhMB8GA1UEChMYSW5maW5lb24gVGVjaG5vbG9n aWVzIEFHMQwwCgYDVQQLEwNBSU0xGzAZBgNVBAMTEklGWCBUUE0gRUsgUm9vdCBD QTAeFw0wNTEwMjAxMzQ3NDNaFw0yNTEwMjAxMzQ3NDNaMHcxCzAJBgNVBAYTAkRF MQ8wDQYDVQQIEwZTYXhvbnkxITAfBgNVBAoTGEluZmluZW9uIFRlY2hub2xvZ2ll cyBBRzEMMAoGA1UECxMDQUlNMSYwJAYDVQQDEx1JRlggVFBNIEVLIEludGVybWVk aWF0ZSBDQSAwMTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALftPhYN t4rE+JnU/XOPICbOBLvfo6iA7nuq7zf4DzsAWBdsZEdFJQfaK331ihG3IpQn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CERTIFICATE-----""") self.assertEqual( agent.virtual, 0) self.assertEqual( agent.active, int(False)) self.assertEqual( agent.key, 'R0xKMU5maWVEaHVxQ0poZUZhWm9yRVkyRHZZUkVIMFA=') self.assertEqual( agent.provider_keys, {}) self.assertEqual( agent.regcount, 1) def test_delete_agent(self): agent = self.session.query(RegistrarMain).filter_by( agent_id=agent_id).first() self.session.query(RegistrarMain).filter_by( agent_id=agent_id).delete() self.session.commit() agent = self.session.query(RegistrarMain).filter_by( agent_id=agent_id).first() self.assertIsNone(agent) def tearDown(self): self.session.close()