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

Commit

Permalink
Fix login_helpers to login v1 environment without UAA
Browse files Browse the repository at this point in the history
  • Loading branch information
jacopen committed Mar 23, 2013
1 parent 2340cb0 commit ccb1547
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 5 deletions.
18 changes: 15 additions & 3 deletions lib/cfoundry/concerns/login_helpers.rb
Expand Up @@ -3,11 +3,23 @@
module CFoundry
module LoginHelpers
def login_prompts
@base.uaa.prompts
if @base.uaa
@base.uaa.prompts
else
{
:username => ["text", "Email"],
:password => ["password", "Password"]
}
end
end

def login(username, password)
@base.token = AuthToken.from_uaa_token_info(@base.uaa.authorize(username, password))
@base.token =
if @base.uaa
AuthToken.from_uaa_token_info(@base.uaa.authorize(username, password))
else
AuthToken.new(@base.create_token({:password => password}, username)[:token])
end
end
end
end
end
4 changes: 3 additions & 1 deletion spec/cfoundry/v1/client_spec.rb
Expand Up @@ -9,9 +9,11 @@

describe "#login" do
include_examples "client login"
include_examples "client login without UAA"
end

describe "#login_prompts" do
include_examples "client login prompts"
include_examples "client login prompts without UAA"
end
end
end
40 changes: 39 additions & 1 deletion spec/support/shared_examples/client_login_examples.rb
Expand Up @@ -43,4 +43,42 @@
expect(client.token).to be_a(CFoundry::AuthToken)
expect(client.token.auth_header).to eq("bearer #{access_token}")
end
end
end

shared_examples_for 'client login prompts without UAA' do
let(:prompts) do
{
:user_id => ["text", "User ID"],
:pin => ["password", "Your 8-digit Pin #"]
}
end

subject { client.login_prompts }

it 'returns the prompts without UAA' do
expect(subject).to eq(prompts)
end
end

shared_examples_for 'client login without UAA' do
let(:email) { 'test@test.com' }
let(:password) { 'secret' }
let(:access_token) { "some-access-token" }

before do
stub(client.base).create_token { access_token }
end

subject { client.login(email, password) }

it 'returns a CC token' do
expect(subject).to be_a(CFoundry::AuthToken)
expect(subject.auth_header).to eq("bearer #{access_token}")
end

it 'saves the data as the token' do
subject
expect(client.token).to be_a(CFoundry::AuthToken)
expect(client.token.auth_header).to eq("bearer #{access_token}")
end
end

0 comments on commit ccb1547

Please sign in to comment.