vidibus-realm 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source :gemcutter
2
+
3
+ # Specify your gem's dependencies in vidibus-realm.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,132 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ vidibus-realm (0.0.1)
5
+ activesupport (~> 3.0.0)
6
+ vidibus-service
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ abstract (1.0.0)
12
+ actionmailer (3.0.3)
13
+ actionpack (= 3.0.3)
14
+ mail (~> 2.2.9)
15
+ actionpack (3.0.3)
16
+ activemodel (= 3.0.3)
17
+ activesupport (= 3.0.3)
18
+ builder (~> 2.1.2)
19
+ erubis (~> 2.6.6)
20
+ i18n (~> 0.4)
21
+ rack (~> 1.2.1)
22
+ rack-mount (~> 0.6.13)
23
+ rack-test (~> 0.5.6)
24
+ tzinfo (~> 0.3.23)
25
+ activemodel (3.0.3)
26
+ activesupport (= 3.0.3)
27
+ builder (~> 2.1.2)
28
+ i18n (~> 0.4)
29
+ activerecord (3.0.3)
30
+ activemodel (= 3.0.3)
31
+ activesupport (= 3.0.3)
32
+ arel (~> 2.0.2)
33
+ tzinfo (~> 0.3.23)
34
+ activeresource (3.0.3)
35
+ activemodel (= 3.0.3)
36
+ activesupport (= 3.0.3)
37
+ activesupport (3.0.3)
38
+ arel (2.0.6)
39
+ bson (1.1.4)
40
+ builder (2.1.2)
41
+ crack (0.1.8)
42
+ diff-lcs (1.1.2)
43
+ erubis (2.6.6)
44
+ abstract (>= 1.0.0)
45
+ httparty (0.6.1)
46
+ crack (= 0.1.8)
47
+ i18n (0.5.0)
48
+ json (1.4.6)
49
+ macaddr (1.0.0)
50
+ mail (2.2.12)
51
+ activesupport (>= 2.3.6)
52
+ i18n (>= 0.4.0)
53
+ mime-types (~> 1.16)
54
+ treetop (~> 1.4.8)
55
+ mime-types (1.16)
56
+ mongo (1.1.4)
57
+ bson (>= 1.1.1)
58
+ mongoid (2.0.0.beta.20)
59
+ activemodel (~> 3.0)
60
+ mongo (~> 1.1)
61
+ tzinfo (~> 0.3.22)
62
+ will_paginate (~> 3.0.pre)
63
+ polyglot (0.3.1)
64
+ rack (1.2.1)
65
+ rack-mount (0.6.13)
66
+ rack (>= 1.0.0)
67
+ rack-test (0.5.6)
68
+ rack (>= 1.0)
69
+ rails (3.0.3)
70
+ actionmailer (= 3.0.3)
71
+ actionpack (= 3.0.3)
72
+ activerecord (= 3.0.3)
73
+ activeresource (= 3.0.3)
74
+ activesupport (= 3.0.3)
75
+ bundler (~> 1.0)
76
+ railties (= 3.0.3)
77
+ railties (3.0.3)
78
+ actionpack (= 3.0.3)
79
+ activesupport (= 3.0.3)
80
+ rake (>= 0.8.7)
81
+ thor (~> 0.14.4)
82
+ rake (0.8.7)
83
+ rr (1.0.2)
84
+ rspec (2.0.1)
85
+ rspec-core (~> 2.0.1)
86
+ rspec-expectations (~> 2.0.1)
87
+ rspec-mocks (~> 2.0.1)
88
+ rspec-core (2.0.1)
89
+ rspec-expectations (2.0.1)
90
+ diff-lcs (>= 1.1.2)
91
+ rspec-mocks (2.0.1)
92
+ rspec-core (~> 2.0.1)
93
+ rspec-expectations (~> 2.0.1)
94
+ thor (0.14.6)
95
+ treetop (1.4.9)
96
+ polyglot (>= 0.3.1)
97
+ tzinfo (0.3.23)
98
+ uuid (2.3.1)
99
+ macaddr (~> 1.0)
100
+ vidibus-core_extensions (0.3.12)
101
+ vidibus-secure (0.0.3)
102
+ activesupport (~> 3.0.0)
103
+ mongoid (~> 2.0.0.beta.20)
104
+ rack
105
+ vidibus-core_extensions
106
+ vidibus-service (0.0.3)
107
+ httparty
108
+ json
109
+ mongoid (~> 2.0.0.beta.20)
110
+ vidibus-core_extensions
111
+ vidibus-secure
112
+ vidibus-uuid
113
+ vidibus-validate_uri
114
+ vidibus-uuid (0.3.8)
115
+ mongoid (~> 2.0.0.beta.20)
116
+ uuid (~> 2.3.1)
117
+ vidibus-validate_uri (0.1.4)
118
+ rails (~> 3.0.0)
119
+ will_paginate (3.0.pre2)
120
+
121
+ PLATFORMS
122
+ ruby
123
+
124
+ DEPENDENCIES
125
+ activesupport (~> 3.0.0)
126
+ bundler (>= 1.0.0)
127
+ rack-test
128
+ rake
129
+ rr
130
+ rspec
131
+ vidibus-realm!
132
+ vidibus-service
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Andre Pankratz
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,7 @@
1
+ = vidibus-realm
2
+
3
+ Description goes here.
4
+
5
+ == Copyright
6
+
7
+ Copyright (c) 2010 Andre Pankratz. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ require "bundler"
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require "rake"
5
+ require "rake/rdoctask"
6
+ require "rspec"
7
+ require "rspec/core/rake_task"
8
+
9
+ Rspec::Core::RakeTask.new(:rcov) do |t|
10
+ t.pattern = "spec/**/*_spec.rb"
11
+ t.rcov = true
12
+ t.rcov_opts = ["--exclude", "^spec,/gems/"]
13
+ end
14
+
15
+ Rake::RDocTask.new do |rdoc|
16
+ version = File.exist?("VERSION") ? File.read("VERSION") : ""
17
+ rdoc.rdoc_dir = "rdoc"
18
+ rdoc.title = "vidibus-service #{version}"
19
+ rdoc.rdoc_files.include("README*")
20
+ rdoc.rdoc_files.include("lib/**/*.rb")
21
+ rdoc.options << "--charset=utf-8"
22
+ end
23
+
@@ -0,0 +1,15 @@
1
+ require "active_support"
2
+
3
+ $:.unshift(File.join(File.dirname(__FILE__), "vidibus"))
4
+ require "realm"
5
+ require "realm/rack"
6
+
7
+ if defined?(::Rails)
8
+ module Vidibus
9
+ module Realm
10
+ class Engine < ::Rails::Engine
11
+ config.app_middleware.use("Vidibus::Realm::Rack")
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1 @@
1
+ require "realm/extensions"
@@ -0,0 +1,5 @@
1
+ require "realm/extensions/controller"
2
+
3
+ ActiveSupport.on_load(:action_controller) do
4
+ include Vidibus::Realm::Extensions::Controller
5
+ end
@@ -0,0 +1,23 @@
1
+ module Vidibus
2
+ module Realm
3
+ module Extensions
4
+ module Controller
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ helper_method :realm
9
+ end
10
+
11
+ # Ensures that a realm is present.
12
+ def ensure_realm!
13
+ realm or render(:text => "Realm required!", :status => :unauthorized)
14
+ end
15
+
16
+ # Returns the current realm.
17
+ def realm
18
+ env[:realm]
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,35 @@
1
+ require "vidibus-service"
2
+
3
+ module Vidibus
4
+ module Realm
5
+ class Rack
6
+ attr_reader :app, :env
7
+
8
+ def initialize(app)
9
+ @app = app
10
+ end
11
+
12
+ def call(env)
13
+ @env = env
14
+ env[:realm] = realm
15
+ app.call(env)
16
+ end
17
+
18
+ protected
19
+
20
+ # Returns current subdomain which is, for now, the realm uuid itself.
21
+ # The hostname must match the current service's domain because it may
22
+ # contain several subdomains as well which are not suitable for
23
+ # identifying the current realm.
24
+ def subdomain
25
+ env["SERVER_NAME"].match(/(.+)\.#{::Service.this.domain}/)
26
+ $1
27
+ end
28
+
29
+ # Returns realm from constant or subdomain.
30
+ def realm
31
+ defined?(VIDIBUS_REALM) ? VIDIBUS_REALM : subdomain
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,5 @@
1
+ module Vidibus
2
+ module Realm
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,25 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
3
+
4
+ require "rubygems"
5
+ require "rspec"
6
+ require "rack/test"
7
+ require "rr"
8
+ # require "webmock/rspec"
9
+
10
+ require "vidibus-realm"
11
+
12
+ # Mongoid.configure do |config|
13
+ # name = "vidibus-user_test"
14
+ # host = "localhost"
15
+ # config.master = Mongo::Connection.new.db(name)
16
+ # config.logger = nil
17
+ # end
18
+
19
+ RSpec.configure do |config|
20
+ # config.include WebMock
21
+ config.mock_with :rr
22
+ # config.before(:each) do
23
+ # Mongoid.master.collections.select {|c| c.name !~ /system/}.each(&:drop)
24
+ # end
25
+ end
@@ -0,0 +1,59 @@
1
+ require "spec_helper"
2
+
3
+ class Service
4
+ def self.this
5
+ OpenStruct.new.tap do |a|
6
+ a.domain = "something.else.local"
7
+ end
8
+ end
9
+ end
10
+
11
+ describe "Vidibus::Realm::Rack" do
12
+ include Rack::Test::Methods
13
+
14
+ def downstream_app
15
+ @downstream_app ||= OpenStruct.new.tap do |a|
16
+ mock(a).call.with_any_args {[200,{"Content-Type" => "text/html"},[]]}
17
+ end
18
+ end
19
+
20
+ def app
21
+ @app ||= Vidibus::Realm::Rack.new(downstream_app)
22
+ end
23
+
24
+ it "should not set realm by default" do
25
+ get "http://something.local"
26
+ last_request.env[:realm].should be_nil
27
+ end
28
+
29
+ it "should set realm by subdomain" do
30
+ get "http://hello.something.else.local"
31
+ last_request.env[:realm].should eql("hello")
32
+ end
33
+
34
+ it "should not set realm by subdomain if hostname does not match the domain of this service" do
35
+ get "http://hello.else.local"
36
+ last_request.env[:realm].should be_nil
37
+ end
38
+
39
+ it "should not set realm by subdomain if no subdomain is available" do
40
+ get "http://something.else.local"
41
+ last_request.env[:realm].should be_nil
42
+ end
43
+
44
+ it "should set realm by constant if no valid subdomain is available" do
45
+ VIDIBUS_REALM = "gotcha"
46
+ get "http://something.else.local"
47
+ last_request.env[:realm].should eql("gotcha")
48
+ end
49
+
50
+ it "should set realm by constant even if a valid subdomain is given" do
51
+ VIDIBUS_REALM = "gotcha"
52
+ get "http://hello.something.else.local"
53
+ last_request.env[:realm].should eql("gotcha")
54
+ end
55
+
56
+ after do
57
+ Object.send(:remove_const, :VIDIBUS_REALM) if defined?(VIDIBUS_REALM)
58
+ end
59
+ end
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path("../lib/vidibus/realm/version", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "vidibus-realm"
6
+ s.version = Vidibus::Realm::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.summary = %q{Basic realm handling for Vidibus applications}
9
+ s.description = %q{Provides realm accessor for application controller}
10
+ s.homepage = "http://github.com/vidibus/vidibus-realm"
11
+ s.authors = ["Andre Pankratz"]
12
+ s.email = "andre@vidibus.com"
13
+
14
+ s.required_rubygems_version = ">= 1.3.6"
15
+ s.rubyforge_project = "vidibus-realm"
16
+
17
+ s.add_dependency "activesupport", "~> 3.0.0"
18
+ s.add_dependency "vidibus-service"
19
+
20
+ s.add_development_dependency "bundler", ">= 1.0.0"
21
+ s.add_development_dependency "rake", ">= 0"
22
+ s.add_development_dependency "rspec", ">= 0"
23
+ s.add_development_dependency "rack-test", ">= 0"
24
+ s.add_development_dependency "rr", ">= 0"
25
+
26
+ s.files = `git ls-files`.split("\n")
27
+ s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
28
+ s.require_path = 'lib'
29
+ end
metadata ADDED
@@ -0,0 +1,184 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vidibus-realm
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Andre Pankratz
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-01-02 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: activesupport
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 7
30
+ segments:
31
+ - 3
32
+ - 0
33
+ - 0
34
+ version: 3.0.0
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: vidibus-service
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 0
48
+ version: "0"
49
+ type: :runtime
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: bundler
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 23
60
+ segments:
61
+ - 1
62
+ - 0
63
+ - 0
64
+ version: 1.0.0
65
+ type: :development
66
+ version_requirements: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ name: rake
69
+ prerelease: false
70
+ requirement: &id004 !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ type: :development
80
+ version_requirements: *id004
81
+ - !ruby/object:Gem::Dependency
82
+ name: rspec
83
+ prerelease: false
84
+ requirement: &id005 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ hash: 3
90
+ segments:
91
+ - 0
92
+ version: "0"
93
+ type: :development
94
+ version_requirements: *id005
95
+ - !ruby/object:Gem::Dependency
96
+ name: rack-test
97
+ prerelease: false
98
+ requirement: &id006 !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ hash: 3
104
+ segments:
105
+ - 0
106
+ version: "0"
107
+ type: :development
108
+ version_requirements: *id006
109
+ - !ruby/object:Gem::Dependency
110
+ name: rr
111
+ prerelease: false
112
+ requirement: &id007 !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ hash: 3
118
+ segments:
119
+ - 0
120
+ version: "0"
121
+ type: :development
122
+ version_requirements: *id007
123
+ description: Provides realm accessor for application controller
124
+ email: andre@vidibus.com
125
+ executables: []
126
+
127
+ extensions: []
128
+
129
+ extra_rdoc_files: []
130
+
131
+ files:
132
+ - .gitignore
133
+ - Gemfile
134
+ - Gemfile.lock
135
+ - LICENSE
136
+ - README.rdoc
137
+ - Rakefile
138
+ - lib/vidibus-realm.rb
139
+ - lib/vidibus/realm.rb
140
+ - lib/vidibus/realm/extensions.rb
141
+ - lib/vidibus/realm/extensions/controller.rb
142
+ - lib/vidibus/realm/rack.rb
143
+ - lib/vidibus/realm/version.rb
144
+ - spec/spec_helper.rb
145
+ - spec/vidibus/realm/rack_spec.rb
146
+ - vidibus-realm.gemspec
147
+ has_rdoc: true
148
+ homepage: http://github.com/vidibus/vidibus-realm
149
+ licenses: []
150
+
151
+ post_install_message:
152
+ rdoc_options: []
153
+
154
+ require_paths:
155
+ - lib
156
+ required_ruby_version: !ruby/object:Gem::Requirement
157
+ none: false
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ hash: 3
162
+ segments:
163
+ - 0
164
+ version: "0"
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
166
+ none: false
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ hash: 23
171
+ segments:
172
+ - 1
173
+ - 3
174
+ - 6
175
+ version: 1.3.6
176
+ requirements: []
177
+
178
+ rubyforge_project: vidibus-realm
179
+ rubygems_version: 1.3.7
180
+ signing_key:
181
+ specification_version: 3
182
+ summary: Basic realm handling for Vidibus applications
183
+ test_files: []
184
+