Skip to content

Commit

Permalink
Fixes #35533 - remove duplicate ssl params of cpdb cmd (theforeman#643)
Browse files Browse the repository at this point in the history
  • Loading branch information
upadhyeammit committed Sep 19, 2022
1 parent 5f9bf72 commit fef74a8
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 10 deletions.
11 changes: 1 addition & 10 deletions definitions/features/candlepin_database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,14 @@ 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']
end
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
Expand Down
44 changes: 44 additions & 0 deletions test/definitions/features/candlepin_database_test.rb
Original file line number Diff line number Diff line change
@@ -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
45 changes: 45 additions & 0 deletions test/support/candlepin_with_ssl.conf
Original file line number Diff line number Diff line change
@@ -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
44 changes: 44 additions & 0 deletions test/support/candlepin_without_ssl.conf
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit fef74a8

Please sign in to comment.