Commit 10d483ea authored by Mike Greiling's avatar Mike Greiling

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
parents 5997a86e df5223de
require 'spec_helper' require 'spec_helper'
describe SessionsController, '(JavaScript fixtures)', type: :controller do context 'U2F' do
include JavaScriptFixturesHelpers include JavaScriptFixturesHelpers
let(:user) { create(:user, :two_factor_via_u2f) }
before(:all) do before(:all) do
clean_frontend_fixtures('u2f/') clean_frontend_fixtures('u2f/')
end end
it 'u2f/authenticate.html.raw' do |example| describe SessionsController, '(JavaScript fixtures)', type: :controller do
fixture = render_template('u2f/_authenticate.html.haml', locals: { render_views
new_user_session_path: "/users/sign_in",
params: {}, before do
resource_name: "user" @request.env['devise.mapping'] = Devise.mappings[:user]
}) end
store_frontend_fixture(fixture, example.description)
end
it 'u2f/register.html.raw' do |example| it 'u2f/authenticate.html.raw' do |example|
user = build(:user, :two_factor_via_otp) allow(controller).to receive(:find_user).and_return(user)
fixture = render_template('u2f/_register.html.haml', locals: { post :create, user: { login: user.username, password: user.password }
create_u2f_profile_two_factor_auth_path: '/profile/two_factor_auth/create_u2f',
current_user: user expect(response).to be_success
}) store_frontend_fixture(response, example.description)
store_frontend_fixture(fixture, example.description) end
end end
private describe Profiles::TwoFactorAuthsController, '(JavaScript fixtures)', type: :controller do
render_views
before do
sign_in(user)
end
it 'u2f/register.html.raw' do |example|
get :show
def render_template(template, **args) expect(response).to be_success
controller = ApplicationController.new store_frontend_fixture(response, example.description)
controller.render_to_string(template: template, layout: false, **args) end
end end
end end
...@@ -10,8 +10,10 @@ ...@@ -10,8 +10,10 @@
(function() { (function() {
describe('U2FAuthenticate', function() { describe('U2FAuthenticate', function() {
fixture.load('u2f/authenticate.html.raw'); fixture.preload('u2f/authenticate.html.raw');
beforeEach(function() { beforeEach(function() {
fixture.load('u2f/authenticate.html.raw');
this.u2fDevice = new MockU2FDevice; this.u2fDevice = new MockU2FDevice;
this.container = $("#js-authenticate-u2f"); this.container = $("#js-authenticate-u2f");
this.component = new window.gl.U2FAuthenticate( this.component = new window.gl.U2FAuthenticate(
......
...@@ -10,8 +10,10 @@ ...@@ -10,8 +10,10 @@
(function() { (function() {
describe('U2FRegister', function() { describe('U2FRegister', function() {
fixture.load('u2f/register.html.raw'); fixture.preload('u2f/register.html.raw');
beforeEach(function() { beforeEach(function() {
fixture.load('u2f/register.html.raw');
this.u2fDevice = new MockU2FDevice; this.u2fDevice = new MockU2FDevice;
this.container = $("#js-register-u2f"); this.container = $("#js-register-u2f");
this.component = new U2FRegister(this.container, $("#js-register-u2f-templates"), {}, "token"); this.component = new U2FRegister(this.container, $("#js-register-u2f-templates"), {}, "token");
......
...@@ -39,6 +39,7 @@ module JavaScriptFixturesHelpers ...@@ -39,6 +39,7 @@ module JavaScriptFixturesHelpers
# #
def parse_response(response) def parse_response(response)
fixture = response.body fixture = response.body
fixture.force_encoding("utf-8")
response_mime_type = Mime::Type.lookup(response.content_type) response_mime_type = Mime::Type.lookup(response.content_type)
if response_mime_type.html? if response_mime_type.html?
...@@ -47,7 +48,7 @@ module JavaScriptFixturesHelpers ...@@ -47,7 +48,7 @@ module JavaScriptFixturesHelpers
link_tags = doc.css('link') link_tags = doc.css('link')
link_tags.remove link_tags.remove
scripts = doc.css('script') scripts = doc.css("script:not([type='text/template'])")
scripts.remove scripts.remove
fixture = doc.to_html fixture = doc.to_html
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment