From c33651b60f709fe9c1708bb93d0dd64ca6878c55 Mon Sep 17 00:00:00 2001 From: David Roetzel Date: Tue, 18 Oct 2022 10:32:39 +0200 Subject: [PATCH] Cleanup and some tests #4 --- app/models/key_file.rb | 20 ------------------- .../required_authentication_test.rb | 5 +++++ test/models/hiera_data_test.rb | 20 +++++++++++++++++++ 3 files changed, 25 insertions(+), 20 deletions(-) delete mode 100644 app/models/key_file.rb diff --git a/app/models/key_file.rb b/app/models/key_file.rb deleted file mode 100644 index d738af2a..00000000 --- a/app/models/key_file.rb +++ /dev/null @@ -1,20 +0,0 @@ -class KeyFile - include ActiveModel::Model - include ActiveModel::Attributes - - attribute :environment - attribute :hierarchy_name, :string - attribute :path, :string - attribute :value, :string - - def self.all(environment, key) - HieraData.new(environment.name).files_including(key).map do |file| - new( - environment: environment, - path: file[:path], - hierarchy_name: file[:hierarchy_name], - value: file[:value] - ) - end - end -end diff --git a/test/integration/required_authentication_test.rb b/test/integration/required_authentication_test.rb index 68da5fbc..81958301 100644 --- a/test/integration/required_authentication_test.rb +++ b/test/integration/required_authentication_test.rb @@ -17,6 +17,11 @@ class AuthenticationEnabledTest < ActionDispatch::IntegrationTest environment_node_key_path("development", "testhost", "hdm::integer") end + test "authentication requirements for files" do + authentication_required_for :get, + environment_key_files_path("multiple_hierarchies", "foobar::timezone") + end + test "authentication requirements for values" do authentication_required_for :patch, environment_node_key_hierarchy_data_file_value_path("development", "testhost", "hdm::integer", "Eyaml hierarchy", "common.yaml") diff --git a/test/models/hiera_data_test.rb b/test/models/hiera_data_test.rb index 3645d800..9373e372 100644 --- a/test/models/hiera_data_test.rb +++ b/test/models/hiera_data_test.rb @@ -99,4 +99,24 @@ class HieraDataTest < ActiveSupport::TestCase assert_equal expected_hash, hiera.lookup_options(node.facts) end + + test "#files_including returns file information for a given key" do + hiera = HieraData.new("multiple_hierarchies") + expected_result = [ + { + path: "nodes/test.host.yaml", + hierarchy_name: "Host specific", + hierarchy_backend: :yaml, + value: "CET" + }, + { + path: "common.yaml", + hierarchy_name: "Global data", + hierarchy_backend: :yaml, + value: "UTC" + } + ] + + assert_equal expected_result, hiera.files_including("foobar::timezone") + end end