2012-11-21 07:11:26 -05:00
|
|
|
Shindo.tests("Fog::Brightbox::OAuth2", ["brightbox"]) do
|
|
|
|
|
|
|
|
tests("CredentialSet") do
|
|
|
|
@client_id = "app-12345"
|
|
|
|
@client_secret = "__mashed_keys_123__"
|
|
|
|
@username = "usr-12345"
|
|
|
|
@password = "__mushed_keys_321__"
|
2012-11-21 09:31:04 -05:00
|
|
|
@access_token = "12efde32fdfe4989"
|
|
|
|
@refresh_token = "7894389f9074f071"
|
2012-11-21 07:11:26 -05:00
|
|
|
|
|
|
|
tests("with client credentials") do
|
|
|
|
credentials = Fog::Brightbox::OAuth2::CredentialSet.new(@client_id, @client_secret)
|
|
|
|
tests("#user_details?").returns(false) { credentials.user_details? }
|
2012-11-21 09:31:04 -05:00
|
|
|
tests("#access_token?").returns(false) { credentials.access_token? }
|
|
|
|
tests("#refresh_token?").returns(false) { credentials.refresh_token? }
|
2012-11-21 13:05:41 -05:00
|
|
|
tests("#best_grant_strategy").returns(true) do
|
|
|
|
credentials.best_grant_strategy.is_a?(Fog::Brightbox::OAuth2::ClientCredentialsStrategy)
|
|
|
|
end
|
2012-11-21 07:11:26 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
tests("with user credentials") do
|
|
|
|
options = {:username => @username, :password => @password}
|
|
|
|
credentials = Fog::Brightbox::OAuth2::CredentialSet.new(@client_id, @client_secret, options)
|
|
|
|
tests("#user_details?").returns(true) { credentials.user_details? }
|
2012-11-21 09:31:04 -05:00
|
|
|
tests("#access_token?").returns(false) { credentials.access_token? }
|
|
|
|
tests("#refresh_token?").returns(false) { credentials.refresh_token? }
|
2012-11-21 13:05:41 -05:00
|
|
|
tests("#best_grant_strategy").returns(true) do
|
|
|
|
credentials.best_grant_strategy.is_a?(Fog::Brightbox::OAuth2::UserCredentialsStrategy)
|
|
|
|
end
|
2012-11-21 07:11:26 -05:00
|
|
|
end
|
2012-11-21 08:59:59 -05:00
|
|
|
|
|
|
|
tests("with existing tokens") do
|
|
|
|
options = {:username => @username, :access_token => @access_token, :refresh_token => @refresh_token}
|
|
|
|
credentials = Fog::Brightbox::OAuth2::CredentialSet.new(@client_id, @client_secret, options)
|
|
|
|
tests("#user_details?").returns(false) { credentials.user_details? }
|
|
|
|
tests("#access_token?").returns(true) { credentials.access_token? }
|
|
|
|
tests("#refresh_token?").returns(true) { credentials.refresh_token? }
|
|
|
|
tests("#best_grant_strategy").returns(true) do
|
|
|
|
credentials.best_grant_strategy.is_a?(Fog::Brightbox::OAuth2::RefreshTokenStrategy)
|
|
|
|
end
|
|
|
|
end
|
2012-11-21 07:11:26 -05:00
|
|
|
end
|
2012-11-21 08:31:43 -05:00
|
|
|
|
|
|
|
tests("GrantTypeStrategy") do
|
|
|
|
credentials = Fog::Brightbox::OAuth2::CredentialSet.new(@client_id, @client_secret)
|
|
|
|
strategy = Fog::Brightbox::OAuth2::GrantTypeStrategy.new(credentials)
|
|
|
|
|
|
|
|
tests("#respond_to? :authorization_body_data").returns(true) do
|
|
|
|
strategy.respond_to?(:authorization_body_data)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
tests("ClientCredentialsStrategy") do
|
|
|
|
credentials = Fog::Brightbox::OAuth2::CredentialSet.new(@client_id, @client_secret)
|
|
|
|
strategy = Fog::Brightbox::OAuth2::ClientCredentialsStrategy.new(credentials)
|
|
|
|
|
|
|
|
tests("#respond_to? :authorization_body_data").returns(true) do
|
|
|
|
strategy.respond_to?(:authorization_body_data)
|
|
|
|
end
|
|
|
|
|
|
|
|
tests("#authorization_body_data") do
|
|
|
|
authorization_body_data = strategy.authorization_body_data
|
|
|
|
test("grant_type == none") { authorization_body_data["grant_type"] == "none" }
|
|
|
|
test("client_id == #{@client_id}") { authorization_body_data["client_id"] == @client_id }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
tests("UserCredentialsStrategy") do
|
|
|
|
options = {:username => @username, :password => @password}
|
|
|
|
credentials = Fog::Brightbox::OAuth2::CredentialSet.new(@client_id, @client_secret, options)
|
|
|
|
strategy = Fog::Brightbox::OAuth2::UserCredentialsStrategy.new(credentials)
|
|
|
|
|
|
|
|
tests("#respond_to? :authorization_body_data").returns(true) do
|
|
|
|
strategy.respond_to?(:authorization_body_data)
|
|
|
|
end
|
|
|
|
|
|
|
|
tests("#authorization_body_data") do
|
|
|
|
authorization_body_data = strategy.authorization_body_data
|
|
|
|
test("grant_type == password") { authorization_body_data["grant_type"] == "password" }
|
|
|
|
test("client_id == #{@client_id}") { authorization_body_data["client_id"] == @client_id }
|
|
|
|
test("username == #{@username}") { authorization_body_data["username"] == @username }
|
|
|
|
test("password == #{@password}") { authorization_body_data["password"] == @password }
|
|
|
|
end
|
|
|
|
end
|
2012-11-21 08:59:59 -05:00
|
|
|
|
|
|
|
tests("RefreshTokenStrategy") do
|
|
|
|
refresh_token = "ab4b39dddf909"
|
|
|
|
options = {:refresh_token => refresh_token}
|
|
|
|
credentials = Fog::Brightbox::OAuth2::CredentialSet.new(@client_id, @client_secret, options)
|
|
|
|
strategy = Fog::Brightbox::OAuth2::RefreshTokenStrategy.new(credentials)
|
|
|
|
|
|
|
|
tests("#respond_to? :authorization_body_data").returns(true) do
|
|
|
|
strategy.respond_to?(:authorization_body_data)
|
|
|
|
end
|
|
|
|
|
|
|
|
tests("#authorization_body_data") do
|
|
|
|
authorization_body_data = strategy.authorization_body_data
|
|
|
|
test("grant_type == refresh_token") { authorization_body_data["grant_type"] == "refresh_token" }
|
|
|
|
test("client_id == #{@client_id}") { authorization_body_data["client_id"] == @client_id }
|
|
|
|
test("refresh_token == #{refresh_token}") { authorization_body_data["refresh_token"] == refresh_token }
|
|
|
|
end
|
|
|
|
end
|
2012-11-21 07:11:26 -05:00
|
|
|
end
|