Mauro S. M. Rodrigues | c3e573c | 2014-02-19 07:59:29 -0500 | [diff] [blame] | 1 | # 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 Treinish | 96e9e88 | 2014-06-09 18:37:19 -0400 | [diff] [blame] | 16 | import json |
Mauro S. M. Rodrigues | c3e573c | 2014-02-19 07:59:29 -0500 | [diff] [blame] | 17 | |
| 18 | import httplib2 |
Mauro S. M. Rodrigues | c3e573c | 2014-02-19 07:59:29 -0500 | [diff] [blame] | 19 | |
ghanshyam | 5ff763f | 2015-02-18 16:15:58 +0900 | [diff] [blame] | 20 | FAKE_AUTH_URL = 'http://fake_uri.com/auth' |
Mauro S. M. Rodrigues | c3e573c | 2014-02-19 07:59:29 -0500 | [diff] [blame] | 21 | |
| 22 | TOKEN = "fake_token" |
| 23 | ALT_TOKEN = "alt_fake_token" |
| 24 | |
| 25 | # Fake Identity v2 constants |
| 26 | COMPUTE_ENDPOINTS_V2 = { |
| 27 | "endpoints": [ |
| 28 | { |
Mauro S. M. Rodrigues | 4e23c45 | 2014-02-24 15:21:58 -0500 | [diff] [blame] | 29 | "adminURL": "http://fake_url/v2/first_endpoint/admin", |
Mauro S. M. Rodrigues | c3e573c | 2014-02-19 07:59:29 -0500 | [diff] [blame] | 30 | "region": "NoMatchRegion", |
Mauro S. M. Rodrigues | 4e23c45 | 2014-02-24 15:21:58 -0500 | [diff] [blame] | 31 | "internalURL": "http://fake_url/v2/first_endpoint/internal", |
| 32 | "publicURL": "http://fake_url/v2/first_endpoint/public" |
Mauro S. M. Rodrigues | c3e573c | 2014-02-19 07:59:29 -0500 | [diff] [blame] | 33 | }, |
| 34 | { |
Mauro S. M. Rodrigues | 4e23c45 | 2014-02-24 15:21:58 -0500 | [diff] [blame] | 35 | "adminURL": "http://fake_url/v2/second_endpoint/admin", |
Mauro S. M. Rodrigues | c3e573c | 2014-02-19 07:59:29 -0500 | [diff] [blame] | 36 | "region": "FakeRegion", |
Mauro S. M. Rodrigues | 4e23c45 | 2014-02-24 15:21:58 -0500 | [diff] [blame] | 37 | "internalURL": "http://fake_url/v2/second_endpoint/internal", |
| 38 | "publicURL": "http://fake_url/v2/second_endpoint/public" |
Mauro S. M. Rodrigues | c3e573c | 2014-02-19 07:59:29 -0500 | [diff] [blame] | 39 | }, |
| 40 | ], |
| 41 | "type": "compute", |
| 42 | "name": "nova" |
| 43 | } |
| 44 | |
| 45 | CATALOG_V2 = [COMPUTE_ENDPOINTS_V2, ] |
| 46 | |
| 47 | ALT_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 | |
| 63 | IDENTITY_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 |
| 80 | COMPUTE_ENDPOINTS_V3 = { |
| 81 | "endpoints": [ |
| 82 | { |
Mauro S. M. Rodrigues | 4e23c45 | 2014-02-24 15:21:58 -0500 | [diff] [blame] | 83 | "id": "first_compute_fake_service", |
Mauro S. M. Rodrigues | c3e573c | 2014-02-19 07:59:29 -0500 | [diff] [blame] | 84 | "interface": "public", |
| 85 | "region": "NoMatchRegion", |
Mauro S. M. Rodrigues | 4e23c45 | 2014-02-24 15:21:58 -0500 | [diff] [blame] | 86 | "url": "http://fake_url/v3/first_endpoint/api" |
Mauro S. M. Rodrigues | c3e573c | 2014-02-19 07:59:29 -0500 | [diff] [blame] | 87 | }, |
| 88 | { |
Mauro S. M. Rodrigues | 4e23c45 | 2014-02-24 15:21:58 -0500 | [diff] [blame] | 89 | "id": "second_fake_service", |
Mauro S. M. Rodrigues | c3e573c | 2014-02-19 07:59:29 -0500 | [diff] [blame] | 90 | "interface": "public", |
| 91 | "region": "FakeRegion", |
Mauro S. M. Rodrigues | 4e23c45 | 2014-02-24 15:21:58 -0500 | [diff] [blame] | 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" |
Mauro S. M. Rodrigues | c3e573c | 2014-02-19 07:59:29 -0500 | [diff] [blame] | 99 | } |
Mauro S. M. Rodrigues | 4e23c45 | 2014-02-24 15:21:58 -0500 | [diff] [blame] | 100 | |
Mauro S. M. Rodrigues | c3e573c | 2014-02-19 07:59:29 -0500 | [diff] [blame] | 101 | ], |
| 102 | "type": "compute", |
| 103 | "id": "fake_compute_endpoint" |
| 104 | } |
| 105 | |
| 106 | CATALOG_V3 = [COMPUTE_ENDPOINTS_V3, ] |
| 107 | |
| 108 | IDENTITY_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 Frittoli | b1b04bb | 2014-04-06 11:57:07 +0100 | [diff] [blame] | 117 | "id": "fake_domain_id", |
Mauro S. M. Rodrigues | c3e573c | 2014-02-19 07:59:29 -0500 | [diff] [blame] | 118 | "name": "fake" |
| 119 | }, |
| 120 | "id": "project_id", |
| 121 | "name": "project_name" |
| 122 | }, |
| 123 | "user": { |
| 124 | "domain": { |
Andrea Frittoli | b1b04bb | 2014-04-06 11:57:07 +0100 | [diff] [blame] | 125 | "id": "fake_domain_id", |
Mauro S. M. Rodrigues | c3e573c | 2014-02-19 07:59:29 -0500 | [diff] [blame] | 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 | |
| 136 | ALT_IDENTITY_V3 = IDENTITY_V3_RESPONSE |
| 137 | |
| 138 | |
| 139 | def _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 | |
| 149 | def _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 | |
| 155 | def _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) |