machina-auth 0.1.5 → 0.1.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ca27cf7dd475d64e5bbf876084d6e7445a56ac65dbf9967d5b9b50a91f04f155
4
- data.tar.gz: ad165e21c3628da603b016a7e40911f7efc3e60131cbad506ee1c5cb2dde48c8
3
+ metadata.gz: 779a01d0ee76aefd789279497b06a5eb82bafc444d783d6f279cf75e31e37b57
4
+ data.tar.gz: 3533cf0c697aa3698225c9527df313f7d09643cd04e641af597d0b0d874ab518
5
5
  SHA512:
6
- metadata.gz: 3830bfe8f9b10c30bfedf347d3efa00ecc36feb09a028ed9372512c7c0a3f6817bee27a321c008394c6361b68c85e2aeb5ad0d71b41a72fd779ea8340d7e7fe6
7
- data.tar.gz: f6c04f4aea2b6ad6f01c5632c3e49e92291a8341bb01c751f11eb22d6612aaad8e7f9b4c1124d77d9138c34094de00f41195cbabd60d6957293613111fa60bef
6
+ metadata.gz: 4d896e66034311c92ef6b5b99f1ffd6d0adfa8033f78922305d354c5009500e516ebbd49b766f615758cbaee4003246017a2fed1209cdbbb2539b3e614e78d5f
7
+ data.tar.gz: e7276fa8589250b587754784882592380d20bf30e05b0dcf71b352b7d5664375decc54907c18821d8369e4aa83ae5f6c00d208ff0efe8f1ecd0f8e86873a3c00
@@ -117,7 +117,6 @@ module Machina
117
117
  def cache_key(token)
118
118
  "machina:session:#{token}"
119
119
  end
120
-
121
120
  end
122
121
  end
123
122
  end
@@ -14,13 +14,12 @@ module Machina
14
14
  def call!
15
15
  manifest = load_manifest
16
16
 
17
- product_id = manifest[:product_id] || Machina.config.product_id
18
- if product_id.blank?
19
- raise Machina::ConfigurationError, 'product_id is required for permission sync (set in machina.yml or Machina.config)'
17
+ if Machina.config.product_id.blank?
18
+ raise Machina::ConfigurationError, 'product_id is required for permission sync (set Machina.config.product_id)'
20
19
  end
21
20
 
22
21
  Machina.identity_client.sync_permissions(
23
- product_id:,
22
+ product_id: Machina.config.product_id,
24
23
  policies: manifest.fetch(:policies, []),
25
24
  permissions: manifest.fetch(:permissions),
26
25
  )
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Machina
4
- VERSION = '0.1.5'
4
+ VERSION = '0.1.6'
5
5
  end
data/lib/machina.rb CHANGED
@@ -101,7 +101,8 @@ module Machina
101
101
  callback = config.identity_callback_uri
102
102
 
103
103
  if callback.blank?
104
- raise ConfigurationError, 'identity_callback_uri must be configured to use authorize_url without an explicit redirect_to'
104
+ raise ConfigurationError,
105
+ 'identity_callback_uri must be configured to use authorize_url without an explicit redirect_to'
105
106
  end
106
107
 
107
108
  return_to.present? ? "#{callback}?return_to=#{CGI.escape(return_to)}" : callback
@@ -19,10 +19,10 @@ RSpec.describe Machina::Current do
19
19
  # but each CurrentAttributes subclass has its own thread-local storage.
20
20
  described_class.authorized = authorized
21
21
 
22
- expect(::Current.authorized).to be_nil
22
+ expect(Current.authorized).to be_nil
23
23
  expect(described_class.authorized).to eq(authorized)
24
24
  ensure
25
- ::Current.reset
25
+ Current.reset
26
26
  end
27
27
 
28
28
  it 'returns nil when nothing is set' do
@@ -4,9 +4,10 @@ require_relative '../rails_helper'
4
4
 
5
5
  RSpec.describe Machina::PermissionSync do
6
6
  let(:client) { instance_double(Machina::IdentityClient) }
7
+ let(:config_product_id) { 'a1b2c3d4-e5f6-7890-abcd-ef1234567890' }
7
8
 
8
9
  before do
9
- Machina.config.product_id = 'a1b2c3d4-e5f6-7890-abcd-ef1234567890'
10
+ Machina.config.product_id = config_product_id
10
11
  allow(Machina).to receive(:identity_client).and_return(client)
11
12
  allow(client).to receive(:sync_permissions)
12
13
  end
@@ -15,7 +16,7 @@ RSpec.describe Machina::PermissionSync do
15
16
  described_class.call!
16
17
 
17
18
  expect(client).to have_received(:sync_permissions).with(
18
- product_id: 'a1b2c3d4-e5f6-7890-abcd-ef1234567890',
19
+ product_id: config_product_id,
19
20
  permissions: [{ key: 'sessions.view', description: 'View sessions' }],
20
21
  policies: [{ name: 'Viewer', api_name: 'viewer', permissions: ['sessions.view'] }],
21
22
  )
@@ -31,8 +32,6 @@ RSpec.describe Machina::PermissionSync do
31
32
  let(:tmpfile) do
32
33
  file = Tempfile.new(['machina', '.yml'])
33
34
  file.write(<<~YAML)
34
- product_id: flat-product-id
35
-
36
35
  permissions:
37
36
  - key: items.view
38
37
  description: View items
@@ -54,7 +53,7 @@ RSpec.describe Machina::PermissionSync do
54
53
  described_class.call!
55
54
 
56
55
  expect(client).to have_received(:sync_permissions).with(
57
- product_id: 'flat-product-id',
56
+ product_id: config_product_id,
58
57
  permissions: [{ key: 'items.view', description: 'View items' }],
59
58
  policies: [{ name: 'Reader', api_name: 'reader', permissions: ['items.view'] }],
60
59
  )
@@ -66,14 +65,12 @@ RSpec.describe Machina::PermissionSync do
66
65
  file = Tempfile.new(['machina', '.yml'])
67
66
  file.write(<<~YAML)
68
67
  test:
69
- product_id: test-product-id
70
68
  permissions:
71
69
  - key: reports.view
72
70
  description: View reports
73
71
  policies: []
74
72
 
75
73
  production:
76
- product_id: prod-product-id
77
74
  permissions:
78
75
  - key: reports.view
79
76
  description: View reports
@@ -85,18 +82,14 @@ RSpec.describe Machina::PermissionSync do
85
82
  file
86
83
  end
87
84
 
88
- before do
89
- Machina.config.manifest = tmpfile.path
90
- Machina.config.product_id = nil
91
- end
92
-
85
+ before { Machina.config.manifest = tmpfile.path }
93
86
  after { tmpfile.unlink }
94
87
 
95
88
  it 'loads the manifest scoped to the current Rails environment' do
96
89
  described_class.call!
97
90
 
98
91
  expect(client).to have_received(:sync_permissions).with(
99
- product_id: 'test-product-id',
92
+ product_id: config_product_id,
100
93
  permissions: [{ key: 'reports.view', description: 'View reports' }],
101
94
  policies: [],
102
95
  )
@@ -107,8 +100,6 @@ RSpec.describe Machina::PermissionSync do
107
100
  let(:tmpfile) do
108
101
  file = Tempfile.new(['machina', '.yml'])
109
102
  file.write(<<~YAML)
110
- product_id: <%= "erb-product-id" %>
111
-
112
103
  permissions:
113
104
  - key: tasks.view
114
105
  description: View tasks
@@ -119,51 +110,20 @@ RSpec.describe Machina::PermissionSync do
119
110
  file
120
111
  end
121
112
 
122
- before do
123
- Machina.config.manifest = tmpfile.path
124
- Machina.config.product_id = nil
125
- end
126
-
113
+ before { Machina.config.manifest = tmpfile.path }
127
114
  after { tmpfile.unlink }
128
115
 
129
116
  it 'evaluates ERB before parsing YAML' do
130
117
  described_class.call!
131
118
 
132
119
  expect(client).to have_received(:sync_permissions).with(
133
- product_id: 'erb-product-id',
120
+ product_id: config_product_id,
134
121
  permissions: [{ key: 'tasks.view', description: 'View tasks' }],
135
122
  policies: [],
136
123
  )
137
124
  end
138
125
  end
139
126
 
140
- context 'when manifest product_id is absent but config product_id is set' do
141
- let(:tmpfile) do
142
- file = Tempfile.new(['machina', '.yml'])
143
- file.write(<<~YAML)
144
- permissions:
145
- - key: items.view
146
- description: View items
147
- policies: []
148
- YAML
149
- file.close
150
- file
151
- end
152
-
153
- before { Machina.config.manifest = tmpfile.path }
154
- after { tmpfile.unlink }
155
-
156
- it 'falls back to Machina.config.product_id' do
157
- described_class.call!
158
-
159
- expect(client).to have_received(:sync_permissions).with(
160
- product_id: 'a1b2c3d4-e5f6-7890-abcd-ef1234567890',
161
- permissions: [{ key: 'items.view', description: 'View items' }],
162
- policies: [],
163
- )
164
- end
165
- end
166
-
167
127
  context 'when policies key is omitted from manifest' do
168
128
  let(:tmpfile) do
169
129
  file = Tempfile.new(['machina', '.yml'])
@@ -183,7 +143,7 @@ RSpec.describe Machina::PermissionSync do
183
143
  described_class.call!
184
144
 
185
145
  expect(client).to have_received(:sync_permissions).with(
186
- product_id: 'a1b2c3d4-e5f6-7890-abcd-ef1234567890',
146
+ product_id: config_product_id,
187
147
  permissions: [{ key: 'items.view', description: 'View items' }],
188
148
  policies: [],
189
149
  )
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: machina-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - ZAR