Sha256: f345fcd485dcefac3f52356deb8159dbb802d1d6c43bb50c94c62379d0e64bed

Contents?: true

Size: 1.98 KB

Versions: 9

Compression:

Stored size: 1.98 KB

Contents

require 'spec_helper'

describe CASino::ServiceRule do
  describe '.allowed?' do
    context 'with an empty table' do
      ['https://www.example.org/', 'http://www.google.com/'].each do |service_url|
        it "allows access to #{service_url}" do
          described_class.allowed?(service_url).should == true
        end
      end
    end

    context 'with a regex rule' do
      before(:each) do
        FactoryGirl.create :service_rule, :regex, url: '^https://.*'
      end

      ['https://www.example.org/', 'https://www.google.com/'].each do |service_url|
        it "allows access to #{service_url}" do
          described_class.allowed?(service_url).should == true
        end
      end

      ['http://www.example.org/', 'http://www.google.com/'].each do |service_url|
        it "does not allow access to #{service_url}" do
          described_class.allowed?(service_url).should == false
        end
      end
    end

    context 'with many regex rules' do
      before(:each) do
        100.times do |counter|
          FactoryGirl.create :service_rule, :regex, url: "^https://www#{counter}.example.com"
        end
      end

      let(:service_url) { 'https://www111.example.com/bla' }

      it 'does not take too long to check a denied service' do
        start = Time.now
        described_class.allowed?(service_url).should == false
        (Time.now - start).should < 0.1
      end
    end

    context 'with a non-regex rule' do
      before(:each) do
        FactoryGirl.create :service_rule, url: 'https://www.google.com/foo'
      end

      ['https://www.google.com/foo'].each do |service_url|
        it "allows access to #{service_url}" do
          described_class.allowed?(service_url).should == true
        end
      end

      ['https://www.example.org/', 'http://www.example.org/', 'https://www.google.com/test'].each do |service_url|
        it "does not allow access to #{service_url}" do
          described_class.allowed?(service_url).should == false
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
casino-2.0.7 spec/model/service_rule_spec.rb
casino-3.0.0.pre.1 spec/model/service_rule_spec.rb
casino-2.0.6 spec/model/service_rule_spec.rb
casino-2.0.5 spec/model/service_rule_spec.rb
casino-2.0.4 spec/model/service_rule_spec.rb
casino-2.0.3 spec/model/service_rule_spec.rb
casino-2.0.2 spec/model/service_rule_spec.rb
casino-2.0.1 spec/model/service_rule_spec.rb
casino-2.0.0 spec/model/service_rule_spec.rb