aptible-auth 0.11.8 → 0.11.10
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.
- checksums.yaml +4 -4
- data/.travis.yml +4 -1
- data/aptible-auth.gemspec +2 -0
- data/lib/aptible/auth/role.rb +1 -1
- data/lib/aptible/auth/token.rb +10 -2
- data/lib/aptible/auth/user.rb +0 -59
- data/lib/aptible/auth/version.rb +1 -1
- data/spec/aptible/auth/organization_spec.rb +1 -1
- data/spec/aptible/auth/resource_spec.rb +1 -1
- data/spec/aptible/auth/token_spec.rb +15 -1
- data/spec/aptible/auth/user_spec.rb +0 -114
- data/spec/spec_helper.rb +2 -0
- metadata +30 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 981b35248a15b30129e3bd155aae3ef7cedc59ac
|
|
4
|
+
data.tar.gz: ae3b8a9e77e095f0c71a1d923629ee65af15c4bc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 83312c36af6756eaa8599516ad25cdfbf96d61d64829609b31de3e63fea97a8ea24595a38529d807d75ba46e04341f82b8b3e9d46c796b4493110c3db336e9fa
|
|
7
|
+
data.tar.gz: 8e152096f8680ef4a670bd10138f3061a68385c147c5769f7039f804b663a94131451a33d0c68c11300c7ee57e3245c6882af71da1e22b5fc7b103b841134b9f
|
data/.travis.yml
CHANGED
data/aptible-auth.gemspec
CHANGED
|
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
|
|
|
20
20
|
spec.require_paths = ['lib']
|
|
21
21
|
|
|
22
22
|
spec.add_dependency 'aptible-billing'
|
|
23
|
+
spec.add_dependency 'activesupport', '~> 4.0'
|
|
23
24
|
spec.add_dependency 'aptible-resource', '>= 0.3.1'
|
|
24
25
|
spec.add_dependency 'stripe', '>= 1.13.0'
|
|
25
26
|
spec.add_dependency 'gem_config'
|
|
@@ -31,4 +32,5 @@ Gem::Specification.new do |spec|
|
|
|
31
32
|
spec.add_development_dependency 'rspec', '~> 2.0'
|
|
32
33
|
spec.add_development_dependency 'rspec-its'
|
|
33
34
|
spec.add_development_dependency 'pry'
|
|
35
|
+
spec.add_development_dependency 'timecop', '~> 0.8.1'
|
|
34
36
|
end
|
data/lib/aptible/auth/role.rb
CHANGED
data/lib/aptible/auth/token.rb
CHANGED
|
@@ -47,6 +47,11 @@ module Aptible
|
|
|
47
47
|
|
|
48
48
|
def authenticate_client(id, secret, subject, options = {})
|
|
49
49
|
options[:scope] ||= 'manage'
|
|
50
|
+
# Unlike other methods, the assertion token grant requirs an "exp"
|
|
51
|
+
# parameter rather than expires_in, but since we'd like to expose a
|
|
52
|
+
# consistent API to consumers, we override it here
|
|
53
|
+
expires_in = options.delete(:expires_in)
|
|
54
|
+
options[:exp] = Time.now.utc.to_i + expires_in if expires_in
|
|
50
55
|
oauth_token = oauth.assertion.get_token({
|
|
51
56
|
iss: id,
|
|
52
57
|
sub: subject
|
|
@@ -68,7 +73,8 @@ module Aptible
|
|
|
68
73
|
options[:scope] ||= 'manage'
|
|
69
74
|
oauth_token = oauth.token_exchange.get_token(
|
|
70
75
|
actor_token, 'urn:ietf:params:oauth:token-type:jwt',
|
|
71
|
-
subject_token, subject_token_type, options
|
|
76
|
+
subject_token, subject_token_type, options
|
|
77
|
+
)
|
|
72
78
|
apply_oauth_response(oauth_token)
|
|
73
79
|
end
|
|
74
80
|
|
|
@@ -93,7 +99,9 @@ module Aptible
|
|
|
93
99
|
elsif (email = options.delete(:user_email))
|
|
94
100
|
authenticate_impersonate(email, 'aptible:user:email', options)
|
|
95
101
|
else
|
|
102
|
+
# rubocop:disable Style/SignalException
|
|
96
103
|
fail 'Unrecognized options'
|
|
104
|
+
# rubocop:enable Style/SignalException
|
|
97
105
|
end
|
|
98
106
|
end
|
|
99
107
|
|
|
@@ -137,7 +145,7 @@ module Aptible
|
|
|
137
145
|
end
|
|
138
146
|
|
|
139
147
|
def parse_private_key(string)
|
|
140
|
-
if string
|
|
148
|
+
if string.start_with?('-----')
|
|
141
149
|
OpenSSL::PKey::RSA.new(string)
|
|
142
150
|
else
|
|
143
151
|
formatted_string = <<-PRIVATE_KEY.gsub(/^\s+/, '')
|
data/lib/aptible/auth/user.rb
CHANGED
|
@@ -12,73 +12,14 @@ module Aptible
|
|
|
12
12
|
field :created_at, type: Time
|
|
13
13
|
field :updated_at, type: Time
|
|
14
14
|
|
|
15
|
-
# rubocop:disable MethodLength
|
|
16
|
-
def set_organization_roles(organization, roles)
|
|
17
|
-
self.roles.each do |role|
|
|
18
|
-
next unless role.organization.id == organization.id
|
|
19
|
-
next if roles.map(&:id).include? role.id
|
|
20
|
-
|
|
21
|
-
role_membership = role.memberships.find do |membership|
|
|
22
|
-
membership.user.id == id
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
role_membership.destroy
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
add_to_roles(roles)
|
|
29
|
-
end
|
|
30
|
-
# rubocop:enable MethodLength
|
|
31
|
-
|
|
32
15
|
def organizations
|
|
33
16
|
roles.map(&:organization).uniq(&:id)
|
|
34
17
|
end
|
|
35
18
|
|
|
36
|
-
def organization_roles(organization)
|
|
37
|
-
roles.select do |role|
|
|
38
|
-
role.links['organization'].href == organization.href
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def organization_privileged_roles(organization)
|
|
43
|
-
privileged_roles.select do |role|
|
|
44
|
-
role.links['organization'].href == organization.href
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
|
|
48
19
|
def operations
|
|
49
20
|
# TODO: Implement query params for /operations
|
|
50
21
|
[]
|
|
51
22
|
end
|
|
52
|
-
|
|
53
|
-
def privileged_organizations
|
|
54
|
-
privileged_roles.map(&:organization)
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def privileged_roles
|
|
58
|
-
@privileged_roles ||= roles.select(&:privileged?)
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
# rubocop:disable PredicateName
|
|
62
|
-
def is_billing_contact?(organization)
|
|
63
|
-
organization.billing_contact_id && organization.billing_contact_id == id
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
def has_role?(role)
|
|
67
|
-
roles.select { |user_role| role.id == user_role.id }.count > 0
|
|
68
|
-
end
|
|
69
|
-
# rubocop:enable PredicateName
|
|
70
|
-
|
|
71
|
-
def can_manage?(organization)
|
|
72
|
-
privileged_organizations.map(&:id).include? organization.id
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
def add_to_roles(roles)
|
|
76
|
-
roles.each { |role| add_to_role(role) }
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
def add_to_role(role)
|
|
80
|
-
role.create_membership(user: self, token: token) unless has_role? role
|
|
81
|
-
end
|
|
82
23
|
end
|
|
83
24
|
end
|
|
84
25
|
end
|
data/lib/aptible/auth/version.rb
CHANGED
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
|
2
2
|
|
|
3
3
|
describe Aptible::Auth::Organization do
|
|
4
4
|
describe '#can_manage_compliance?' do
|
|
5
|
-
before { subject.stub(:billing_detail)
|
|
5
|
+
before { subject.stub(:billing_detail) { billing_detail } }
|
|
6
6
|
|
|
7
7
|
context 'without a billing detail' do
|
|
8
8
|
let(:billing_detail) { nil }
|
|
@@ -112,6 +112,20 @@ describe Aptible::Auth::Token do
|
|
|
112
112
|
subject.authenticate_client(*args)
|
|
113
113
|
end
|
|
114
114
|
|
|
115
|
+
it 'should replace expires_in in exp' do
|
|
116
|
+
args << { expires_in: 1800 }
|
|
117
|
+
Timecop.freeze do
|
|
118
|
+
expect(oauth.assertion).to receive(:get_token).with(
|
|
119
|
+
iss: 'id',
|
|
120
|
+
sub: 'user@example.com',
|
|
121
|
+
exp: Time.now.to_i + 1800,
|
|
122
|
+
algorithm: 'foobar',
|
|
123
|
+
scope: 'manage'
|
|
124
|
+
)
|
|
125
|
+
subject.authenticate_client(*args)
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
115
129
|
it 'should set the access_token' do
|
|
116
130
|
subject.authenticate_client(*args)
|
|
117
131
|
expect(subject.access_token).to eq 'access_token'
|
|
@@ -158,7 +172,7 @@ describe Aptible::Auth::Token do
|
|
|
158
172
|
end
|
|
159
173
|
|
|
160
174
|
it 'should return a correct :private_key for Base64-only keys' do
|
|
161
|
-
stripped_key = private_key_string.gsub(/^-.*-$/, '').
|
|
175
|
+
stripped_key = private_key_string.gsub(/^-.*-$/, '').delete("\n")
|
|
162
176
|
params = subject.call(stripped_key)
|
|
163
177
|
expect(params[:private_key]).to be_a OpenSSL::PKey::RSA
|
|
164
178
|
end
|
|
@@ -1,35 +1,6 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe Aptible::Auth::User do
|
|
4
|
-
describe '#can_manage?' do
|
|
5
|
-
let(:developer) { double 'Aptible::Auth::Role' }
|
|
6
|
-
let(:owner) { double 'Aptible::Auth::Role' }
|
|
7
|
-
let(:org) { double 'Aptible::Auth::Organization' }
|
|
8
|
-
|
|
9
|
-
before do
|
|
10
|
-
org.stub(:id) { 1 }
|
|
11
|
-
developer.stub(:organization) { org }
|
|
12
|
-
allow(developer).to receive(:privileged?).and_return(false)
|
|
13
|
-
owner.stub(:organization) { org }
|
|
14
|
-
allow(owner).to receive(:privileged?).and_return(true)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
it 'should return false if not member of org privileged role' do
|
|
18
|
-
subject.stub(:roles) { [developer] }
|
|
19
|
-
expect(subject.can_manage?(org)).to eq false
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
it 'should return true if member of org privileged role' do
|
|
23
|
-
subject.stub(:roles) { [developer, owner] }
|
|
24
|
-
expect(subject.can_manage?(org)).to eq true
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
it 'should return false if member of no roles' do
|
|
28
|
-
subject.stub(:roles) { [] }
|
|
29
|
-
expect(subject.can_manage?(org)).to eq false
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
4
|
describe '#organizations' do
|
|
34
5
|
let(:so) { double 'Aptible::Auth::Role' }
|
|
35
6
|
let(:owner) { double 'Aptible::Auth::Role' }
|
|
@@ -51,89 +22,4 @@ describe Aptible::Auth::User do
|
|
|
51
22
|
expect(subject.organizations.count).to eq 1
|
|
52
23
|
end
|
|
53
24
|
end
|
|
54
|
-
|
|
55
|
-
describe '#roles' do
|
|
56
|
-
let(:so) { double 'Aptible::Auth::Role' }
|
|
57
|
-
let(:owner) { double 'Aptible::Auth::Role' }
|
|
58
|
-
|
|
59
|
-
before do
|
|
60
|
-
so.stub(:id) { 1 }
|
|
61
|
-
owner.stub(:id) { 2 }
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
it 'should have role' do
|
|
65
|
-
subject.stub(:roles) { [so] }
|
|
66
|
-
expect(subject.has_role?(so)).to eq true
|
|
67
|
-
expect(subject.has_role?(owner)).to eq false
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
describe '#set_organization_roles' do
|
|
72
|
-
let(:so) { double 'Aptible::Auth::Role' }
|
|
73
|
-
let(:owner) { double 'Aptible::Auth::Role' }
|
|
74
|
-
let(:org) { double 'Aptible::Auth::Organization' }
|
|
75
|
-
let(:owner_membership) { double 'Aptible::Auth::Membership' }
|
|
76
|
-
let(:so_membership) { double 'Aptible::Auth::Membership' }
|
|
77
|
-
|
|
78
|
-
before do
|
|
79
|
-
org.stub(:id) { 1 }
|
|
80
|
-
|
|
81
|
-
so.stub(:organization) { org }
|
|
82
|
-
so.stub(:id) { 1 }
|
|
83
|
-
|
|
84
|
-
owner.stub(:organization) { org }
|
|
85
|
-
owner.stub(:id) { 2 }
|
|
86
|
-
|
|
87
|
-
allow(Aptible::Auth::Role).to receive(:find)
|
|
88
|
-
.with(1, token: 'token').and_return(so)
|
|
89
|
-
allow(Aptible::Auth::Role).to receive(:find)
|
|
90
|
-
.with(2, token: 'token').and_return(owner)
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
it 'should overwrite existing memberships' do
|
|
94
|
-
subject.stub(:roles) { [so] }
|
|
95
|
-
subject.stub(:token) { 'token' }
|
|
96
|
-
subject.stub(:headers) { {} }
|
|
97
|
-
so_membership.stub(:user) { subject }
|
|
98
|
-
so_membership.stub(:role) { so }
|
|
99
|
-
so.stub(:memberships) { [so_membership] }
|
|
100
|
-
owner.stub(:memberships) { [] }
|
|
101
|
-
|
|
102
|
-
expect(so_membership).to receive(:destroy)
|
|
103
|
-
expect(owner).to receive(:create_membership)
|
|
104
|
-
.with(user: subject, token: 'token')
|
|
105
|
-
|
|
106
|
-
subject.set_organization_roles(org, [owner])
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
it 'should create new memberships' do
|
|
110
|
-
subject.stub(:roles) { [] }
|
|
111
|
-
subject.stub(:token) { 'token' }
|
|
112
|
-
subject.stub(:headers) { {} }
|
|
113
|
-
so.stub(:memberships) { [] }
|
|
114
|
-
owner.stub(:memberships) { [] }
|
|
115
|
-
|
|
116
|
-
expect(so).to receive(:create_membership)
|
|
117
|
-
.with(user: subject, token: 'token')
|
|
118
|
-
expect(owner).to receive(:create_membership)
|
|
119
|
-
.with(user: subject, token: 'token')
|
|
120
|
-
|
|
121
|
-
subject.set_organization_roles(org, [so, owner])
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
it 'should delete all existing memberships' do
|
|
125
|
-
subject.stub(:roles) { [so, owner] }
|
|
126
|
-
so.stub(:memberships) { [so_membership] }
|
|
127
|
-
owner.stub(:memberships) { [owner_membership] }
|
|
128
|
-
so_membership.stub(:user) { subject }
|
|
129
|
-
so_membership.stub(:role) { so }
|
|
130
|
-
owner_membership.stub(:user) { subject }
|
|
131
|
-
owner_membership.stub(:role) { owner }
|
|
132
|
-
|
|
133
|
-
expect(so_membership).to receive(:destroy)
|
|
134
|
-
expect(owner_membership).to receive(:destroy)
|
|
135
|
-
|
|
136
|
-
subject.set_organization_roles(org, [])
|
|
137
|
-
end
|
|
138
|
-
end
|
|
139
25
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: aptible-auth
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.11.
|
|
4
|
+
version: 0.11.10
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Frank Macreery
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-
|
|
11
|
+
date: 2016-09-13 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: aptible-billing
|
|
@@ -24,6 +24,20 @@ dependencies:
|
|
|
24
24
|
- - ">="
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
26
|
version: '0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: activesupport
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '4.0'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '4.0'
|
|
27
41
|
- !ruby/object:Gem::Dependency
|
|
28
42
|
name: aptible-resource
|
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -164,6 +178,20 @@ dependencies:
|
|
|
164
178
|
- - ">="
|
|
165
179
|
- !ruby/object:Gem::Version
|
|
166
180
|
version: '0'
|
|
181
|
+
- !ruby/object:Gem::Dependency
|
|
182
|
+
name: timecop
|
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
|
184
|
+
requirements:
|
|
185
|
+
- - "~>"
|
|
186
|
+
- !ruby/object:Gem::Version
|
|
187
|
+
version: 0.8.1
|
|
188
|
+
type: :development
|
|
189
|
+
prerelease: false
|
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
191
|
+
requirements:
|
|
192
|
+
- - "~>"
|
|
193
|
+
- !ruby/object:Gem::Version
|
|
194
|
+
version: 0.8.1
|
|
167
195
|
description: Ruby client for auth.aptible.com
|
|
168
196
|
email:
|
|
169
197
|
- frank@macreery.com
|