diff --git a/definitions/features/candlepin_database.rb b/definitions/features/candlepin_database.rb index 2841e284f..0780ac128 100644 --- a/definitions/features/candlepin_database.rb +++ b/definitions/features/candlepin_database.rb @@ -75,7 +75,7 @@ def load_configuration # rubocop:enable Metrics/MethodLength def extend_with_db_options - db_options = { '-d' => construct_database_string } + db_options = { '-d' => configuration['database'] } if check_option_using_cpdb_help('dbhost') db_options['--dbhost'] = configuration['host'] db_options['--dbport'] = configuration['port'] @@ -83,15 +83,6 @@ def extend_with_db_options db_options end - def construct_database_string - db_str = configuration['database'] - extra_opts = [] - extra_opts << "ssl=#{configuration['ssl']}" if configuration['ssl'] - extra_opts << "sslfactory=#{configuration['sslfactory']}" if configuration['sslfactory'] - db_str += "?#{extra_opts.join('&')}" unless extra_opts.empty? - db_str - end - def fetch_extra_param(url, key_name) query_string = url.split('?')[1] return nil unless query_string diff --git a/test/definitions/features/candlepin_database_test.rb b/test/definitions/features/candlepin_database_test.rb new file mode 100644 index 000000000..0812bc088 --- /dev/null +++ b/test/definitions/features/candlepin_database_test.rb @@ -0,0 +1,44 @@ +require 'test_helper' +require 'minitest/stub_const' + +describe Features::CandlepinDatabase do + include DefinitionsTestHelper + subject { Features::CandlepinDatabase.new } + let(:subject_ins) { Features::CandlepinDatabase.any_instance } + + let(:cp_config_dir) do + File.expand_path('../../../support/', __FILE__) + end + + def stub_with_ssl_config + Features::CandlepinDatabase.stub_const(:CANDLEPIN_DB_CONFIG, + cp_config_dir + '/candlepin_with_ssl.conf') do + yield + end + end + + def stub_without_ssl_config + Features::CandlepinDatabase.stub_const(:CANDLEPIN_DB_CONFIG, + cp_config_dir + '/candlepin_without_ssl.conf') do + yield + end + end + + describe '.configuration' do + it 'The url includes ssl attributes when ssl is enabled' do + stub_with_ssl_config do + url = subject.configuration['url'] + assert_includes url, 'ssl=true' + assert_includes url, 'sslrootcert=/usr/share/foreman/root.crt' + end + end + + it 'The url does not include ssl attributes when ssl is disabled' do + stub_without_ssl_config do + url = subject.configuration['url'] + refute_includes url, 'ssl=true' + refute_includes url, 'sslrootcert=/usr/share/foreman/root.crt' + end + end + end +end diff --git a/test/support/candlepin_with_ssl.conf b/test/support/candlepin_with_ssl.conf new file mode 100644 index 000000000..7032c866a --- /dev/null +++ b/test/support/candlepin_with_ssl.conf @@ -0,0 +1,45 @@ +### File managed with puppet ### +## Module: 'candlepin' + +candlepin.consumer_system_name_pattern=.+ +candlepin.environment_content_filtering=true +candlepin.auth.basic.enable=false +candlepin.auth.trusted.enable=false + +candlepin.audit.hornetq.config_path=/etc/candlepin/broker.xml + +candlepin.auth.oauth.enable=true +candlepin.auth.oauth.consumer.katello.secret=abcdabcd + +module.config.adapter_module=org.candlepin.katello.KatelloModule + +candlepin.ca_key=/etc/candlepin/certs/candlepin-ca.key +candlepin.ca_cert=/etc/candlepin/certs/candlepin-ca.crt +candlepin.crl.file=/var/lib/candlepin/candlepin-crl.crl + +candlepin.async.jobs.ExpiredPoolsCleanupJob.schedule=0 0 0 * * ? + +# Required for https://hibernate.atlassian.net/browse/HHH-12927 +log4j.logger.org.hibernate.internal.SessionImpl=ERROR + +# uncomment to enable debug logging in candlepin.log: +#log4j.logger.org.candlepin=DEBUG +jpa.config.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect +jpa.config.hibernate.connection.driver_class=org.postgresql.Driver +jpa.config.hibernate.connection.url=jdbc:postgresql://host.example.com:5432/candlepin1db?ssl=true&sslrootcert=/usr/share/foreman/root.crt +jpa.config.hibernate.hbm2ddl.auto=validate +jpa.config.hibernate.connection.username=candlepin +jpa.config.hibernate.connection.password=password + +org.quartz.jobStore.misfireThreshold=60000 +org.quartz.jobStore.useProperties=false +org.quartz.jobStore.dataSource=myDS +org.quartz.jobStore.tablePrefix=QRTZ_ +org.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreTX +org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.PostgreSQLDelegate + +org.quartz.dataSource.myDS.driver=org.postgresql.Driver +org.quartz.dataSource.myDS.URL=jdbc:postgresql://host.example.com:5432/candlepin1db?ssl=true&sslrootcert=/usr/share/foreman/root.crt +org.quartz.dataSource.myDS.user=candlepin +org.quartz.dataSource.myDS.password=password +org.quartz.dataSource.myDS.maxConnections=5 \ No newline at end of file diff --git a/test/support/candlepin_without_ssl.conf b/test/support/candlepin_without_ssl.conf new file mode 100644 index 000000000..d2f3a5858 --- /dev/null +++ b/test/support/candlepin_without_ssl.conf @@ -0,0 +1,44 @@ +### File managed with puppet ### +## Module: 'candlepin' + +candlepin.consumer_system_name_pattern=.+ +candlepin.environment_content_filtering=true +candlepin.auth.basic.enable=false +candlepin.auth.trusted.enable=false + +candlepin.audit.hornetq.config_path=/etc/candlepin/broker.xml + +candlepin.auth.oauth.enable=true +candlepin.auth.oauth.consumer.katello.secret=abcdabcd + +module.config.adapter_module=org.candlepin.katello.KatelloModule + +candlepin.ca_key=/etc/candlepin/certs/candlepin-ca.key +candlepin.ca_cert=/etc/candlepin/certs/candlepin-ca.crt + +candlepin.async.jobs.ExpiredPoolsCleanupJob.schedule=0 0 0 * * ? + +# Required for https://hibernate.atlassian.net/browse/HHH-12927 +log4j.logger.org.hibernate.internal.SessionImpl=ERROR + +# uncomment to enable debug logging in candlepin.log: +#log4j.logger.org.candlepin=DEBUG +jpa.config.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect +jpa.config.hibernate.connection.driver_class=org.postgresql.Driver +jpa.config.hibernate.connection.url=jdbc:postgresql://localhost:5432/candlepin +jpa.config.hibernate.hbm2ddl.auto=validate +jpa.config.hibernate.connection.username=candlepin +jpa.config.hibernate.connection.password=password + +org.quartz.jobStore.misfireThreshold=60000 +org.quartz.jobStore.useProperties=false +org.quartz.jobStore.dataSource=myDS +org.quartz.jobStore.tablePrefix=QRTZ_ +org.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreTX +org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.PostgreSQLDelegate + +org.quartz.dataSource.myDS.driver=org.postgresql.Driver +org.quartz.dataSource.myDS.URL=jdbc:postgresql://localhost:5432/candlepin +org.quartz.dataSource.myDS.user=candlepin +org.quartz.dataSource.myDS.password=password +org.quartz.dataSource.myDS.maxConnections=5