Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Added a check that the agent permission subject keeps its short name

Damian Legawiec3205f0661326
diff --git a/spree/api/spec/controllers/spree/api/v3/admin/me_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/me_controller_spec.rb
index 9d65e4f7c3..dbcffec76d 100644
--- a/spree/api/spec/controllers/spree/api/v3/admin/me_controller_spec.rb
+++ b/spree/api/spec/controllers/spree/api/v3/admin/me_controller_spec.rb
@@ -94,6 +94,30 @@ RSpec.describe Spree::Api::V3::Admin::MeController, type: :controller do
end
end
+ # The dashboard checks this permission by a constant, so the name the
+ # endpoint serializes and the name the SPA compares against have to be the
+ # same string.
+ context 'as a staffer who may manage connected agents' do
+ let(:staffer) do
+ create(:admin_user, :without_admin_role).tap do |user|
+ create(:role_user, user: user,
+ role: create(:role, name: 'integrator',
+ permissions: %w[write_oauth_applications], resource: store))
+ end
+ end
+ let(:headers) do
+ { 'Authorization' => "Bearer #{Spree::Api::V3::TestingSupport.generate_jwt(staffer, audience: Spree::Api::V3::JwtAuthentication::JWT_AUDIENCE_ADMIN)}" }
+ end
+
+ it 'names the OAuth application subject the way the dashboard expects' do
+ subject
+ subjects = json_response['permissions'].flat_map { |rule| rule['subjects'] }
+
+ expect(subjects).to include('oauth_application')
+ expect(subjects.grep(/::/)).to be_empty
+ end
+ end
+
context 'as a staffer with different roles on different stores' do
let(:store_b) { create(:store) }
let(:staffer) do