Skip to content

Commit

Permalink
add change password by name
Browse files Browse the repository at this point in the history
Change-Id: Ic9e565443e4eab84f55e2891e17ce55ca66bd1c6
  • Loading branch information
daleolds committed Mar 10, 2012
1 parent 3342b83 commit f0a8203
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
14 changes: 12 additions & 2 deletions gem/lib/uaa/user_account.rb
Expand Up @@ -86,11 +86,21 @@ def delete(user_id)
end

def delete_by_name(username)
qinfo = query_by_value(:id, :username, username)
delete user_id_from_name(username)
end

def change_password_by_name(username, new_password)
change_password(user_id_from_name(username), new_password)
end

private

def user_id_from_name(name)
qinfo = query_by_value(:id, :username, name)
unless qinfo && qinfo[:resources] && qinfo[:resources][0] && qinfo[:resources][0][:id]
raise NotFound, "user #{username} not found in #{@target}"
end
delete qinfo[:resources][0][:id]
qinfo[:resources][0][:id]
end

end
19 changes: 11 additions & 8 deletions gem/spec/integration_spec.rb
Expand Up @@ -14,9 +14,9 @@
require 'spec_helper'
require 'uaa'

ENV["UAA_CLIENT_ID"] = "scim"
ENV["UAA_CLIENT_SECRET"] = "scimsecret"
ENV["UAA_CLIENT_TARGET"] = "http://localhost:8080/uaa"
#ENV["UAA_CLIENT_ID"] = "scim"
#ENV["UAA_CLIENT_SECRET"] = "scimsecret"
#ENV["UAA_CLIENT_TARGET"] = "http://localhost:8080/uaa"

if ENV["UAA_CLIENT_ID"] && ENV["UAA_CLIENT_SECRET"] && ENV["UAA_CLIENT_TARGET"]

Expand Down Expand Up @@ -57,23 +57,26 @@
puts usr[:id]
end

it "finds the user" do
it "finds the user by name" do
user_info = @user_acct.query_by_value("id", "username", @username)
puts JSON.pretty_generate(user_info)
puts user_info
end

it "gets the user" do
it "gets the user by id" do
user_id = ENV["UAA_USER_ID"]
user_info = @user_acct.get(user_id)
puts JSON.pretty_generate(user_info)
puts user_info[:meta][:version]
end

it "changes the user's password by name" do
@user_acct.change_password_by_name(@username, "newpassword")
# TODO: query that the user is gone
end

it "deletes the user by name" do
user_id = ENV["UAA_USER_ID"]
puts user_id
@user_acct.delete(user_id)
@user_acct.delete_by_name(@username)
# TODO: query that the user is gone
end

Expand Down

0 comments on commit f0a8203

Please sign in to comment.