Sha256: 44d8fa2daa1a20ec955706971db8a12bffc00091796b0b167bf6b0073df51c85

Contents?: true

Size: 1.24 KB

Versions: 54

Compression:

Stored size: 1.24 KB

Contents

require 'spec_helper'
require 'rack/csrf'

describe Locomotive::Steam::Liquid::Tags::Csrf do

  before do
    allow(Rack::Csrf).to receive(:field).and_return('token')
    allow(Rack::Csrf).to receive(:token).and_return(42)
  end

  let(:request)   { instance_double('Request', env: {}) }
  let(:services)  { Locomotive::Steam::Services.build_instance(request) }
  let(:context)   { ::Liquid::Context.new({}, {}, { services: services }) }

  subject { render_template(template, context) }

  describe 'csrf_param' do

    let(:template)  { '{% csrf_param %}' }
    it { is_expected.to eq '<input type="hidden" name="token" value="42" />' }

    context 'protection not enabled' do

      before { allow(services.configuration).to receive(:csrf_protection).and_return(false) }
      it { is_expected.to eq '' }

    end

  end

  describe 'rendering the meta tag used by ajax requests' do

    let(:template)  { '{% csrf_meta %}' }

    it { is_expected.to match '<meta name="csrf-param" content="token" />' }
    it { is_expected.to match '<meta name="csrf-token" content="42" />' }

    context 'protection not enabled' do

      before { allow(services.configuration).to receive(:csrf_protection).and_return(false) }
      it { is_expected.to eq '' }

    end

  end

end

Version data entries

54 entries across 54 versions & 1 rubygems

Version Path
locomotivecms_steam-1.8.0.alpha2 spec/unit/liquid/tags/csrf_spec.rb
locomotivecms_steam-1.8.0.alpha1 spec/unit/liquid/tags/csrf_spec.rb
locomotivecms_steam-1.7.1 spec/unit/liquid/tags/csrf_spec.rb
locomotivecms_steam-1.7.0 spec/unit/liquid/tags/csrf_spec.rb
locomotivecms_steam-1.6.1 spec/unit/liquid/tags/csrf_spec.rb
locomotivecms_steam-1.6.0 spec/unit/liquid/tags/csrf_spec.rb
locomotivecms_steam-1.6.0.rc1 spec/unit/liquid/tags/csrf_spec.rb
locomotivecms_steam-1.6.0.beta1 spec/unit/liquid/tags/csrf_spec.rb
locomotivecms_steam-1.5.3 spec/unit/liquid/tags/csrf_spec.rb
locomotivecms_steam-1.5.2 spec/unit/liquid/tags/csrf_spec.rb
locomotivecms_steam-1.5.1 spec/unit/liquid/tags/csrf_spec.rb
locomotivecms_steam-1.5.0 spec/unit/liquid/tags/csrf_spec.rb
locomotivecms_steam-1.5.0.rc1 spec/unit/liquid/tags/csrf_spec.rb
locomotivecms_steam-1.5.0.rc0 spec/unit/liquid/tags/csrf_spec.rb
locomotivecms_steam-1.5.0.beta3 spec/unit/liquid/tags/csrf_spec.rb
locomotivecms_steam-1.5.0.beta2 spec/unit/liquid/tags/csrf_spec.rb
locomotivecms_steam-1.5.0.beta1 spec/unit/liquid/tags/csrf_spec.rb
locomotivecms_steam-1.4.1 spec/unit/liquid/tags/csrf_spec.rb
locomotivecms_steam-1.4.0 spec/unit/liquid/tags/csrf_spec.rb
locomotivecms_steam-1.4.0.rc2 spec/unit/liquid/tags/csrf_spec.rb