Skip to content

Commit

Permalink
Update keystone_spec
Browse files Browse the repository at this point in the history
Add app_cred_id and app_cred_secret
Add keystone_request_body_app_cred
Add context with good application credentials
Add context with wrong application credentials
  • Loading branch information
diedpigs committed Jun 18, 2019
1 parent d65b254 commit 339bd1e
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions source/spec/vagrant-openstack-provider/client/keystone_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
config.stub(:project_name) { 'testTenant' }
config.stub(:ssl_ca_file) { nil }
config.stub(:ssl_verify_peer) { true }
config.stub(:app_cred_id) { 'dummy' }
config.stub(:app_cred_secret) { 'dummy' }
end
end

Expand Down Expand Up @@ -81,6 +83,10 @@
]}}'
end

let(:keystone_request_body_app_cred) do
'{"auth":{"identity":{"methods":["application_credential"],"application_credential":{"id":"dummy","secret":"dummy"}}}}'
end

before :each do
@keystone_client = VagrantPlugins::Openstack.keystone
end
Expand Down Expand Up @@ -183,6 +189,7 @@
config.stub(:project_domain_name) { 'dummy' }
config.stub(:identity_api_version) { '3' }
config.stub(:openstack_auth_url) { 'http://keystoneAuthV3' }
config.stub(:openstack_auth_type) { nil }

stub_request(:post, 'http://keystoneAuthV3/auth/tokens')
.with(
Expand All @@ -206,6 +213,7 @@
config.stub(:project_domain_name) { 'dummy' }
config.stub(:identity_api_version) { '3' }
config.stub(:openstack_auth_url) { 'http://keystoneAuthV3' }
config.stub(:openstack_auth_type) { nil }

stub_request(:post, 'http://keystoneAuthV3/auth/tokens')
.with(
Expand All @@ -225,5 +233,53 @@
expect { @keystone_client.authenticate(env) }.to raise_error(Errors::AuthenticationFailed)
end
end

context 'with good application credentials' do
it 'store token and tenant id' do
config.stub(:identity_api_version) { '3' }
config.stub(:openstack_auth_url) { 'http://keystoneAuthV3' }
config.stub(:openstack_auth_type) { 'v3applicationcredential' }

stub_request(:post, 'http://keystoneAuthV3/auth/tokens')
.with(
body: keystone_request_body_app_cred,
headers: keystone_request_headers)
.to_return(
status: 200,
body: keystone_response_body_v3,
headers: keystone_response_headers_v3)

@keystone_client.authenticate(env)

session.token.should eq('0123456789')
session.project_id.should eq('012345678910')
end
end

context 'with wrong application credentials' do
it 'raise an unauthorized error ' do
config.stub(:identity_api_version) { '3' }
config.stub(:openstack_auth_url) { 'http://keystoneAuthV3' }
config.stub(:openstack_auth_type) { nil }
config.stub(:openstack_auth_type) { 'v3applicationcredential' }

stub_request(:post, 'http://keystoneAuthV3/auth/tokens')
.with(
body: keystone_request_body_app_cred,
headers: keystone_request_headers)
.to_return(
status: 404,
body: '{
"error": {
"message": "Could not find Application Credential: dummy",
"code": 404,
"title": "Not Found"
}
}',
headers: keystone_response_headers_v3)

expect { @keystone_client.authenticate(env) }.to raise_error(Errors::BadAuthenticationEndpoint)
end
end
end
end

0 comments on commit 339bd1e

Please sign in to comment.