miau 1.1.6 → 1.1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/lib/miau/error.rb +4 -8
  3. data/lib/miau/error.rb.bak +10 -0
  4. data/lib/miau/run.rb +2 -2
  5. data/lib/miau/version.rb +2 -1
  6. data/lib/miau/version.rb.bak +16 -0
  7. data/lib/miau.rb +5 -0
  8. data/lib/miau.rb.bak +74 -0
  9. metadata +10 -52
  10. data/.github/workflows/rake.yml +0 -27
  11. data/.gitignore +0 -10
  12. data/.ruby-gemset +0 -1
  13. data/.ruby-version +0 -1
  14. data/Appraisals +0 -13
  15. data/Gemfile +0 -12
  16. data/Gemfile.lock +0 -279
  17. data/Rakefile +0 -10
  18. data/gemfiles/rails_6.1.gemfile +0 -16
  19. data/gemfiles/rails_7.0.gemfile +0 -16
  20. data/gemfiles/rails_7.1.gemfile +0 -15
  21. data/miau.gemspec +0 -27
  22. data/test/authorization_test.rb +0 -28
  23. data/test/benchmark_test.rb +0 -34
  24. data/test/controller_test.rb +0 -58
  25. data/test/controllers/orders_controller_test.rb +0 -47
  26. data/test/internal/app/controllers/application_controller.rb +0 -7
  27. data/test/internal/app/controllers/orders_controller.rb +0 -61
  28. data/test/internal/app/controllers/posts_controller.rb +0 -10
  29. data/test/internal/app/models/application_record.rb +0 -3
  30. data/test/internal/app/models/order.rb +0 -2
  31. data/test/internal/app/models/post.rb +0 -2
  32. data/test/internal/app/policies/orders_policy.rb +0 -16
  33. data/test/internal/app/policies/posts_policy.rb +0 -18
  34. data/test/internal/app/views/orders/new.html.erb +0 -5
  35. data/test/internal/config/database.yml +0 -3
  36. data/test/internal/config/routes.rb +0 -3
  37. data/test/internal/db/migrate/20141016161801_create_orders.rb +0 -10
  38. data/test/internal/db/schema.rb +0 -8
  39. data/test/miau_test.rb +0 -46
  40. data/test/run_test.rb +0 -69
  41. data/test/storage_test.rb +0 -51
  42. data/test/test_helper.rb +0 -17
  43. /data/{LICENSE → MIT-LICENSE} +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4ff4fcf400151bdd20347e5bc2cd8f215a11e8ea6b519840c6032ed3ac18a57b
4
- data.tar.gz: bc678ee4c5c2029d66a5f9d7970ae81e0eb334bb4a493cde94f3445f5d1a9e25
3
+ metadata.gz: bfe1c8f3bc0844078afe66eb87172eb9d372e727cedc6a3d99e276b37b741c4a
4
+ data.tar.gz: 0dc15287104641bec95f8073387e047770dfd5b02f5f5e5980f6357f460450fb
5
5
  SHA512:
6
- metadata.gz: a2f4c5d1a4b5947fe6d5ff836291909d5428de7e0745d7e50654327637b173c573646446c4846ca62789b1f590e13fe43f057fa82eac7a03c85faf7483115014
7
- data.tar.gz: f87d22f71705710792a13a2490d71a632a3c55fd0f40bd7cf5e342d58b58c6066777e23dab777af0a0e674103182dec768caf04a73d9f6db58a35ed5453f2e9a
6
+ metadata.gz: 913283a22edaf93ce62275e9a93e30971fdeacd15ba8eb3f5d5066a74d745535a6d992aac40ca94fae58eb006f3bcb4cb8a6bcb28496e9a105509e250a28d8f2
7
+ data.tar.gz: effe13f27bd0da506d83203c0f454f9df5fd6305c726184d7eb13e92d903719fa8df2fc1fe768ec58ff43a917e3c6c102a3aee76c99957020000a13a285c5767
data/lib/miau/error.rb CHANGED
@@ -3,15 +3,11 @@
3
3
  module Miau
4
4
  class Error < StandardError; end
5
5
 
6
- class NotAuthorizedError < Error
7
- end
6
+ class NotAuthorizedError < Error; end
8
7
 
9
- class NotDefinedError < Error
10
- end
8
+ class NotDefinedError < Error; end
11
9
 
12
- class AuthorizationNotPerformedError < Error
13
- end
10
+ class AuthorizationNotPerformedError < Error; end
14
11
 
15
- class OverwriteError < Error
16
- end
12
+ class OverwriteError < Error; end
17
13
  end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Miau
4
+ class Error < StandardError; end
5
+
6
+ class NotAuthorizedError < Error; end
7
+ class NotDefinedError < Error; end
8
+ class AuthorizationNotPerformedError < Error; end
9
+ class OverwriteError < Error; end
10
+ end
data/lib/miau/run.rb CHANGED
@@ -36,12 +36,12 @@ module Miau
36
36
  end
37
37
 
38
38
  def raise_undef(policy, action)
39
- msg = "NotDefined policy <#{policy}> action <#{action}>"
39
+ msg = "policy <#{policy}> action <#{action}>"
40
40
  raise NotDefinedError, msg
41
41
  end
42
42
 
43
43
  def raise_authorize(controller, action)
44
- msg = "NotAuthorized controller <#{controller}> action <#{action}>"
44
+ msg = "controller <#{controller}> action <#{action}>"
45
45
  raise NotAuthorizedError, msg
46
46
  end
47
47
  end
data/lib/miau/version.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Miau
4
- VERSION = "1.1.6" # 2024-01-13
4
+ VERSION = "1.1.7" # 2024-04-24
5
+ # VERSION = "1.1.6" # 2024-01-13
5
6
  # VERSION = "1.1.1" # 2024-01-06
6
7
  # VERSION = "1.1.0" # 2024-01-06
7
8
  # VERSION = "1.0.3" # 2023-12-13
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Miau
4
+ VERSION = "1.1.6" # 2024-01-13
5
+ # VERSION = "1.1.1" # 2024-01-06
6
+ # VERSION = "1.1.0" # 2024-01-06
7
+ # VERSION = "1.0.3" # 2023-12-13
8
+ # VERSION = "1.0.2" # 2023-11-05
9
+ # VERSION = "1.0.1" # 2023-04-24
10
+ # VERSION = "1.0.0" # 2022-01-23
11
+ # VERSION = "0.1.2" # 2021-12-10
12
+ # VERSION = "0.1.1" # 2021-11-06
13
+ # VERSION = "0.1.0" # 2021-09-13
14
+ # VERSION = "0.0.2" # 2021-09-11
15
+ # VERSION = "0.0.1"
16
+ end
data/lib/miau.rb CHANGED
@@ -44,6 +44,11 @@ module Miau
44
44
  controller = params[:controller].to_sym
45
45
  action = params[:action].to_sym
46
46
  policy = PolicyStorage.instance.find_or_create_policy(controller)
47
+ unless policy
48
+ msg = "missing class #{controller.capitalize}Policy"
49
+ raise NotDefinedError, msg
50
+ end
51
+
47
52
  policy.user = miau_user
48
53
  policy.action = action
49
54
 
data/lib/miau.rb.bak ADDED
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concern"
4
+ require "miau/version"
5
+ require "miau/error"
6
+ require "miau/storage"
7
+ require "miau/run"
8
+ require "miau/application_policy"
9
+
10
+ module Miau
11
+ extend ActiveSupport::Concern
12
+
13
+ included do
14
+ if respond_to?(:helper_method)
15
+ helper_method :authorized?
16
+ helper_method :miau_user
17
+ end
18
+ end
19
+
20
+ def authorize!(resource = nil, hsh = {})
21
+ @_miau_authorization_performed = true
22
+ return true if authorized?(resource, hsh)
23
+
24
+ controller = params[:controller].to_sym
25
+ action = params[:action].to_sym
26
+ PolicyRun.instance.raise_authorize(controller, action)
27
+ end
28
+
29
+ def authorized?(resource = nil, hsh = {})
30
+ controller = params[:controller].to_sym
31
+ action = params[:action].to_sym
32
+ policy = PolicyStorage.instance.find_or_create_policy(controller)
33
+ PolicyRun.instance.raise_undef(policy, action) unless policy
34
+
35
+ policy.user = miau_user
36
+ policy.resource = resource
37
+ methods = PolicyRun.instance.find_methods(policy, controller, action)
38
+ PolicyRun.instance.raise_undef(policy, action) unless methods
39
+
40
+ PolicyRun.instance.runs(policy, methods)
41
+ end
42
+
43
+ def authorize_controller!
44
+ controller = params[:controller].to_sym
45
+ action = params[:action].to_sym
46
+ policy = PolicyStorage.instance.find_or_create_policy(controller)
47
+ p 22222
48
+ unless policy
49
+ p 11111111111111
50
+ # msg = "undefined class #{controller.capitalize}Policy"
51
+ # raise NotDefinedError, msg
52
+ end
53
+
54
+ policy.user = miau_user
55
+ policy.action = action
56
+
57
+ @_miau_authorization_performed = true
58
+ return true if PolicyRun.instance.runs(policy, :controller)
59
+
60
+ PolicyRun.instance.raise_authorize policy, action
61
+ end
62
+
63
+ def miau_user
64
+ current_user
65
+ end
66
+
67
+ def verify_authorized
68
+ raise AuthorizationNotPerformedError unless miau_authorization_performed?
69
+ end
70
+
71
+ def miau_authorization_performed?
72
+ !!@_miau_authorization_performed
73
+ end
74
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: miau
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.6
4
+ version: 1.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dittmar Krall
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-13 00:00:00.000000000 Z
11
+ date: 2024-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: appraisal
@@ -66,69 +66,27 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: sqlite3
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
69
  description: |
84
70
  MIAU (MIcro AUthorization) provides some helpers which
85
71
  raises an exception if a given user violates a policy.
86
72
  email: dittmar.krall@matiq.com
87
73
  executables: []
88
74
  extensions: []
89
- extra_rdoc_files: []
75
+ extra_rdoc_files:
76
+ - README.md
77
+ - MIT-LICENSE
90
78
  files:
91
- - ".github/workflows/rake.yml"
92
- - ".gitignore"
93
- - ".ruby-gemset"
94
- - ".ruby-version"
95
- - Appraisals
96
- - Gemfile
97
- - Gemfile.lock
98
- - LICENSE
79
+ - MIT-LICENSE
99
80
  - README.md
100
- - Rakefile
101
- - gemfiles/rails_6.1.gemfile
102
- - gemfiles/rails_7.0.gemfile
103
- - gemfiles/rails_7.1.gemfile
104
81
  - lib/miau.rb
82
+ - lib/miau.rb.bak
105
83
  - lib/miau/application_policy.rb
106
84
  - lib/miau/error.rb
85
+ - lib/miau/error.rb.bak
107
86
  - lib/miau/run.rb
108
87
  - lib/miau/storage.rb
109
88
  - lib/miau/version.rb
110
- - miau.gemspec
111
- - test/authorization_test.rb
112
- - test/benchmark_test.rb
113
- - test/controller_test.rb
114
- - test/controllers/orders_controller_test.rb
115
- - test/internal/app/controllers/application_controller.rb
116
- - test/internal/app/controllers/orders_controller.rb
117
- - test/internal/app/controllers/posts_controller.rb
118
- - test/internal/app/models/application_record.rb
119
- - test/internal/app/models/order.rb
120
- - test/internal/app/models/post.rb
121
- - test/internal/app/policies/orders_policy.rb
122
- - test/internal/app/policies/posts_policy.rb
123
- - test/internal/app/views/orders/new.html.erb
124
- - test/internal/config/database.yml
125
- - test/internal/config/routes.rb
126
- - test/internal/db/migrate/20141016161801_create_orders.rb
127
- - test/internal/db/schema.rb
128
- - test/miau_test.rb
129
- - test/run_test.rb
130
- - test/storage_test.rb
131
- - test/test_helper.rb
89
+ - lib/miau/version.rb.bak
132
90
  homepage: https://github.com/matique/miau
133
91
  licenses:
134
92
  - MIT
@@ -148,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
106
  - !ruby/object:Gem::Version
149
107
  version: '0'
150
108
  requirements: []
151
- rubygems_version: 3.5.3
109
+ rubygems_version: 3.5.9
152
110
  signing_key:
153
111
  specification_version: 4
154
112
  summary: Simple and lightweight authorization solution for Rails.
@@ -1,27 +0,0 @@
1
- # see also https://github.com/whitequark/parser/blob/master/.github/workflows/test.yml
2
- name: Rake
3
-
4
- on: [push]
5
-
6
- jobs:
7
- test:
8
- strategy:
9
- fail-fast: false
10
- matrix:
11
- ruby_version: ["3.0", 3.2, 3.3]
12
- gemfile:
13
- - Gemfile
14
- - gemfiles/Gemfile.rails-7.1
15
- - gemfiles/Gemfile.rails-7.0
16
- - gemfiles/Gemfile.rails-6.1
17
- runs-on: ubuntu-latest
18
-
19
- steps:
20
- - uses: actions/checkout@v3
21
- - name: Set up Ruby
22
- uses: ruby/setup-ruby@v1
23
- with:
24
- ruby-version: ${{ matrix.ruby_version }}
25
- bundler-cache: true
26
- - name: Build and test with Rake
27
- run: bundle exec rake
data/.gitignore DELETED
@@ -1,10 +0,0 @@
1
- /.bundle/
2
- /tmp/
3
- /coverage/
4
- /.watchr
5
-
6
- *.gem
7
- *.log
8
- *.lock
9
-
10
- **/db/test.sqlite*
data/.ruby-gemset DELETED
@@ -1 +0,0 @@
1
- rails-7.1
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- ruby-3.3.0
data/Appraisals DELETED
@@ -1,13 +0,0 @@
1
- appraise "rails-7.1" do
2
- gem "rails", "~> 7.1"
3
- end
4
-
5
- appraise "rails-7.0" do
6
- gem "rails", "~> 7.0"
7
- gem "dryer-config", "~> 7.0"
8
- end
9
-
10
- appraise "rails-6.1" do
11
- gem "rails", "~> 6.1"
12
- gem "dryer-config", "~> 6.0"
13
- end
data/Gemfile DELETED
@@ -1,12 +0,0 @@
1
- source "https://rubygems.org"
2
- gemspec
3
-
4
- gem "rails"
5
-
6
- group :test do
7
- gem "benchmark-ips"
8
- gem "observr"
9
- gem "ricecream"
10
- gem "simplecov", require: false
11
- gem "standard", require: false
12
- end
data/Gemfile.lock DELETED
@@ -1,279 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- miau (1.1.6)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- actioncable (7.1.2)
10
- actionpack (= 7.1.2)
11
- activesupport (= 7.1.2)
12
- nio4r (~> 2.0)
13
- websocket-driver (>= 0.6.1)
14
- zeitwerk (~> 2.6)
15
- actionmailbox (7.1.2)
16
- actionpack (= 7.1.2)
17
- activejob (= 7.1.2)
18
- activerecord (= 7.1.2)
19
- activestorage (= 7.1.2)
20
- activesupport (= 7.1.2)
21
- mail (>= 2.7.1)
22
- net-imap
23
- net-pop
24
- net-smtp
25
- actionmailer (7.1.2)
26
- actionpack (= 7.1.2)
27
- actionview (= 7.1.2)
28
- activejob (= 7.1.2)
29
- activesupport (= 7.1.2)
30
- mail (~> 2.5, >= 2.5.4)
31
- net-imap
32
- net-pop
33
- net-smtp
34
- rails-dom-testing (~> 2.2)
35
- actionpack (7.1.2)
36
- actionview (= 7.1.2)
37
- activesupport (= 7.1.2)
38
- nokogiri (>= 1.8.5)
39
- racc
40
- rack (>= 2.2.4)
41
- rack-session (>= 1.0.1)
42
- rack-test (>= 0.6.3)
43
- rails-dom-testing (~> 2.2)
44
- rails-html-sanitizer (~> 1.6)
45
- actiontext (7.1.2)
46
- actionpack (= 7.1.2)
47
- activerecord (= 7.1.2)
48
- activestorage (= 7.1.2)
49
- activesupport (= 7.1.2)
50
- globalid (>= 0.6.0)
51
- nokogiri (>= 1.8.5)
52
- actionview (7.1.2)
53
- activesupport (= 7.1.2)
54
- builder (~> 3.1)
55
- erubi (~> 1.11)
56
- rails-dom-testing (~> 2.2)
57
- rails-html-sanitizer (~> 1.6)
58
- activejob (7.1.2)
59
- activesupport (= 7.1.2)
60
- globalid (>= 0.3.6)
61
- activemodel (7.1.2)
62
- activesupport (= 7.1.2)
63
- activerecord (7.1.2)
64
- activemodel (= 7.1.2)
65
- activesupport (= 7.1.2)
66
- timeout (>= 0.4.0)
67
- activestorage (7.1.2)
68
- actionpack (= 7.1.2)
69
- activejob (= 7.1.2)
70
- activerecord (= 7.1.2)
71
- activesupport (= 7.1.2)
72
- marcel (~> 1.0)
73
- activesupport (7.1.2)
74
- base64
75
- bigdecimal
76
- concurrent-ruby (~> 1.0, >= 1.0.2)
77
- connection_pool (>= 2.2.5)
78
- drb
79
- i18n (>= 1.6, < 2)
80
- minitest (>= 5.1)
81
- mutex_m
82
- tzinfo (~> 2.0)
83
- appraisal (2.5.0)
84
- bundler
85
- rake
86
- thor (>= 0.14.0)
87
- ast (2.4.2)
88
- base64 (0.2.0)
89
- benchmark-ips (2.13.0)
90
- bigdecimal (3.1.5)
91
- builder (3.2.4)
92
- combustion (1.3.7)
93
- activesupport (>= 3.0.0)
94
- railties (>= 3.0.0)
95
- thor (>= 0.14.6)
96
- concurrent-ruby (1.2.2)
97
- connection_pool (2.4.1)
98
- crass (1.0.6)
99
- date (3.3.4)
100
- docile (1.4.0)
101
- drb (2.2.0)
102
- ruby2_keywords
103
- erubi (1.12.0)
104
- globalid (1.2.1)
105
- activesupport (>= 6.1)
106
- i18n (1.14.1)
107
- concurrent-ruby (~> 1.0)
108
- io-console (0.7.1)
109
- irb (1.11.1)
110
- rdoc
111
- reline (>= 0.4.2)
112
- json (2.7.1)
113
- language_server-protocol (3.17.0.3)
114
- lint_roller (1.1.0)
115
- loofah (2.22.0)
116
- crass (~> 1.0.2)
117
- nokogiri (>= 1.12.0)
118
- mail (2.8.1)
119
- mini_mime (>= 0.1.1)
120
- net-imap
121
- net-pop
122
- net-smtp
123
- marcel (1.0.2)
124
- mini_mime (1.1.5)
125
- minitest (5.21.1)
126
- mutex_m (0.2.0)
127
- net-imap (0.4.9.1)
128
- date
129
- net-protocol
130
- net-pop (0.1.2)
131
- net-protocol
132
- net-protocol (0.2.2)
133
- timeout
134
- net-smtp (0.4.0.1)
135
- net-protocol
136
- nio4r (2.7.0)
137
- nokogiri (1.16.0-aarch64-linux)
138
- racc (~> 1.4)
139
- nokogiri (1.16.0-arm-linux)
140
- racc (~> 1.4)
141
- nokogiri (1.16.0-arm64-darwin)
142
- racc (~> 1.4)
143
- nokogiri (1.16.0-x86-linux)
144
- racc (~> 1.4)
145
- nokogiri (1.16.0-x86_64-darwin)
146
- racc (~> 1.4)
147
- nokogiri (1.16.0-x86_64-linux)
148
- racc (~> 1.4)
149
- observr (1.0.5)
150
- parallel (1.24.0)
151
- parser (3.3.0.3)
152
- ast (~> 2.4.1)
153
- racc
154
- psych (5.1.2)
155
- stringio
156
- racc (1.7.3)
157
- rack (3.0.8)
158
- rack-session (2.0.0)
159
- rack (>= 3.0.0)
160
- rack-test (2.1.0)
161
- rack (>= 1.3)
162
- rackup (2.1.0)
163
- rack (>= 3)
164
- webrick (~> 1.8)
165
- rails (7.1.2)
166
- actioncable (= 7.1.2)
167
- actionmailbox (= 7.1.2)
168
- actionmailer (= 7.1.2)
169
- actionpack (= 7.1.2)
170
- actiontext (= 7.1.2)
171
- actionview (= 7.1.2)
172
- activejob (= 7.1.2)
173
- activemodel (= 7.1.2)
174
- activerecord (= 7.1.2)
175
- activestorage (= 7.1.2)
176
- activesupport (= 7.1.2)
177
- bundler (>= 1.15.0)
178
- railties (= 7.1.2)
179
- rails-dom-testing (2.2.0)
180
- activesupport (>= 5.0.0)
181
- minitest
182
- nokogiri (>= 1.6)
183
- rails-html-sanitizer (1.6.0)
184
- loofah (~> 2.21)
185
- nokogiri (~> 1.14)
186
- railties (7.1.2)
187
- actionpack (= 7.1.2)
188
- activesupport (= 7.1.2)
189
- irb
190
- rackup (>= 1.0.0)
191
- rake (>= 12.2)
192
- thor (~> 1.0, >= 1.2.2)
193
- zeitwerk (~> 2.6)
194
- rainbow (3.1.1)
195
- rake (13.1.0)
196
- rdoc (6.6.2)
197
- psych (>= 4.0.0)
198
- regexp_parser (2.9.0)
199
- reline (0.4.2)
200
- io-console (~> 0.5)
201
- rexml (3.2.6)
202
- ricecream (0.2.1)
203
- rubocop (1.59.0)
204
- json (~> 2.3)
205
- language_server-protocol (>= 3.17.0)
206
- parallel (~> 1.10)
207
- parser (>= 3.2.2.4)
208
- rainbow (>= 2.2.2, < 4.0)
209
- regexp_parser (>= 1.8, < 3.0)
210
- rexml (>= 3.2.5, < 4.0)
211
- rubocop-ast (>= 1.30.0, < 2.0)
212
- ruby-progressbar (~> 1.7)
213
- unicode-display_width (>= 2.4.0, < 3.0)
214
- rubocop-ast (1.30.0)
215
- parser (>= 3.2.1.0)
216
- rubocop-performance (1.20.2)
217
- rubocop (>= 1.48.1, < 2.0)
218
- rubocop-ast (>= 1.30.0, < 2.0)
219
- ruby-progressbar (1.13.0)
220
- ruby2_keywords (0.0.5)
221
- simplecov (0.22.0)
222
- docile (~> 1.1)
223
- simplecov-html (~> 0.11)
224
- simplecov_json_formatter (~> 0.1)
225
- simplecov-html (0.12.3)
226
- simplecov_json_formatter (0.1.4)
227
- sqlite3 (1.7.0-aarch64-linux)
228
- sqlite3 (1.7.0-arm-linux)
229
- sqlite3 (1.7.0-arm64-darwin)
230
- sqlite3 (1.7.0-x86-linux)
231
- sqlite3 (1.7.0-x86_64-darwin)
232
- sqlite3 (1.7.0-x86_64-linux)
233
- standard (1.33.0)
234
- language_server-protocol (~> 3.17.0.2)
235
- lint_roller (~> 1.0)
236
- rubocop (~> 1.59.0)
237
- standard-custom (~> 1.0.0)
238
- standard-performance (~> 1.3)
239
- standard-custom (1.0.2)
240
- lint_roller (~> 1.0)
241
- rubocop (~> 1.50)
242
- standard-performance (1.3.1)
243
- lint_roller (~> 1.1)
244
- rubocop-performance (~> 1.20.2)
245
- stringio (3.1.0)
246
- thor (1.3.0)
247
- timeout (0.4.1)
248
- tzinfo (2.0.6)
249
- concurrent-ruby (~> 1.0)
250
- unicode-display_width (2.5.0)
251
- webrick (1.8.1)
252
- websocket-driver (0.7.6)
253
- websocket-extensions (>= 0.1.0)
254
- websocket-extensions (0.1.5)
255
- zeitwerk (2.6.12)
256
-
257
- PLATFORMS
258
- aarch64-linux
259
- arm-linux
260
- arm64-darwin
261
- x86-linux
262
- x86_64-darwin
263
- x86_64-linux
264
-
265
- DEPENDENCIES
266
- appraisal
267
- benchmark-ips
268
- combustion
269
- miau!
270
- minitest
271
- observr
272
- rails
273
- ricecream
274
- simplecov
275
- sqlite3
276
- standard
277
-
278
- BUNDLED WITH
279
- 2.5.3
data/Rakefile DELETED
@@ -1,10 +0,0 @@
1
- require "rake/testtask"
2
-
3
- desc "Run the tests."
4
- Rake::TestTask.new do |t|
5
- t.libs << "test"
6
- t.pattern = "test/**/*_test.rb"
7
- t.verbose = false
8
- end
9
-
10
- task default: :test
@@ -1,16 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rails", "~> 6.1"
6
- gem "dryer-config", "~> 6.0"
7
-
8
- group :test do
9
- gem "benchmark-ips"
10
- gem "observr"
11
- gem "ricecream"
12
- gem "simplecov", require: false
13
- gem "standard", require: false
14
- end
15
-
16
- gemspec path: "../"
@@ -1,16 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rails", "~> 7.0"
6
- gem "dryer-config", "~> 7.0"
7
-
8
- group :test do
9
- gem "benchmark-ips"
10
- gem "observr"
11
- gem "ricecream"
12
- gem "simplecov", require: false
13
- gem "standard", require: false
14
- end
15
-
16
- gemspec path: "../"
@@ -1,15 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rails", "~> 7.1"
6
-
7
- group :test do
8
- gem "benchmark-ips"
9
- gem "observr"
10
- gem "ricecream"
11
- gem "simplecov", require: false
12
- gem "standard", require: false
13
- end
14
-
15
- gemspec path: "../"
data/miau.gemspec DELETED
@@ -1,27 +0,0 @@
1
- require_relative "lib/miau/version"
2
-
3
- Gem::Specification.new do |s|
4
- s.name = "miau"
5
- s.version = Miau::VERSION
6
- s.platform = Gem::Platform::RUBY
7
- s.summary = %(Simple and lightweight authorization solution for Rails.)
8
- s.license = "MIT"
9
-
10
- s.description = <<~EOS
11
- MIAU (MIcro AUthorization) provides some helpers which
12
- raises an exception if a given user violates a policy.
13
- EOS
14
-
15
- s.authors = ["Dittmar Krall"]
16
- s.email = "dittmar.krall@matiq.com"
17
- s.homepage = "https://github.com/matique/miau"
18
-
19
- s.files = `git ls-files`.split("\n")
20
- s.require_paths = ["lib"]
21
-
22
- s.add_development_dependency "appraisal"
23
- s.add_development_dependency "combustion"
24
- s.add_development_dependency "minitest"
25
- s.add_development_dependency "ricecream"
26
- s.add_development_dependency "sqlite3"
27
- end
@@ -1,28 +0,0 @@
1
- require "test_helper"
2
-
3
- describe Miau, "performed authorization" do
4
- let(:user) { "User" }
5
- let(:post) { Post.new(user, 1) }
6
- let(:params) { {action: "si", controller: "posts"} }
7
- let(:posts_controller) { PostsController.new(user, params) }
8
-
9
- def test_does_nothing_when_authorized
10
- posts_controller.authorize!(post)
11
- posts_controller.verify_authorized
12
- end
13
-
14
- def test_exception_when_not_authorized
15
- assert_raises(Miau::AuthorizationNotPerformedError) {
16
- posts_controller.verify_authorized
17
- }
18
- end
19
-
20
- def test_authorization_performed
21
- posts_controller.authorize!(post)
22
- assert posts_controller.miau_authorization_performed?
23
- end
24
-
25
- def test_authorization_not_performed
26
- refute posts_controller.miau_authorization_performed?
27
- end
28
- end
@@ -1,34 +0,0 @@
1
- require "test_helper"
2
- require "benchmark"
3
- require "benchmark/ips"
4
-
5
- describe "Internal timings" do
6
- let(:user) { "User" }
7
- let(:params) { {action: "si", controller: "posts"} }
8
- let(:posts_controller) { PostsController.new(user, params) }
9
- let(:storage) { Miau::PolicyStorage.instance }
10
-
11
- # run_flag = true
12
- run_flag ||= false
13
-
14
- it "times ips" do
15
- return unless run_flag
16
-
17
- Benchmark.ips do |x|
18
- x.report("empty ") {}
19
- x.report("authorize! ") { posts_controller.authorize! }
20
- x.report("authorized? ") { posts_controller.authorized? }
21
- # x.report("PostsPolicy.new") { PostsPolicy.new }
22
- # x.report("find_or_create_policy") {
23
- # storage.find_or_create_policy "application"
24
- # }
25
- # x.report("name & constantize.new") {
26
- # klass = :posts
27
- # name = "#{klass.to_s.camelcase}Policy"
28
- # name.constantize.new
29
- # }
30
-
31
- x.compare!
32
- end
33
- end
34
- end
@@ -1,58 +0,0 @@
1
- require "test_helper"
2
-
3
- class NotController
4
- include Miau
5
-
6
- attr_accessor :current_user, :params
7
-
8
- def initialize(current_user, params = {})
9
- @current_user = current_user
10
- @params = params
11
- end
12
- end
13
-
14
- class NotPolicy < ApplicationPolicy
15
- end
16
-
17
- class FalseController
18
- include Miau
19
-
20
- attr_accessor :current_user, :params
21
-
22
- def initialize(current_user, params = {})
23
- @current_user = current_user
24
- @params = params
25
- end
26
- end
27
-
28
- class FalsePolicy < ApplicationPolicy
29
- def controller
30
- false
31
- end
32
- end
33
-
34
- describe Miau, "controller" do
35
- let(:user) { "User" }
36
-
37
- def test_authorize_controller!
38
- params = {controller: "posts", action: :any}
39
- posts_controller = PostsController.new(user, params)
40
- posts_controller.authorize_controller!
41
- end
42
-
43
- def test_authorize_controller_not_defined
44
- params = {controller: "not", action: :any}
45
- not_controller = NotController.new(user, params)
46
- assert_raises(Miau::NotDefinedError) {
47
- not_controller.authorize_controller!
48
- }
49
- end
50
-
51
- def test_authorize_controller_false
52
- params = {controller: "false", action: :any}
53
- false_controller = FalseController.new(user, params)
54
- assert_raises(Miau::NotAuthorizedError) {
55
- false_controller.authorize_controller!
56
- }
57
- end
58
- end
@@ -1,47 +0,0 @@
1
- require "test_helper"
2
-
3
- class OrdersControllerTest < ActionDispatch::IntegrationTest
4
- setup do
5
- @order = Order.create!(name: "Name", qty: 123)
6
- end
7
-
8
- def test_new
9
- out, _err = capture_io do
10
- get new_order_url
11
- end
12
-
13
- assert_response :success
14
- assert_equal "controller\nnew\n", out
15
- end
16
-
17
- def test_create
18
- out, _err = capture_io do
19
- assert_difference("Order.count") do
20
- post orders_url, params: {order: {name: @order.name, qty: 234}}
21
- end
22
- end
23
-
24
- assert_redirected_to order_url(Order.last)
25
- assert_equal "controller\n", out
26
- end
27
-
28
- def test_update
29
- out, _err = capture_io do
30
- patch order_url(@order), params: {order: {name: @order.name}}
31
- end
32
-
33
- assert_redirected_to order_url(@order)
34
- assert_equal "controller\n", out
35
- end
36
-
37
- def test_destroy
38
- out, _err = capture_io do
39
- assert_difference("Order.count", -1) do
40
- delete order_url(@order)
41
- end
42
- end
43
-
44
- assert_redirected_to orders_url
45
- assert_equal "controller\ndestroy\n", out
46
- end
47
- end
@@ -1,7 +0,0 @@
1
- class ApplicationController < ActionController::Base
2
- include Miau
3
-
4
- def miau_user
5
- "User"
6
- end
7
- end
@@ -1,61 +0,0 @@
1
- class OrdersController < ApplicationController
2
- before_action :authorize_controller!
3
- before_action :set_order, only: %i[show edit update destroy]
4
-
5
- # # GET /orders
6
- # def index
7
- # @orders = Order.all
8
- # end
9
- #
10
- # # GET /orders/1
11
- # def show
12
- # end
13
-
14
- # GET /orders/new
15
- def new
16
- @order = Order.new
17
- end
18
-
19
- # # GET /orders/1/edit
20
- # def edit
21
- # end
22
-
23
- # POST /orders
24
- def create
25
- @order = Order.new(order_params)
26
-
27
- if @order.save
28
- redirect_to @order, notice: "Order was successfully created."
29
- else
30
- render :new, status: :unprocessable_entity
31
- end
32
- end
33
-
34
- # PATCH/PUT /orders/1
35
- def update
36
- if @order.update(order_params)
37
- redirect_to @order, notice: "Order was successfully updated.", status: :see_other
38
- else
39
- render :edit, status: :unprocessable_entity
40
- end
41
- end
42
-
43
- # DELETE /orders/1
44
- def destroy
45
- authorize!
46
- @order.destroy!
47
- redirect_to orders_url, notice: "Order was successfully destroyed.", status: :see_other
48
- end
49
-
50
- private
51
-
52
- # Use callbacks to share common setup or constraints between actions.
53
- def set_order
54
- @order = Order.find(params[:id])
55
- end
56
-
57
- # Only allow a list of trusted parameters through.
58
- def order_params
59
- params.require(:order).permit(:name, :qty)
60
- end
61
- end
@@ -1,10 +0,0 @@
1
- class PostsController
2
- include Miau
3
-
4
- attr_accessor :current_user, :params
5
-
6
- def initialize(current_user, params = {})
7
- @current_user = current_user
8
- @params = params
9
- end
10
- end
@@ -1,3 +0,0 @@
1
- class ApplicationRecord < ActiveRecord::Base
2
- primary_abstract_class
3
- end
@@ -1,2 +0,0 @@
1
- class Order < ApplicationRecord
2
- end
@@ -1,2 +0,0 @@
1
- class Post < Struct.new(:user, :id)
2
- end
@@ -1,16 +0,0 @@
1
- class OrdersPolicy < ApplicationPolicy
2
- def controller
3
- puts :controller
4
- true
5
- end
6
-
7
- def new
8
- puts :new
9
- true
10
- end
11
-
12
- def destroy
13
- puts :destroy
14
- true
15
- end
16
- end
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class PostsPolicy < ApplicationPolicy
4
- miau %i[asi bsi], :si
5
- miau %i[sino], %i[si no]
6
-
7
- def controller
8
- true
9
- end
10
-
11
- def si
12
- true
13
- end
14
-
15
- def no
16
- false
17
- end
18
- end
@@ -1,5 +0,0 @@
1
- <% if authorized? %>
2
- <p> authorized </p>
3
- <% else %>
4
- <p> NOT authorized </p>
5
- <% end %>
@@ -1,3 +0,0 @@
1
- test:
2
- adapter: sqlite3
3
- database: db/test.sqlite3
@@ -1,3 +0,0 @@
1
- Rails.application.routes.draw do
2
- resources :orders
3
- end
@@ -1,10 +0,0 @@
1
- class CreateOrders < ActiveRecord::Migration
2
- def change
3
- create_table :orders do |t|
4
- t.string :name
5
- t.string :qty
6
-
7
- t.timestamps null: false
8
- end
9
- end
10
- end
@@ -1,8 +0,0 @@
1
- ActiveRecord::Schema.define(version: 20141016161801) do
2
- create_table "orders", force: true do |t|
3
- t.string "name"
4
- t.string "qty"
5
- t.datetime "created_at", null: false
6
- t.datetime "updated_at", null: false
7
- end
8
- end
data/test/miau_test.rb DELETED
@@ -1,46 +0,0 @@
1
- require "test_helper"
2
-
3
- describe Miau do
4
- let(:user) { "User" }
5
- let(:post) { Post.new(user, 1) }
6
- let(:params) { {action: "si", controller: "posts"} }
7
- let(:posts_controller) { PostsController.new(user, params) }
8
-
9
- describe "#authorize!" do
10
- def test_ok_no_raise
11
- posts_controller.authorize!(post)
12
- end
13
-
14
- def test_return_false
15
- posts_controller.params[:action] = "no"
16
- assert_raises(Miau::NotAuthorizedError) {
17
- posts_controller.authorize!(post)
18
- }
19
- end
20
-
21
- def test_NotDefinedError
22
- posts_controller.params[:controller] = "articles"
23
- assert_raises(Miau::NotDefinedError) {
24
- posts_controller.authorize!(post)
25
- }
26
- end
27
-
28
- def test_NoMethodError
29
- posts_controller.params[:action] = "unknown"
30
- assert_raises(Miau::NotDefinedError) {
31
- posts_controller.authorize!(post)
32
- }
33
- end
34
- end
35
-
36
- describe "#authorized?" do
37
- def test_return_true
38
- assert posts_controller.authorized?(post)
39
- end
40
-
41
- def test_return_false
42
- posts_controller.params[:action] = "no"
43
- refute posts_controller.authorized?(post)
44
- end
45
- end
46
- end
data/test/run_test.rb DELETED
@@ -1,69 +0,0 @@
1
- require "test_helper"
2
-
3
- class ApplicationPolicy
4
- miau :nein, :ja
5
-
6
- def ja
7
- true
8
- end
9
- end
10
-
11
- class SiiPolicy < ApplicationPolicy
12
- miau :no, :si
13
-
14
- def si
15
- true
16
- end
17
-
18
- def run
19
- puts :run # use by capture_io
20
- true
21
- end
22
- end
23
-
24
- describe Miau, "run2" do
25
- let(:storage) { Miau::PolicyStorage.instance }
26
- let(:miau_run) { Miau::PolicyRun.instance }
27
- let(:policy) { SiiPolicy.new }
28
- let(:user) { "User" }
29
-
30
- def test_find_methods_si
31
- assert_equal :si, miau_run.find_methods(policy, :sii, :si)
32
- end
33
-
34
- def test_find_methods_no
35
- assert_equal :si, miau_run.find_methods(policy, :sii, :no)
36
- end
37
-
38
- def test_find_methods_unknown
39
- refute miau_run.find_methods(policy, :sii, :unknown)
40
- end
41
-
42
- def test_find_methods_ja
43
- assert_equal :ja, miau_run.find_methods(policy, :sii, :ja)
44
- end
45
-
46
- def test_find_methods_nein
47
- assert_equal :ja, miau_run.find_methods(policy, :sii, :ja)
48
- end
49
-
50
- def test_runs
51
- out, _err = capture_io do
52
- miau_run.runs(policy, :run)
53
- end
54
-
55
- assert_equal "run\n", out
56
- end
57
-
58
- def test_raise_undef
59
- assert_raises(Miau::NotDefinedError) {
60
- miau_run.raise_undef(:sii, :ja)
61
- }
62
- end
63
-
64
- def test_raise_authorize
65
- assert_raises(Miau::NotAuthorizedError) {
66
- miau_run.raise_authorize(:sii, :ja)
67
- }
68
- end
69
- end
data/test/storage_test.rb DELETED
@@ -1,51 +0,0 @@
1
- require "test_helper"
2
- require "yaml"
3
-
4
- class MyPolicy < ApplicationPolicy
5
- miau %i[appli2], :appli1
6
- miau %i[appli3], %i[fail ok]
7
-
8
- def appli1
9
- true
10
- end
11
-
12
- def fail
13
- false
14
- end
15
-
16
- def ok
17
- true
18
- end
19
- end
20
-
21
- describe Miau, "storage" do
22
- let(:storage) { Miau::PolicyStorage.instance }
23
-
24
- def test_add_policy_method
25
- storage.add_policy "my", "fail", "ok"
26
-
27
- str = storage.to_yaml
28
- assert_match(/:my/, str)
29
- assert_match(/:fail: :ok/, str)
30
- end
31
-
32
- def test_find_or_create_policy
33
- storage.find_or_create_policy "application"
34
-
35
- assert ApplicationPolicy, storage.instances[:application]
36
- end
37
-
38
- def test_overwrite
39
- storage.add_policy "my", "first", "ok"
40
- assert_raises(Miau::OverwriteError) {
41
- storage.add_policy "my", "first", "ok"
42
- }
43
- end
44
-
45
- def test_coverage_to_yaml
46
- str = storage.to_yaml
47
-
48
- assert str
49
- # puts str
50
- end
51
- end
data/test/test_helper.rb DELETED
@@ -1,17 +0,0 @@
1
- if ENV["COVERAGE"]
2
- require "simplecov"
3
- SimpleCov.start do
4
- add_filter "/test/"
5
- end
6
- end
7
-
8
- ENV["RAILS_ENV"] ||= "test"
9
-
10
- require "miau"
11
-
12
- require "combustion"
13
- Combustion.path = "test/internal"
14
- Combustion.initialize! :active_record
15
-
16
- require "minitest/autorun"
17
- require "rails/test_help"
File without changes