diff options
Diffstat (limited to 'spec/controllers/application_controller_spec.rb')
-rw-r--r-- | spec/controllers/application_controller_spec.rb | 108 |
1 files changed, 46 insertions, 62 deletions
diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb index 59a6cfbf4f5..b73ca0c2346 100644 --- a/spec/controllers/application_controller_spec.rb +++ b/spec/controllers/application_controller_spec.rb @@ -50,70 +50,36 @@ describe ApplicationController do end end - describe "#authenticate_user_from_token!" do - describe "authenticating a user from a private token" do - controller(described_class) do - def index - render text: "authenticated" - end - end - - context "when the 'private_token' param is populated with the private token" do - it "logs the user in" do - get :index, private_token: user.private_token - expect(response).to have_http_status(200) - expect(response.body).to eq("authenticated") - end - end - - context "when the 'PRIVATE-TOKEN' header is populated with the private token" do - it "logs the user in" do - @request.headers['PRIVATE-TOKEN'] = user.private_token - get :index - expect(response).to have_http_status(200) - expect(response.body).to eq("authenticated") - end - end - - it "doesn't log the user in otherwise" do - @request.headers['PRIVATE-TOKEN'] = "token" - get :index, private_token: "token", authenticity_token: "token" - expect(response.status).not_to eq(200) - expect(response.body).not_to eq("authenticated") + describe "#authenticate_user_from_personal_access_token!" do + controller(described_class) do + def index + render text: 'authenticated' end end - describe "authenticating a user from a personal access token" do - controller(described_class) do - def index - render text: 'authenticated' - end - end - - let(:personal_access_token) { create(:personal_access_token, user: user) } + let(:personal_access_token) { create(:personal_access_token, user: user) } - context "when the 'personal_access_token' param is populated with the personal access token" do - it "logs the user in" do - get :index, private_token: personal_access_token.token - expect(response).to have_http_status(200) - expect(response.body).to eq('authenticated') - end + context "when the 'personal_access_token' param is populated with the personal access token" do + it "logs the user in" do + get :index, private_token: personal_access_token.token + expect(response).to have_gitlab_http_status(200) + expect(response.body).to eq('authenticated') end + end - context "when the 'PERSONAL_ACCESS_TOKEN' header is populated with the personal access token" do - it "logs the user in" do - @request.headers["PRIVATE-TOKEN"] = personal_access_token.token - get :index - expect(response).to have_http_status(200) - expect(response.body).to eq('authenticated') - end + context "when the 'PERSONAL_ACCESS_TOKEN' header is populated with the personal access token" do + it "logs the user in" do + @request.headers["PRIVATE-TOKEN"] = personal_access_token.token + get :index + expect(response).to have_gitlab_http_status(200) + expect(response.body).to eq('authenticated') end + end - it "doesn't log the user in otherwise" do - get :index, private_token: "token" - expect(response.status).not_to eq(200) - expect(response.body).not_to eq('authenticated') - end + it "doesn't log the user in otherwise" do + get :index, private_token: "token" + expect(response.status).not_to eq(200) + expect(response.body).not_to eq('authenticated') end end @@ -152,21 +118,25 @@ describe ApplicationController do end end + before do + sign_in user + end + context 'when format is handled' do let(:requested_format) { :json } it 'returns 200 response' do - get :index, private_token: user.private_token, format: requested_format + get :index, format: requested_format - expect(response).to have_http_status 200 + expect(response).to have_gitlab_http_status 200 end end context 'when format is not handled' do it 'returns 404 response' do - get :index, private_token: user.private_token + get :index - expect(response).to have_http_status 404 + expect(response).to have_gitlab_http_status 404 end end end @@ -183,7 +153,7 @@ describe ApplicationController do context 'when the request format is atom' do it "logs the user in" do get :index, rss_token: user.rss_token, format: :atom - expect(response).to have_http_status 200 + expect(response).to have_gitlab_http_status 200 expect(response.body).to eq 'authenticated' end end @@ -191,7 +161,7 @@ describe ApplicationController do context 'when the request format is not atom' do it "doesn't log the user in" do get :index, rss_token: user.rss_token - expect(response.status).not_to have_http_status 200 + expect(response.status).not_to have_gitlab_http_status 200 expect(response.body).not_to eq 'authenticated' end end @@ -221,6 +191,20 @@ describe ApplicationController do end end + describe '#set_page_title_header' do + let(:controller) { described_class.new } + + it 'URI encodes UTF-8 characters in the title' do + response = double(headers: {}) + allow_any_instance_of(PageLayoutHelper).to receive(:page_title).and_return('€100 · GitLab') + allow(controller).to receive(:response).and_return(response) + + controller.send(:set_page_title_header) + + expect(response.headers['Page-Title']).to eq('%E2%82%AC100%20%C2%B7%20GitLab') + end + end + context 'two-factor authentication' do let(:controller) { described_class.new } |