Skip to content

Commit

Permalink
Merge pull request #1014 from SUSE/scc-endpoints
Browse files Browse the repository at this point in the history
Scc endpoints
  • Loading branch information
digitaltom authored Jul 6, 2023
2 parents 4232f5c + 47ab6f4 commit 7229597
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 13 deletions.
13 changes: 12 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,19 @@

get '/api/health/status', to: 'api/health#status'

# :nocov:
mount StrictAuthentication::Engine, at: '/api/auth' if defined?(StrictAuthentication::Engine)
mount RegistrationSharing::Engine, at: '/api/regsharing' if defined?(RegistrationSharing::Engine)
mount InstanceVerification::Engine, at: '/api/instance' if defined?(InstanceVerification::Engine)
mount SccSumaApi::Engine, at: '/api/scc' if defined?(SccSumaApi::Engine)

if defined?(SccSumaApi::Engine)
mount SccSumaApi::Engine, at: '/api/scc'

get '/connect/organizations/products/unscoped', to: redirect(path: '/api/scc/unscoped-products')
get '/connect/organizations/repositories', to: redirect(path: '/api/scc/repos')
get '/connect/organizations/subscriptions', to: redirect(path: '/api/scc/subs')
get '/connect/organizations/orders', to: redirect(path: '/api/scc/orders')
get '/suma/product_tree.json', to: redirect(path: '/api/scc/product-tree')
end
# :nocov:
end
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ def unscoped_products
update_cache unless cache_is_valid?

unscoped_products_json = File.read(@unscoped_products_path)
render status: :ok, json: { result: JSON.parse(unscoped_products_json) }
render status: :ok, json: JSON.parse(unscoped_products_json)
end

def list
render status: :ok, json: { result: [] }
render status: :ok, json: []
end

def product_tree
render status: :ok, json: { result: product_tree_json }
render status: :ok, json: product_tree_json
end

protected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,27 @@ module SccSumaApi
file_fixture('products/dummy_products.json'),
Rails.root.join('tmp/unscoped_products.json')
)

get '/api/scc/unscoped-products', params: payload
end

after { File.delete(unscoped_file) if File.exist?(unscoped_file) }

its(:code) { is_expected.to eq '200' }
its(:body) { is_expected.to eq "{\"result\":#{products.to_json}}" }
context 'redirect from SCC endpoint' do
before do
get '/connect/organizations/products/unscoped', params: payload
end

its(:code) { is_expected.to eq '301' }
its(:body) { is_expected.to include 'http://www.example.com/api/scc/unscoped-products' }
end

context 'endpoints return unscoped products' do
before do
get '/api/scc/unscoped-products', params: payload
end

its(:code) { is_expected.to eq '200' }
its(:body) { is_expected.to eq products.to_json.to_s }
end
end

context 'cache is not valid' do
Expand All @@ -62,15 +75,22 @@ module SccSumaApi
end

its(:code) { is_expected.to eq '200' }
its(:body) { is_expected.to eq "{\"result\":#{products.to_json}}" }
its(:body) { is_expected.to eq products.to_json.to_s }
end
end

context 'get repos redirect' do
before { get '/connect/organizations/repositories' }

its(:code) { is_expected.to eq '301' }
its(:body) { is_expected.to include 'http://www.example.com/api/scc/repos' }
end

context 'get repos' do
before { get '/api/scc/repos' }

its(:code) { is_expected.to eq '200' }
its(:body) { is_expected.to eq '{"result":[]}' }
its(:body) { is_expected.to eq '[]' }
end

context 'get product tree' do
Expand All @@ -82,13 +102,28 @@ module SccSumaApi
allow_any_instance_of(File).to receive(:read).and_return products.to_json
FileUtils.cp(file_fixture('products/dummy_products.json'), product_tree_file)

get '/api/scc/product-tree'
get '/suma/product_tree.json'
end

after { File.delete(product_tree_file) if File.exist?(product_tree_file) }

its(:code) { is_expected.to eq '200' }
its(:body) { is_expected.to eq "{\"result\":#{products.to_json}}" }
context 'SCC endpoint redirect' do
before do
get '/suma/product_tree.json'
end

its(:code) { is_expected.to eq '301' }
its(:body) { is_expected.to include 'http://www.example.com/api/scc/product-tree' }
end

context 'endpoint returns product tree json output' do
before do
get '/api/scc/product-tree'
end

its(:code) { is_expected.to eq '200' }
its(:body) { is_expected.to eq products.to_json.to_s }
end
end
end
end
Expand Down

0 comments on commit 7229597

Please sign in to comment.