aker-rails 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +45 -0
- data/README.md +151 -0
- data/lib/aker/rails/application.rb +60 -0
- data/lib/aker/rails/secured_controller.rb +66 -0
- data/lib/aker/rails/test/helpers.rb +33 -0
- data/lib/aker/rails/test.rb +5 -0
- data/lib/aker/rails/version.rb +7 -0
- data/lib/aker/rails.rb +16 -0
- data/rails/init.rb +18 -0
- data/spec/aker/rails/application_spec.rb +87 -0
- data/spec/aker/rails/secured_controller_spec.rb +69 -0
- data/spec/aker/rails/test/helpers_spec.rb +40 -0
- data/spec/aker/rails_spec.rb +13 -0
- data/spec/deprecation_helper.rb +61 -0
- data/spec/spec_helper.rb +11 -0
- metadata +113 -0
data/CHANGELOG.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
Aker-Rails History
|
2
|
+
==================
|
3
|
+
|
4
|
+
2.0.2
|
5
|
+
-----
|
6
|
+
|
7
|
+
### Development
|
8
|
+
|
9
|
+
- First open-source version.
|
10
|
+
- Project renamed from `bcsec-rails` to `aker-rails` to match the
|
11
|
+
renaming of the main project.
|
12
|
+
- Switch integration test suite from Celerity to Mechanize. (#3931)
|
13
|
+
This eliminates the JRuby dependency for integration testing.
|
14
|
+
|
15
|
+
Bcsec-Rails History
|
16
|
+
===================
|
17
|
+
|
18
|
+
2.0.1
|
19
|
+
-----
|
20
|
+
|
21
|
+
### Fixed
|
22
|
+
|
23
|
+
- The bcsec middleware is no longer appended to the stack multiple
|
24
|
+
times when class reloading is active. (#4486)
|
25
|
+
|
26
|
+
### Development
|
27
|
+
|
28
|
+
- Use bundler 1.0. (#3930)
|
29
|
+
- CI builds use most-recent-available gems for all dependencies,
|
30
|
+
including prerelease versions of bcsec. (#4422, #4427)
|
31
|
+
|
32
|
+
2.0.0
|
33
|
+
-----
|
34
|
+
|
35
|
+
### Features
|
36
|
+
|
37
|
+
- Package bcsec-rails as a gem
|
38
|
+
- Namespace everything under `Bcsec::Rails`
|
39
|
+
|
40
|
+
### Development
|
41
|
+
|
42
|
+
- Full integrated test suite with cucumber, celerity, and a sample app
|
43
|
+
- Full API documentation
|
44
|
+
- Start tracking changes to the plugin
|
45
|
+
- Move to internal git repo
|
data/README.md
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
Aker-Rails
|
2
|
+
===========
|
3
|
+
|
4
|
+
`aker-rails` is the Rails plugin for Aker 3.0 and later. It is a
|
5
|
+
thin wrapper around Aker's rack support.
|
6
|
+
|
7
|
+
There are separate plugins for Rails 3.x and Rails 2.3.x. You're
|
8
|
+
looking at the version for **Rails 2.3.x**. The version for Rails 3.x
|
9
|
+
has a version number with major version 3.
|
10
|
+
|
11
|
+
Setup
|
12
|
+
-----
|
13
|
+
|
14
|
+
### Prerequisites
|
15
|
+
|
16
|
+
`aker-rails` requires Rails ~> 2.3.5.
|
17
|
+
|
18
|
+
Since `aker-rails` is just a thin wrapper, you'll want to be familiar
|
19
|
+
with [Aker][] before you get started.
|
20
|
+
|
21
|
+
[Aker]: http://rubydoc.info/github/NUBIC/aker/master/file/README.md
|
22
|
+
|
23
|
+
### Get the gem
|
24
|
+
|
25
|
+
`aker-rails` is a gem plugin. In order to use it, either install the
|
26
|
+
gem at the system level or (better) include it in your bundler-using
|
27
|
+
application's Gemfile.
|
28
|
+
|
29
|
+
#### Okay
|
30
|
+
|
31
|
+
!!!plain
|
32
|
+
$ gem install aker-rails
|
33
|
+
|
34
|
+
#### Better
|
35
|
+
|
36
|
+
# in your Gemfile
|
37
|
+
gem 'aker-rails', '~> 2.0'
|
38
|
+
|
39
|
+
### Add it to the application
|
40
|
+
|
41
|
+
Next, configure the gem into your Rails application's environment.
|
42
|
+
(This is necessary for gem plugins even if you are using bundler.)
|
43
|
+
|
44
|
+
# In config/environment.rb's initializer block
|
45
|
+
config.gem "aker-rails", :lib => 'aker/rails', :version => '~> 2.0'
|
46
|
+
|
47
|
+
### Add an initializer for aker
|
48
|
+
|
49
|
+
Put your global configuration in an initializer. By _global
|
50
|
+
configuration_ I mean the parts that are the same no matter which
|
51
|
+
environment you are using, like the portal name and the modes. (N.b.:
|
52
|
+
You have to put it in an initializer — if you just put it at the
|
53
|
+
end of `config/environment.rb` it won't work.)
|
54
|
+
|
55
|
+
# In config/initializers/aker.rb
|
56
|
+
Aker.configure do
|
57
|
+
# The authentication protocol to use for interactive access.
|
58
|
+
# `:form` is the default.
|
59
|
+
ui_mode :form
|
60
|
+
|
61
|
+
# The authentication protocol(s) to use for non-interactive
|
62
|
+
# access. There is no default.
|
63
|
+
api_mode :http_basic
|
64
|
+
|
65
|
+
# The portal to which this application belongs. Optional.
|
66
|
+
portal :ENU
|
67
|
+
end
|
68
|
+
|
69
|
+
For more information on the configuration syntax and options, see the
|
70
|
+
aker API documentation for {Aker::Configuration}.
|
71
|
+
|
72
|
+
### Add per-environment configurations
|
73
|
+
|
74
|
+
In the environment initializer for each of your application's
|
75
|
+
environments, put the parts of the Aker configuration which are
|
76
|
+
env-specific. E.g., the LDAP server you use in production might not be
|
77
|
+
visible from your workstation. This means that the `authorities` line
|
78
|
+
will be env-specific.
|
79
|
+
|
80
|
+
# In config/environments/production.rb, for example
|
81
|
+
config.after_initialize do
|
82
|
+
Aker.configure do
|
83
|
+
# The authorities to use. See the aker API documentation
|
84
|
+
# for `Aker::Authorities` for options.
|
85
|
+
authorities :ldap
|
86
|
+
|
87
|
+
# The server-central parameters file for authority
|
88
|
+
# and policy parameters (optional). See
|
89
|
+
# `Aker::CentralParameters` for a discussion of why this is a
|
90
|
+
# good idea.
|
91
|
+
central '/etc/nubic/aker-prod.yml'
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
Integration into your app
|
96
|
+
-------------------------
|
97
|
+
|
98
|
+
With the plugin installed, Aker provides a general infrastructure for
|
99
|
+
supporting authentication and authorization in your application. If
|
100
|
+
you want to _require_ authentication or authorization for particular
|
101
|
+
resources (and I think you do), you need to do a bit more
|
102
|
+
configuration.
|
103
|
+
|
104
|
+
### Securing pages
|
105
|
+
|
106
|
+
In any controller which authentication is required, include
|
107
|
+
{Aker::Rails::SecuredController}. If authentication is required for
|
108
|
+
all controllers, you can include this module in
|
109
|
+
`ApplicationController`.
|
110
|
+
|
111
|
+
If you want to further require that all actions in a controller
|
112
|
+
require that the user be a member of a certain group, you can use the
|
113
|
+
{Aker::Rails::SecuredController::ClassMethods#permit permit} method:
|
114
|
+
|
115
|
+
class ManuscriptController < ActionController::Base
|
116
|
+
include Aker::Rails::SecuredController
|
117
|
+
permit :editor
|
118
|
+
end
|
119
|
+
|
120
|
+
### Partial authorization
|
121
|
+
|
122
|
+
Aker also supports resources which are only partially limited to a
|
123
|
+
particular group or groups. The helper for this is also called
|
124
|
+
{Aker::Rails::Application#permit? permit}:
|
125
|
+
|
126
|
+
# In a controller action
|
127
|
+
class DashboardController < ActionController::Base
|
128
|
+
# ...
|
129
|
+
def index
|
130
|
+
if permit?(:editor)
|
131
|
+
@manuscripts = Manuscript.all
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
# Or in a view
|
137
|
+
<%= permit?(:editor) do %>
|
138
|
+
@manuscripts.collect { |m| m.title }.join(', ')
|
139
|
+
<% end %>
|
140
|
+
|
141
|
+
This permit helper is available to all controllers and views, not just
|
142
|
+
ones that mix in {Aker::Rails::SecuredController}. This means you
|
143
|
+
can have a publically-accessible page which has additional/different
|
144
|
+
content for a logged-in user.
|
145
|
+
|
146
|
+
### The current user
|
147
|
+
|
148
|
+
Aker provides a method {Aker::Rails::Application#current_user
|
149
|
+
current_user} to all controllers and views. It will return a
|
150
|
+
{Aker::User} object for the current user, or `nil` if there isn't
|
151
|
+
one.
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'aker/rails'
|
2
|
+
|
3
|
+
module Aker::Rails
|
4
|
+
##
|
5
|
+
# A mixin for the rails application controller. Provides global
|
6
|
+
# aker integration, but does not enforce any authentication or
|
7
|
+
# authorization requirements. (See
|
8
|
+
# {Aker::Rails::SecuredController} for one way to enforce
|
9
|
+
# authentication and authorization.)
|
10
|
+
#
|
11
|
+
# This module is automatically mixed into the application controller
|
12
|
+
# when the plugin is initialized.
|
13
|
+
module Application
|
14
|
+
##
|
15
|
+
# Sets up the aker global infrastructure and helpers in the
|
16
|
+
# application controller.
|
17
|
+
#
|
18
|
+
# @return [void]
|
19
|
+
def self.included(controller_class)
|
20
|
+
controller_class.class_eval do
|
21
|
+
helper_method :current_user, :permit?, :permit
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
##
|
26
|
+
# Sets up the aker global infrastructure that is not affected by
|
27
|
+
# Rails' development-mode class reloading.
|
28
|
+
#
|
29
|
+
# @return [void]
|
30
|
+
def self.one_time_setup
|
31
|
+
Aker::Rack.use_in(ActionController::Dispatcher.middleware)
|
32
|
+
Rack::Request.send(:include, Aker::Rack::RequestExt)
|
33
|
+
end
|
34
|
+
|
35
|
+
##
|
36
|
+
# Exposes the logged-in user (if any) to the application.
|
37
|
+
#
|
38
|
+
# This method is also available to views (i.e., it is a helper).
|
39
|
+
#
|
40
|
+
# @return [Aker::User,nil]
|
41
|
+
def current_user
|
42
|
+
request.env['aker.check'].user
|
43
|
+
end
|
44
|
+
|
45
|
+
##
|
46
|
+
# Aids group-level authorization. It is safe to call this method
|
47
|
+
# without checking that there is a logged in user first.
|
48
|
+
#
|
49
|
+
# This method delegates directly to {Aker::Rack::Facade#permit?};
|
50
|
+
# see the documentation for that method for more information.
|
51
|
+
#
|
52
|
+
# This method is also available to views (i.e., it is a helper).
|
53
|
+
#
|
54
|
+
# @return [Boolean,Object,nil]
|
55
|
+
def permit?(*groups, &block)
|
56
|
+
request.env['aker.check'].permit?(*groups, &block)
|
57
|
+
end
|
58
|
+
alias :permit :permit?
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'aker/rails'
|
2
|
+
|
3
|
+
module Aker::Rails
|
4
|
+
##
|
5
|
+
# This mixin tags a controller as always requiring authentication.
|
6
|
+
#
|
7
|
+
# It also adds a
|
8
|
+
# {Aker::Rails::SecuredController::ClassMethods#permit method}
|
9
|
+
# which allows you to mark a controller as only accessible to a
|
10
|
+
# particular group or groups. For example:
|
11
|
+
#
|
12
|
+
# class SecretController
|
13
|
+
# include Aker::Rails::SecuredController
|
14
|
+
# permit :confidential
|
15
|
+
# end
|
16
|
+
module SecuredController
|
17
|
+
##
|
18
|
+
# @private implements the behavior described by the module
|
19
|
+
# description
|
20
|
+
# @return [void]
|
21
|
+
def self.included(controller_class)
|
22
|
+
controller_class.before_filter :aker_authorize
|
23
|
+
controller_class.extend ClassMethods
|
24
|
+
end
|
25
|
+
|
26
|
+
##
|
27
|
+
# The filter which actually forces any user accessing a controller
|
28
|
+
# which mixes this in to be authenticated.
|
29
|
+
#
|
30
|
+
# It delegates to {Aker::Rack::Facade#authentication_required!};
|
31
|
+
# see that method's documentation for more information.
|
32
|
+
#
|
33
|
+
# @return [void]
|
34
|
+
def aker_authorize
|
35
|
+
request.env['aker.check'].authentication_required!
|
36
|
+
end
|
37
|
+
|
38
|
+
##
|
39
|
+
# Extensions for the rails controller DSL for
|
40
|
+
# authentication-required controllers.
|
41
|
+
#
|
42
|
+
# @see SecuredController
|
43
|
+
module ClassMethods
|
44
|
+
##
|
45
|
+
# Tags a controller as requiring that a user both be
|
46
|
+
# authenticated and belong to one of a set of groups.
|
47
|
+
#
|
48
|
+
# It delegates to {Aker::Rack::Facade#permit!}; see that
|
49
|
+
# methods's documentation for more information.
|
50
|
+
#
|
51
|
+
# @return [void]
|
52
|
+
def permit(*groups)
|
53
|
+
options =
|
54
|
+
if Hash === groups.last
|
55
|
+
groups.pop
|
56
|
+
else
|
57
|
+
{}
|
58
|
+
end
|
59
|
+
|
60
|
+
before_filter(options) do |controller|
|
61
|
+
controller.request.env['aker.check'].permit!(*groups)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), %w(.. test))
|
2
|
+
|
3
|
+
##
|
4
|
+
# Helpers for common test tasks.
|
5
|
+
#
|
6
|
+
# To use these helpers with a Rails application using RSpec:
|
7
|
+
#
|
8
|
+
# # spec/spec_helper.rb
|
9
|
+
# Spec::Runner.configure do |config|
|
10
|
+
# config.include Aker::Rails::Test::Helpers
|
11
|
+
# ...
|
12
|
+
# end
|
13
|
+
module Aker::Rails::Test::Helpers
|
14
|
+
include Aker::Test::Helpers
|
15
|
+
|
16
|
+
##
|
17
|
+
# Logs in a user.
|
18
|
+
#
|
19
|
+
# Users can be identified by:
|
20
|
+
#
|
21
|
+
# * their username
|
22
|
+
# * building a `Aker::User` instance representing that user
|
23
|
+
# * the return value of
|
24
|
+
#
|
25
|
+
# Aker.authority.valid_credentials?(:user, username, password)
|
26
|
+
#
|
27
|
+
# (which is a `Aker::User`)
|
28
|
+
#
|
29
|
+
# @param [String, Aker::User] user a user's username or `Aker::User` object
|
30
|
+
def login_as(user)
|
31
|
+
request.env.merge!(login_env(user))
|
32
|
+
end
|
33
|
+
end
|
data/lib/aker/rails.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'aker'
|
2
|
+
|
3
|
+
module Aker
|
4
|
+
##
|
5
|
+
# Rails integration for aker. In general, it is a thin wrapper
|
6
|
+
# around aker's rack integration.
|
7
|
+
#
|
8
|
+
# Everything in this module is in the `aker-rails` gem plugin.
|
9
|
+
module Rails
|
10
|
+
autoload :VERSION, 'aker/rails/version'
|
11
|
+
|
12
|
+
autoload :Application, 'aker/rails/application'
|
13
|
+
autoload :SecuredController, 'aker/rails/secured_controller'
|
14
|
+
autoload :Test, 'aker/rails/test'
|
15
|
+
end
|
16
|
+
end
|
data/rails/init.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'aker/rails'
|
2
|
+
|
3
|
+
Rails.logger.debug "Initializing aker-rails"
|
4
|
+
# We do this up here to allow the application to override if desired
|
5
|
+
Aker.configure {
|
6
|
+
logger Rails.logger
|
7
|
+
}
|
8
|
+
config.after_initialize do
|
9
|
+
Aker::Rails::Application.one_time_setup
|
10
|
+
|
11
|
+
if config.cache_classes
|
12
|
+
ApplicationController.send(:include, Aker::Rails::Application)
|
13
|
+
else
|
14
|
+
config.to_prepare do
|
15
|
+
ApplicationController.send(:include, Aker::Rails::Application)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require File.expand_path("../../../spec_helper", __FILE__)
|
2
|
+
require 'rack'
|
3
|
+
require 'action_controller'
|
4
|
+
|
5
|
+
module Aker::Rails
|
6
|
+
class FakeApplicationController
|
7
|
+
attr_accessor :request
|
8
|
+
|
9
|
+
def self.helper_method(*names)
|
10
|
+
helper_methods.concat(names)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.helper_methods
|
14
|
+
@helper_methods ||= []
|
15
|
+
end
|
16
|
+
|
17
|
+
Aker.configure { }
|
18
|
+
include Application
|
19
|
+
Aker.configuration = nil
|
20
|
+
end
|
21
|
+
|
22
|
+
describe Application do
|
23
|
+
before do
|
24
|
+
@controller = FakeApplicationController.new
|
25
|
+
|
26
|
+
@env = Rack::MockRequest.env_for('/')
|
27
|
+
@env['aker.check'] = (@aker = mock)
|
28
|
+
@controller.request = Rack::Request.new(@env)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "adds current_user" do
|
32
|
+
@aker.should_receive(:user).and_return(Aker::User.new("jo"))
|
33
|
+
|
34
|
+
@controller.current_user.username.should == "jo"
|
35
|
+
end
|
36
|
+
|
37
|
+
it "defines current_user as a helper method" do
|
38
|
+
@controller.class.helper_methods.should include(:current_user)
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "#permit?" do
|
42
|
+
it "delegates to the aker rack facade" do
|
43
|
+
@aker.should_receive(:permit?).with(:bar, :quux)
|
44
|
+
|
45
|
+
@controller.permit?(:bar, :quux)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "passes a block to the aker rack facade, if present" do
|
49
|
+
@aker.should_receive(:permit?).with(:bar, :quux).and_yield
|
50
|
+
|
51
|
+
@controller.permit?(:bar, :quux) { 1 + 1 }.should == 2
|
52
|
+
end
|
53
|
+
|
54
|
+
it "is registered as a helper method" do
|
55
|
+
@controller.class.helper_methods.should include(:permit?)
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "permit alias" do
|
59
|
+
it "exists" do
|
60
|
+
@aker.should_receive(:permit?).with(:bar, :baz)
|
61
|
+
|
62
|
+
@controller.permit(:bar, :baz)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "is also registered as a helper method" do
|
66
|
+
@controller.class.helper_methods.should include(:permit)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe Application, ".one_time_setup" do
|
73
|
+
before do
|
74
|
+
Aker.configure { }
|
75
|
+
|
76
|
+
Application.one_time_setup
|
77
|
+
end
|
78
|
+
|
79
|
+
after do
|
80
|
+
Aker.configuration = nil
|
81
|
+
end
|
82
|
+
|
83
|
+
it "adds the aker middleware to the action controller middleware stack" do
|
84
|
+
ActionController::Dispatcher.middleware.should include(Aker::Rack::Setup)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require File.expand_path("../../../spec_helper", __FILE__)
|
2
|
+
require 'rack'
|
3
|
+
|
4
|
+
module Aker::Rails
|
5
|
+
class SomeController
|
6
|
+
attr_accessor :request
|
7
|
+
|
8
|
+
def initialize(request)
|
9
|
+
@request = request
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.before_filter(*args, &block)
|
13
|
+
filter =
|
14
|
+
if block
|
15
|
+
block
|
16
|
+
else
|
17
|
+
args.shift
|
18
|
+
end
|
19
|
+
self.before_filters << [filter, *args]
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.before_filters
|
23
|
+
@before_filters ||= []
|
24
|
+
end
|
25
|
+
|
26
|
+
include Aker::Rails::SecuredController
|
27
|
+
end
|
28
|
+
|
29
|
+
describe SecuredController do
|
30
|
+
before do
|
31
|
+
@request = Rack::Request.new(Rack::MockRequest.env_for("/some"))
|
32
|
+
@aker = (@request.env['aker.check'] = mock)
|
33
|
+
@controller = SomeController.new(@request)
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#aker_authorize" do
|
37
|
+
it "is registered as a filter" do
|
38
|
+
@controller.class.before_filters.should == [ [:aker_authorize] ]
|
39
|
+
end
|
40
|
+
|
41
|
+
it "invokes authentication_required on the aker rack facade" do
|
42
|
+
@aker.should_receive(:authentication_required!)
|
43
|
+
@controller.aker_authorize
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe ".permit" do
|
48
|
+
it "adds a filter" do
|
49
|
+
@controller.class.permit(:foo, :quux)
|
50
|
+
@controller.class.should have(2).before_filters
|
51
|
+
@controller.class.before_filters.last[0].class.should == Proc
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "and options" do
|
55
|
+
it "passes options on to before_filter" do
|
56
|
+
@controller.class.permit(:foo, :quux, :only => :zamm)
|
57
|
+
@controller.class.before_filters.last[1].should == { :only => :zamm }
|
58
|
+
end
|
59
|
+
|
60
|
+
it "passes empty options if no options are specified" do
|
61
|
+
@controller.class.permit(:foo, :quux, :vom)
|
62
|
+
@controller.class.before_filters.last[1].should == {}
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# filter behavior is further characterized in integrated tests
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require File.expand_path("../../../../spec_helper", __FILE__)
|
2
|
+
require 'action_controller'
|
3
|
+
require 'action_controller/test_process'
|
4
|
+
|
5
|
+
module Aker::Rails::Test
|
6
|
+
describe Helpers do
|
7
|
+
before do
|
8
|
+
Aker.configure do
|
9
|
+
s = Aker::Authorities::Static.new
|
10
|
+
|
11
|
+
s.valid_credentials!(:user, "jo", "50-50")
|
12
|
+
authorities s
|
13
|
+
end
|
14
|
+
|
15
|
+
@test_case = Class.new do
|
16
|
+
include Aker::Rails::Test::Helpers
|
17
|
+
|
18
|
+
def request
|
19
|
+
@request ||= ActionController::TestRequest.new
|
20
|
+
end
|
21
|
+
end.new
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#login_as" do
|
25
|
+
it "logs in a user by username" do
|
26
|
+
@test_case.login_as("jo")
|
27
|
+
|
28
|
+
@test_case.request.env['aker.check'].user.username.should == "jo"
|
29
|
+
end
|
30
|
+
|
31
|
+
it "accepts Aker::User objects" do
|
32
|
+
user = Aker::User.new("jo")
|
33
|
+
|
34
|
+
@test_case.login_as(user)
|
35
|
+
|
36
|
+
@test_case.request.env['aker.check'].user.should == user
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require File.expand_path("../../spec_helper", __FILE__)
|
2
|
+
|
3
|
+
describe Aker::Rails do
|
4
|
+
describe "::VERSION" do
|
5
|
+
it "exists" do
|
6
|
+
lambda { Aker::Rails::VERSION }.should_not raise_error
|
7
|
+
end
|
8
|
+
|
9
|
+
it "has three or four dot-separated parts" do
|
10
|
+
Aker::Rails::VERSION.split('.').size.should be_between(3, 4)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Aker::Rails
|
2
|
+
module Spec
|
3
|
+
# Copied from aker due to laziness. May want to separate out and
|
4
|
+
# share later.
|
5
|
+
|
6
|
+
class DeprecationMode
|
7
|
+
def self.use_in(spec_config)
|
8
|
+
spec_config.include DeprecationHelper
|
9
|
+
|
10
|
+
spec_config.before(:each) do
|
11
|
+
@original_deprecation_mode, Aker::Deprecation.mode =
|
12
|
+
Aker::Deprecation.mode, DeprecationMode.new
|
13
|
+
end
|
14
|
+
|
15
|
+
spec_config.after(:each) do
|
16
|
+
begin
|
17
|
+
Aker::Deprecation.mode.fail_if_any_very_obsolete
|
18
|
+
ensure
|
19
|
+
Aker::Deprecation.mode = @original_deprecation_mode
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def messages
|
25
|
+
@messages ||= []
|
26
|
+
end
|
27
|
+
|
28
|
+
def report(level, message, version)
|
29
|
+
messages << { :level => level, :message => message, :version => version }
|
30
|
+
end
|
31
|
+
|
32
|
+
def reset
|
33
|
+
@messages = nil
|
34
|
+
end
|
35
|
+
|
36
|
+
def fail_if_any_very_obsolete
|
37
|
+
obs = messages.select { |m| very_obsolete?(m[:version]) }
|
38
|
+
unless obs.empty?
|
39
|
+
fail "Very obsolete code still present. Remove it and its specs.\n" <<
|
40
|
+
"- #{obs.collect { |o| o[:message] }.join("\n- ")}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def very_obsolete?(version)
|
45
|
+
# "very obsolete" if it was deprecated at least two minor
|
46
|
+
# versions ago
|
47
|
+
major_minor(Aker::Rails::VERSION) - Rational(2, 10) >= major_minor(version)
|
48
|
+
end
|
49
|
+
|
50
|
+
def major_minor(version)
|
51
|
+
Rational(version.split('.')[0, 2].inject(0) { |s, i| s = s * 10 + i.to_i }, 10)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
module DeprecationHelper
|
56
|
+
def deprecation_message(n=0)
|
57
|
+
(Aker::Deprecation.mode.messages[n] || {})[:message]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require "spec"
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
4
|
+
|
5
|
+
require 'aker/rails'
|
6
|
+
|
7
|
+
require File.expand_path('../deprecation_helper', __FILE__)
|
8
|
+
|
9
|
+
Spec::Runner.configure do |config|
|
10
|
+
Aker::Rails::Spec::DeprecationMode.use_in(config)
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aker-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 11
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
- 2
|
10
|
+
version: 2.0.2
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- David Yip
|
14
|
+
- Rhett Sutphin
|
15
|
+
- Peter Nyberg
|
16
|
+
autorequire:
|
17
|
+
bindir: bin
|
18
|
+
cert_chain: []
|
19
|
+
|
20
|
+
date: 2011-07-20 00:00:00 -05:00
|
21
|
+
default_executable:
|
22
|
+
dependencies:
|
23
|
+
- !ruby/object:Gem::Dependency
|
24
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 9
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 3
|
33
|
+
- 5
|
34
|
+
version: 2.3.5
|
35
|
+
requirement: *id001
|
36
|
+
name: rails
|
37
|
+
prerelease: false
|
38
|
+
type: :runtime
|
39
|
+
- !ruby/object:Gem::Dependency
|
40
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 7
|
46
|
+
segments:
|
47
|
+
- 3
|
48
|
+
- 0
|
49
|
+
version: "3.0"
|
50
|
+
requirement: *id002
|
51
|
+
name: aker
|
52
|
+
prerelease: false
|
53
|
+
type: :runtime
|
54
|
+
description:
|
55
|
+
email: r-sutphin@northwestern.edu
|
56
|
+
executables: []
|
57
|
+
|
58
|
+
extensions: []
|
59
|
+
|
60
|
+
extra_rdoc_files: []
|
61
|
+
|
62
|
+
files:
|
63
|
+
- CHANGELOG.md
|
64
|
+
- README.md
|
65
|
+
- lib/aker/rails/application.rb
|
66
|
+
- lib/aker/rails/secured_controller.rb
|
67
|
+
- lib/aker/rails/test/helpers.rb
|
68
|
+
- lib/aker/rails/test.rb
|
69
|
+
- lib/aker/rails/version.rb
|
70
|
+
- lib/aker/rails.rb
|
71
|
+
- spec/aker/rails/application_spec.rb
|
72
|
+
- spec/aker/rails/secured_controller_spec.rb
|
73
|
+
- spec/aker/rails/test/helpers_spec.rb
|
74
|
+
- spec/aker/rails_spec.rb
|
75
|
+
- spec/deprecation_helper.rb
|
76
|
+
- spec/spec_helper.rb
|
77
|
+
- rails/init.rb
|
78
|
+
has_rdoc: true
|
79
|
+
homepage: https://github.com/NUBIC/aker-rails
|
80
|
+
licenses: []
|
81
|
+
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
hash: 3
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
version: "0"
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
hash: 3
|
102
|
+
segments:
|
103
|
+
- 0
|
104
|
+
version: "0"
|
105
|
+
requirements: []
|
106
|
+
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 1.3.7
|
109
|
+
signing_key:
|
110
|
+
specification_version: 3
|
111
|
+
summary: Easy Rails integration for the Aker security framework
|
112
|
+
test_files: []
|
113
|
+
|