diaspora/features/step_definitions/implicit_flow_steps.rb
theworldbright 7b80a7408d Add integration tests for implicit flow
Squashed commits:
[d5001fe] Refactor
[8d8a23f] Add test for when authorization is denied
[659fc56] Adjust password flow integration test
2016-01-04 16:49:50 +09:00

41 lines
1.6 KiB
Ruby

Given(/^the OpenID scope exists$/) do
OpenidConnect::Scope.create(name: "openid")
end
Given /^I send a post request from that client to the implicit flow authorization endpoint$/ do
client_json = JSON.parse(last_response.body)
auth_endpoint_url = "/openid_connect/authorizations/new"
visit auth_endpoint_url + "?client_id=" + client_json["o_auth_application"]["client_id"] + "&redirect_uri=" + "http://localhost:3000" +
"&response_type=id_token token" + "&scope=openid" + "&nonce=hello" + "&state=hi"
end
Given /^I send a post request from that client to the implicit flow authorization endpoint using a invalid client id/ do
auth_endpoint_url = "/openid_connect/authorizations/new"
visit auth_endpoint_url + "?client_id=randomid" + "&redirect_uri=" + "http://localhost:3000" +
"&response_type=id_token token" + "&scope=openid" + "&nonce=hello" + "&state=hi"
end
When /^I give my consent and authorize the client$/ do
click_button "Approve"
end
When /^I deny authorization to the client$/ do
click_button "Deny"
end
Then /^I should not see any tokens in the redirect url$/ do
access_token = current_url[/(?<=access_token=)[^&]+/]
id_token = current_url[/(?<=access_token=)[^&]+/]
expect(access_token).to eq(nil)
expect(id_token).to eq(nil)
end
When /^I parse the bearer tokens and use it to access user info$/ do
access_token = current_url[/(?<=access_token=)[^&]+/]
user_info_endpoint_url = "/api/v0/user/"
get user_info_endpoint_url, access_token: access_token
end
Then /^I should see an "([^\"]*)" error$/ do |error_message|
expect(page).to have_content(error_message)
end