Skip to content

Commit

Permalink
print path when Not Authorized
Browse files Browse the repository at this point in the history
Signed-off-by: Maria Shaldibina <mshaldibina@pivotal.io>
  • Loading branch information
medvedzver committed Jun 25, 2015
1 parent b6eab67 commit 4b2ac07
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions bosh-director/lib/bosh/director/api/extensions/scoping.rb
Expand Up @@ -37,9 +37,9 @@ def scope(allowed_scope)
if requires_authentication? && (@user.nil? || !identity_provider.valid_access?(@user, scope))
response['WWW-Authenticate'] = 'Basic realm="BOSH Director"'
if @user.nil?
message = "Not authorized\n"
message = "Not authorized: '#{request.path}'\n"
else
message = "Not authorized: #{request.path} requires one of the scopes: #{identity_provider.required_scopes(scope).join(", ")}\n"
message = "Not authorized: '#{request.path}' requires one of the scopes: #{identity_provider.required_scopes(scope).join(", ")}\n"
end
throw(:halt, [401, message])
end
Expand Down
6 changes: 3 additions & 3 deletions bosh-director/spec/unit/api/extensions/scoping_spec.rb
Expand Up @@ -45,7 +45,7 @@ module Api
it 'returns a detailed error message' do
get '/test_route'
expect(last_response.status).to eq(401)
expect(last_response.body).to include("Not authorized: /test_route requires one of the scopes: fake-valid-scope-1, fake-valid-scope-2")
expect(last_response.body).to include("Not authorized: '/test_route' requires one of the scopes: fake-valid-scope-1, fake-valid-scope-2")
end

context 'when identity provider is not UAA' do
Expand All @@ -54,7 +54,7 @@ module Api
it 'return generic error messsage' do
get '/test_route'
expect(last_response.status).to eq(401)
expect(last_response.body).to eq("Not authorized\n")
expect(last_response.body).to eq("Not authorized: '/test_route'\n")
end
end
end
Expand Down Expand Up @@ -85,7 +85,7 @@ def requires_authentication?
it 'returns non-authorized' do
get '/read'
expect(last_response.status).to eq(401)
expect(last_response.body).to include("Not authorized\n")
expect(last_response.body).to include("Not authorized: '/read'\n")
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions spec/integration/uaa/login_spec.rb
Expand Up @@ -114,7 +114,7 @@
it 'can only access read resources' do
client_env = {'BOSH_CLIENT' => 'read-access', 'BOSH_CLIENT_SECRET' => 'secret'}
output = deploy_from_scratch(no_login: true, env: client_env, failure_expected: true)
expect(output).to include('Not authorized: /deployments requires one of the scopes: bosh.admin, bosh.deadbeef.admin')
expect(output).to include(`Not authorized: '/deployments' requires one of the scopes: bosh.admin, bosh.deadbeef.admin`)

output = bosh_runner.run('deployments', env: client_env, failure_expected: true)
expect(output).to match /No deployments/
Expand All @@ -129,10 +129,10 @@
expect(output).to match /release has been created/

output = bosh_runner.run('task latest --debug', env: read_client_env, failure_expected: true)
expect(output).to match /Not authorized: \/tasks\/[0-9]+\/output requires one of the scopes: bosh.admin, bosh.deadbeef.admin/
expect(output).to match /Not authorized: '\/tasks\/[0-9]+\/output' requires one of the scopes: bosh.admin, bosh.deadbeef.admin/

output = bosh_runner.run('task latest --cpi', env: read_client_env, failure_expected: true)
expect(output).to match /Not authorized: \/tasks\/[0-9]+\/output requires one of the scopes: bosh.admin, bosh.deadbeef.admin/
expect(output).to match /Not authorized: '\/tasks\/[0-9]+\/output' requires one of the scopes: bosh.admin, bosh.deadbeef.admin/

output = bosh_runner.run('task latest --debug', env: admin_client_env)
expect(output).to match /DEBUG/
Expand All @@ -150,7 +150,7 @@

# AuthError because verification is happening on director side
output = bosh_runner.run('vms', env: client_env, failure_expected: true)
expect(output).to include('Not authorized: /deployments requires one of the scopes: bosh.admin, bosh.deadbeef.admin, bosh.read, bosh.deadbeef.read')
expect(output).to include(`Not authorized: '/deployments' requires one of the scopes: bosh.admin, bosh.deadbeef.admin, bosh.read, bosh.deadbeef.read`)
end
end

Expand Down

0 comments on commit 4b2ac07

Please sign in to comment.