forked from cloudfoundry-attic/cf-release
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
uaa: added integration test for auth tokens
- Loading branch information
Bob Nugmanov and Dmitriy Kalinin
committed
Mar 20, 2013
1 parent
780f72b
commit c6e6b7c
Showing
2 changed files
with
46 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters