Skip to content
This repository has been archived by the owner on Jan 25, 2022. It is now read-only.

Commit

Permalink
Added test case for missing name field breaking UAA retrieval, also u…
Browse files Browse the repository at this point in the history
…sed a conditional block for clearer visibility
  • Loading branch information
jamesrf committed Feb 10, 2014
1 parent e9c824a commit 0362ecc
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/cfoundry/v2/user.rb
Expand Up @@ -83,10 +83,13 @@ def get_meta_from_uaa
return if not user[:error].nil?

@emails = user[:emails]
return if user[:name].nil?
@name ||= {}
@name[:familyName] = user[:name][:familyname]
@name[:givenName] = user[:name][:givenname]

if not user[:name].nil?
@name ||= {}
@name[:familyName] = user[:name][:familyname]
@name[:givenName] = user[:name][:givenname]
end

end

end
Expand Down
74 changes: 74 additions & 0 deletions spec/cfoundry/v2/user_spec.rb
Expand Up @@ -200,6 +200,80 @@ module V2
subject.family_name.should == nil
end

it "should not fail to retrieve metadata from the UAA if name field is missing" do
stub_request(:get, /#{uaa_target}\/Users\/user-guid-\d{1,2}/).to_return :status => 200,
:headers => {'Content-Type' => 'application/json'},
:body => <<EOF
{
"id": "00000000-0000-0000-0000-000000000000",
"meta": {
"version": 0,
"created": "2013-06-24T13:44:38.000Z",
"lastModified": "2013-06-24T13:44:38.000Z"
},
"userName": "#{user_email}",
"emails": [
{
"value": "#{user_email}"
}
],
"groups": [
{
"value": "00000000-0000-0000-0000-000000000000",
"display": "password.write",
"type": "DIRECT"
},
{
"value": "00000000-0000-0000-0000-000000000000",
"display": "openid",
"type": "DIRECT"
},
{
"value": "00000000-0000-0000-0000-000000000000",
"display": "uaa.user",
"type": "DIRECT"
},
{
"value": "00000000-0000-0000-0000-000000000000",
"display": "scim.userids",
"type": "DIRECT"
},
{
"value": "00000000-0000-0000-0000-000000000000",
"display": "approvals.me",
"type": "DIRECT"
},
{
"value": "00000000-0000-0000-0000-000000000000",
"display": "cloud_controller.write",
"type": "DIRECT"
},
{
"value": "00000000-0000-0000-0000-000000000000",
"display": "scim.me",
"type": "DIRECT"
},
{
"value": "00000000-0000-0000-0000-000000000000",
"display": "cloud_controller.read",
"type": "DIRECT"
}
],
"approvals": [
],
"active": true,
"schemas": [
"urn:scim:schemas:core:1.0"
]
}
EOF
subject.email.should == user_email
subject.given_name.should == nil
subject.family_name.should == nil
subject.full_name.should == nil
end

end
end
end
Expand Down

0 comments on commit 0362ecc

Please sign in to comment.