OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Refactor the spec and cover an optional `alt` query parameter for userinfo request.
Pavel Balashov293ff129e69e
diff --git a/spec/requests/openid_google_provider_callback_spec.rb b/spec/requests/openid_google_provider_callback_spec.rbindex db3ab52f7af..2927db78520 100644--- a/spec/requests/openid_google_provider_callback_spec.rb+++ b/spec/requests/openid_google_provider_callback_spec.rb@@ -33,23 +33,26 @@ describe 'OpenID Google provider callback' doinclude Rack::Test::Methodsinclude API::V3::Utilities::PathHelper- it 'redirects user without errors', webmock: true, with_settings: {- plugin_openproject_openid_connect: {- "providers" => { "google" => { "identifier" => "identifier", "secret" => "secret" } }- }- } do- with_enterprise_token :openid_providers- auth_hash = { "state" => "623960f1b4f1020941387659f022497f536ad3c95fa7e53b0f03bdbf36debd59f76320801ea2723df520",- "code" => "4/0AVHEtk6HMPLH08Uw8OVoSaAbd2oTi7Z6wOlBsMQ99Yj3qgKhhyKAxUQBvQ2MZuRzvueOgQ",- "scope" => "email profile https://www.googleapis.com/auth/userinfo.email openid https://www.googleapis.com/auth/userinfo.profile",- "authuser" => "0",- "prompt" => "none" }+ let(:auth_hash) do+ { "state" => "623960f1b4f1020941387659f022497f536ad3c95fa7e53b0f03bdbf36debd59f76320801ea2723df520",+ "code" => "4/0AVHEtk6HMPLH08Uw8OVoSaAbd2oTi7Z6wOlBsMQ99Yj3qgKhhyKAxUQBvQ2MZuRzvueOgQ",+ "scope" => "email profile https://www.googleapis.com/auth/userinfo.email openid https://www.googleapis.com/auth/userinfo.profile",+ "authuser" => "0",+ "prompt" => "none" }+ end+ let(:uri) douri = URI('/auth/google/callback')uri.query = URI.encode_www_form([['code', auth_hash['code']],['state', auth_hash['state']],['scope', auth_hash['scope']],['authuser', auth_hash['authuser']],['prompt', auth_hash['prompt']]])+ uri+ end++ before do+ with_enterprise_token :openid_providers+stub_request(:post, "https://accounts.google.com/o/oauth2/token").to_return(status: 200,body: {@@ -64,7 +67,7 @@ describe 'OpenID Google provider callback' do}.to_json,headers: { "content-type" => "application/json; charset=utf-8" })- stub_request(:get, "https://www.googleapis.com/oauth2/v3/userinfo?alt=json").to_return(+ stub_request(:get, Addressable::Template.new("https://www.googleapis.com/oauth2/v3/userinfo{?alt}")).to_return(status: 200,body: { "sub" => "107403511037921355307","name" => "Firstname Lastname",@@ -76,10 +79,17 @@ describe 'OpenID Google provider callback' do"locale" => "en-GB" }.to_json,headers: { "content-type" => "application/json; charset=utf-8" })+allow_any_instance_of(OmniAuth::Strategies::OpenIDConnect).to receive(:session) {- { 'omniauth.state' => auth_hash['state'] }- }+ { 'omniauth.state' => auth_hash['state'] }+ }+ end+ it 'redirects user without errors', webmock: true, with_settings: {+ plugin_openproject_openid_connect: {+ "providers" => { "google" => { "identifier" => "identifier", "secret" => "secret" } }+ }+ } doresponse = get uri.to_sexpect(response.status).to eq(302)expect(response.body).to eq("<html><body>You are being <a href=\"http://example.org/two_factor_authentication/request\">redirected</a>.</body></html>")