Skip to content

Commit

Permalink
uaa: added integration test for auth tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
Bob Nugmanov and Dmitriy Kalinin committed Mar 20, 2013
1 parent 780f72b commit c6e6b7c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
50 changes: 46 additions & 4 deletions spec/integration/info_spec.rb
@@ -1,16 +1,58 @@
require "spec_helper"
require "net/http"
require "uri"

describe "Cloud controller", :type => :integration do
start_nats
start_cc

it "responds to /info" do
result = Net::HTTP.get_response(URI.parse("http://localhost:8181/info"))
result.code.should == "200"
make_http_request("/info").tap do |r|
r.code.should == "200"
r.json_body["version"].should == 2
end
end

it "authenticate and authorize with valid token" do
unauthorized_token = {"Authorization" => "bearer unauthorized-token"}
make_http_request("/v2/stacks", unauthorized_token).tap do |r|
r.code.should == "401"
end

authorized_token = {"Authorization" => "bearer #{admin_token}"}
make_http_request("/v2/stacks", authorized_token).tap do |r|
r.code.should == "200"
r.json_body["resources"].should be_a(Array)
end
end

def admin_token
token = {
"aud" => "cloud_controller",
"exp" => Time.now.to_i + 10_000,
"client_id" => Sham.guid,
"scope" => ["cloud_controller.admin"],
}
CF::UAA::TokenCoder.encode(token, :skey => "tokensecret", :algorithm => "HS256")
end

JSON.parse(result.body).tap do |r|
r["version"].should == 2
def make_http_request(path, headers = {})
url = URI.parse("http://localhost:8181#{path}")

response = Net::HTTP.new(url.host, url.port).start do |http|
request = Net::HTTP::Get.new(url.path)
headers.each do |name, value|
request.add_field(name, value)
end
http.request(request)
end

response.extend(Module.new do
def json_body
@json_body ||= JSON.parse(body)
end
end)

response
end
end
1 change: 0 additions & 1 deletion spec/vcap/uaa_util_spec.rb
Expand Up @@ -2,7 +2,6 @@

require File.expand_path("../spec_helper", __FILE__)
require "vcap/uaa_util"
require "openssl"

module VCAP
describe UaaTokenDecoder do
Expand Down

0 comments on commit c6e6b7c

Please sign in to comment.