fortress 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,81 @@
1
+ require 'spec_helper'
2
+ require 'fortress/mechanism'
3
+
4
+ describe Fortress::Mechanism do
5
+ before { @controller = OpenStruct.new(name: 'ConcertsController') }
6
+ describe '.parse_options' do
7
+ context 'passing the `:if` option' do
8
+ context 'with the `:index` action only' do
9
+ it 'should add the `:if` key to the controller key with ' \
10
+ 'the `:action` Array [:index]' do
11
+ subject.parse_options(@controller, :index, if: :method_name)
12
+
13
+ controller_if = subject.authorisations['ConcertsController'][:if]
14
+ expect(controller_if).to be_present
15
+
16
+ expect(controller_if[:actions]).to eql([:index])
17
+ end
18
+ end
19
+ context 'with actions `:index, :show, :destroy`' do
20
+ it 'should add the `:if` key to the controller key with ' \
21
+ 'the `:action` Array [:index, :show, :destroy]' do
22
+ subject.parse_options(@controller, [:index, :show, :destroy],
23
+ if: :method_name)
24
+
25
+ controller_if = subject.authorisations['ConcertsController'][:if]
26
+ expect(controller_if).to be_present
27
+
28
+ expect(controller_if[:actions]).to eql([:index, :show, :destroy])
29
+ end
30
+ end
31
+ end
32
+ context 'passing the `:except` option' do
33
+ context 'with `:index` action only' do
34
+ it 'should add the `:except` key to the controller key with ' \
35
+ 'the `:action` Array [:index]' do
36
+ subject.parse_options(@controller, nil, except: :index)
37
+
38
+ excepted = subject.authorisations['ConcertsController'][:except]
39
+ expect(excepted).to eql([:index])
40
+ end
41
+ end
42
+ context 'with `:index, :new, :update` actions' do
43
+ it 'should add the `:except` key to the controller key with ' \
44
+ 'the `:action` Array [:index, :new, :update]' do
45
+ subject.parse_options(@controller, nil,
46
+ except: [:index, :new, :update])
47
+
48
+ excepted = subject.authorisations['ConcertsController'][:except]
49
+ expect(excepted).to eql([:index, :new, :update])
50
+ end
51
+ end
52
+ end
53
+ end
54
+ describe '.authorise!' do
55
+ context 'passing `:all`' do
56
+ it 'should add the `:all` key as true to the controller key' do
57
+ subject.authorise!('ConcertsController', :all)
58
+
59
+ expect(subject.authorisations['ConcertsController'][:all]).to be_truthy
60
+ end
61
+ end
62
+ context 'passing `:index`' do
63
+ it 'should add the `:only` key as the Array [:index] to ' \
64
+ 'the controller key' do
65
+ subject.authorise!('ConcertsController', :index)
66
+
67
+ controller_only = subject.authorisations['ConcertsController'][:only]
68
+ expect(controller_only).to eql([:index])
69
+ end
70
+ end
71
+ context 'passing `[:index, :destroy]`' do
72
+ it 'should add the `:only` key as the Array [:index] to ' \
73
+ 'the controller key' do
74
+ subject.authorise!('ConcertsController', [:index, :destroy])
75
+
76
+ controller_only = subject.authorisations['ConcertsController'][:only]
77
+ expect(controller_only).to eql([:index, :destroy])
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,92 @@
1
+ require 'action_controller/railtie'
2
+ require 'rspec/rails'
3
+
4
+ require 'fortress/controller'
5
+
6
+ # This file was generated by the `rspec --init` command. Conventionally, all
7
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
8
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
9
+ # this file to always be loaded, without a need to explicitly require it in any
10
+ # files.
11
+ #
12
+ # Given that it is always loaded, you are encouraged to keep this file as
13
+ # light-weight as possible. Requiring heavyweight dependencies from this file
14
+ # will add to the boot time of your test suite on EVERY test run, even for an
15
+ # individual file that may not need all of that loaded. Instead, consider
16
+ # making a separate helper file that requires the additional dependencies and
17
+ # performs the additional setup, and require it from the spec files that
18
+ # actually need it.
19
+ #
20
+ # The `.rspec` file also contains a few flags that are not defaults but that
21
+ # users commonly want.
22
+ #
23
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
24
+ RSpec.configure do |config|
25
+ # rspec-expectations config goes here. You can use an alternate
26
+ # assertion/expectation library such as wrong or the stdlib/minitest
27
+ # assertions if you prefer.
28
+ config.expect_with :rspec do |expectations|
29
+ # This option will default to `true` in RSpec 4. It makes the `description`
30
+ # and `failure_message` of custom matchers include text for helper methods
31
+ # defined using `chain`, e.g.:
32
+ # be_bigger_than(2).and_smaller_than(4).description
33
+ # # => "be bigger than 2 and smaller than 4"
34
+ # ...rather than:
35
+ # # => "be bigger than 2"
36
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
37
+ end
38
+
39
+ # rspec-mocks config goes here. You can use an alternate test double
40
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
41
+ config.mock_with :rspec do |mocks|
42
+ # Prevents you from mocking or stubbing a method that does not exist on
43
+ # a real object. This is generally recommended, and will default to
44
+ # `true` in RSpec 4.
45
+ mocks.verify_partial_doubles = true
46
+ end
47
+
48
+ # The settings below are suggested to provide a good initial experience
49
+ # with RSpec, but feel free to customize to your heart's content.
50
+
51
+ # These two settings work together to allow you to limit a spec run
52
+ # to individual examples or groups you care about by tagging them with
53
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
54
+ # get run.
55
+ # config.filter_run :focus
56
+ # config.run_all_when_everything_filtered = true
57
+
58
+ # Limits the available syntax to the non-monkey patched syntax that is
59
+ # recommended.
60
+ # config.disable_monkey_patching!
61
+
62
+ # This setting enables warnings. It's recommended, but in some cases may
63
+ # be too noisy due to issues in dependencies.
64
+ # config.warnings = true
65
+
66
+ # Many RSpec users commonly either run the entire suite or an individual
67
+ # file, and it's useful to allow more verbose output when running an
68
+ # individual spec file.
69
+ # if config.files_to_run.one?
70
+ # # Use the documentation formatter for detailed output,
71
+ # # unless a formatter has already been configured
72
+ # # (e.g. via a command-line flag).
73
+ # config.default_formatter = 'doc'
74
+ # end
75
+
76
+ # Print the 10 slowest examples and example groups at the
77
+ # end of the spec run, to help surface which specs are running
78
+ # particularly slow.
79
+ # config.profile_examples = 10
80
+
81
+ # Run specs in random order to surface order dependencies. If you find an
82
+ # order dependency and want to debug it, you can fix the order by providing
83
+ # the seed, which is printed after each run.
84
+ # --seed 1234
85
+ # config.order = :random
86
+
87
+ # Seed global randomization in this process using the `--seed` CLI option.
88
+ # Setting this allows you to use `--seed` to deterministically reproduce
89
+ # test failures related to randomization by passing the same `--seed` value
90
+ # as the one that triggered the failure.
91
+ # Kernel.srand config.seed
92
+ end
metadata ADDED
@@ -0,0 +1,199 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fortress
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Guillaume Hain
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: actionpack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: 'The rigths management libraries available today are all based on the
112
+ principle: everything is open and you close it explicitely. Fortress is immediately
113
+ closing access to every actions of every controllers when you install it. It''s
114
+ then up to you to open the allowed actions.'
115
+ email:
116
+ - zedtux@zedroot.org
117
+ executables:
118
+ - bundler
119
+ - erubis
120
+ - htmldiff
121
+ - ldiff
122
+ - nokogiri
123
+ - rackup
124
+ - rails
125
+ - rake
126
+ - rspec
127
+ - rubocop
128
+ - ruby-parse
129
+ - ruby-rewrite
130
+ - thor
131
+ extensions: []
132
+ extra_rdoc_files: []
133
+ files:
134
+ - ".gitignore"
135
+ - ".rspec"
136
+ - ".ruby-gemset"
137
+ - ".ruby-version"
138
+ - ".travis.yml"
139
+ - Gemfile
140
+ - LICENSE.txt
141
+ - README.md
142
+ - Rakefile
143
+ - bin/bundler
144
+ - bin/erubis
145
+ - bin/htmldiff
146
+ - bin/ldiff
147
+ - bin/nokogiri
148
+ - bin/rackup
149
+ - bin/rails
150
+ - bin/rake
151
+ - bin/rspec
152
+ - bin/rubocop
153
+ - bin/ruby-parse
154
+ - bin/ruby-rewrite
155
+ - bin/thor
156
+ - fortress.gemspec
157
+ - lib/fortress.rb
158
+ - lib/fortress/controller.rb
159
+ - lib/fortress/controller_interface.rb
160
+ - lib/fortress/mechanism.rb
161
+ - lib/fortress/version.rb
162
+ - spec/fixtures/application.rb
163
+ - spec/fixtures/controllers.rb
164
+ - spec/fortress/controller_interface_spec.rb
165
+ - spec/fortress/controller_spec.rb
166
+ - spec/fortress/mechanism_spec.rb
167
+ - spec/spec_helper.rb
168
+ homepage: https://github.com/YourCursus/fortress
169
+ licenses:
170
+ - MIT
171
+ metadata: {}
172
+ post_install_message:
173
+ rdoc_options: []
174
+ require_paths:
175
+ - lib
176
+ required_ruby_version: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ required_rubygems_version: !ruby/object:Gem::Requirement
182
+ requirements:
183
+ - - ">="
184
+ - !ruby/object:Gem::Version
185
+ version: '0'
186
+ requirements: []
187
+ rubyforge_project:
188
+ rubygems_version: 2.4.5
189
+ signing_key:
190
+ specification_version: 4
191
+ summary: Secure your Rails application from preventing access to everything to opening
192
+ allowed actions.
193
+ test_files:
194
+ - spec/fixtures/application.rb
195
+ - spec/fixtures/controllers.rb
196
+ - spec/fortress/controller_interface_spec.rb
197
+ - spec/fortress/controller_spec.rb
198
+ - spec/fortress/mechanism_spec.rb
199
+ - spec/spec_helper.rb