Skip to content

Commit

Permalink
Merge changes I96ff626e,I0710bd12
Browse files Browse the repository at this point in the history
* changes:
  Gracefully fail for old cli config file
  work around CFID-270, location header changed by CF
  • Loading branch information
daleolds authored and Gerrit Code Review committed Aug 3, 2012
2 parents 68b5a0b + 1e386b6 commit e7929a6
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
1 change: 0 additions & 1 deletion gem/lib/cli/common.rb
Expand Up @@ -11,7 +11,6 @@
# subcomponent's license, as noted in the LICENSE file.
#++

require 'open-uri'
require 'cli/base'
require 'cli/config'

Expand Down
8 changes: 8 additions & 0 deletions gem/lib/cli/config.rb
Expand Up @@ -37,6 +37,14 @@ def self.load(config = nil)
@config_file = nil
elsif File.exists?(@config_file = config)
@config = YAML.load_file(@config_file)
@config.each { |k, v|
next unless k.to_s =~ / /
STDERR.puts "", "Invalid config file #{@config_file}.",
"If it's from an old version of uaac, please remove it.",
"Note that the uaac command structure has changed.",
"Please review the new commands with 'uaac help'", ""
exit 1
}
end
@config = Util.hash_keys(@config, :tosym)
@context = current_subhash(@config[@target][:contexts]) if @target = current_subhash(@config)
Expand Down
20 changes: 17 additions & 3 deletions gem/lib/uaa/token_issuer.rb
Expand Up @@ -70,9 +70,23 @@ def implicit_grant_with_creds(credentials, scope = nil)

status, body, headers = request(:post, uri, body, headers)
raise BadResponse, "status #{status}" unless status == 302
loc = headers[:location].split('#')
raise BadResponse, "bad location header" unless loc.length == 2 && URI.parse(loc[0]) == URI.parse(redir_uri)
parse_implicit_params loc[1], state
req_uri, reply_uri = URI.parse(redir_uri), URI.parse(headers[:location])
fragment, reply_uri.fragment = reply_uri.fragment, nil
return parse_implicit_params(fragment, state) if req_uri == reply_uri

# work around bug when uaa is behind proxy that rewrites location header
if reply_uri.scheme == "https"
reply_uri.scheme = "http"
if req_uri == URI.parse(reply_uri.to_s)
logger.warn("Scheme of location URL in reply is different than requested")
return parse_implicit_params(fragment, state)
end
puts req_uri.inspect, reply_uri.inspect
end

raise BadResponse, "bad location header"
rescue URI::Error => e
raise BadResponse, "bad location header in reply: #{e.message}"
end

# constructs a uri that the client is to return to the browser to direct
Expand Down
2 changes: 1 addition & 1 deletion gem/lib/uaa/util.rb
Expand Up @@ -13,7 +13,7 @@

require 'yajl/json_gem'
require 'logger'
require 'open-uri'
require 'uri'

module CF; module UAA end end

Expand Down

0 comments on commit e7929a6

Please sign in to comment.