def test_up(self):
        """Verify that the client behaves as expected when the IAS server is
           functioning properly.
        """
        self.mock_server.restart("up")
        client = IasClient(URL, None, 5)

        siglist = client.get_signature_revocation_lists(gid="gid")
        received = self.mock_server.get_received()

        self.assertEqual(received["command"], "GET")
        self.assertEqual(received["path"], "/attestation/v3/sigrl/gid")
        self.assertEqual(siglist, "thisisasignaturelist")

        verification = client.post_verify_attestation("thisisaquote",
                                                      "thisisamanifest",
                                                      34608138615)
        received = self.mock_server.get_received()
        received_data = json.loads(received["data"].decode())

        self.assertEqual(received["command"], "POST")
        self.assertEqual(received["path"], "/attestation/v3/report")
        self.assertEqual(
            received_data, {
                "isvEnclaveQuote": "thisisaquote",
                "pseManifest": "thisisamanifest",
                "nonce": 34608138615,
            })
        self.assertEqual(
            verification, {
                "verification_report": '{"thisisa":"verification_report"}',
                "signature": "signature",
            })
    def test_up(self):
        """Verify that the client behaves as expected when the IAS server is
           functioning properly.
        """
        self.mock_server.restart("up")
        client = IasClient(URL, None, 5)

        siglist = client.get_signature_revocation_lists(gid="gid")
        received = self.mock_server.get_received()

        self.assertEqual(received["command"], "GET")
        self.assertEqual(received["path"], "/attestation/sgx/v2/sigrl/gid")
        self.assertEqual(siglist, "thisisasignaturelist")

        verification = client.post_verify_attestation(
            "thisisaquote", "thisisamanifest", 34608138615
        )
        received = self.mock_server.get_received()
        received_data = json.loads(received["data"].decode())

        self.assertEqual(received["command"], "POST")
        self.assertEqual(received["path"], "/attestation/sgx/v2/report")
        self.assertEqual(received_data, {
            "isvEnclaveQuote": "thisisaquote",
            "pseManifest": "thisisamanifest",
            "nonce": 34608138615,
        })
        self.assertEqual(verification, {
            "verification_report": '{"thisisa":"verification_report"}',
            "signature": "signature",
        })
 def test_down(self):
     """Verify that the client throws a connection error if the IAS server
        doesn't repond correctly.
     """
     self.mock_server.restart("down")
     client = IasClient(URL, None, 5)
     self.assertRaises(requests.exceptions.ConnectionError,
                       client.get_signature_revocation_lists)
     self.assertRaises(requests.exceptions.ConnectionError,
                       client.post_verify_attestation, "")
 def test_slow(self):
     """Verify that the client throws a timeout error if the IAS server is
        slow to respond.
     """
     self.mock_server.restart("slow")
     client = IasClient(URL, None, 0.1)
     self.assertRaises(requests.exceptions.Timeout,
                       client.get_signature_revocation_lists)
     self.assertRaises(requests.exceptions.Timeout,
                       client.post_verify_attestation, "")
 def test_error(self):
     """Verify that the client behaves as expected when the IAS server
        returns an HTTP status code that is an error.
     """
     self.mock_server.restart("error")
     client = IasClient(URL, None, 5)
     self.assertRaises(requests.HTTPError,
                       client.get_signature_revocation_lists)
     self.assertRaises(requests.HTTPError, client.post_verify_attestation,
                       "")
import cProfile
from sawtooth_ias_client.ias_client import IasClient
from tests.unit import mock_ias_server

URL = "http://127.0.0.1:8008"
mockServer = mock_ias_server.create(URL)
mockServer.start("up")
client = IasClient(URL, None, 5)


def test_get_signature_revocation_lists(benchmark):
    result = benchmark(client.get_signature_revocation_lists, gid="gid")
    return


def test_post_verify_attestation(benchmark):
    result = benchmark(client.post_verify_attestation, "thisisaquote",
                       "thisisamanifest", 34608138615)
    return