blob: ad78f857a4c08b45b206725077b98f5b4cf3953e [file] [log] [blame]
Mauro S. M. Rodriguesc3e573c2014-02-19 07:59:29 -05001# Copyright 2014 IBM Corp.
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
Matthew Treinish96e9e882014-06-09 18:37:19 -040016import json
Mauro S. M. Rodriguesc3e573c2014-02-19 07:59:29 -050017
18import httplib2
Mauro S. M. Rodriguesc3e573c2014-02-19 07:59:29 -050019
ghanshyam5ff763f2015-02-18 16:15:58 +090020FAKE_AUTH_URL = 'http://fake_uri.com/auth'
Mauro S. M. Rodriguesc3e573c2014-02-19 07:59:29 -050021
22TOKEN = "fake_token"
23ALT_TOKEN = "alt_fake_token"
24
25# Fake Identity v2 constants
26COMPUTE_ENDPOINTS_V2 = {
27 "endpoints": [
28 {
Mauro S. M. Rodrigues4e23c452014-02-24 15:21:58 -050029 "adminURL": "http://fake_url/v2/first_endpoint/admin",
Mauro S. M. Rodriguesc3e573c2014-02-19 07:59:29 -050030 "region": "NoMatchRegion",
Mauro S. M. Rodrigues4e23c452014-02-24 15:21:58 -050031 "internalURL": "http://fake_url/v2/first_endpoint/internal",
32 "publicURL": "http://fake_url/v2/first_endpoint/public"
Mauro S. M. Rodriguesc3e573c2014-02-19 07:59:29 -050033 },
34 {
Mauro S. M. Rodrigues4e23c452014-02-24 15:21:58 -050035 "adminURL": "http://fake_url/v2/second_endpoint/admin",
Mauro S. M. Rodriguesc3e573c2014-02-19 07:59:29 -050036 "region": "FakeRegion",
Mauro S. M. Rodrigues4e23c452014-02-24 15:21:58 -050037 "internalURL": "http://fake_url/v2/second_endpoint/internal",
38 "publicURL": "http://fake_url/v2/second_endpoint/public"
Mauro S. M. Rodriguesc3e573c2014-02-19 07:59:29 -050039 },
40 ],
41 "type": "compute",
42 "name": "nova"
43}
44
45CATALOG_V2 = [COMPUTE_ENDPOINTS_V2, ]
46
47ALT_IDENTITY_V2_RESPONSE = {
48 "access": {
49 "token": {
50 "expires": "2020-01-01T00:00:10Z",
51 "id": ALT_TOKEN,
52 "tenant": {
53 "id": "fake_tenant_id"
54 },
55 },
56 "user": {
57 "id": "fake_user_id",
58 },
59 "serviceCatalog": CATALOG_V2,
60 },
61}
62
63IDENTITY_V2_RESPONSE = {
64 "access": {
65 "token": {
66 "expires": "2020-01-01T00:00:10Z",
67 "id": TOKEN,
68 "tenant": {
69 "id": "fake_tenant_id"
70 },
71 },
72 "user": {
73 "id": "fake_user_id",
74 },
75 "serviceCatalog": CATALOG_V2,
76 },
77}
78
79# Fake Identity V3 constants
80COMPUTE_ENDPOINTS_V3 = {
81 "endpoints": [
82 {
Mauro S. M. Rodrigues4e23c452014-02-24 15:21:58 -050083 "id": "first_compute_fake_service",
Mauro S. M. Rodriguesc3e573c2014-02-19 07:59:29 -050084 "interface": "public",
85 "region": "NoMatchRegion",
Mauro S. M. Rodrigues4e23c452014-02-24 15:21:58 -050086 "url": "http://fake_url/v3/first_endpoint/api"
Mauro S. M. Rodriguesc3e573c2014-02-19 07:59:29 -050087 },
88 {
Mauro S. M. Rodrigues4e23c452014-02-24 15:21:58 -050089 "id": "second_fake_service",
Mauro S. M. Rodriguesc3e573c2014-02-19 07:59:29 -050090 "interface": "public",
91 "region": "FakeRegion",
Mauro S. M. Rodrigues4e23c452014-02-24 15:21:58 -050092 "url": "http://fake_url/v3/second_endpoint/api"
93 },
94 {
95 "id": "third_fake_service",
96 "interface": "admin",
97 "region": "MiddleEarthRegion",
98 "url": "http://fake_url/v3/third_endpoint/api"
Mauro S. M. Rodriguesc3e573c2014-02-19 07:59:29 -050099 }
Mauro S. M. Rodrigues4e23c452014-02-24 15:21:58 -0500100
Mauro S. M. Rodriguesc3e573c2014-02-19 07:59:29 -0500101 ],
102 "type": "compute",
103 "id": "fake_compute_endpoint"
104}
105
106CATALOG_V3 = [COMPUTE_ENDPOINTS_V3, ]
107
108IDENTITY_V3_RESPONSE = {
109 "token": {
110 "methods": [
111 "token",
112 "password"
113 ],
114 "expires_at": "2020-01-01T00:00:10.000123Z",
115 "project": {
116 "domain": {
Andrea Frittolib1b04bb2014-04-06 11:57:07 +0100117 "id": "fake_domain_id",
Mauro S. M. Rodriguesc3e573c2014-02-19 07:59:29 -0500118 "name": "fake"
119 },
120 "id": "project_id",
121 "name": "project_name"
122 },
123 "user": {
124 "domain": {
Andrea Frittolib1b04bb2014-04-06 11:57:07 +0100125 "id": "fake_domain_id",
Mauro S. M. Rodriguesc3e573c2014-02-19 07:59:29 -0500126 "name": "domain_name"
127 },
128 "id": "fake_user_id",
129 "name": "username"
130 },
131 "issued_at": "2013-05-29T16:55:21.468960Z",
132 "catalog": CATALOG_V3
133 }
134}
135
136ALT_IDENTITY_V3 = IDENTITY_V3_RESPONSE
137
138
139def _fake_v3_response(self, uri, method="GET", body=None, headers=None,
140 redirections=5, connection_type=None):
141 fake_headers = {
142 "status": "201",
143 "x-subject-token": TOKEN
144 }
145 return (httplib2.Response(fake_headers),
146 json.dumps(IDENTITY_V3_RESPONSE))
147
148
149def _fake_v2_response(self, uri, method="GET", body=None, headers=None,
150 redirections=5, connection_type=None):
151 return (httplib2.Response({"status": "200"}),
152 json.dumps(IDENTITY_V2_RESPONSE))
153
154
155def _fake_auth_failure_response():
156 # the response body isn't really used in this case, but lets send it anyway
157 # to have a safe check in some future change on the rest client.
158 body = {
159 "unauthorized": {
160 "message": "Unauthorized",
161 "code": "401"
162 }
163 }
164 return httplib2.Response({"status": "401"}), json.dumps(body)