Skip to content

Commit

Permalink
Add and update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jlledom committed Apr 25, 2024
1 parent 9d3ced1 commit bd3df29
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 1 deletion.
32 changes: 32 additions & 0 deletions test/fixtures/ca_cert.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
-----BEGIN CERTIFICATE-----
MIIFlzCCA3+gAwIBAgIUNoP0p+Pbe6euu8fgEZ/pjYhxZn4wDQYJKoZIhvcNAQEL
BQAwWzELMAkGA1UEBhMCWFgxFTATBgNVBAcMDERlZmF1bHQgQ2l0eTEPMA0GA1UE
CgwGM3NjYWxlMRQwEgYDVQQLDAtQb3J0YSB0ZXN0czEOMAwGA1UEAwwFcG9ydGEw
HhcNMjMxMTE3MTE1NTA3WhcNMzMxMTE0MTE1NTA3WjBbMQswCQYDVQQGEwJYWDEV
MBMGA1UEBwwMRGVmYXVsdCBDaXR5MQ8wDQYDVQQKDAYzc2NhbGUxFDASBgNVBAsM
C1BvcnRhIHRlc3RzMQ4wDAYDVQQDDAVwb3J0YTCCAiIwDQYJKoZIhvcNAQEBBQAD
ggIPADCCAgoCggIBAJQji9/fteAd+VHeSH6ToloKL0d8w51ecnYpQ44htbbeZZZz
BeEy0QmsU+bVV9DOyIO26bu6LgNLD1Nfo53e8WeLsWymzgZwh+JJ3V6JOeYEfk9L
LXDFPc6vUCgF/wg2VTbHxQAYakaCjFXZc0M6WBV+c7558d0OLAidfOIY24LeuICh
frAGm2rJjX1wYamgne6J3MAE0LgRVaIs5Y59huUobxEEDLf+Tp/LwLTZpUUCpIW5
fHDCtmzpTunbr6LniWVWjKkUEZaMJuIPagkqkftb1SCaOHZi7vGr/lnsVmNFVeXv
RxQ3WUaR9+ZSZWw4xco4C364UCvxl20oeUphhBoDUhxfr2gGEB3MWPB8Z3MXPAST
SDzXYeUlR6oSWKP2Ugn53Pmk8mfhoa32haCM+aMWWk7uf885sk/nKs2Mx+Kk1EbB
v4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nlbB2qy/Aj2rK18/l1Xfw==
-----END CERTIFICATE-----
2 changes: 1 addition & 1 deletion test/unit/backend/storage_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class Backend::StorageTest < ActiveSupport::TestCase

def given_redis_config(yaml)
FakeFS do
FakeFS.with_fresh do
config = Rails.root.join('config', 'backend_redis.yml')
FakeFS::FileSystem.clone(config.dirname, '/tmp/config')
config.open('w') { |f| f.puts(yaml) }
Expand Down
File renamed without changes.
46 changes: 46 additions & 0 deletions test/unit/three_scale/redis_config_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,51 @@ class RedisConfigTest < ActiveSupport::TestCase
assert config.key? :size
assert_equal 5, config[:size]
end

%i[ca_file ca_path].each do |param|
test "it takes given #{param} when provided" do
value = 'any_value'
raw_config = { url: 'rediss://my-secure-redis/1', ssl_params: {}}
raw_config[:ssl_params][param] = value

result = RedisConfig.new(raw_config)

assert result.key? :ssl_params
assert result[:ssl_params].key? param
assert_equal value, result[:ssl_params][param]
end
end

test 'it trusts on CAs in config/ca_cert.pem if no ca_file or ca_path are provided' do
FakeFS.with_fresh do
FakeFS::FileSystem.clone(file_fixture_path)
FakeFS::FileSystem.clone(Rails.root.join('config'))
FileUtils.cp file_fixture('ca_cert.pem'), Rails.root.join('config')

result = RedisConfig.new(url: 'rediss://my-secure-redis/1')

assert result.key? :ssl_params
assert result[:ssl_params].key? :ca_file
assert_equal Rails.root.join('config/ca_cert.pem').to_s, result[:ssl_params][:ca_file]
end
end

test 'it trusts on CAs in config/ca_cert.pem if ca_file or ca_path are provided empty' do
FakeFS.with_fresh do
FakeFS::FileSystem.clone(file_fixture_path)
FakeFS::FileSystem.clone(Rails.root.join('config'))
FileUtils.cp file_fixture('ca_cert.pem'), Rails.root.join('config')

result = RedisConfig.new(url: 'rediss://my-secure-redis/1', ssl_params: { ca_file: nil, ca_path: ''})

assert_equal Rails.root.join('config/ca_cert.pem').to_s, result[:ssl_params][:ca_file]
end
end

test "it doesn't trust any CA if no ca_file or ca_path are provided and config/ca_cert.pem doesn't exist" do
result = RedisConfig.new(url: 'rediss://my-secure-redis/1')

assert_not result.key? :ssl_params
end
end
end

0 comments on commit bd3df29

Please sign in to comment.