conjur-rack 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 90340dd3a8dbc2f410a43b66ef10d010e76a9ffd
4
+ data.tar.gz: 9cc5f13b006ac102df5a28b65da08e7f3a7ef6dd
5
+ SHA512:
6
+ metadata.gz: 9223bfe5621080f8b9dba63e2de5593e2f6e44d2ad34d3beb60c8447a0ff8340eae3d1530420975052cfcbe6d26a66e2bbc5c8a1737f0019a2ee437c0fe458a3
7
+ data.tar.gz: 58042ba2ee61e535da72b1395ab7f48e1a873d8fba78fdc0ac1ab1a01a15b3dda63e7ba78fe83a550876c180238fbe5d38917d50f5c0485cf8dba1f42bfdbb67
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+
19
+ # IDE garbage
20
+ /.idea
data/.project ADDED
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <projectDescription>
3
+ <name>conjur-rack</name>
4
+ <comment></comment>
5
+ <projects>
6
+ </projects>
7
+ <buildSpec>
8
+ <buildCommand>
9
+ <name>com.aptana.ide.core.unifiedBuilder</name>
10
+ <arguments>
11
+ </arguments>
12
+ </buildCommand>
13
+ </buildSpec>
14
+ <natures>
15
+ <nature>com.aptana.ruby.core.rubynature</nature>
16
+ <nature>com.aptana.projects.webnature</nature>
17
+ </natures>
18
+ </projectDescription>
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use --create 2.0.0@conjur-rack
data/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # v1.4.0
2
+
3
+ * Add `validated_global_privilege` helper function to get the global privilege, if any, which has been submitted with the request and verified by the Conjur server.
4
+
5
+ # v1.3.0
6
+
7
+ * Add handling for `X-Forwarded-For` and `X-Conjur-Privilege`
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in conjur-rack.gemspec
4
+ gemspec
5
+
6
+ gem 'conjur-api', github: 'conjurinc/api-ruby', branch: 'master'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Kevin Gilpin
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Conjur::Rack
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'conjur-rack'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install conjur-rack
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+ require 'ci/reporter/rake/rspec'
4
+
5
+ RSpec::Core::RakeTask.new(:spec) do |t|
6
+ t.rspec_opts = "--format doc"
7
+ unless ENV["CONJUR_ENV"] == "ci"
8
+ t.rspec_opts << " --color"
9
+ else
10
+ Rake::Task["ci:setup:rspec"].invoke
11
+ end
12
+ end
13
+
14
+ task :default => :spec
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'conjur/rack/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "conjur-rack"
8
+ spec.version = Conjur::Rack::VERSION
9
+ spec.authors = ["Kevin Gilpin"]
10
+ spec.email = ["kgilpin@conjur.net"]
11
+ spec.description = %q{Rack authenticator and basic User struct}
12
+ spec.summary = %q{Rack authenticator and basic User struct}
13
+ spec.homepage = "http://github.com/conjurinc/conjur-rack"
14
+ spec.license = "Private"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "slosilo"
22
+ spec.add_dependency "conjur-api", ">= 4.17"
23
+ spec.add_dependency "rack"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.3"
26
+ spec.add_development_dependency "rake"
27
+ spec.add_development_dependency "rspec", ">=2.9", "<3.0"
28
+ spec.add_development_dependency 'ci_reporter_rspec'
29
+ end
@@ -0,0 +1,3 @@
1
+ require "conjur/rack/version"
2
+ require "conjur/rack/authenticator"
3
+ require "conjur/rack/path_prefix"
@@ -0,0 +1,125 @@
1
+ require "conjur/rack/user"
2
+
3
+ module Conjur
4
+ module Rack
5
+ def self.identity?
6
+ !Thread.current[:conjur_rack_identity].nil?
7
+ end
8
+
9
+ def self.user
10
+ User.new(identity[0], identity[1], privilege, remote_ip)
11
+ end
12
+
13
+ def self.identity
14
+ Thread.current[:conjur_rack_identity] or raise "No Conjur identity for current request"
15
+ end
16
+
17
+ def self.privilege
18
+ Thread.current[:conjur_rack_privilege]
19
+ end
20
+
21
+ def self.remote_ip
22
+ Thread.current[:conjur_rack_remote_ip]
23
+ end
24
+
25
+ class Authenticator
26
+ class AuthorizationError < SecurityError
27
+ end
28
+ class SignatureError < SecurityError
29
+ end
30
+
31
+ attr_reader :app, :options
32
+
33
+ # +options+:
34
+ # :except :: a list of request path patterns for which to skip authentication
35
+ def initialize app, options = {}
36
+ @app = app
37
+ @options = options
38
+ end
39
+
40
+ # threadsafe accessors, values are established explicitly below
41
+ def env; Thread.current[:rack_env] ; end
42
+ def token; Thread.current[:conjur_rack_token] ; end
43
+ def account; Thread.current[:conjur_rack_account]; end
44
+ def privilege; Thread.current[:conjur_rack_privilege]; end
45
+ def remote_ip; Thread.current[:conjur_rack_remote_ip]; end
46
+
47
+ def call rackenv
48
+ # never store request-specific variables as application attributes
49
+ Thread.current[:rack_env] = rackenv
50
+ if authenticate?
51
+ begin
52
+ identity = verify_authorization_and_get_identity # [token, account]
53
+
54
+ Thread.current[:conjur_rack_token] = identity[0]
55
+ Thread.current[:conjur_rack_account] = identity[1]
56
+ Thread.current[:conjur_rack_identity] = identity
57
+ Thread.current[:conjur_rack_privilege] = conjur_privilege
58
+ Thread.current[:conjur_rack_remote_ip] = remote_ip
59
+
60
+ rescue SecurityError, RestClient::Exception
61
+ return error 401, $!.message
62
+ end
63
+ end
64
+ begin
65
+ @app.call rackenv
66
+ ensure
67
+ Thread.current[:rack_env] = nil
68
+ Thread.current[:conjur_rack_identity] = nil
69
+ Thread.current[:conjur_rack_token] = nil
70
+ Thread.current[:conjur_rack_account] = nil
71
+ Thread.current[:conjur_rack_privilege] = nil
72
+ Thread.current[:conjur_rack_remote_ip] = nil
73
+ end
74
+ end
75
+
76
+ protected
77
+
78
+ def validate_token_and_get_account token
79
+ failure = SignatureError.new("Unathorized: Invalid token")
80
+ raise failure unless (signer = Slosilo.token_signer token)
81
+ raise failure unless signer =~ /\Aauthn:(.+)\z/
82
+ return $1
83
+ end
84
+
85
+ def error status, message
86
+ [status, { 'Content-Type' => 'text/plain', 'Content-Length' => message.length.to_s }, [message] ]
87
+ end
88
+
89
+ def verify_authorization_and_get_identity
90
+ if authorization.to_s[/^Token token="(.*)"/]
91
+ token = JSON.parse(Base64.decode64($1))
92
+ account = validate_token_and_get_account(token)
93
+ return [token, account]
94
+ else
95
+ raise AuthorizationError.new("Authorization missing")
96
+ end
97
+ end
98
+
99
+ def authenticate?
100
+ if options[:except]
101
+ options[:except].find{|p| p.match(path)}.nil?
102
+ else
103
+ true
104
+ end
105
+ end
106
+
107
+ def conjur_privilege
108
+ env['HTTP_X_CONJUR_PRIVILEGE']
109
+ end
110
+
111
+ def authorization
112
+ env['HTTP_AUTHORIZATION']
113
+ end
114
+
115
+ def remote_ip
116
+ require 'rack/request'
117
+ ::Rack::Request.new(env).ip
118
+ end
119
+
120
+ def path
121
+ [ env['SCRIPT_NAME'], env['PATH_INFO'] ].join
122
+ end
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,31 @@
1
+ # https://raw.github.com/merb/merb/master/merb-core/lib/merb-core/rack/middleware/path_prefix.rb
2
+ module Conjur
3
+ module Rack
4
+ class PathPrefix
5
+ EMPTY_STRING = ""
6
+ SLASH = "/"
7
+
8
+ # @api private
9
+ def initialize(app, path_prefix = nil)
10
+ @app = app
11
+ @path_prefix = /^#{Regexp.escape(path_prefix)}/
12
+ end
13
+
14
+ # @api plugin
15
+ def call(env)
16
+ strip_path_prefix(env)
17
+ @app.call(env)
18
+ end
19
+
20
+ # @api private
21
+ def strip_path_prefix(env)
22
+ ['PATH_INFO', 'REQUEST_URI'].each do |path_key|
23
+ if env[path_key] =~ @path_prefix
24
+ env[path_key].sub!(@path_prefix, EMPTY_STRING)
25
+ env[path_key] = SLASH if env[path_key].empty?
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,79 @@
1
+ require 'conjur/api'
2
+
3
+ module Conjur
4
+ module Rack
5
+ class User
6
+ attr_accessor :token, :account, :privilege, :remote_ip
7
+
8
+ def initialize(token, account, privilege = nil, remote_ip = nil)
9
+ @token = token
10
+ @account = account
11
+ @privilege = privilege
12
+ @remote_ip = remote_ip
13
+ end
14
+
15
+ # This file was accidently calling account conjur_account,
16
+ # I'm adding an alias in case that's going on anywhere else.
17
+ # -- Jon
18
+ alias :conjur_account :account
19
+ alias :conjur_account= :account=
20
+
21
+ def new_association(cls, params = {})
22
+ cls.new params.merge({userid: login})
23
+ end
24
+
25
+ # Returns the global privilege which was present on the request, if and only
26
+ # if the user actually has that privilege.
27
+ #
28
+ # Returns nil if no global privilege was present in the request headers,
29
+ # or if a global privilege was present in the request headers, but the user doesn't
30
+ # actually have that privilege according to the Conjur server.
31
+ def validated_global_privilege
32
+ unless @validated_global_privilege
33
+ @privilege = nil if @privilege && !api.global_privilege_permitted?(@privilege)
34
+ @validated_global_privilege = true
35
+ end
36
+ @privilege
37
+ end
38
+
39
+ # True if and only if the user has valid global 'reveal' privilege.
40
+ def global_reveal?
41
+ validated_global_privilege == "reveal"
42
+ end
43
+
44
+ # True if and only if the user has valid global 'sudo' privilege.
45
+ def global_sudo?
46
+ validated_global_privilege == "sudo"
47
+ end
48
+
49
+ def login
50
+ token["data"] or raise "No data field in token"
51
+ end
52
+
53
+ def roleid
54
+ tokens = login.split('/')
55
+ role_kind, roleid = if tokens.length == 1
56
+ [ 'user', login ]
57
+ else
58
+ [ tokens[0], tokens[1..-1].join('/') ]
59
+ end
60
+ [ account, role_kind, roleid ].join(':')
61
+ end
62
+
63
+ def role
64
+ api.role(roleid)
65
+ end
66
+
67
+ def api(cls = Conjur::API)
68
+ args = [ token ]
69
+ args.push remote_ip if remote_ip
70
+ api = cls.new_from_token(*args)
71
+ if privilege
72
+ api.with_privilege(privilege)
73
+ else
74
+ api
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,5 @@
1
+ module Conjur
2
+ module Rack
3
+ VERSION = "1.4.0"
4
+ end
5
+ end
@@ -0,0 +1,109 @@
1
+ require 'spec_helper'
2
+
3
+ require 'conjur/rack/authenticator'
4
+
5
+ describe Conjur::Rack::Authenticator do
6
+ let(:app) { double(:app) }
7
+ let(:options) { {} }
8
+ let(:authenticator) { Conjur::Rack::Authenticator.new(app, options) }
9
+ let(:call) { authenticator.call env }
10
+
11
+ context "#call" do
12
+ context "with Conjur authorization" do
13
+ before{ stub_const 'Slosilo', Module.new }
14
+ let(:env) {
15
+ {
16
+ 'HTTP_AUTHORIZATION' => "Token token=\"#{basic_64}\""
17
+ }.tap do |e|
18
+ e['HTTP_X_CONJUR_PRIVILEGE'] = privilege if privilege
19
+ e['HTTP_X_FORWARDED_FOR'] = remote_ip if remote_ip
20
+ end
21
+ }
22
+ let(:basic_64) { Base64.strict_encode64(token.to_json) }
23
+ let(:token) { { "data" => "foobar" } }
24
+ let(:sample_account) { "someacc" }
25
+ let(:privilege) { nil }
26
+ let(:remote_ip) { nil }
27
+
28
+ context "of a valid token" do
29
+
30
+ before(:each) {
31
+ Slosilo.stub token_signer: 'authn:'+sample_account
32
+ }
33
+
34
+ it 'launches app' do
35
+ app.should_receive(:call).with(env).and_return app
36
+ call.should == app
37
+ end
38
+
39
+ context 'Authable provides module method conjur_user' do
40
+ let(:stubuser) { "some value" }
41
+ before {
42
+ app.stub(:call) { Conjur::Rack.user }
43
+ }
44
+
45
+ context 'when called in app context' do
46
+ let(:invoke) {
47
+ Conjur::Rack::User.should_receive(:new).
48
+ with(token, sample_account, privilege, remote_ip).
49
+ and_return(stubuser)
50
+ Conjur::Rack.should_receive(:user).and_call_original
51
+ call
52
+ }
53
+
54
+ shared_examples_for 'returns User built from token' do
55
+ specify {
56
+ invoke.should == stubuser
57
+ }
58
+ end
59
+
60
+ it_should_behave_like 'returns User built from token'
61
+
62
+ context 'with X-Conjur-Privilege' do
63
+ let(:privilege) { "sudo" }
64
+ it_should_behave_like 'returns User built from token'
65
+ end
66
+
67
+ context 'with X-Forwarded-For' do
68
+ let(:remote_ip) { "66.0.0.1" }
69
+ it_should_behave_like 'returns User built from token'
70
+ end
71
+ end
72
+
73
+ context 'called out of app context' do
74
+ it { lambda { Conjur::Rack.user }.should raise_error }
75
+ end
76
+ end
77
+ end
78
+ context "of an invalid token" do
79
+ it "returns a 401 error" do
80
+ Slosilo.stub token_signer: nil
81
+ call.should == [401, {"Content-Type"=>"text/plain", "Content-Length"=>"26"}, ["Unathorized: Invalid token"]]
82
+ end
83
+ end
84
+ context "of a token invalid for authn" do
85
+ it "returns a 401 error" do
86
+ Slosilo.stub token_signer: 'a-totally-different-key'
87
+ call.should == [401, {"Content-Type"=>"text/plain", "Content-Length"=>"26"}, ["Unathorized: Invalid token"]]
88
+ end
89
+ end
90
+ end
91
+ end
92
+ context "without authorization" do
93
+ context "to a protected path" do
94
+ let(:env) { { 'SCRIPT_NAME' => '/pathname' } }
95
+ it "returns a 401 error" do
96
+ call.should == [401, {"Content-Type"=>"text/plain", "Content-Length"=>"21"}, ["Authorization missing"]]
97
+ end
98
+ end
99
+ context "to an unprotected path" do
100
+ let(:except) { [ /^\/foo/ ] }
101
+ let(:env) { { 'SCRIPT_NAME' => '', 'PATH_INFO' => '/foo/bar' } }
102
+ it "proceeds" do
103
+ options[:except] = except
104
+ app.should_receive(:call).with(env).and_return app
105
+ call.should == app
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ require 'conjur/rack/path_prefix'
4
+
5
+ describe Conjur::Rack::PathPrefix do
6
+ let(:app) { double(:app) }
7
+ let(:prefix) { "/api" }
8
+ let(:path_prefix) { Conjur::Rack::PathPrefix.new(app, prefix) }
9
+ let(:call) { path_prefix.call env }
10
+ let(:env) {
11
+ {
12
+ 'PATH_INFO' => path
13
+ }
14
+ }
15
+
16
+ context "#call" do
17
+ context "/api/hosts" do
18
+ let(:path) { "/api/hosts" }
19
+ it "matches" do
20
+ app.should_receive(:call).with({ 'PATH_INFO' => '/hosts' }).and_return app
21
+ call
22
+ end
23
+ end
24
+ context "/api" do
25
+ let(:path) { "/api" }
26
+ it "doesn't erase the path completely" do
27
+ app.should_receive(:call).with({ 'PATH_INFO' => '/' }).and_return app
28
+ call
29
+ end
30
+ end
31
+ context "with non-matching prefix" do
32
+ let(:path) { "/hosts" }
33
+ it "doesn't match" do
34
+ app.should_receive(:call).with({ 'PATH_INFO' => '/hosts' }).and_return app
35
+ call
36
+ end
37
+ end
38
+ end
39
+
40
+ end
@@ -0,0 +1,121 @@
1
+ require 'spec_helper'
2
+
3
+ describe Conjur::Rack::User do
4
+ let(:login){ 'admin' }
5
+ let(:token){ {'data' => login} }
6
+ let(:account){ 'acct' }
7
+ let(:privilege) { nil }
8
+ let(:remote_ip) { nil }
9
+
10
+ subject{ described_class.new token, account, privilege, remote_ip }
11
+
12
+ its(:token){ should == token }
13
+ its(:account){ should == account }
14
+ its(:conjur_account){ should == account }
15
+ its(:login){ should == token['data'] }
16
+
17
+ it "aliases setter for account to conjur_account" do
18
+ subject.conjur_account = "changed!"
19
+ subject.account.should == "changed!"
20
+ end
21
+
22
+ describe '#new_assocation' do
23
+ let(:associate){ Class.new }
24
+ let(:params){{foo: 'bar'}}
25
+ it "calls cls.new with params including userid: login" do
26
+ associate.should_receive(:new).with(params.merge(userid: subject.login))
27
+ subject.new_association(associate, params)
28
+ end
29
+ end
30
+
31
+ describe '#roleid' do
32
+ let(:login){ tokens.join('/') }
33
+ context "when login contains one token 'foobar'" do
34
+ let(:tokens){ ['foobar'] }
35
+ its(:roleid){ should == "#{account}:user:#{login}" }
36
+ end
37
+ context "when login contains tokens ['foo', 'bar']" do
38
+ let(:tokens){ ["foos", "bar"] }
39
+ its(:roleid){ should == "#{account}:#{tokens[0]}:#{tokens[1]}"}
40
+ end
41
+ context "when login contains tokens ['foo','bar','baz']" do
42
+ let(:tokens){ ['foo', 'bar', 'baz'] }
43
+ its(:roleid){ should == "#{account}:#{tokens[0]}:#{tokens[1]}/#{tokens[2]}" }
44
+ end
45
+ end
46
+
47
+ describe '#role' do
48
+ let(:roleid){ 'the role id' }
49
+ let(:api){ double('conjur api') }
50
+ before do
51
+ subject.stub(:roleid).and_return roleid
52
+ subject.stub(:api).and_return api
53
+ end
54
+
55
+ it 'passes roleid to api.role' do
56
+ api.should_receive(:role).with(roleid).and_return 'the role'
57
+ subject.role.should == 'the role'
58
+ end
59
+ end
60
+
61
+ describe "#global_reveal?" do
62
+ context "with global privilege" do
63
+ let(:privilege) { "reveal" }
64
+ let(:api){ Conjur::API.new_from_token "the-token" }
65
+ before do
66
+ subject.stub(:api).and_return api
67
+ end
68
+ it "checks the API function global_privilege_permitted?" do
69
+ api.should_receive(:resource).with("!:!:conjur").and_return resource = double(:resource)
70
+ resource.should_receive(:permitted?).with("reveal").and_return true
71
+ expect(subject.global_reveal?).to be_true
72
+ # The result is cached
73
+ subject.global_reveal?
74
+ end
75
+ end
76
+ context "without a global privilege" do
77
+ it "simply returns nil" do
78
+ expect(subject.global_reveal?).to be_false
79
+ end
80
+ end
81
+ end
82
+
83
+ describe '#api' do
84
+ context "when given a class" do
85
+ let(:cls){ double('API class') }
86
+ it "calls cls.new_from_token with its token" do
87
+ cls.should_receive(:new_from_token).with(token).and_return 'the api'
88
+ subject.api(cls).should == 'the api'
89
+ end
90
+ end
91
+ context 'when not given args' do
92
+ shared_examples_for "builds the api" do
93
+ specify {
94
+ subject.api.should == 'the api'
95
+ }
96
+ end
97
+
98
+ context "with no extra args" do
99
+ before {
100
+ Conjur::API.should_receive(:new_from_token).with(token).and_return 'the api'
101
+ }
102
+ it_should_behave_like "builds the api"
103
+ end
104
+ context "with remote_ip" do
105
+ let(:remote_ip) { "the-ip" }
106
+ before {
107
+ Conjur::API.should_receive(:new_from_token).with(token, 'the-ip').and_return 'the api'
108
+ }
109
+ it_should_behave_like "builds the api"
110
+ end
111
+ context "with privilege" do
112
+ let(:privilege) { "sudo" }
113
+ before {
114
+ Conjur::API.should_receive(:new_from_token).with(token).and_return api = double(:api)
115
+ expect(api).to receive(:with_privilege).with("sudo").and_return('the api')
116
+ }
117
+ it_should_behave_like "builds the api"
118
+ end
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
3
+ $:.unshift File.join(File.dirname(__FILE__), "lib")
4
+
5
+ # Allows loading of an environment config based on the environment
6
+ require 'rspec'
7
+ require 'securerandom'
8
+
9
+ RSpec.configure do |config|
10
+ end
11
+
metadata ADDED
@@ -0,0 +1,170 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: conjur-rack
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.4.0
5
+ platform: ruby
6
+ authors:
7
+ - Kevin Gilpin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-10-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: slosilo
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: conjur-api
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '4.17'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '4.17'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rack
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
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: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
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: '2.9'
90
+ - - "<"
91
+ - !ruby/object:Gem::Version
92
+ version: '3.0'
93
+ type: :development
94
+ prerelease: false
95
+ version_requirements: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '2.9'
100
+ - - "<"
101
+ - !ruby/object:Gem::Version
102
+ version: '3.0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: ci_reporter_rspec
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ description: Rack authenticator and basic User struct
118
+ email:
119
+ - kgilpin@conjur.net
120
+ executables: []
121
+ extensions: []
122
+ extra_rdoc_files: []
123
+ files:
124
+ - ".gitignore"
125
+ - ".project"
126
+ - ".rvmrc"
127
+ - CHANGELOG.md
128
+ - Gemfile
129
+ - LICENSE.txt
130
+ - README.md
131
+ - Rakefile
132
+ - conjur-rack.gemspec
133
+ - lib/conjur/rack.rb
134
+ - lib/conjur/rack/authenticator.rb
135
+ - lib/conjur/rack/path_prefix.rb
136
+ - lib/conjur/rack/user.rb
137
+ - lib/conjur/rack/version.rb
138
+ - spec/rack/authenticator_spec.rb
139
+ - spec/rack/path_prefix_spec.rb
140
+ - spec/rack/user_spec.rb
141
+ - spec/spec_helper.rb
142
+ homepage: http://github.com/conjurinc/conjur-rack
143
+ licenses:
144
+ - Private
145
+ metadata: {}
146
+ post_install_message:
147
+ rdoc_options: []
148
+ require_paths:
149
+ - lib
150
+ required_ruby_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ required_rubygems_version: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ requirements: []
161
+ rubyforge_project:
162
+ rubygems_version: 2.4.8
163
+ signing_key:
164
+ specification_version: 4
165
+ summary: Rack authenticator and basic User struct
166
+ test_files:
167
+ - spec/rack/authenticator_spec.rb
168
+ - spec/rack/path_prefix_spec.rb
169
+ - spec/rack/user_spec.rb
170
+ - spec/spec_helper.rb