Skip to content

Commit

Permalink
remove ambiguous short option in change secret cmd
Browse files Browse the repository at this point in the history
[fixes #43430491]

Change-Id: Iefa3ecb8b4772520280f478d6ea9df80c3c74146
  • Loading branch information
daleolds committed Jan 30, 2013
1 parent 21b9484 commit b6c7a90
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/cli/client_reg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def client_info(defaults)
}
end

define_option :old_secret, "-o", "--old_secret <secret>", "current secret"
define_option :old_secret, "--old_secret <secret>", "current secret"
desc "secret change", "Change secret for authenticated client in current context", :old_secret, :secret do
return gripe "context not set" unless client_id = Config.context.to_s
scim_request { |cr|
Expand Down
2 changes: 1 addition & 1 deletion lib/cli/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
# Cloud Foundry namespace
module CF
module UAA
CLI_VERSION = "1.3.7"
CLI_VERSION = "1.3.8"
end
end
7 changes: 4 additions & 3 deletions lib/stub/uaa.rb
Original file line number Diff line number Diff line change
Expand Up @@ -366,15 +366,16 @@ def scim_to_client(info)

route :put, %r{^/oauth/clients/([^/]+)/secret$}, "content-type" => %r{application/json} do
info = Util.json_parse(request.body, :down)
return not_found(match[1]) unless id = server.scim.id(match[1], :client)
return bad_request("no new secret given") unless info['secret']
if oldsecret = info['oldsecret']
return unless valid_token("clients.secret")
return not_found(match[1]) unless client = server.scim.get(match[1], :client, :client_secret)
return not_found(match[1]) unless client = server.scim.get(id, :client, :client_secret)
return bad_request("old secret does not match") unless oldsecret == client[:client_secret]
else
return unless valid_token("uaa.admin")
end
return bad_request("no new secret given") unless info['secret']
server.scim.set_hidden_attr(match[1], :client_secret, info['secret'])
server.scim.set_hidden_attr(id, :client_secret, info['secret'])
reply.json(status: "ok", message: "secret updated")
end

Expand Down
11 changes: 10 additions & 1 deletion spec/client_reg_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module CF::UAA
before :all do
#Util.default_logger(:trace)
Cli.configure("", nil, StringIO.new, true)
setup_target(authorities: "scim.read", grant_types: "client_credentials")
setup_target(authorities: "scim.read,clients.secret", grant_types: "client_credentials")
@test_user, @test_pwd = "sam_#{Time.now.to_i}", "correcthorsebatterystaple"
end

Expand Down Expand Up @@ -54,6 +54,15 @@ module CF::UAA
Cli.output.string.should include "access_token", @test_client
end

it "changes it's client secret" do
Cli.run("token client get #{@test_client} -s #{@test_secret}").should be
Cli.run("token decode").should be
Cli.run("secret change --old_secret #{@test_secret} --secret newclientsecret").should be
Cli.run("token client get #{@test_client} -s newclientsecret").should be
Cli.run("secret change --old_secret newclientsecret -s #{@test_secret}").should be
Cli.run("token client get #{@test_client} -s #{@test_secret}").should be
end

it "fails to create a user account as test client" do
Cli.run("user add #{@test_user} -p #{@test_pwd}").should be_nil
Cli.output.string.should include "access_denied"
Expand Down
4 changes: 3 additions & 1 deletion spec/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ module CF::UAA

it "changes a user's password" do
Cli.run("token get #{@test_user} #{@test_pwd}").should be
Cli.run("password change -p newpwd --old_password #{@test_pwd}").should be
Cli.run("password change --password newpwd --old_password #{@test_pwd}").should be
Cli.run("token get #{@test_user} newpwd").should be
Cli.run("password change -p #{@test_pwd} -o newpwd").should be
Cli.run("token get #{@test_user} #{@test_pwd}").should be
Cli.output.string.should include "Successfully fetched token"
end

Expand Down

0 comments on commit b6c7a90

Please sign in to comment.