Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/models/system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ def update_system_uptime(day: nil, hours: nil)
end
end

def update_instance_data(instance_data)
update!(instance_data: instance_data)
end

before_update do |system|
# reset SCC sync timestamp so that the system can be re-synced on change
system.scc_synced_at = nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ def self.verify_instance(request, logger, system)
is_valid = verification_provider.instance_valid?
# update repository and registry cache
InstanceVerification.set_cache_active(cache_key, system.proxy_byos_mode)
# update the instance data when valid and not in the cache
# before RMT 2.22, there was no need as the instance data was fresh from the client
# after 2.22 we are using instance data from the DB and we need to refresh that data
system.update_instance_data(decoded_instance_data)
is_valid
rescue InstanceVerification::Exception => e
if system.byos?
Expand All @@ -127,10 +131,10 @@ def self.verify_instance(request, logger, system)
if result[:is_active]
# update the cache for the base product
InstanceVerification.set_cache_active(cache_key, 'byos')
system.update_instance_data(decoded_instance_data)
return true
end
# if can not get the activations, set the cache inactive
# "AAA YmFy-foo-product-129_15.3_x86_64""
InstanceVerification.set_cache_inactive(cache_key, system.proxy_byos_mode)
end
ZypperAuth.zypper_auth_message(request, system, verification_provider, e.message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@
"#{Base64.strict_encode64(payload_token[:token])}-foo-#{product.product_class}"
end
let(:active_cache_entry) { cache_entry + '-active' }
let(:headers) { auth_header.merge('X-Instance-Data' => 'dummy_instance_data') }
let(:headers) { auth_header.merge('X-Instance-Data' => Base64.strict_encode64('dummy_instance_data')) }

before do
allow(InstanceVerification::Providers::Example).to receive(:new).and_return(plugin_double)
Expand All @@ -429,7 +429,7 @@

# expect(InstanceVerification).to receive(:update_cache).with(cache_entry, 'hybrid')
expect(InstanceVerification).to receive(:update_cache).with(active_cache_entry, 'hybrid', registry: false)
headers['X-Instance-Data'] = instance_data
headers['X-Instance-Data'] = Base64.strict_encode64(instance_data)
post url, params: payload_token, headers: headers
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
let(:plugin_double) { instance_double('InstanceVerification::Providers::Example') }

before do
headers['X-Instance-Data'] = 'IMDS'
headers['X-Instance-Data'] = Base64.strict_encode64('IMDS')
Thread.current[:logger] = RMT::Logger.new('/dev/null')
end

Expand Down Expand Up @@ -68,7 +68,7 @@
allow(File).to receive(:join).and_call_original
allow(InstanceVerification).to receive(:update_cache)
allow(InstanceVerification).to receive(:verify_instance).and_call_original
headers['X-Instance-Data'] = 'IMDS'
headers['X-Instance-Data'] = Base64.strict_encode64('IMDS')
end

it 'refreshes registry cache key only' do
Expand Down Expand Up @@ -128,7 +128,7 @@
allow(InstanceVerification).to receive(:update_cache)
allow(InstanceVerification).to receive(:verify_instance).and_call_original
stub_request(:get, scc_systems_activations_url).to_return(status: 200, body: [body_active].to_json, headers: {})
headers['X-Instance-Data'] = 'IMDS'
headers['X-Instance-Data'] = Base64.strict_encode64('IMDS')
end

context 'no registry' do
Expand Down Expand Up @@ -276,7 +276,7 @@

before do
allow(InstanceVerification).to receive(:update_cache)
headers['X-Instance-Data'] = 'IMDS'
headers['X-Instance-Data'] = Base64.strict_encode64('IMDS')
Thread.current[:logger] = RMT::Logger.new('/dev/null')
end

Expand Down Expand Up @@ -317,7 +317,7 @@

before do
allow(InstanceVerification).to receive(:update_cache)
headers['X-Instance-Data'] = 'IMDS'
headers['X-Instance-Data'] = Base64.strict_encode64('IMDS')
Thread.current[:logger] = RMT::Logger.new('/dev/null')
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
]
}
end
let(:headers) { auth_header.merge('X-Instance-Data' => 'dummy_instance_data') }
let(:headers) { auth_header.merge('X-Instance-Data' => Base64.strict_encode64('dummy_instance_data')) }

before do
allow(plugin_double).to(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

context 'when service is not registered' do
before do
headers['X-Instance-Data'] = 'IMDS'
headers['X-Instance-Data'] = Base64.strict_encode64('IMDS')
get "/services/#{service.id}", headers: headers
end

Expand All @@ -54,7 +54,7 @@

context 'when service is registered' do
before do
headers['X-Instance-Data'] = 'IMDS'
headers['X-Instance-Data'] = Base64.strict_encode64('IMDS')
allow_any_instance_of(InstanceVerification::Providers::Example).to(
receive(:instance_valid?).and_return(true)
)
Expand All @@ -74,7 +74,7 @@
include_context 'auth header', :system, :login, :password

before do
headers['X-Instance-Data'] = 'IMDS'
headers['X-Instance-Data'] = Base64.strict_encode64('IMDS')
allow_any_instance_of(InstanceVerification::Providers::Example).to(
receive(:instance_valid?).and_return(true)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module StrictAuthentication
context 'valid instance' do
before do
allow(InstanceVerification).to receive(:verify_instance).and_return(true)
get '/api/auth/check', headers: auth_header.merge({ 'X-Original-URI': requested_uri, 'X-Instance-Data': 'IMDS' })
get '/api/auth/check', headers: auth_header.merge({ 'X-Original-URI': requested_uri, 'X-Instance-Data': Base64.strict_encode64('IMDS') })
allow(File).to receive(:directory?)
allow(Dir).to receive(:mkdir)
allow(FileUtils).to receive(:touch)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
end

context 'with X-Instance-Data headers' do
let(:headers) { auth_header.merge(version_header).merge({ 'X-Instance-Data' => 'instance_data' }) }
let(:headers) { auth_header.merge(version_header).merge({ 'X-Instance-Data' => Base64.strict_encode64('instance_data') }) }

it 'has service URLs with HTTP scheme' do
data = JSON.parse(response.body)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
end

context 'with instance_data headers and instance data is invalid' do
let(:headers) { auth_header.merge({ 'X-Original-URI': requested_uri, 'X-Instance-Data': 'test' }) }
let(:headers) { auth_header.merge({ 'X-Original-URI': requested_uri, 'X-Instance-Data': Base64.strict_encode64('test') }) }

before do
allow(InstanceVerification).to receive(:reg_code_in_cache?).and_return(nil)
Expand All @@ -96,8 +96,8 @@
end
let(:requested_uri_byos) { '/repo' + local_path + '/repodata/repomd.xml' }
let(:paid_requested_uri_byos) { '/repo' + paid_local_path + '/repodata/repomd.xml' }
let(:headers) { auth_header.merge({ 'X-Original-URI': requested_uri_byos, 'X-Instance-Data': 'test' }) }
let(:paid_headers) { auth_header.merge({ 'X-Original-URI': paid_requested_uri_byos, 'X-Instance-Data': 'test' }) }
let(:headers) { auth_header.merge({ 'X-Original-URI': requested_uri_byos, 'X-Instance-Data': Base64.strict_encode64('test') }) }
let(:paid_headers) { auth_header.merge({ 'X-Original-URI': paid_requested_uri_byos, 'X-Instance-Data': Base64.strict_encode64('test') }) }
let(:body_active) do
{
id: 1,
Expand Down Expand Up @@ -322,7 +322,7 @@
end

context 'with instance_data headers and instance data is valid' do
let(:headers) { auth_header.merge({ 'X-Original-URI': requested_uri, 'X-Instance-Data': 'test' }) }
let(:headers) { auth_header.merge({ 'X-Original-URI': requested_uri, 'X-Instance-Data': Base64.strict_encode64('test') }) }
let(:data_export_double) { instance_double('DataExport::Handlers::Example') }

before do
Expand All @@ -346,7 +346,7 @@
let(:scc_systems_activations_url) { 'https://scc.suse.com/connect/systems/activations' }
let(:system_hybrid) { FactoryBot.create(:system, :hybrid, :with_activated_paid_extension, pubcloud_reg_code: 'INTERNAL-USE-FOO') }
let(:requested_uri) { '/repo' + system_hybrid.repositories.first[:local_path] + '/repodata/repomd.xml' }
let(:headers) { auth_header.merge({ 'X-Original-URI': requested_uri, 'X-Instance-Data': 'test' }) }
let(:headers) { auth_header.merge({ 'X-Original-URI': requested_uri, 'X-Instance-Data': Base64.strict_encode64('test') }) }
let(:ltss_prod) do
activation = system_hybrid.activations.find { |act| act.product.product_class.include?('LTSS') }
activation.product
Expand Down
1 change: 1 addition & 0 deletions spec/factories/systems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
end

trait :hybrid do
pubcloud_reg_code { 'regitration_code' }
proxy_byos_mode { :hybrid }
end

Expand Down
5 changes: 5 additions & 0 deletions spec/models/system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@
system.reload
expect(system.scc_synced_at).to be(nil)
end

it 'update the instance data' do
system.update_instance_data('foo')
expect(system.instance_data).to eq('foo')
end
end

it 'assigns nil system_token on create' do
Expand Down