Skip to content

Commit

Permalink
Merge pull request openshift#365 from jtharris/bugs/BZ953049
Browse files Browse the repository at this point in the history
Merged by openshift-bot
  • Loading branch information
OpenShift Bot committed Apr 18, 2013
2 parents c26f363 + 67ccb96 commit 4195d9a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
6 changes: 6 additions & 0 deletions lib/rhc/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,10 @@ def initialize(min_version, current_version)
super "The server does not support this command (requires #{min_version}, found #{current_version})."
end
end

class InvalidURIException < Exception
def initialize(uri)
super "Invalid URI specified: #{uri}"
end
end
end
10 changes: 7 additions & 3 deletions lib/rhc/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,18 @@ def to_host(s)
s =~ %r(^http(?:s)?://) ? URI(s).host : s
end
def to_uri(s)
URI(s =~ %r(^http(?:s)?://) ? s : "https://#{s}")
begin
URI(s =~ %r(^http(?:s)?://) ? s : "https://#{s}")
rescue URI::InvalidURIError
raise RHC::InvalidURIException.new(s)
end
end
def openshift_rest_endpoint
uri = to_uri((options.server rescue nil) || ENV['LIBRA_SERVER'] || "openshift.redhat.com")
uri.path = '/broker/rest/api' if uri.path.blank? || uri.path == '/'
uri
end

def token_for_user
options.token or (token_store.get(options.rhlogin, options.server) if options.rhlogin)
end
Expand Down Expand Up @@ -338,7 +342,7 @@ def hosts_file_contains?(host)
end
end
end

def with_tolerant_encoding(&block)
# :nocov:
if RUBY_VERSION.to_f >= 1.9
Expand Down
21 changes: 13 additions & 8 deletions spec/rhc/commands/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,19 @@
end

context 'when API is at version 1.2' do
before do
before do
rest_client.stub(:api_version_negotiated).and_return('1.2')
end
it('should output an error') { run_output.should =~ /Connected to foo.com.*Using API version 1.2/m }
it { expect { run }.to exit_with_code(0) }
end
end

describe 'run against an invalid server url' do
let(:arguments) { ['server', '--server', 'invalid_uri', '-l', 'person', '-p', ''] }
it('should output an invalid URI error') { run_output.should match('Invalid URI specified: invalid_uri') }
end

describe 'run' do
let(:arguments) { ['server'] }
before{ rest_client.stub(:auth).and_return(nil) }
Expand All @@ -43,16 +48,16 @@

context 'when 1 issue' do
before do
stub_request(:get, 'https://openshift.redhat.com/app/status/status.json').with(&user_agent_header).to_return(:body =>
stub_request(:get, 'https://openshift.redhat.com/app/status/status.json').with(&user_agent_header).to_return(:body =>
{'open' => [
{'issue' => {
'created_at' => '2011-05-22T17:31:32-04:00',
'id' => 11,
'title' => 'Root cause',
{'issue' => {
'created_at' => '2011-05-22T17:31:32-04:00',
'id' => 11,
'title' => 'Root cause',
'updates' => [{
'created_at' => '2012-05-22T13:48:20-04:00',
'created_at' => '2012-05-22T13:48:20-04:00',
'description' => 'Working on update'
}]
}]
}}]}.to_json)
end
it { expect { run }.to exit_with_code(1) }
Expand Down

0 comments on commit 4195d9a

Please sign in to comment.