Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed get_file method to receive a resource as parameter. #17406

Merged
merged 1 commit into from
May 17, 2018
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: 2 additions & 2 deletions lib/vmdb/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def save(resource = MiqServer.my_server)
end

# NOTE: Used by Configuration -> Advanced
def self.get_file
Vmdb::Settings.encrypt_passwords!(::Settings.to_hash).to_yaml
def self.get_file(resource = MiqServer.my_server)
Vmdb::Settings.encrypt_passwords!(resource.settings_for_resource.to_hash).to_yaml
end

# NOTE: Used by Configuration -> Advanced
Expand Down
48 changes: 43 additions & 5 deletions spec/lib/vmdb/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,50 @@
let(:password) { "pa$$w0rd" }
let(:enc_pass) { MiqPassword.encrypt(password) }

it ".get_file" do
stub_settings(:http_proxy => {:default => {:host => "proxy.example.com", :user => "user", :password => password, :port => 80}})
describe ".get_file" do
it "for current server" do
_guid, server, _zone = EvmSpecHelper.local_guid_miq_server_zone
Vmdb::Settings.save!(
server,
:http_proxy => {
:default => {
:host => "proxy.example.com",
:user => "user",
:password => password,
:port => 80
}
}
)
server.reload
yaml = VMDB::Config.get_file
yaml = YAML.load(yaml)
expect(yaml.fetch_path(:http_proxy, :default, :host)).to eq "proxy.example.com"
expect(yaml.fetch_path(:http_proxy, :default, :user)).to eq "user"
expect(yaml.fetch_path(:http_proxy, :default, :port)).to eq 80
expect(yaml.fetch_path(:http_proxy, :default, :password)).to be_encrypted
end

expect(VMDB::Config.get_file).to eq(
"---\n:http_proxy:\n :default:\n :host: proxy.example.com\n :user: user\n :password: #{enc_pass}\n :port: 80\n"
)
it "for specified resource" do
resource = FactoryGirl.create(:miq_server)
Vmdb::Settings.save!(
resource,
:http_proxy => {
:default => {
:host => "proxy.example.com",
:user => "user",
:password => password,
:port => 80
}
}
)
resource.reload
yaml = VMDB::Config.get_file(resource)
yaml = YAML.load(yaml)
expect(yaml.fetch_path(:http_proxy, :default, :host)).to eq "proxy.example.com"
expect(yaml.fetch_path(:http_proxy, :default, :user)).to eq "user"
expect(yaml.fetch_path(:http_proxy, :default, :port)).to eq 80
expect(yaml.fetch_path(:http_proxy, :default, :password)).to be_encrypted
end
end

context ".save_file" do
Expand Down