diff --git a/lib/aviator/openstack/identity/v2/public/create_token.rb b/lib/aviator/openstack/identity/v2/public/create_token.rb index e2c26e9..befd665 100644 --- a/lib/aviator/openstack/identity/v2/public/create_token.rb +++ b/lib/aviator/openstack/identity/v2/public/create_token.rb @@ -7,8 +7,9 @@ define_request :create_token do http_method :post - required_param :username - required_param :password + optional_param :username + optional_param :password + optional_param :tokenId optional_param :tenantName optional_param :tenantId @@ -22,14 +23,24 @@ define_request :create_token do def body - p = { - auth: { - passwordCredentials: { - username: params[:username], - password: params[:password] - } - } - } + p = if params[:tokenId] + { + auth: { + token: { + id: params[:tokenId] + } + } + } + else + { + auth: { + passwordCredentials: { + username: params[:username], + password: params[:password] + } + } + } + end p[:auth][:tenantName] = params[:tenantName] if params[:tenantName] p[:auth][:tenantId] = params[:tenantId] if params[:tenantId] diff --git a/test/aviator/openstack/identity/v2/public/create_token_test.rb b/test/aviator/openstack/identity/v2/public/create_token_test.rb index b05efbc..60092be 100644 --- a/test/aviator/openstack/identity/v2/public/create_token_test.rb +++ b/test/aviator/openstack/identity/v2/public/create_token_test.rb @@ -40,12 +40,12 @@ class Aviator::Test it 'has the correct list of required parameters' do - klass.required_params.must_equal [:username, :password] + klass.required_params.must_equal [] end it 'has the correct list of optional parameters' do - klass.optional_params.must_equal [:tenantName, :tenantId] + klass.optional_params.must_equal [:username, :password, :tokenId, :tenantName, :tenantId] end @@ -94,6 +94,31 @@ class Aviator::Test end + it 'leads to a valid response when provided with a token' do + service = Aviator::Service.new( + provider: 'openstack', + service: 'identity', + default_session_data: RequestHelper.admin_bootstrap_session_data + ) + + response = service.request :create_token do |params| + params[:username] = Environment.openstack_admin[:auth_credentials][:username] + params[:password] = Environment.openstack_admin[:auth_credentials][:password] + end + + token = response.body[:access][:token][:id] + + response = service.request :create_token do |params| + params[:tokenId] = token + params[:tenantName] = Environment.openstack_admin[:auth_credentials][:tenantName] + end + + response.status.must_equal 200 + response.body.wont_be_nil + response.headers.wont_be_nil + end + + it 'leads to a valid response when provided with invalid params' do service = Aviator::Service.new( provider: 'openstack', diff --git a/test/cassettes/openstack/identity/v2/public/create_token/leads_to_a_valid_response_when_provided_with_a_token.yml b/test/cassettes/openstack/identity/v2/public/create_token/leads_to_a_valid_response_when_provided_with_a_token.yml new file mode 100644 index 0000000..53deace --- /dev/null +++ b/test/cassettes/openstack/identity/v2/public/create_token/leads_to_a_valid_response_when_provided_with_a_token.yml @@ -0,0 +1,98 @@ +--- +http_interactions: +- request: + method: post + uri: :5000/v2.0/tokens + body: + encoding: UTF-8 + string: ! '{"auth":{"passwordCredentials":{"username":"admin","password":""}}}' + headers: + Content-Type: + - application/json + User-Agent: + - Faraday v0.8.8 + response: + status: + code: 200 + message: + headers: + vary: + - X-Auth-Token + content-type: + - application/json + content-length: + - '329' + date: + - Wed, 28 Aug 2013 23:50:40 GMT + connection: + - close + body: + encoding: US-ASCII + string: ! '{"access": {"token": {"issued_at": "2013-08-28T23:50:40.142756", + "expires": "2013-08-29T23:50:40Z", "id": "7936a6fa365a47e5b165a5d15f667a32"}, + "serviceCatalog": [], "user": {"username": "admin", "roles_links": [], "id": + "cbbcc4f7aef6435fa2da7e5f0b2f1e97", "roles": [], "name": "admin"}, "metadata": + {"is_admin": 0, "roles": []}}}' + http_version: + recorded_at: Wed, 28 Aug 2013 23:48:15 GMT +- request: + method: post + uri: :5000/v2.0/tokens + body: + encoding: UTF-8 + string: ! '{"auth":{"token":{"id":"7936a6fa365a47e5b165a5d15f667a32"},"tenantName":"admin"}}' + headers: + Content-Type: + - application/json + User-Agent: + - Faraday v0.8.8 + response: + status: + code: 200 + message: + headers: + vary: + - X-Auth-Token + content-type: + - application/json + content-length: + - '2648' + date: + - Wed, 28 Aug 2013 23:50:40 GMT + connection: + - close + body: + encoding: US-ASCII + string: ! '{"access": {"token": {"issued_at": "2013-08-28T23:50:40.615438", + "expires": "2013-08-29T23:50:40Z", "id": "ebdd1c61693546208a273fc891e65c4b", + "tenant": {"description": null, "enabled": true, "id": "3cab25130620477b8b03f1bfa8741603", + "name": "admin"}}, "serviceCatalog": [{"endpoints": [{"adminURL": "http://192.168.56.11:8774/v2/3cab25130620477b8b03f1bfa8741603", + "region": "RegionOne", "internalURL": "http://192.168.56.11:8774/v2/3cab25130620477b8b03f1bfa8741603", + "id": "3b72a66bf2f0491bb8dba827cade0d48", "publicURL": "http://192.168.56.11:8774/v2/3cab25130620477b8b03f1bfa8741603"}], + "endpoints_links": [], "type": "compute", "name": "nova"}, {"endpoints": [{"adminURL": + "http://192.168.56.11:3333", "region": "RegionOne", "internalURL": "http://192.168.56.11:3333", + "id": "482f749b370c40eab8788d6d0bc47f48", "publicURL": "http://192.168.56.11:3333"}], + "endpoints_links": [], "type": "s3", "name": "s3"}, {"endpoints": [{"adminURL": + "http://192.168.56.11:9292", "region": "RegionOne", "internalURL": "http://192.168.56.11:9292", + "id": "0cd5d5d5a0c24721a0392b47c89e3640", "publicURL": "http://192.168.56.11:9292"}], + "endpoints_links": [], "type": "image", "name": "glance"}, {"endpoints": [{"adminURL": + "http://192.168.56.11:8777", "region": "RegionOne", "internalURL": "http://192.168.56.11:8777", + "id": "4eb4edec1d2647bfb8ba4f9a5757169d", "publicURL": "http://192.168.56.11:8777"}], + "endpoints_links": [], "type": "metering", "name": "ceilometer"}, {"endpoints": + [{"adminURL": "http://192.168.56.11:8776/v1/3cab25130620477b8b03f1bfa8741603", + "region": "RegionOne", "internalURL": "http://192.168.56.11:8776/v1/3cab25130620477b8b03f1bfa8741603", + "id": "009e8a41953d439f845b2a0c0dc28b73", "publicURL": "http://192.168.56.11:8776/v1/3cab25130620477b8b03f1bfa8741603"}], + "endpoints_links": [], "type": "volume", "name": "cinder"}, {"endpoints": + [{"adminURL": "http://192.168.56.11:8773/services/Admin", "region": "RegionOne", + "internalURL": "http://192.168.56.11:8773/services/Cloud", "id": "6820836ec6834548bf7b54da0271dded", + "publicURL": "http://192.168.56.11:8773/services/Cloud"}], "endpoints_links": + [], "type": "ec2", "name": "ec2"}, {"endpoints": [{"adminURL": "http://192.168.56.11:35357/v2.0", + "region": "RegionOne", "internalURL": "http://192.168.56.11:5000/v2.0", "id": + "24a95f51f67949e784971e97463ee4d8", "publicURL": "http://192.168.56.11:5000/v2.0"}], + "endpoints_links": [], "type": "identity", "name": "keystone"}], "user": {"username": + "admin", "roles_links": [], "id": "cbbcc4f7aef6435fa2da7e5f0b2f1e97", "roles": + [{"name": "admin"}], "name": "admin"}, "metadata": {"is_admin": 0, "roles": + ["01a81f2dbb3441f1aaa8fe68a7c6f546"]}}}' + http_version: + recorded_at: Wed, 28 Aug 2013 23:48:15 GMT +recorded_with: VCR 2.5.0