From 1f74509a7542b7bbfbd180d490774ab27ab6d2b4 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Fri, 23 Feb 2018 11:05:39 +0800 Subject: [PATCH] FIX: 2FA prompt incorrectly displayed on admin login page. --- app/views/users/admin_login.html.erb | 10 ++++++---- spec/controllers/users_controller_spec.rb | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/app/views/users/admin_login.html.erb b/app/views/users/admin_login.html.erb index c7752523e90..ed372e49d69 100644 --- a/app/views/users/admin_login.html.erb +++ b/app/views/users/admin_login.html.erb @@ -7,10 +7,12 @@ <%= @message %> <% if @error %>

<%= @error %>

<% end %> - <%=form_tag({}, method: :put) do %> - <%= label_tag(:second_factor_token, t('login.second_factor_description')) %> - <%= text_field_tag(:second_factor_token, nil, autofocus: true) %>

- <%= submit_tag t('submit')%> + <% if @second_factor_required %> + <%=form_tag({}, method: :put) do %> + <%= label_tag(:second_factor_token, t('login.second_factor_description')) %> + <%= text_field_tag(:second_factor_token, nil, autofocus: true) %>

+ <%= submit_tag t('submit')%> + <% end %> <% end %> <% else %> <%=form_tag({}, method: :put) do %> diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index 35f172aa04e..502efb7e4fc 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -523,6 +523,21 @@ describe UsersController do end end + context 'when email is incorrect' do + render_views + + it 'should return the right response' do + get :admin_login, params: { email: 'random' } + + expect(response.status).to eq(200) + + response_body = response.body + + expect(response_body).to match(I18n.t("admin_login.errors.unknown_email_address")) + expect(response_body).to_not match(I18n.t("login.second_factor_description")) + end + end + context 'logs in admin' do it 'does not log in admin with invalid token' do SiteSetting.sso_url = "https://www.example.com/sso"