Skip to content
This repository has been archived by the owner on Aug 29, 2018. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #375 from smarterclayton/bug_959144_respect_disabl…
…e_authorization_tokens_in_setup

Merged by openshift-bot
  • Loading branch information
OpenShift Bot committed May 3, 2013
2 parents 7e0d407 + 24ec69b commit 0e9bc8d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/rhc/helpers.rb
Expand Up @@ -163,7 +163,7 @@ def openshift_rest_endpoint
end

def token_for_user
options.token or (token_store.get(options.rhlogin, options.server) if options.rhlogin)
options.token or (token_store.get(options.rhlogin, options.server) if options.rhlogin && options.use_authorization_tokens)
end

def client_from_options(opts)
Expand Down
2 changes: 2 additions & 0 deletions spec/rhc/auth_spec.rb
Expand Up @@ -422,6 +422,8 @@
before{ subject.put('foo', 'bar', 'token') }
it("can be retrieved"){ subject.get('foo', 'bar').should == 'token' }
end

it("should handle missing files"){ subject.get('foo', 'other').should be_nil }
it("should put a file on disk"){ expect{ subject.put('test', 'server', 'value') }.to change{ Dir.entries(dir).length }.by(1) }

describe "#clear" do
Expand Down
1 change: 1 addition & 0 deletions spec/rhc/command_spec.rb
Expand Up @@ -306,6 +306,7 @@ def context_var

context "when tokens are not allowed" do
it("calls the server") { rest_client.send(:auth).is_a? RHC::Auth::Basic }
it("does not have a token set") { command_for(*arguments).send(:token_for_user).should be_nil }
end

context "when tokens are allowed" do
Expand Down
21 changes: 19 additions & 2 deletions spec/rhc/wizard_spec.rb
Expand Up @@ -175,6 +175,23 @@ def expect_raise_from_api(error)
options.insecure.should be_false
end

context "when the config has enabled tokens" do
let(:default_options){ {:rhlogin => user, :password => password, :server => server, :use_authorization_tokens => true} }
let(:store){ mock }
before{ RHC::Auth::TokenStore.should_receive(:new).any_number_of_times.and_return(store) }
before{ expect_client_test(true) }

it "should check for an existing token" do
store.should_receive(:get).and_return(nil)

subject.should_receive(:info).with(/OpenShift can create and store a token on disk/).ordered
subject.should_receive(:agree).with(/Generate a token now?/).ordered.and_return(false)

subject.send(:login_stage).should be_true
options.token.should be_nil
end
end

context "with a server that supports tokens" do
before{ expect_client_test(true) }
let(:token){ 'a_test_value' }
Expand All @@ -183,7 +200,7 @@ def expect_raise_from_api(error)
before{ RHC::Auth::TokenStore.should_receive(:new).any_number_of_times.and_return(store) }

it "should not generate a token if the user does not request it" do
store.should_receive(:get).and_return(nil)
store.should_not_receive(:get)
subject.should_receive(:info).with(/OpenShift can create and store a token on disk/).ordered
subject.should_receive(:agree).with(/Generate a token now?/).ordered.and_return(false)

Expand All @@ -192,7 +209,7 @@ def expect_raise_from_api(error)
end

it "should generate a token if the user requests it" do
store.should_receive(:get).and_return(nil)
store.should_not_receive(:get)
subject.should_receive(:info).with(/OpenShift can create and store a token on disk/).ordered
subject.should_receive(:agree).with(/Generate a token now?/).ordered.and_return(true)
subject.should_receive(:say).with(/Generating an authorization token for this client /).ordered
Expand Down

0 comments on commit 0e9bc8d

Please sign in to comment.