summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorMike Greiling <mike@pixelcog.com>2017-01-05 14:10:43 -0600
committerMike Greiling <mike@pixelcog.com>2017-01-05 14:10:43 -0600
commit10d483eaaaccc336399fa83a0ac5f7ecd9cea352 (patch)
tree14d9df1251e0fd0cccccfd20a92f06fabf0a28dd /spec
parent5997a86e680e22454522819e1b959d18cad48d1f (diff)
parentdf5223de61253ba1511ae3ecbb7c447819177ecb (diff)
downloadgitlab-ce-10d483eaaaccc336399fa83a0ac5f7ecd9cea352.tar.gz
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
Diffstat (limited to 'spec')
-rw-r--r--spec/javascripts/fixtures/u2f.rb48
-rw-r--r--spec/javascripts/u2f/authenticate_spec.js4
-rw-r--r--spec/javascripts/u2f/register_spec.js4
-rw-r--r--spec/support/javascript_fixtures_helpers.rb3
4 files changed, 36 insertions, 23 deletions
diff --git a/spec/javascripts/fixtures/u2f.rb b/spec/javascripts/fixtures/u2f.rb
index 076c38ec4b1..c9c0b891237 100644
--- a/spec/javascripts/fixtures/u2f.rb
+++ b/spec/javascripts/fixtures/u2f.rb
@@ -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)
- end
+ describe SessionsController, '(JavaScript fixtures)', type: :controller do
+ render_views
+
+ before do
+ @request.env['devise.mapping'] = Devise.mappings[:user]
+ end
- it 'u2f/register.html.raw' do |example|
- user = build(:user, :two_factor_via_otp)
+ it 'u2f/authenticate.html.raw' do |example|
+ allow(controller).to receive(:find_user).and_return(user)
- 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)
+ post :create, user: { login: user.username, password: user.password }
+
+ expect(response).to be_success
+ store_frontend_fixture(response, example.description)
+ 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)
- 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
diff --git a/spec/javascripts/u2f/authenticate_spec.js b/spec/javascripts/u2f/authenticate_spec.js
index cd40a1e321f..f6399b22865 100644
--- a/spec/javascripts/u2f/authenticate_spec.js
+++ b/spec/javascripts/u2f/authenticate_spec.js
@@ -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(
diff --git a/spec/javascripts/u2f/register_spec.js b/spec/javascripts/u2f/register_spec.js
index 9fb150a2c8f..7eda2ac4c24 100644
--- a/spec/javascripts/u2f/register_spec.js
+++ b/spec/javascripts/u2f/register_spec.js
@@ -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");
diff --git a/spec/support/javascript_fixtures_helpers.rb b/spec/support/javascript_fixtures_helpers.rb
index 29dd4de62ff..0b8729db0f9 100644
--- a/spec/support/javascript_fixtures_helpers.rb
+++ b/spec/support/javascript_fixtures_helpers.rb
@@ -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