elucid-merb-ssl-requirement 0.0.2 → 0.0.3

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/README CHANGED
@@ -5,6 +5,10 @@ SSL requirement adds a declarative way of specifying that certain actions
5
5
  should only be allowed to run under SSL, and if they're accessed without it,
6
6
  they should be redirected.
7
7
 
8
+ note: unlike the Rails plugin of which this is a port, this plugin does not
9
+ provide an ssl_allowed method. actions that have not been specified as SSL
10
+ only can run either with or without and will not be redirected to http.
11
+
8
12
  Example:
9
13
 
10
14
  class Application < Merb::Controller
@@ -13,25 +17,21 @@ Example:
13
17
 
14
18
  class Accounts < ApplicationController
15
19
  ssl_required :signup, :payment
16
- ssl_allowed :index
17
-
20
+
18
21
  def signup
19
- # Non-SSL access will be redirected to SSL
20
- end
21
-
22
- def payment
23
- # Non-SSL access will be redirected to SSL
22
+ # non-SSL access will be redirected to SSL
24
23
  end
25
24
 
26
- def index
27
- # This action will work either with or without SSL
25
+ def payment
26
+ # non-SSL access will be redirected to SSL
28
27
  end
29
28
 
30
29
  def other
31
- # SSL access will be redirected to non-SSL
30
+ # other actions will work either with or without SSL
31
+ # and will not be redirected to a different protocol
32
32
  end
33
33
  end
34
-
34
+
35
35
  You can overwrite the protected method ssl_required? to rely on other things
36
36
  than just the declarative specification. Say, only premium accounts get SSL.
37
37
 
@@ -41,4 +41,5 @@ times you'll want to run other before filters before that. They should then be
41
41
  declared ahead of including this module.
42
42
 
43
43
  Copyright (c) 2005 David Heinemeier Hansson, released under the MIT license
44
- Copyright (c) 2008 Steve Tooke
44
+ Copyright (c) 2008 Steve Tooke
45
+ Copyright (c) 2008 Justin Giancola
data/Rakefile CHANGED
@@ -5,14 +5,12 @@ require 'merb-core'
5
5
  require 'merb-core/tasks/merb'
6
6
 
7
7
  GEM_NAME = "merb-ssl-requirement"
8
- GEM_VERSION = "0.0.1"
9
- AUTHOR = "Steve Tooke"
10
- EMAIL = "steve.tooke@gmail.com"
11
- SUMMARY = "Merb plugin that provides ssl_requirement from rails"
12
- HOMEPAGE = "http://www.merbivore.com"
8
+ GEM_VERSION = "0.0.3"
9
+ AUTHORS = ["Steve Tooke", "Justin Giancola"]
10
+ EMAIL = "justin.giancola@gmail.com"
11
+ SUMMARY = "Merb plugin similar to ssl_requirement from Rails (note: does not provide ssl_allowed class method)"
13
12
 
14
13
  spec = Gem::Specification.new do |s|
15
- s.rubyforge_project = 'merb'
16
14
  s.name = GEM_NAME
17
15
  s.version = GEM_VERSION
18
16
  s.platform = Gem::Platform::RUBY
@@ -20,13 +18,11 @@ spec = Gem::Specification.new do |s|
20
18
  s.extra_rdoc_files = ["README", "LICENSE", 'TODO']
21
19
  s.summary = SUMMARY
22
20
  s.description = s.summary
23
- s.author = AUTHOR
21
+ s.authors = AUTHORS
24
22
  s.email = EMAIL
25
- s.homepage = HOMEPAGE
26
23
  s.add_dependency('merb-core', '>= 0.9.10')
27
24
  s.require_path = 'lib'
28
25
  s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,spec}/**/*")
29
-
30
26
  end
31
27
 
32
28
  Rake::GemPackageTask.new(spec) do |pkg|
@@ -48,4 +44,4 @@ task :gemspec do
48
44
  File.open("#{GEM_NAME}.gemspec", "w") do |file|
49
45
  file.puts spec.to_ruby
50
46
  end
51
- end
47
+ end
@@ -1,5 +1,6 @@
1
1
  # Copyright (c) 2005 David Heinemeier Hansson
2
2
  # Copyright (c) 2008 Steve Tooke
3
+ # Copyright (c) 2008 Justin Giancola
3
4
  #
4
5
  # Permission is hereby granted, free of charge, to any person obtaining
5
6
  # a copy of this software and associated documentation files (the
@@ -32,40 +33,22 @@ module SslRequirement
32
33
  self.ssl_required_actions.push(*actions)
33
34
  end
34
35
 
35
- def ssl_allowed(*actions)
36
- # write_inheritable_array(:ssl_allowed_actions, actions)
37
- self.ssl_allowed_actions.push(*actions)
38
- end
39
-
40
36
  def ssl_required_actions
41
37
  @ssl_required_actions ||= []
42
38
  end
43
-
44
- def ssl_allowed_actions
45
- @ssl_allowed_actions ||= []
46
- end
47
39
  end
48
-
40
+
49
41
  protected
50
- # Returns true if the current action is supposed to run as SSL
51
- def ssl_required?
52
- # (self.class.read_inheritable_attribute(:ssl_required_actions) || []).include?(action_name.to_sym)
53
- self.class.ssl_required_actions.include?(action_name.to_sym)
54
- end
55
-
56
- def ssl_allowed?
57
- self.class.ssl_allowed_actions.include?(action_name.to_sym)
58
- # (self.class.read_inheritable_attribute(:ssl_allowed_actions) || []).include?(action_name.to_sym)
59
- end
42
+ # Returns true if the current action is supposed to run as SSL
43
+ def ssl_required?
44
+ # (self.class.read_inheritable_attribute(:ssl_required_actions) || []).include?(action_name.to_sym)
45
+ self.class.ssl_required_actions.include?(action_name.to_sym)
46
+ end
60
47
 
61
48
  private
62
- def ensure_proper_protocol
63
- return true if ssl_allowed?
64
-
65
- if ssl_required? && !request.ssl?
66
- throw :halt, redirect("https://" + request.host + request.uri)
67
- elsif request.ssl? && !ssl_required?
68
- throw :halt, redirect("http://" + request.host + request.uri)
69
- end
49
+ def ensure_proper_protocol
50
+ if ssl_required? && !request.ssl?
51
+ throw :halt, redirect("https://" + request.host + request.uri)
70
52
  end
71
- end
53
+ end
54
+ end
@@ -1,26 +1,25 @@
1
1
  class Secure < Merb::Controller
2
2
  include SslRequirement
3
-
3
+
4
4
  ssl_required :a, :b
5
- ssl_allowed :c
6
-
5
+
7
6
  def a
8
7
  'a'
9
8
  end
10
-
9
+
11
10
  def b
12
11
  return 'b'
13
12
  end
14
-
13
+
15
14
  def c
16
15
  return 'c'
17
16
  end
18
-
17
+
19
18
  def d
20
19
  return 'd'
21
20
  end
22
- #
21
+ #
23
22
  # def set_flash
24
23
  # flash[:foo] = "bar"
25
24
  # end
26
- end
25
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,13 +1,13 @@
1
1
  $:.push File.join(File.dirname(__FILE__), '..', 'lib')
2
-
2
+
3
3
  require "rubygems"
4
4
  require "merb-core"
5
5
  require "merb-ssl-requirement"
6
6
  require File.dirname(__FILE__) / "controllers" / "ssl-requirement"
7
7
  require "spec"
8
-
8
+
9
9
  Merb.start :environment => 'test'
10
-
10
+
11
11
  Spec::Runner.configure do |config|
12
12
  config.include Merb::Test::RequestHelper
13
- end
13
+ end
@@ -1,21 +1,11 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
3
  describe "SslRequirement" do
4
-
4
+
5
5
  it "should not accidently introduce any methods as controller actions" do
6
6
  Merb::Controller.callable_actions.should be_empty
7
7
  end
8
-
9
- end
10
8
 
11
- describe "ssl_allowed" do
12
- it "should allow http connection to allowed action" do
13
- dispatch_to(Secure, :c, {}, 'HTTPS' => nil).body.should == "c"
14
- end
15
-
16
- it "should allow https connection to allowed action" do
17
- dispatch_to(Secure, :c, {}, 'HTTPS' => 'on').body.should == "c"
18
- end
19
9
  end
20
10
 
21
11
  describe "ssl_required" do
@@ -24,7 +14,7 @@ describe "ssl_required" do
24
14
  controller.should redirect
25
15
  controller.headers['Location'].should match(%r{^https://})
26
16
  end
27
-
17
+
28
18
  it "should allow https connection to required actions" do
29
19
  dispatch_to(Secure, :a, {}, 'HTTPS' => 'on').body.should == "a"
30
20
  end
@@ -34,10 +24,10 @@ describe "non-ssl actions" do
34
24
  it "should allow http connection" do
35
25
  dispatch_to(Secure, :d, {}, 'HTTPS' => nil).body.should == "d"
36
26
  end
37
-
38
- it "should redirect https connection to http" do
27
+
28
+ it "should not redirect https connection to http" do
39
29
  controller = dispatch_to(Secure, :d, {}, 'HTTPS' => 'on')
40
- controller.should redirect
41
- controller.headers['Location'].should match(%r{^http://})
30
+ controller.should_not redirect
31
+ controller.body.should == "d"
42
32
  end
43
- end
33
+ end
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elucid-merb-ssl-requirement
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Tooke
8
+ - Justin Giancola
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
12
 
12
- date: 2008-10-27 00:00:00 -07:00
13
+ date: 2009-06-14 00:00:00 -07:00
13
14
  default_executable:
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency
@@ -22,8 +23,8 @@ dependencies:
22
23
  - !ruby/object:Gem::Version
23
24
  version: 0.9.10
24
25
  version:
25
- description: Merb plugin that provides ssl_requirement from rails
26
- email: steve.tooke@gmail.com
26
+ description: "Merb plugin similar to ssl_requirement from Rails (note: does not provide ssl_allowed class method)"
27
+ email: justin.giancola@gmail.com
27
28
  executables: []
28
29
 
29
30
  extensions: []
@@ -45,7 +46,7 @@ files:
45
46
  - spec/spec_helper.rb
46
47
  - spec/ssl_requirement_spec.rb
47
48
  has_rdoc: true
48
- homepage: http://www.merbivore.com
49
+ homepage:
49
50
  post_install_message:
50
51
  rdoc_options: []
51
52
 
@@ -65,10 +66,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
66
  version:
66
67
  requirements: []
67
68
 
68
- rubyforge_project: merb
69
+ rubyforge_project:
69
70
  rubygems_version: 1.2.0
70
71
  signing_key:
71
72
  specification_version: 2
72
- summary: Merb plugin that provides ssl_requirement from rails
73
+ summary: "Merb plugin similar to ssl_requirement from Rails (note: does not provide ssl_allowed class method)"
73
74
  test_files: []
74
75