Merge branch 'fix-u2f-fixtures' into 26226-generate-all-haml-fixtures-within-teaspoon-fixtures-task
* fix-u2f-fixtures: generate u2f frontend fixtures dynamically force utf-8 encoding for prior to fixture parsing to prevent nokogiri issues exclude script type=text/template from dom scrubbing
This commit is contained in:
commit
10d483eaaa
4 changed files with 36 additions and 23 deletions
|
@ -1,35 +1,43 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe SessionsController, '(JavaScript fixtures)', type: :controller do
|
||||
context 'U2F' do
|
||||
include JavaScriptFixturesHelpers
|
||||
|
||||
let(:user) { create(:user, :two_factor_via_u2f) }
|
||||
|
||||
before(:all) do
|
||||
clean_frontend_fixtures('u2f/')
|
||||
end
|
||||
|
||||
it 'u2f/authenticate.html.raw' do |example|
|
||||
fixture = render_template('u2f/_authenticate.html.haml', locals: {
|
||||
new_user_session_path: "/users/sign_in",
|
||||
params: {},
|
||||
resource_name: "user"
|
||||
})
|
||||
store_frontend_fixture(fixture, example.description)
|
||||
describe SessionsController, '(JavaScript fixtures)', type: :controller do
|
||||
render_views
|
||||
|
||||
before do
|
||||
@request.env['devise.mapping'] = Devise.mappings[:user]
|
||||
end
|
||||
|
||||
it 'u2f/authenticate.html.raw' do |example|
|
||||
allow(controller).to receive(:find_user).and_return(user)
|
||||
|
||||
post :create, user: { login: user.username, password: user.password }
|
||||
|
||||
expect(response).to be_success
|
||||
store_frontend_fixture(response, example.description)
|
||||
end
|
||||
end
|
||||
|
||||
it 'u2f/register.html.raw' do |example|
|
||||
user = build(:user, :two_factor_via_otp)
|
||||
describe Profiles::TwoFactorAuthsController, '(JavaScript fixtures)', type: :controller do
|
||||
render_views
|
||||
|
||||
fixture = render_template('u2f/_register.html.haml', locals: {
|
||||
create_u2f_profile_two_factor_auth_path: '/profile/two_factor_auth/create_u2f',
|
||||
current_user: user
|
||||
})
|
||||
store_frontend_fixture(fixture, example.description)
|
||||
end
|
||||
before do
|
||||
sign_in(user)
|
||||
end
|
||||
|
||||
private
|
||||
it 'u2f/register.html.raw' do |example|
|
||||
get :show
|
||||
|
||||
def render_template(template, **args)
|
||||
controller = ApplicationController.new
|
||||
controller.render_to_string(template: template, layout: false, **args)
|
||||
expect(response).to be_success
|
||||
store_frontend_fixture(response, example.description)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,8 +10,10 @@
|
|||
|
||||
(function() {
|
||||
describe('U2FAuthenticate', function() {
|
||||
fixture.load('u2f/authenticate.html.raw');
|
||||
fixture.preload('u2f/authenticate.html.raw');
|
||||
|
||||
beforeEach(function() {
|
||||
fixture.load('u2f/authenticate.html.raw');
|
||||
this.u2fDevice = new MockU2FDevice;
|
||||
this.container = $("#js-authenticate-u2f");
|
||||
this.component = new window.gl.U2FAuthenticate(
|
||||
|
|
|
@ -10,8 +10,10 @@
|
|||
|
||||
(function() {
|
||||
describe('U2FRegister', function() {
|
||||
fixture.load('u2f/register.html.raw');
|
||||
fixture.preload('u2f/register.html.raw');
|
||||
|
||||
beforeEach(function() {
|
||||
fixture.load('u2f/register.html.raw');
|
||||
this.u2fDevice = new MockU2FDevice;
|
||||
this.container = $("#js-register-u2f");
|
||||
this.component = new U2FRegister(this.container, $("#js-register-u2f-templates"), {}, "token");
|
||||
|
|
|
@ -39,6 +39,7 @@ module JavaScriptFixturesHelpers
|
|||
#
|
||||
def parse_response(response)
|
||||
fixture = response.body
|
||||
fixture.force_encoding("utf-8")
|
||||
|
||||
response_mime_type = Mime::Type.lookup(response.content_type)
|
||||
if response_mime_type.html?
|
||||
|
@ -47,7 +48,7 @@ module JavaScriptFixturesHelpers
|
|||
link_tags = doc.css('link')
|
||||
link_tags.remove
|
||||
|
||||
scripts = doc.css('script')
|
||||
scripts = doc.css("script:not([type='text/template'])")
|
||||
scripts.remove
|
||||
|
||||
fixture = doc.to_html
|
||||
|
|
Loading…
Reference in a new issue