cf-uaac 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/cf-uaac.gemspec +2 -0
- data/lib/cli/base.rb +3 -1
- data/lib/cli/common.rb +1 -1
- data/lib/cli/curl.rb +83 -0
- data/lib/cli/runner.rb +2 -1
- data/lib/cli/token.rb +21 -16
- data/lib/cli/version.rb +1 -1
- data/lib/stub/server.rb +3 -1
- data/lib/stub/uaa.rb +15 -2
- data/spec/client_reg_spec.rb +11 -2
- data/spec/curl_spec.rb +94 -0
- data/spec/token_spec.rb +12 -0
- metadata +118 -29
    
        data/.gitignore
    CHANGED
    
    
    
        data/cf-uaac.gemspec
    CHANGED
    
    | @@ -26,6 +26,7 @@ Gem::Specification.new do |s| | |
| 26 26 |  | 
| 27 27 | 
             
              s.rubyforge_project = "cf-uaac"
         | 
| 28 28 |  | 
| 29 | 
            +
              s.license       = "Apache 2.0"
         | 
| 29 30 | 
             
              s.files         = `git ls-files`.split("\n")
         | 
| 30 31 | 
             
              s.test_files    = `git ls-files -- {test,spec,features}/*`.split("\n")
         | 
| 31 32 | 
             
              s.executables   = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
         | 
| @@ -34,6 +35,7 @@ Gem::Specification.new do |s| | |
| 34 35 | 
             
              # dependencies
         | 
| 35 36 | 
             
              s.add_development_dependency "bundler"
         | 
| 36 37 | 
             
              s.add_development_dependency "rake"
         | 
| 38 | 
            +
              s.add_development_dependency "rack"
         | 
| 37 39 | 
             
              s.add_development_dependency "rspec"
         | 
| 38 40 | 
             
              s.add_development_dependency "simplecov"
         | 
| 39 41 | 
             
              s.add_development_dependency "simplecov-rcov"
         | 
    
        data/lib/cli/base.rb
    CHANGED
    
    | @@ -244,7 +244,9 @@ class BaseCli | |
| 244 244 | 
             
                @option_defs, @parser, orig = {}, OptionParser.new, args
         | 
| 245 245 | 
             
                opts = @topics.each_with_object({}) do |tpc, o|
         | 
| 246 246 | 
             
                  tpc.option_defs.each do |k, optdef|
         | 
| 247 | 
            -
                    @parser.on(*optdef)  | 
| 247 | 
            +
                    @parser.on(*optdef) do |v|
         | 
| 248 | 
            +
                      o[k] = (o[k] ? Array(o[k]).push(v) : v )
         | 
| 249 | 
            +
                    end
         | 
| 248 250 | 
             
                    @option_defs[k] = optdef
         | 
| 249 251 | 
             
                  end
         | 
| 250 252 | 
             
                end
         | 
    
        data/lib/cli/common.rb
    CHANGED
    
    
    
        data/lib/cli/curl.rb
    ADDED
    
    | @@ -0,0 +1,83 @@ | |
| 1 | 
            +
            require 'cli/common'
         | 
| 2 | 
            +
            require 'rack'
         | 
| 3 | 
            +
            require 'net/http'
         | 
| 4 | 
            +
            require 'uaa/http'
         | 
| 5 | 
            +
            require 'json'
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            module CF::UAA
         | 
| 8 | 
            +
              class CurlCli < CommonCli
         | 
| 9 | 
            +
                include Http
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                topic "CURL"
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                define_option :request, "-X", "--request <method>", "request method type, defaults to GET"
         | 
| 14 | 
            +
                define_option :data, "-d", "--data <data>", "data included in request body"
         | 
| 15 | 
            +
                define_option :header, "-H", "--header <header>", "header to be included in the request"
         | 
| 16 | 
            +
                define_option :insecure, "-k", "--insecure", "makes request without verifying SSL certificates"
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                desc "curl [path]", "CURL to a UAA endpoint", :request, :data, :header, :insecure do |path|
         | 
| 19 | 
            +
                  return say_command_help(["curl"]) unless path
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                  uri = parse_uri(path)
         | 
| 22 | 
            +
                  opts[:request] ||= "GET"
         | 
| 23 | 
            +
                  print_request(opts[:request], uri, opts[:data], opts[:header])
         | 
| 24 | 
            +
                  response = make_request(uri, opts)
         | 
| 25 | 
            +
                  print_response(response)
         | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                def parse_uri(path)
         | 
| 29 | 
            +
                  uri = URI.parse(path)
         | 
| 30 | 
            +
                  unless uri.host
         | 
| 31 | 
            +
                    uri = URI.parse("#{Config.target}#{path}")
         | 
| 32 | 
            +
                  end
         | 
| 33 | 
            +
                  uri
         | 
| 34 | 
            +
                end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                def print_request(request, uri, data, header)
         | 
| 37 | 
            +
                  say "#{request} #{uri.to_s}"
         | 
| 38 | 
            +
                  say "REQUEST BODY: \"#{data}\"" if data
         | 
| 39 | 
            +
                  if header
         | 
| 40 | 
            +
                    say "REQUEST HEADERS:"
         | 
| 41 | 
            +
                    Array(header).each do |h|
         | 
| 42 | 
            +
                      say "  #{h}"
         | 
| 43 | 
            +
                    end
         | 
| 44 | 
            +
                  end
         | 
| 45 | 
            +
                  say ""
         | 
| 46 | 
            +
                end
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                def make_request(uri, options)
         | 
| 49 | 
            +
                  http = Net::HTTP.new(uri.host, uri.port)
         | 
| 50 | 
            +
                  if uri.scheme == "https"
         | 
| 51 | 
            +
                    http.use_ssl = true
         | 
| 52 | 
            +
                    if options[:insecure]
         | 
| 53 | 
            +
                      http.verify_mode = OpenSSL::SSL::VERIFY_NONE
         | 
| 54 | 
            +
                    end
         | 
| 55 | 
            +
                  end
         | 
| 56 | 
            +
                  request_class = Net::HTTP.const_get("#{options[:request][0]}#{options[:request][1..-1].downcase}")
         | 
| 57 | 
            +
                  req = request_class.new(uri.request_uri)
         | 
| 58 | 
            +
                  req["Authorization"] = "Bearer #{Config.value(:access_token)}"
         | 
| 59 | 
            +
                  Array(options[:header]).each do |h|
         | 
| 60 | 
            +
                    key, value = h.split(":")
         | 
| 61 | 
            +
                    req[key] = value
         | 
| 62 | 
            +
                  end
         | 
| 63 | 
            +
                  http.request(req, options[:data])
         | 
| 64 | 
            +
                end
         | 
| 65 | 
            +
             | 
| 66 | 
            +
                def print_response(response)
         | 
| 67 | 
            +
                  say "#{response.code} #{response.message}"
         | 
| 68 | 
            +
                  say "RESPONSE HEADERS:"
         | 
| 69 | 
            +
                  response.each_capitalized do |key, value|
         | 
| 70 | 
            +
                    say "  #{key}: #{value}"
         | 
| 71 | 
            +
                  end
         | 
| 72 | 
            +
             | 
| 73 | 
            +
                  say "RESPONSE BODY:"
         | 
| 74 | 
            +
                  if response['Content-Type'].include?('application/json')
         | 
| 75 | 
            +
                    parsed = JSON.parse(response.body)
         | 
| 76 | 
            +
                    formatted = JSON.pretty_generate(parsed)
         | 
| 77 | 
            +
                    say formatted
         | 
| 78 | 
            +
                  else
         | 
| 79 | 
            +
                    say response.body
         | 
| 80 | 
            +
                  end
         | 
| 81 | 
            +
                end
         | 
| 82 | 
            +
              end
         | 
| 83 | 
            +
            end
         | 
    
        data/lib/cli/runner.rb
    CHANGED
    
    | @@ -17,12 +17,13 @@ require 'cli/user' | |
| 17 17 | 
             
            require 'cli/group'
         | 
| 18 18 | 
             
            require 'cli/info'
         | 
| 19 19 | 
             
            require 'cli/client_reg'
         | 
| 20 | 
            +
            require 'cli/curl'
         | 
| 20 21 |  | 
| 21 22 | 
             
            module CF::UAA
         | 
| 22 23 |  | 
| 23 24 | 
             
            class Cli < BaseCli
         | 
| 24 25 | 
             
              @overview = "UAA Command Line Interface"
         | 
| 25 | 
            -
              @topics = [MiscCli, InfoCli, TokenCli, UserCli, GroupCli, ClientCli]
         | 
| 26 | 
            +
              @topics = [MiscCli, InfoCli, TokenCli, UserCli, GroupCli, ClientCli, CurlCli]
         | 
| 26 27 | 
             
              @global_options = [:help, :version, :debug, :trace, :config]
         | 
| 27 28 |  | 
| 28 29 | 
             
              def self.configure(config_file = "", input = $stdin, output = $stdout,
         | 
    
        data/lib/cli/token.rb
    CHANGED
    
    | @@ -73,9 +73,14 @@ class TokenCli < CommonCli | |
| 73 73 | 
             
                return gripe "attempt to get token failed\n" unless token_info && token_info["access_token"]
         | 
| 74 74 | 
             
                contents = TokenCoder.decode(token_info["access_token"], verify: false)
         | 
| 75 75 | 
             
                Config.context = contents["user_name"] || contents["client_id"] || "bad_token"
         | 
| 76 | 
            -
                 | 
| 77 | 
            -
                Config.add_opts( | 
| 78 | 
            -
                Config.add_opts  | 
| 76 | 
            +
                did_save = true
         | 
| 77 | 
            +
                (did_save &= Config.add_opts(user_id: contents["user_id"])) if contents["user_id"]
         | 
| 78 | 
            +
                (did_save &= Config.add_opts(client_id: contents["client_id"])) if contents["client_id"]
         | 
| 79 | 
            +
                jti = token_info.delete("jti") if token_info.has_key? "jti"
         | 
| 80 | 
            +
                did_save &= Config.add_opts token_info
         | 
| 81 | 
            +
                (did_save &= Config.add_opts(scope: contents["scope"])) if contents["scope"]
         | 
| 82 | 
            +
                (did_save &= Config.add_opts(jti: jti)) if jti
         | 
| 83 | 
            +
                did_save
         | 
| 79 84 | 
             
              end
         | 
| 80 85 |  | 
| 81 86 | 
             
              def issuer_request(client_id, secret = nil)
         | 
| @@ -91,7 +96,7 @@ class TokenCli < CommonCli | |
| 91 96 | 
             
              desc "token get [credentials...]",
         | 
| 92 97 | 
             
                  "Gets a token by posting user credentials with an implicit grant request",
         | 
| 93 98 | 
             
                  :client, :scope do |*args|
         | 
| 94 | 
            -
                client_name = opts[:client] || " | 
| 99 | 
            +
                client_name = opts[:client] || "cf"
         | 
| 95 100 | 
             
                reply = issuer_request(client_name, "") { |ti|
         | 
| 96 101 | 
             
                  prompts = ti.prompts
         | 
| 97 102 | 
             
                  creds = {}
         | 
| @@ -135,8 +140,8 @@ class TokenCli < CommonCli | |
| 135 140 | 
             
                say_success "refresh" if set_context(reply)
         | 
| 136 141 | 
             
              end
         | 
| 137 142 |  | 
| 138 | 
            -
               | 
| 139 | 
            -
               | 
| 143 | 
            +
              CF_TOKEN_FILE = File.join ENV["HOME"], ".cf_token"
         | 
| 144 | 
            +
              CF_TARGET_FILE = File.join ENV["HOME"], ".cf_target"
         | 
| 140 145 |  | 
| 141 146 | 
             
              def use_browser(client_id, secret = nil)
         | 
| 142 147 | 
             
                catcher = Stub::Server.new(TokenCatcher,
         | 
| @@ -156,26 +161,26 @@ class TokenCli < CommonCli | |
| 156 161 | 
             
                  print "."
         | 
| 157 162 | 
             
                end
         | 
| 158 163 | 
             
                say_success(secret ? "authorization code" : "implicit") if set_context(catcher.info[:token_info])
         | 
| 159 | 
            -
                return unless opts[: | 
| 164 | 
            +
                return unless opts[:cf]
         | 
| 160 165 | 
             
                begin
         | 
| 161 | 
            -
                   | 
| 162 | 
            -
                  tok_json = File.open( | 
| 163 | 
            -
                   | 
| 164 | 
            -
                   | 
| 165 | 
            -
                  File.open( | 
| 166 | 
            +
                  cf_target = File.open(CF_TARGET_FILE, 'r') { |f| f.read.strip }
         | 
| 167 | 
            +
                  tok_json = File.open(CF_TOKEN_FILE, 'r') { |f| f.read } if File.exists?(CF_TOKEN_FILE)
         | 
| 168 | 
            +
                  cf_tokens = Util.json_parse(tok_json, :none) || {}
         | 
| 169 | 
            +
                  cf_tokens[cf_target] = auth_header
         | 
| 170 | 
            +
                  File.open(CF_TOKEN_FILE, 'w') { |f| f.write(cf_tokens.to_json) }
         | 
| 166 171 | 
             
                rescue Exception => e
         | 
| 167 | 
            -
                  gripe "\nUnable to save token to  | 
| 172 | 
            +
                  gripe "\nUnable to save token to cf token file"
         | 
| 168 173 | 
             
                  complain e
         | 
| 169 174 | 
             
                end
         | 
| 170 175 | 
             
              end
         | 
| 171 176 |  | 
| 172 177 | 
             
              define_option :port, "--port <number>", "pin internal server to specific port"
         | 
| 173 | 
            -
              define_option : | 
| 178 | 
            +
              define_option :cf, "--[no-]cf", "save token in the ~/.cf_tokens file"
         | 
| 174 179 | 
             
              desc "token authcode get", "Gets a token using the authcode flow with browser",
         | 
| 175 | 
            -
                  :client, :secret, :scope, : | 
| 180 | 
            +
                  :client, :secret, :scope, :cf, :port do use_browser(clientname, clientsecret) end
         | 
| 176 181 |  | 
| 177 182 | 
             
              desc "token implicit get", "Gets a token using the implicit flow with browser",
         | 
| 178 | 
            -
                  :client, :scope, : | 
| 183 | 
            +
                  :client, :scope, :cf, :port do use_browser opts[:client] || "cf" end
         | 
| 179 184 |  | 
| 180 185 | 
             
              define_option :key, "--key <key>", "Token validation key"
         | 
| 181 186 | 
             
              desc "token decode [token] [tokentype]", "Show token contents as parsed locally or by the UAA. " +
         | 
    
        data/lib/cli/version.rb
    CHANGED
    
    
    
        data/lib/stub/server.rb
    CHANGED
    
    | @@ -17,6 +17,7 @@ require 'logger' | |
| 17 17 | 
             
            require 'pp'
         | 
| 18 18 | 
             
            require 'erb'
         | 
| 19 19 | 
             
            require 'multi_json'
         | 
| 20 | 
            +
            require 'rack'
         | 
| 20 21 |  | 
| 21 22 | 
             
            module Stub
         | 
| 22 23 |  | 
| @@ -88,7 +89,8 @@ class Reply | |
| 88 89 | 
             
              attr_accessor :status, :headers, :body
         | 
| 89 90 | 
             
              def initialize(status = 200) @status, @headers, @cookies, @body = status, {}, [], "" end
         | 
| 90 91 | 
             
              def to_s
         | 
| 91 | 
            -
                 | 
| 92 | 
            +
                message = Rack::Utils::HTTP_STATUS_CODES[@status]
         | 
| 93 | 
            +
                reply = "HTTP/1.1 #{@status} #{message.upcase if message}\r\n"
         | 
| 92 94 | 
             
                headers["server"], headers["date"] = "stub server", DateTime.now.httpdate
         | 
| 93 95 | 
             
                headers["content-length"] = body.bytesize
         | 
| 94 96 | 
             
                headers.each { |k, v| reply << "#{k}: #{v}\r\n" }
         | 
    
        data/lib/stub/uaa.rb
    CHANGED
    
    | @@ -68,6 +68,17 @@ class StubUAAConn < Stub::Base | |
| 68 68 | 
             
                reply.body = File.read File.expand_path(File.join(__FILE__, '..', '..', 'lib', 'cli', 'favicon.ico'))
         | 
| 69 69 | 
             
              end
         | 
| 70 70 |  | 
| 71 | 
            +
              route :put, '/another-fake-endpoint' do
         | 
| 72 | 
            +
                return unless valid_token("clients.read")
         | 
| 73 | 
            +
                parsed = JSON.parse(request.body)
         | 
| 74 | 
            +
                reply_in_kind(202, parsed.merge(:updated => 42))
         | 
| 75 | 
            +
              end
         | 
| 76 | 
            +
             | 
| 77 | 
            +
              route :get, '/my-fake-endpoint' do
         | 
| 78 | 
            +
                return unless valid_token("clients.read")
         | 
| 79 | 
            +
                reply_in_kind(200, "some fake response text")
         | 
| 80 | 
            +
              end
         | 
| 81 | 
            +
             | 
| 71 82 | 
             
              route :get, '/' do reply_in_kind "welcome to stub UAA, version #{VERSION}" end
         | 
| 72 83 | 
             
              route :get, '/varz' do reply_in_kind(mem: 0, type: 'UAA', app: { version: VERSION } ) end
         | 
| 73 84 | 
             
              route :get, '/token_key' do reply_in_kind(alg: "none", value: "none") end
         | 
| @@ -222,7 +233,9 @@ class StubUAAConn < Stub::Base | |
| 222 233 | 
             
                    return redir_err_f(cburi, state, "invalid_scope")
         | 
| 223 234 | 
             
                  end
         | 
| 224 235 | 
             
                  # TODO: how to stub any remaining scopes that are not auto-approve?
         | 
| 225 | 
            -
                   | 
| 236 | 
            +
                  token_reply_info = token_reply_info(client, granted_scope, user, query["state"])
         | 
| 237 | 
            +
                  token_reply_info.delete(:scope) if query["scope"]
         | 
| 238 | 
            +
                  return redir_with_fragment(cburi, token_reply_info)
         | 
| 226 239 | 
             
                end
         | 
| 227 240 | 
             
                return redir_err_q(cburi, state, "invalid_request") unless request.method == "get"
         | 
| 228 241 | 
             
                return redir_err_q(cburi, state, "unsupported_response_type") unless query["response_type"] == 'code'
         | 
| @@ -493,7 +506,7 @@ class StubUAA < Stub::Server | |
| 493 506 | 
             
                @scim.add(:client, 'client_id' => client, 'client_secret' => secret,
         | 
| 494 507 | 
             
                    'authorized_grant_types' => ["client_credentials"], 'authorities' => gids,
         | 
| 495 508 | 
             
                    'access_token_validity' => 60 * 60 * 24 * 7)
         | 
| 496 | 
            -
                @scim.add(:client, 'client_id' => " | 
| 509 | 
            +
                @scim.add(:client, 'client_id' => "cf", 'authorized_grant_types' => ["implicit"],
         | 
| 497 510 | 
             
                    'scope' => [@scim.id("openid", :group), @scim.id("password.write", :group)],
         | 
| 498 511 | 
             
                    'access_token_validity' => 5 * 60 )
         | 
| 499 512 | 
             
                info = { commit_id: "not implemented",
         | 
    
        data/spec/client_reg_spec.rb
    CHANGED
    
    | @@ -22,7 +22,8 @@ describe ClientCli do | |
| 22 22 |  | 
| 23 23 | 
             
              before :all do
         | 
| 24 24 | 
             
                #Util.default_logger(:trace)
         | 
| 25 | 
            -
                 | 
| 25 | 
            +
                @output = StringIO.new
         | 
| 26 | 
            +
                Cli.configure("", nil, @output, true)
         | 
| 26 27 | 
             
                setup_target(authorities: "scim.read,clients.secret", grant_types: "client_credentials")
         | 
| 27 28 | 
             
                @test_user, @test_pwd = "sam_#{Time.now.to_i}", "correcthorsebatterystaple"
         | 
| 28 29 | 
             
              end
         | 
| @@ -51,7 +52,15 @@ describe ClientCli do | |
| 51 52 |  | 
| 52 53 | 
             
                it "logs in as test client" do
         | 
| 53 54 | 
             
                  Cli.run("context").should be # login was in before :all block
         | 
| 54 | 
            -
                  Cli.output.string.should include  | 
| 55 | 
            +
                  Cli.output.string.should include @test_client
         | 
| 56 | 
            +
                  Cli.output.string.should match /access_token: \S+?\s+token_type/m
         | 
| 57 | 
            +
                end
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                it "does not wrap the output of the access token in the terminal" do
         | 
| 60 | 
            +
                  @output.stub(:tty?) { true }
         | 
| 61 | 
            +
                  HighLine::SystemExtensions.stub(:terminal_size) { [80] }
         | 
| 62 | 
            +
                  Cli.run("context").should be
         | 
| 63 | 
            +
                  Cli.output.string.should match /access_token: \S+?\s+token_type/m
         | 
| 55 64 | 
             
                end
         | 
| 56 65 |  | 
| 57 66 | 
             
                it "changes it's client secret" do
         | 
    
        data/spec/curl_spec.rb
    ADDED
    
    | @@ -0,0 +1,94 @@ | |
| 1 | 
            +
            #--
         | 
| 2 | 
            +
            # Cloud Foundry 2012.02.03 Beta
         | 
| 3 | 
            +
            # Copyright (c) [2009-2012] VMware, Inc. All Rights Reserved.
         | 
| 4 | 
            +
            #
         | 
| 5 | 
            +
            # This product is licensed to you under the Apache License, Version 2.0 (the "License").
         | 
| 6 | 
            +
            # You may not use this product except in compliance with the License.
         | 
| 7 | 
            +
            #
         | 
| 8 | 
            +
            # This product includes a number of subcomponents with
         | 
| 9 | 
            +
            # separate copyright notices and license terms. Your use of these
         | 
| 10 | 
            +
            # subcomponents is subject to the terms and conditions of the
         | 
| 11 | 
            +
            # subcomponent's license, as noted in the LICENSE file.
         | 
| 12 | 
            +
            #++
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            require 'spec_helper'
         | 
| 15 | 
            +
            require 'cli'
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            module CF::UAA
         | 
| 18 | 
            +
              describe CurlCli do
         | 
| 19 | 
            +
                include SpecHelper
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                before :all do
         | 
| 22 | 
            +
                  Cli.configure("", nil, StringIO.new, true)
         | 
| 23 | 
            +
                  setup_target(authorities: "clients.read,scim.read,scim.write")
         | 
| 24 | 
            +
                  Cli.run("token client get #{@test_client} -s #{@test_secret}").should be
         | 
| 25 | 
            +
                  Config.yaml.should include("access_token")
         | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                after :all do
         | 
| 29 | 
            +
                  cleanup_target
         | 
| 30 | 
            +
                end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                it "prints usage when the path argument is not specified" do
         | 
| 33 | 
            +
                  Cli.run("curl")
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                  Cli.output.string.should include "curl [path]"
         | 
| 36 | 
            +
                  Cli.output.string.should include "-X | --request <method>"
         | 
| 37 | 
            +
                  Cli.output.string.should include "-d | --data <data>"
         | 
| 38 | 
            +
                end
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                it "hits the URL on the UAA target" do
         | 
| 41 | 
            +
                  Cli.run("curl /my-fake-endpoint")
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                  Cli.output.string.should include "GET #{@target}/my-fake-endpoint"
         | 
| 44 | 
            +
                  Cli.output.string.should_not include "REQUEST BODY"
         | 
| 45 | 
            +
                  Cli.output.string.should_not include "REQUEST HEADERS"
         | 
| 46 | 
            +
                  Cli.output.string.should include "200 OK"
         | 
| 47 | 
            +
                  Cli.output.string.should include "RESPONSE BODY:"
         | 
| 48 | 
            +
                  Cli.output.string.should include "some fake response text"
         | 
| 49 | 
            +
                end
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                it "displays the correct response text when we include a body in the request" do
         | 
| 52 | 
            +
                  Cli.run("curl -X PUT -d '{\"fake\": true}' -H 'Accept: application/json' /another-fake-endpoint")
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                  Cli.output.string.should include "PUT #{@target}/another-fake-endpoint"
         | 
| 55 | 
            +
                  Cli.output.string.should include "REQUEST BODY: \"{\"fake\": true}\""
         | 
| 56 | 
            +
                  Cli.output.string.should include "Accept: application/json"
         | 
| 57 | 
            +
                  Cli.output.string.should include "202 ACCEPTED"
         | 
| 58 | 
            +
                  Cli.output.string.should include "RESPONSE BODY:"
         | 
| 59 | 
            +
                  Cli.output.string.should include "\"fake\": true"
         | 
| 60 | 
            +
                  Cli.output.string.should include "\"updated\": 42"
         | 
| 61 | 
            +
                end
         | 
| 62 | 
            +
             | 
| 63 | 
            +
                it "uses headers passed from the command line" do
         | 
| 64 | 
            +
                  Cli.run("curl -H \"X-Something: non-standard header\" -H \"X-Another: something\" /my-fake-endpoint")
         | 
| 65 | 
            +
             | 
| 66 | 
            +
                  Cli.output.string.should include "GET #{@target}/my-fake-endpoint"
         | 
| 67 | 
            +
                  Cli.output.string.should include "REQUEST HEADERS:"
         | 
| 68 | 
            +
                  Cli.output.string.should include "  X-Something: non-standard header"
         | 
| 69 | 
            +
                  Cli.output.string.should include "  X-Another: something"
         | 
| 70 | 
            +
                  Cli.output.string.should include "RESPONSE HEADERS:"
         | 
| 71 | 
            +
                  Cli.output.string.should include "  Content-Type: text/plain"
         | 
| 72 | 
            +
                end
         | 
| 73 | 
            +
             | 
| 74 | 
            +
                it "hits an external server when a request host is specified in the command" do
         | 
| 75 | 
            +
                  Cli.run("curl http://example.com/something")
         | 
| 76 | 
            +
             | 
| 77 | 
            +
                  Cli.output.string.should include "GET http://example.com/something"
         | 
| 78 | 
            +
                  Cli.output.string.should include "404 Not Found"
         | 
| 79 | 
            +
                end
         | 
| 80 | 
            +
             | 
| 81 | 
            +
                it "prints non-JSON responses" do
         | 
| 82 | 
            +
                  Cli.run("curl http://example.com/something")
         | 
| 83 | 
            +
             | 
| 84 | 
            +
                  Cli.output.string.should_not include "JSON::ParserError"
         | 
| 85 | 
            +
                end
         | 
| 86 | 
            +
             | 
| 87 | 
            +
                it "makes insecure requests with the -k flag" do
         | 
| 88 | 
            +
                  Cli.run("curl https://example.com/ -k")
         | 
| 89 | 
            +
             | 
| 90 | 
            +
                  Cli.output.string.should_not include "ECONNRESET"
         | 
| 91 | 
            +
                  Cli.output.string.should include "200 OK"
         | 
| 92 | 
            +
                end
         | 
| 93 | 
            +
              end
         | 
| 94 | 
            +
            end
         | 
    
        data/spec/token_spec.rb
    CHANGED
    
    | @@ -43,6 +43,17 @@ describe TokenCli do | |
| 43 43 | 
             
              it "logs in with implicit grant & posted credentials as a user" do
         | 
| 44 44 | 
             
                Cli.run("token get #{@test_user} #{@test_pwd}").should be
         | 
| 45 45 | 
             
                Cli.output.string.should include("Successfully fetched token")
         | 
| 46 | 
            +
                Cli.run("context")
         | 
| 47 | 
            +
                Cli.output.string.should match /scope: password\.write openid$/
         | 
| 48 | 
            +
              end
         | 
| 49 | 
            +
             | 
| 50 | 
            +
              it "can request a specific scope" do
         | 
| 51 | 
            +
                Cli.run("token delete")
         | 
| 52 | 
            +
                Cli.output.truncate 0
         | 
| 53 | 
            +
                Cli.run("token get --scope password.write #{@test_user} #{@test_pwd}").should be
         | 
| 54 | 
            +
                Cli.output.string.should include("Successfully fetched token")
         | 
| 55 | 
            +
                Cli.run("context")
         | 
| 56 | 
            +
                Cli.output.string.should match /scope: password\.write$/
         | 
| 46 57 | 
             
              end
         | 
| 47 58 |  | 
| 48 59 | 
             
              it "decodes the token" do
         | 
| @@ -55,6 +66,7 @@ describe TokenCli do | |
| 55 66 | 
             
              end
         | 
| 56 67 |  | 
| 57 68 | 
             
              it "gets authenticated user information" do
         | 
| 69 | 
            +
                Cli.run("token get #{@test_user} #{@test_pwd}").should be
         | 
| 58 70 | 
             
                Cli.run("me").should be
         | 
| 59 71 | 
             
                Cli.output.string.should include(@test_user)
         | 
| 60 72 | 
             
              end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: cf-uaac
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 2.0. | 
| 4 | 
            +
              version: 2.0.1
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors:
         | 
| @@ -13,11 +13,11 @@ authors: | |
| 13 13 | 
             
            autorequire: 
         | 
| 14 14 | 
             
            bindir: bin
         | 
| 15 15 | 
             
            cert_chain: []
         | 
| 16 | 
            -
            date:  | 
| 16 | 
            +
            date: 2014-07-03 00:00:00.000000000 Z
         | 
| 17 17 | 
             
            dependencies:
         | 
| 18 18 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 19 19 | 
             
              name: bundler
         | 
| 20 | 
            -
              requirement:  | 
| 20 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 21 21 | 
             
                none: false
         | 
| 22 22 | 
             
                requirements:
         | 
| 23 23 | 
             
                - - ! '>='
         | 
| @@ -25,10 +25,15 @@ dependencies: | |
| 25 25 | 
             
                    version: '0'
         | 
| 26 26 | 
             
              type: :development
         | 
| 27 27 | 
             
              prerelease: false
         | 
| 28 | 
            -
              version_requirements:  | 
| 28 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 29 | 
            +
                none: false
         | 
| 30 | 
            +
                requirements:
         | 
| 31 | 
            +
                - - ! '>='
         | 
| 32 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            +
                    version: '0'
         | 
| 29 34 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 30 35 | 
             
              name: rake
         | 
| 31 | 
            -
              requirement:  | 
| 36 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 32 37 | 
             
                none: false
         | 
| 33 38 | 
             
                requirements:
         | 
| 34 39 | 
             
                - - ! '>='
         | 
| @@ -36,10 +41,31 @@ dependencies: | |
| 36 41 | 
             
                    version: '0'
         | 
| 37 42 | 
             
              type: :development
         | 
| 38 43 | 
             
              prerelease: false
         | 
| 39 | 
            -
              version_requirements:  | 
| 44 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 45 | 
            +
                none: false
         | 
| 46 | 
            +
                requirements:
         | 
| 47 | 
            +
                - - ! '>='
         | 
| 48 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 49 | 
            +
                    version: '0'
         | 
| 50 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 51 | 
            +
              name: rack
         | 
| 52 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 53 | 
            +
                none: false
         | 
| 54 | 
            +
                requirements:
         | 
| 55 | 
            +
                - - ! '>='
         | 
| 56 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 57 | 
            +
                    version: '0'
         | 
| 58 | 
            +
              type: :development
         | 
| 59 | 
            +
              prerelease: false
         | 
| 60 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 61 | 
            +
                none: false
         | 
| 62 | 
            +
                requirements:
         | 
| 63 | 
            +
                - - ! '>='
         | 
| 64 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 65 | 
            +
                    version: '0'
         | 
| 40 66 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 41 67 | 
             
              name: rspec
         | 
| 42 | 
            -
              requirement:  | 
| 68 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 43 69 | 
             
                none: false
         | 
| 44 70 | 
             
                requirements:
         | 
| 45 71 | 
             
                - - ! '>='
         | 
| @@ -47,10 +73,15 @@ dependencies: | |
| 47 73 | 
             
                    version: '0'
         | 
| 48 74 | 
             
              type: :development
         | 
| 49 75 | 
             
              prerelease: false
         | 
| 50 | 
            -
              version_requirements:  | 
| 76 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 77 | 
            +
                none: false
         | 
| 78 | 
            +
                requirements:
         | 
| 79 | 
            +
                - - ! '>='
         | 
| 80 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 81 | 
            +
                    version: '0'
         | 
| 51 82 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 52 83 | 
             
              name: simplecov
         | 
| 53 | 
            -
              requirement:  | 
| 84 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 54 85 | 
             
                none: false
         | 
| 55 86 | 
             
                requirements:
         | 
| 56 87 | 
             
                - - ! '>='
         | 
| @@ -58,10 +89,15 @@ dependencies: | |
| 58 89 | 
             
                    version: '0'
         | 
| 59 90 | 
             
              type: :development
         | 
| 60 91 | 
             
              prerelease: false
         | 
| 61 | 
            -
              version_requirements:  | 
| 92 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 93 | 
            +
                none: false
         | 
| 94 | 
            +
                requirements:
         | 
| 95 | 
            +
                - - ! '>='
         | 
| 96 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 97 | 
            +
                    version: '0'
         | 
| 62 98 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 63 99 | 
             
              name: simplecov-rcov
         | 
| 64 | 
            -
              requirement:  | 
| 100 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 65 101 | 
             
                none: false
         | 
| 66 102 | 
             
                requirements:
         | 
| 67 103 | 
             
                - - ! '>='
         | 
| @@ -69,10 +105,15 @@ dependencies: | |
| 69 105 | 
             
                    version: '0'
         | 
| 70 106 | 
             
              type: :development
         | 
| 71 107 | 
             
              prerelease: false
         | 
| 72 | 
            -
              version_requirements:  | 
| 108 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 109 | 
            +
                none: false
         | 
| 110 | 
            +
                requirements:
         | 
| 111 | 
            +
                - - ! '>='
         | 
| 112 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 113 | 
            +
                    version: '0'
         | 
| 73 114 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 74 115 | 
             
              name: ci_reporter
         | 
| 75 | 
            -
              requirement:  | 
| 116 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 76 117 | 
             
                none: false
         | 
| 77 118 | 
             
                requirements:
         | 
| 78 119 | 
             
                - - ! '>='
         | 
| @@ -80,10 +121,15 @@ dependencies: | |
| 80 121 | 
             
                    version: '0'
         | 
| 81 122 | 
             
              type: :development
         | 
| 82 123 | 
             
              prerelease: false
         | 
| 83 | 
            -
              version_requirements:  | 
| 124 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 125 | 
            +
                none: false
         | 
| 126 | 
            +
                requirements:
         | 
| 127 | 
            +
                - - ! '>='
         | 
| 128 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 129 | 
            +
                    version: '0'
         | 
| 84 130 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 85 131 | 
             
              name: cf-uaa-lib
         | 
| 86 | 
            -
              requirement:  | 
| 132 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 87 133 | 
             
                none: false
         | 
| 88 134 | 
             
                requirements:
         | 
| 89 135 | 
             
                - - ~>
         | 
| @@ -91,10 +137,15 @@ dependencies: | |
| 91 137 | 
             
                    version: 2.0.0
         | 
| 92 138 | 
             
              type: :runtime
         | 
| 93 139 | 
             
              prerelease: false
         | 
| 94 | 
            -
              version_requirements:  | 
| 140 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 141 | 
            +
                none: false
         | 
| 142 | 
            +
                requirements:
         | 
| 143 | 
            +
                - - ~>
         | 
| 144 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 145 | 
            +
                    version: 2.0.0
         | 
| 95 146 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 96 147 | 
             
              name: highline
         | 
| 97 | 
            -
              requirement:  | 
| 148 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 98 149 | 
             
                none: false
         | 
| 99 150 | 
             
                requirements:
         | 
| 100 151 | 
             
                - - ! '>='
         | 
| @@ -102,10 +153,15 @@ dependencies: | |
| 102 153 | 
             
                    version: '0'
         | 
| 103 154 | 
             
              type: :runtime
         | 
| 104 155 | 
             
              prerelease: false
         | 
| 105 | 
            -
              version_requirements:  | 
| 156 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 157 | 
            +
                none: false
         | 
| 158 | 
            +
                requirements:
         | 
| 159 | 
            +
                - - ! '>='
         | 
| 160 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 161 | 
            +
                    version: '0'
         | 
| 106 162 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 107 163 | 
             
              name: eventmachine
         | 
| 108 | 
            -
              requirement:  | 
| 164 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 109 165 | 
             
                none: false
         | 
| 110 166 | 
             
                requirements:
         | 
| 111 167 | 
             
                - - ! '>='
         | 
| @@ -113,10 +169,15 @@ dependencies: | |
| 113 169 | 
             
                    version: '0'
         | 
| 114 170 | 
             
              type: :runtime
         | 
| 115 171 | 
             
              prerelease: false
         | 
| 116 | 
            -
              version_requirements:  | 
| 172 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 173 | 
            +
                none: false
         | 
| 174 | 
            +
                requirements:
         | 
| 175 | 
            +
                - - ! '>='
         | 
| 176 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 177 | 
            +
                    version: '0'
         | 
| 117 178 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 118 179 | 
             
              name: launchy
         | 
| 119 | 
            -
              requirement:  | 
| 180 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 120 181 | 
             
                none: false
         | 
| 121 182 | 
             
                requirements:
         | 
| 122 183 | 
             
                - - ! '>='
         | 
| @@ -124,10 +185,15 @@ dependencies: | |
| 124 185 | 
             
                    version: '0'
         | 
| 125 186 | 
             
              type: :runtime
         | 
| 126 187 | 
             
              prerelease: false
         | 
| 127 | 
            -
              version_requirements:  | 
| 188 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 189 | 
            +
                none: false
         | 
| 190 | 
            +
                requirements:
         | 
| 191 | 
            +
                - - ! '>='
         | 
| 192 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 193 | 
            +
                    version: '0'
         | 
| 128 194 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 129 195 | 
             
              name: em-http-request
         | 
| 130 | 
            -
              requirement:  | 
| 196 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 131 197 | 
             
                none: false
         | 
| 132 198 | 
             
                requirements:
         | 
| 133 199 | 
             
                - - ! '>='
         | 
| @@ -135,10 +201,15 @@ dependencies: | |
| 135 201 | 
             
                    version: 1.0.0.beta.3
         | 
| 136 202 | 
             
              type: :runtime
         | 
| 137 203 | 
             
              prerelease: false
         | 
| 138 | 
            -
              version_requirements:  | 
| 204 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 205 | 
            +
                none: false
         | 
| 206 | 
            +
                requirements:
         | 
| 207 | 
            +
                - - ! '>='
         | 
| 208 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 209 | 
            +
                    version: 1.0.0.beta.3
         | 
| 139 210 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 140 211 | 
             
              name: json_pure
         | 
| 141 | 
            -
              requirement:  | 
| 212 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 142 213 | 
             
                none: false
         | 
| 143 214 | 
             
                requirements:
         | 
| 144 215 | 
             
                - - ! '>='
         | 
| @@ -146,7 +217,12 @@ dependencies: | |
| 146 217 | 
             
                    version: '0'
         | 
| 147 218 | 
             
              type: :runtime
         | 
| 148 219 | 
             
              prerelease: false
         | 
| 149 | 
            -
              version_requirements:  | 
| 220 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 221 | 
            +
                none: false
         | 
| 222 | 
            +
                requirements:
         | 
| 223 | 
            +
                - - ! '>='
         | 
| 224 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 225 | 
            +
                    version: '0'
         | 
| 150 226 | 
             
            description: Client command line tools for interacting with the CloudFoundry User
         | 
| 151 227 | 
             
              Account and Authorization (UAA) server.  The UAA is an OAuth2 Authorization Server
         | 
| 152 228 | 
             
              so it can be used by webapps and command line apps to obtain access tokens to act
         | 
| @@ -185,6 +261,7 @@ files: | |
| 185 261 | 
             
            - lib/cli/client_reg.rb
         | 
| 186 262 | 
             
            - lib/cli/common.rb
         | 
| 187 263 | 
             
            - lib/cli/config.rb
         | 
| 264 | 
            +
            - lib/cli/curl.rb
         | 
| 188 265 | 
             
            - lib/cli/favicon.ico
         | 
| 189 266 | 
             
            - lib/cli/group.rb
         | 
| 190 267 | 
             
            - lib/cli/info.rb
         | 
| @@ -197,6 +274,7 @@ files: | |
| 197 274 | 
             
            - lib/stub/uaa.rb
         | 
| 198 275 | 
             
            - spec/client_reg_spec.rb
         | 
| 199 276 | 
             
            - spec/common_spec.rb
         | 
| 277 | 
            +
            - spec/curl_spec.rb
         | 
| 200 278 | 
             
            - spec/group_spec.rb
         | 
| 201 279 | 
             
            - spec/http_spec.rb
         | 
| 202 280 | 
             
            - spec/info_spec.rb
         | 
| @@ -205,7 +283,8 @@ files: | |
| 205 283 | 
             
            - spec/token_spec.rb
         | 
| 206 284 | 
             
            - spec/user_spec.rb
         | 
| 207 285 | 
             
            homepage: https://github.com/cloudfoundry/cf-uaac
         | 
| 208 | 
            -
            licenses: | 
| 286 | 
            +
            licenses:
         | 
| 287 | 
            +
            - Apache 2.0
         | 
| 209 288 | 
             
            post_install_message: 
         | 
| 210 289 | 
             
            rdoc_options: []
         | 
| 211 290 | 
             
            require_paths:
         | 
| @@ -224,8 +303,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 224 303 | 
             
                  version: '0'
         | 
| 225 304 | 
             
            requirements: []
         | 
| 226 305 | 
             
            rubyforge_project: cf-uaac
         | 
| 227 | 
            -
            rubygems_version: 1.8. | 
| 306 | 
            +
            rubygems_version: 1.8.23
         | 
| 228 307 | 
             
            signing_key: 
         | 
| 229 308 | 
             
            specification_version: 3
         | 
| 230 309 | 
             
            summary: Command line interface for CloudFoundry UAA
         | 
| 231 | 
            -
            test_files: | 
| 310 | 
            +
            test_files:
         | 
| 311 | 
            +
            - spec/client_reg_spec.rb
         | 
| 312 | 
            +
            - spec/common_spec.rb
         | 
| 313 | 
            +
            - spec/curl_spec.rb
         | 
| 314 | 
            +
            - spec/group_spec.rb
         | 
| 315 | 
            +
            - spec/http_spec.rb
         | 
| 316 | 
            +
            - spec/info_spec.rb
         | 
| 317 | 
            +
            - spec/setup_helper.rb
         | 
| 318 | 
            +
            - spec/spec_helper.rb
         | 
| 319 | 
            +
            - spec/token_spec.rb
         | 
| 320 | 
            +
            - spec/user_spec.rb
         |