Exemple #1
0
    def _test_token(self, kargs, expected):
        sot = rackspace.Token(**kargs)

        self.assertEqual(common.TEST_TOKEN, sot.token)
        headers = {}
        self.assertEqual(expected, sot.get_auth_data(headers))
        return sot
Exemple #2
0
    def test_empty_token(self):
        kargs = {
            "token": "",
            "tenant_id": common.TEST_TENANT_ID,
        }

        with testtools.ExpectedException(exceptions.AuthorizationFailure):
            rackspace.Token(**kargs)
Exemple #3
0
    def test_authorize_bad_response(self):
        kargs = {
            "token": common.TEST_TOKEN,
            "tenant_name": common.TEST_TENANT_NAME
        }
        sot = rackspace.Token(**kargs)
        xport = self.create_mock_transport({})

        with testtools.ExpectedException(exceptions.InvalidResponse):
            sot.authorize(xport)
Exemple #4
0
    def test_invalidate(self):
        kargs = {
            "token": common.TEST_TOKEN,
            "tenant_name": common.TEST_TENANT_NAME,
        }
        sot = rackspace.Token(**kargs)
        expected = {"tenantName": common.TEST_TENANT_NAME,
                    "token": {"id": common.TEST_TOKEN}}
        headers = {}
        self.assertEqual(expected, sot.get_auth_data(headers))

        self.assertEqual(True, sot.invalidate())

        self.assertEqual(None, sot.token)
        self.assertEqual(None, sot.access_info)
Exemple #5
0
    def test_authorize_tenant_name(self):
        kargs = {
            "tenant_name": common.TEST_TENANT_NAME,
            "token": common.TEST_TOKEN,
        }
        sot = rackspace.Token(**kargs)
        xport = self.create_mock_transport(TEST_RESPONSE_DICT)

        resp = sot.authorize(xport)

        eurl = rackspace.AUTH_URL.rstrip("/") + "/tokens"
        eheaders = {"Accept": "application/json"}
        ejson = {"auth": {"token": {"id": common.TEST_TOKEN},
                          "tenantName": common.TEST_TENANT_NAME}}
        xport.post.assert_called_with(eurl, headers=eheaders, json=ejson)
        ecatalog = TEST_RESPONSE_DICT["access"].copy()
        ecatalog["version"] = "v2.0"
        self.assertEqual(ecatalog, resp._info)