Skip to content

Commit

Permalink
Merge pull request #19202 from lpichler/set_tenant_from_group_for_key…
Browse files Browse the repository at this point in the history
…pairs

Set tenant from group in Authentification(KeyPairs) model

(cherry picked from commit f30f408)

https://bugzilla.redhat.com/show_bug.cgi?id=1730066
  • Loading branch information
gtanzillo authored and simaishi committed Aug 27, 2019
1 parent c4ebda3 commit e618ece
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/models/authentication.rb
Expand Up @@ -36,6 +36,8 @@ def self.new(*args, &block)
before_save :set_credentials_changed_on
after_save :after_authentication_changed

before_validation :set_tenant_from_group

serialize :options

include OwnershipMixin
Expand Down Expand Up @@ -152,6 +154,10 @@ def native_ref

private

def set_tenant_from_group
self.tenant_id = miq_group.tenant_id if miq_group
end

def set_credentials_changed_on
return unless @auth_changed
self.credentials_changed_on = Time.now.utc
Expand Down
13 changes: 13 additions & 0 deletions spec/models/authentication_spec.rb
@@ -1,4 +1,17 @@
describe Authentication do
describe ".set_ownership" do
let!(:authentication) { FactoryBot.create(:authentication) }
let(:tenant) { FactoryBot.create(:tenant) }
let!(:group) { FactoryBot.create(:miq_group, :tenant => tenant) }

it "sets tenant from group" do
expect(authentication.tenant).to be_nil
authentication.class.set_ownership([authentication.id], :group => group)

expect(authentication.reload.tenant.id).to eq(tenant.id)
end
end

describe ".encrypted_columns" do
it "returns the encrypted columns" do
expected = %w(password password_encrypted auth_key auth_key_encrypted service_account service_account_encrypted auth_key_password auth_key_password_encrypted become_password become_password_encrypted)
Expand Down

0 comments on commit e618ece

Please sign in to comment.