Ejemplo n.º 1
0
 def setUp(self):
     """
     Initialize core and root
     """
     self.core = MimicCore(Clock(), [])
     self.root = MimicRoot(self.core).app.resource()
     self.node_details_attributes = [
         "instance_uuid", "target_power_state", "chassis_uuid",
         "properties", "uuid", "driver_info", "target_provision_state",
         "last_error", "console_enabled", "extra", "driver", "links",
         "maintenance_reason", "updated_at", "provision_updated_at",
         "maintenance", "provision_state", "reservation", "created_at",
         "power_state", "instance_info", "ports", "name",
         "driver_internal_info", "inspection_finished_at",
         "inspection_started_at", "clean_step"
     ]
     self.url = "/ironic/v1/nodes"
     self.create_request = {
         "chassis_uuid": str(uuid4()),
         "driver": "agent_ipmitool",
         "driver_info": {
             "ipmi_username": "******",
             "ipmi_address": "127.0.0.0",
             "ipmi_password": "******"
         },
         "name": "test_node",
         "properties": {
             "cpus": "1",
             "local_gb": "10",
             "memory_mb": "1024"
         }
     }
 def setUp(self):
     self.core = MimicCore(Clock(), [])
     self.root = MimicRoot(self.core).app.resource()
     self.uri = "/identity/v2.0/services"
     self.eeapi_name = u"externalServiceName"
     self.headers = {b'X-Auth-Token': [b'ABCDEF987654321']}
     self.verb = b"GET"
Ejemplo n.º 3
0
    def test_tick(self):
        """
        ``/mimic/v1.1/tick`` (handled by :func:`MimicRoot.advance_time`)
        advances the clock associated with the service.
        """
        clock = Clock()

        def do():
            do.done = True

        do.done = False
        clock.callLater(3.5, do)
        core = MimicCore(clock, [])
        root = MimicRoot(core, clock).app.resource()
        self.assertEqual(do.done, False)
        jreq = json_request(
            self, root, "POST", "/mimic/v1.1/tick", body={"amount": 3.6}
        )
        [response, json_content] = self.successResultOf(jreq)
        self.assertEqual(response.code, 200)
        expected = {
            'advanced': 3.6,
            'now': '1970-01-01T00:00:03.600000Z',
        }
        self.assertEqual(json_content, expected)
        self.assertEqual(do.done, True)
Ejemplo n.º 4
0
    def test_response_has_auth_token(self):
        """
        The JSON response has a access.token.id key corresponding to its
        MimicCore session, and therefore access.token.tenant.id should match
        that session's tenant_id.
        """
        core = MimicCore(Clock(), [])
        root = MimicRoot(core).app.resource()

        (response, json_body) = self.successResultOf(
            json_request(
                self, root, "POST", "/identity/v2.0/tokens", {
                    "auth": {
                        "passwordCredentials": {
                            "username": "******",
                            "password": "******"
                        }
                    }
                }))

        self.assertEqual(200, response.code)
        token = json_body['access']['token']['id']
        tenant_id = json_body['access']['token']['tenant']['id']
        session = core.sessions.session_for_token(token)
        self.assertEqual(token, session.token)
        self.assertEqual(tenant_id, session.tenant_id)
Ejemplo n.º 5
0
 def setUp(self):
     """
     Initialize core and root
     """
     self.core = MimicCore(Clock(), [])
     self.root = MimicRoot(self.core).app.resource()
     self.url = "/valkyrie/v2.0"
Ejemplo n.º 6
0
 def createSwiftService(self, rackspace_flavor=True):
     """
     Set up to create the requests
     """
     self.swift_mock = SwiftMock(rackspace_flavor)
     self.core = MimicCore(Clock(), [self.swift_mock])
     self.root = MimicRoot(self.core).app.resource()
     self.response = request(
         self,
         self.root,
         b"POST",
         b"/identity/v2.0/tokens",
         dumps({
             "auth": {
                 "passwordCredentials": {
                     "username": "******",
                     "password": "******",
                 },
                 # TODO: should this really be 'tenantId'?
                 "tenantName": "fun_tenant",
             }
         }).encode("utf-8"))
     self.auth_response = self.successResultOf(self.response)
     text_body = self.successResultOf(treq.content(
         self.auth_response)).decode("utf-8")
     self.json_body = loads(text_body)
Ejemplo n.º 7
0
    def test_get_token_and_catalog_for_token_credentials(self):
        """
        The response returned should include the credentials that were supplied
        during authentication
        """
        core = MimicCore(Clock(), [ExampleAPI()])
        root = MimicRoot(core).app.resource()

        (response, json_body) = self.successResultOf(
            json_request(
                self, root, "POST", "/identity/v2.0/tokens", {
                    "auth": {
                        "tenantId": "12345",
                        "token": {
                            "id": "iuyiuyiuy-uyiuyiuy-1987878"
                        }
                    }
                }))
        self.assertEqual(response.code, 200)
        tenant_id = json_body["access"]["token"]["tenant"]["id"]
        self.assertEqual(tenant_id, "12345")
        tenant_name = json_body["access"]["token"]["tenant"]["name"]
        self.assertEqual(tenant_name, tenant_id)
        user_name = json_body["access"]["user"]["name"]
        self.assertTrue(user_name)
Ejemplo n.º 8
0
    def __init__(self, test_case, apis):
        """
        Initialize a mimic core and the specified :obj:`mimic.imimic.IAPIMock`s

        :param apis: A list of :obj:`mimic.imimic.IAPIMock` objects to be
            initialized
        """
        self.test_case = test_case
        self.clock = Clock()
        self.core = MimicCore(self.clock, apis)
        self.root = MimicRoot(self.core).app.resource()

        # Pass in arbitrary username and password
        self.auth = TenantAuthentication(test_case, self.root, "test1",
                                         "test1password")

        # map some attributes and methods
        self.service_catalog_json = self.auth.service_catalog_json
        self.get_service_endpoint = self.auth.get_service_endpoint

        # Tenant ID of test tenant authenticated against mimic identity
        self.tenant_id = self.auth.service_catalog_json["access"]["token"][
            "tenant"]["id"]
        service_name = apis[0].catalog_entries(self.tenant_id)[0].name
        self.uri = self.get_service_endpoint(service_name)
Ejemplo n.º 9
0
    def test_auth_accepts_tenant_id(self):
        """
        If "tenantId" is passed, the tenant specified is used instead of a
        generated tenant ID.
        """
        core = MimicCore(Clock(), [])
        root = MimicRoot(core).app.resource()

        (response, json_body) = self.successResultOf(
            json_request(
                self, root, "POST", "/identity/v2.0/tokens", {
                    "auth": {
                        "passwordCredentials": {
                            "username": "******",
                            "password": "******"
                        },
                        "tenantId": "turtlepower"
                    }
                }))

        self.assertEqual(200, response.code)
        self.assertEqual("turtlepower",
                         json_body['access']['token']['tenant']['id'])
        token = json_body['access']['token']['id']
        session = core.sessions.session_for_token(token)
        self.assertEqual(token, session.token)
        self.assertEqual("turtlepower", session.tenant_id)
Ejemplo n.º 10
0
    def test_api_service_endpoints_are_not_duplicated(self):
        """
        The service catalog should not duplicate endpoints for an entry/endpoints
        """
        regions_and_versions_list = [("ORD", "v1"), ("DFW", "v1"),
                                     ("DFW", "v2"), ("IAD", "v3")]
        core = MimicCore(
            Clock(),
            [ExampleAPI(regions_and_versions=regions_and_versions_list)])
        root = MimicRoot(core).app.resource()

        (response, json_body) = self.successResultOf(
            json_request(
                self, root, "POST", "/identity/v2.0/tokens", {
                    "auth": {
                        "passwordCredentials": {
                            "username": "******",
                            "password": "******"
                        }
                    }
                }))
        self.assertEqual(response.code, 200)
        service_catalog = json_body["access"]["serviceCatalog"]
        self.assertEqual(len(service_catalog), 1)
        endpoints_list = service_catalog[0]["endpoints"]
        self.assertEqual(len(endpoints_list), 4)
Ejemplo n.º 11
0
    def setUp(self):
        """
        Create a check
        """
        core = MimicCore(Clock(), [])
        self.root = MimicRoot(core).app.resource()
        self.create_check = {
            "check": {
                "attributes": {
                    "name": "name",
                    "module": "module",
                    "target": "target",
                    "period": "period",
                    "timeout": "timeout",
                    "filterset": "filterset"
                }
            }
        }
        self.create_check_xml_payload = xmltodict.unparse(
            self.create_check).encode("utf-8")
        self.check_id = uuid.uuid4()
        url = "noit/checks/set/{0}".format(self.check_id)

        (self.response, response_body) = self.successResultOf(
            request_with_content(self,
                                 self.root,
                                 "PUT",
                                 url,
                                 body=self.create_check_xml_payload))
        self.create_json_response = xmltodict.parse(response_body)
Ejemplo n.º 12
0
    def test_response_has_same_roles_despite_number_of_auths(self):
        """
        The JSON response for authenticate has only one `identity:user-admin`
        role, no matter how many times the user authenticates.
        """
        core = MimicCore(Clock(), [])
        root = MimicRoot(core).app.resource()

        creds = {
            "auth": {
                "passwordCredentials": {
                    "username": "******",
                    "password": "******"
                }
            }
        }

        self.successResultOf(
            json_request(self, root, "POST", "/identity/v2.0/tokens", creds))
        self.successResultOf(
            json_request(self, root, "POST", "/identity/v2.0/tokens", creds))
        (response, json_body) = self.successResultOf(
            json_request(self, root, "POST", "/identity/v2.0/tokens", creds))

        self.assertEqual(200, response.code)
        self.assertEqual(json_body['access']['user']['roles'],
                         HARD_CODED_ROLES)
Ejemplo n.º 13
0
 def setUp(self):
     """
     Create a :obj:`MimicCore` with :obj:`QueueApi` as the only plugin,
     and create a queue
     """
     self.clock = Clock()
     self.core = MimicCore(self.clock, [QueueApi()])
     self.root = MimicRoot(self.core).app.resource()
     self.response = request(
         self, self.root, b"POST", "/identity/v2.0/tokens",
         json.dumps({
             "auth": {
                 "passwordCredentials": {
                     "username": "******",
                     "password": "******",
                 },
             }
         }).encode("utf-8"))
     self.auth_response = self.successResultOf(self.response)
     self.json_body = self.successResultOf(
         treq.json_content(self.auth_response))
     self.uri = self.json_body['access']['serviceCatalog'][0]['endpoints'][
         0]['publicURL']
     self.queue_name = "test_queue"
     self.create_queue = request(self, self.root, b"PUT",
                                 self.uri + '/queues/' + self.queue_name)
     self.create_queue_response = self.successResultOf(self.create_queue)
Ejemplo n.º 14
0
    def test_get_token_and_catalog_for_api_credentials(self):
        """
        The response returned should include the credentials that were supplied
        during authentication
        """
        core = MimicCore(Clock(), [ExampleAPI()])
        root = MimicRoot(core).app.resource()

        (response, json_body) = self.successResultOf(
            json_request(
                self, root, "POST", "/identity/v2.0/tokens", {
                    "auth": {
                        "RAX-KSKEY:apiKeyCredentials": {
                            "username": "******",
                            "apiKey": "jhgjhghg-nhghghgh-12222"
                        },
                        "tenantName": "12345"
                    }
                }))
        self.assertEqual(response.code, 200)
        tenant_id = json_body["access"]["token"]["tenant"]["id"]
        self.assertEqual(tenant_id, "12345")
        tenant_name = json_body["access"]["token"]["tenant"]["name"]
        self.assertEqual(tenant_name, tenant_id)
        user_name = json_body["access"]["user"]["name"]
        self.assertEqual(user_name, "demoauthor")
Ejemplo n.º 15
0
    def test_response_service_catalog_has_base_uri(self):
        """
        The JSON response's service catalog whose endpoints all begin with
        the same base URI as the request.
        """
        core = MimicCore(Clock(), [ExampleAPI()])
        root = MimicRoot(core).app.resource()

        (response, json_body) = self.successResultOf(
            json_request(
                self, root, "POST", "http://mybase/identity/v2.0/tokens", {
                    "auth": {
                        "passwordCredentials": {
                            "username": "******",
                            "password": "******"
                        }
                    }
                }))

        self.assertEqual(200, response.code)
        services = json_body['access']['serviceCatalog']
        self.assertEqual(1, len(services))

        urls = [endpoint['publicURL'] for endpoint in services[0]['endpoints']]
        self.assertEqual(1, len(urls))
        self.assertTrue(
            urls[0].startswith('http://mybase/'),
            '{0} does not start with "http://mybase"'.format(urls[0]))
Ejemplo n.º 16
0
 def setUp(self):
     """
     Initialize core and root
     """
     self.core = MimicCore(Clock(), [])
     self.root = MimicRoot(self.core).app.resource()
     self.uri = "/glance/v2/images"
     self.create_request = {"name": "OnMetal - MIMIC", "distro": "linux"}
 def setUp(self):
     self.core = MimicCore(Clock(), [])
     self.root = MimicRoot(self.core).app.resource()
     self.uri = "/identity/v2.0/OS-KSCATALOG/endpointTemplates"
     self.eeapi_name = u"externalServiceName"
     self.eeapi = make_example_external_api(self,
                                            name=self.eeapi_name,
                                            set_enabled=True)
     self.headers = {b'X-Auth-Token': [b'ABCDEF987654321']}
     self.verb = b"GET"
Ejemplo n.º 18
0
    def test_send_grid(self):
        """
        ``/sendgrid/mail.send.json`` returns response code 200.
        """
        core = MimicCore(Clock(), [])
        root = MimicRoot(core).app.resource()

        response = self.successResultOf(
            request(self, root, b"POST", "/sendgrid/mail.send.json"))
        self.assertEqual(200, response.code)
Ejemplo n.º 19
0
    def test_fastly(self):
        """
        The /fastly pointing to the fastly endpoint
        """
        core = MimicCore(Clock(), [])
        root = MimicRoot(core).app.resource()

        (response, json_content) = self.successResultOf(
            json_request(self, root, b'GET', '/fastly'))
        self.assertEqual(200, response.code)
        self.assertEqual(json_content, {'status': 'ok'})
Ejemplo n.º 20
0
    def test_authentication_request_with_no_body_causes_http_bad_request(self):
        """
        The response for empty body request is bad_request.
        """
        core = MimicCore(Clock(), [])
        root = MimicRoot(core).app.resource()

        (response, json_body) = self.successResultOf(
            json_request(self, root, "POST", "/identity/v2.0/tokens", ""))

        self.assertEqual(400, response.code)
Ejemplo n.º 21
0
 def setUp(self):
     self.tenant_id = 'some_tenant'
     self.core = MimicCore(Clock(), [])
     self.root = MimicRoot(self.core).app.resource()
     self.uri = ("/identity/v2.0/tenants/" + self.tenant_id +
                 "/OS-KSCATALOG/endpoints")
     self.eeapi_name = u"externalServiceName"
     self.eeapi = make_example_external_api(self,
                                            name=self.eeapi_name,
                                            set_enabled=False)
     self.headers = {b'X-Auth-Token': [b'ABCDEF987654321']}
     self.verb = b"POST"
Ejemplo n.º 22
0
 def setUp(self):
     self.tenant_id = 'some_tenant'
     self.core = MimicCore(Clock(), [])
     self.root = MimicRoot(self.core).app.resource()
     self.eeapi_name = u"externalServiceName"
     self.eeapi = make_example_external_api(self, name=self.eeapi_name)
     self.template_id = get_template_id(self, self.eeapi)
     self.assertIsNotNone(self.template_id)
     self.uri = ("/identity/v2.0/tenants/" + self.tenant_id +
                 "/OS-KSCATALOG/endpoints/" + self.template_id)
     self.headers = {b'X-Auth-Token': [b'ABCDEF987654321']}
     self.verb = b"DELETE"
Ejemplo n.º 23
0
    def test_response_for_get_username(self):
        """
        Test to verify :func: `get_username`.
        """
        core = MimicCore(Clock(), [ExampleAPI()])
        root = MimicRoot(core).app.resource()

        (response, json_body) = self.successResultOf(
            json_request(self, root, "GET",
                         "http://mybase/identity/v1.1/mosso/123456"))
        self.assertEqual(301, response.code)
        self.assertTrue(json_body['user']['id'])
Ejemplo n.º 24
0
    def test_domain_mock(self):
        """
        A GET on ``http://mimic-host.example.com:port/domain`` should return
        the list of all the domains; empty, if no plugins are registered.
        """

        core = MimicCore(Clock(), [])
        root = MimicRoot(core).app.resource()

        response = self.successResultOf(request(
            self, root, b"GET",
            "http://mybase/domain"))
        self.assertEqual(200, response.code)
Ejemplo n.º 25
0
    def make_request_to_site(self):
        """
        Make a request and return the response.
        """
        core = MimicCore(Clock(), [ExampleAPI('response!')])
        root = MimicRoot(core).app.resource()

        # get the region and service id registered for the example API
        (region, service_id) = one_api(self, core)
        url = "/mimicking/{0}/{1}".format(service_id, region)
        response = self.successResultOf(
            request(self, root, "GET", url, headers={"one": ["two"]}))
        return (response, url)
Ejemplo n.º 26
0
    def __init__(self, test_case, domains):
        """
        Initialize a mimic core and the specified :obj:`mimic.imimic.IAPIMock`s

        :param domains: A list of :obj:`mimic.imimic.IAPIDomainMock` objects to
            be initialized
        """
        self.test_case = test_case
        self.clock = Clock()
        self.core = MimicCore(self.clock, [], domains=domains)
        self.root = MimicRoot(self.core).app.resource()

        self.uri = '/domain/{0}'.format(domains[0].domain())
Ejemplo n.º 27
0
    def test_authentication_request_with_invalid_body_causes_http_bad_request(
            self):
        """
        The response for not JSON body request is bad_request.
        """
        core = MimicCore(Clock(), [])
        root = MimicRoot(core).app.resource()

        response = self.successResultOf(
            request(self, root, "POST", "/identity/v2.0/tokens",
                    "{ bad request: }"))

        self.assertEqual(400, response.code)
Ejemplo n.º 28
0
    def test_session_created_for_token(self):
        """
        A session is created for the token provided
        """
        core = MimicCore(Clock(), [])
        root = MimicRoot(core).app.resource()

        token = '1234567890'

        request(self, root, "GET",
                "/identity/v2.0/tokens/{0}/endpoints".format(token))

        session = core.sessions.session_for_token(token)
        self.assertEqual(token, session.token)
Ejemplo n.º 29
0
def startMimic():
    """
    Setup the mimic application using steps similar to
    :obj:`mimic.tap.makeService' and start listening for requests.
    """
    clock = Clock()
    core = MimicCore.fromPlugins(clock)
    root = MimicRoot(core, clock)
    site = Site(root.app.resource())
    site.displayTracebacks = False

    endpoint = serverFromString(reactor,
                                b"tcp:{0}:interface=127.0.0.1".format(_PORT))
    endpoint.listen(site)
Ejemplo n.º 30
0
    def test_domain_mock_with_an_example_mock(self):
        """
        A GET on the ``http://mimic-host.example.com:port/domain`` should
        return the list of all the domains, enumerating all registered plugins.
        """
        example_domain_api = ExampleDomainAPI()
        core = MimicCore(Clock(), [], [example_domain_api])
        root = MimicRoot(core).app.resource()

        response, content = self.successResultOf(json_request(
            self, root, b"GET",
            "http://mybase/domain"))
        self.assertEqual(200, response.code)
        self.assertEqual(content, [u'api.example.com'])