blob: c903e47001ab57f9ddb1942515ae3db4dc11ae93 [file] [log] [blame]
Matthew Treinish9e26ca82016-02-23 11:43:20 -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
Jordan Pittier00f25962016-03-18 17:10:07 +010016from oslo_serialization import jsonutils as json
Matthew Treinish9e26ca82016-02-23 11:43:20 -050017
Jordan Pittier00f25962016-03-18 17:10:07 +010018from tempest.tests.lib import fake_http
Matthew Treinish9e26ca82016-02-23 11:43:20 -050019
20FAKE_AUTH_URL = 'http://fake_uri.com/auth'
21
22TOKEN = "fake_token"
23ALT_TOKEN = "alt_fake_token"
24
25# Fake Identity v2 constants
26COMPUTE_ENDPOINTS_V2 = {
27 "endpoints": [
28 {
29 "adminURL": "http://fake_url/v2/first_endpoint/admin",
30 "region": "NoMatchRegion",
31 "internalURL": "http://fake_url/v2/first_endpoint/internal",
32 "publicURL": "http://fake_url/v2/first_endpoint/public"
33 },
34 {
35 "adminURL": "http://fake_url/v2/second_endpoint/admin",
36 "region": "FakeRegion",
37 "internalURL": "http://fake_url/v2/second_endpoint/internal",
38 "publicURL": "http://fake_url/v2/second_endpoint/public"
39 },
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_alt_tenant_id"
54 },
55 },
56 "user": {
57 "id": "fake_alt_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 {
83 "id": "first_compute_fake_service",
84 "interface": "public",
85 "region": "NoMatchRegion",
86 "url": "http://fake_url/v3/first_endpoint/api"
87 },
88 {
89 "id": "second_fake_service",
90 "interface": "public",
91 "region": "FakeRegion",
92 "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"
99 }
100
101 ],
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": {
117 "id": "fake_domain_id",
118 "name": "fake"
119 },
120 "id": "project_id",
121 "name": "project_name"
122 },
123 "user": {
124 "domain": {
125 "id": "fake_domain_id",
126 "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
Andrea Frittoli (andreaf)3e82af72016-05-05 22:53:38 +0100136IDENTITY_V3_RESPONSE_DOMAIN_SCOPE = {
137 "token": {
138 "methods": [
139 "token",
140 "password"
141 ],
142 "expires_at": "2020-01-01T00:00:10.000123Z",
143 "domain": {
144 "id": "fake_domain_id",
145 "name": "domain_name"
146 },
147 "user": {
148 "domain": {
149 "id": "fake_domain_id",
150 "name": "domain_name"
151 },
152 "id": "fake_user_id",
153 "name": "username"
154 },
155 "issued_at": "2013-05-29T16:55:21.468960Z",
156 "catalog": CATALOG_V3
157 }
158}
159
160IDENTITY_V3_RESPONSE_NO_SCOPE = {
161 "token": {
162 "methods": [
163 "token",
164 "password"
165 ],
166 "expires_at": "2020-01-01T00:00:10.000123Z",
167 "user": {
168 "domain": {
169 "id": "fake_domain_id",
170 "name": "domain_name"
171 },
172 "id": "fake_user_id",
173 "name": "username"
174 },
175 "issued_at": "2013-05-29T16:55:21.468960Z",
176 }
177}
178
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500179ALT_IDENTITY_V3 = IDENTITY_V3_RESPONSE
180
181
182def _fake_v3_response(self, uri, method="GET", body=None, headers=None,
183 redirections=5, connection_type=None):
184 fake_headers = {
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500185 "x-subject-token": TOKEN
186 }
Jordan Pittier00f25962016-03-18 17:10:07 +0100187 return (fake_http.fake_http_response(fake_headers, status=201),
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500188 json.dumps(IDENTITY_V3_RESPONSE))
189
190
Andrea Frittoli (andreaf)3e82af72016-05-05 22:53:38 +0100191def _fake_v3_response_domain_scope(self, uri, method="GET", body=None,
192 headers=None, redirections=5,
193 connection_type=None):
194 fake_headers = {
195 "status": "201",
196 "x-subject-token": TOKEN
197 }
198 return (fake_http.fake_http_response(fake_headers, status=201),
199 json.dumps(IDENTITY_V3_RESPONSE_DOMAIN_SCOPE))
200
201
202def _fake_v3_response_no_scope(self, uri, method="GET", body=None,
203 headers=None, redirections=5,
204 connection_type=None):
205 fake_headers = {
206 "status": "201",
207 "x-subject-token": TOKEN
208 }
209 return (fake_http.fake_http_response(fake_headers, status=201),
210 json.dumps(IDENTITY_V3_RESPONSE_NO_SCOPE))
211
212
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500213def _fake_v2_response(self, uri, method="GET", body=None, headers=None,
214 redirections=5, connection_type=None):
Jordan Pittier00f25962016-03-18 17:10:07 +0100215 return (fake_http.fake_http_response({}, status=200),
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500216 json.dumps(IDENTITY_V2_RESPONSE))
217
218
219def _fake_auth_failure_response():
220 # the response body isn't really used in this case, but lets send it anyway
221 # to have a safe check in some future change on the rest client.
222 body = {
223 "unauthorized": {
224 "message": "Unauthorized",
225 "code": "401"
226 }
227 }
Jordan Pittier00f25962016-03-18 17:10:07 +0100228 return fake_http.fake_http_response({}, status=401), json.dumps(body)