|
76 | 76 | end.and_call_original |
77 | 77 | subject.register |
78 | 78 | end |
| 79 | + end |
| 80 | + |
| 81 | + context "when using ssl with pem-encoded client certificates" do |
| 82 | + let(:tls_certificate) { Stud::Temporary.file.path } |
| 83 | + let(:tls_private_key) { Stud::Temporary.file.path } |
| 84 | + before do |
| 85 | + `openssl req -x509 -batch -nodes -newkey rsa:2048 -keyout #{tls_private_key} -out #{tls_certificate}` |
| 86 | + end |
| 87 | + |
| 88 | + after :each do |
| 89 | + File.delete(tls_certificate) |
| 90 | + File.delete(tls_private_key) |
| 91 | + subject.close |
| 92 | + end |
| 93 | + |
| 94 | + subject do |
| 95 | + settings = { |
| 96 | + "hosts" => "node01", |
| 97 | + "ssl" => true, |
| 98 | + "tls_certificate" => tls_certificate, |
| 99 | + "tls_private_key" => tls_private_key |
| 100 | + } |
| 101 | + next LogStash::Outputs::ElasticSearch.new(settings) |
| 102 | + end |
| 103 | + |
| 104 | + it "should pass the pem certificate parameters to the ES client" do |
| 105 | + expect(::Manticore::Client) |
| 106 | + .to receive(:new) { |args| expect(args[:ssl]).to include(:client_cert => tls_certificate, :client_key => tls_private_key) } |
| 107 | + .and_return(manticore_double) |
| 108 | + subject.register |
| 109 | + end |
79 | 110 |
|
80 | 111 | end |
| 112 | + |
| 113 | + context "when using both pem-encoded and jks-encoded client certificates" do |
| 114 | + let(:tls_certificate) { Stud::Temporary.file.path } |
| 115 | + let(:tls_private_key) { Stud::Temporary.file.path } |
| 116 | + before do |
| 117 | + `openssl req -x509 -batch -nodes -newkey rsa:2048 -keyout #{tls_private_key} -out #{tls_certificate}` |
| 118 | + end |
| 119 | + |
| 120 | + after :each do |
| 121 | + File.delete(tls_private_key) |
| 122 | + File.delete(tls_certificate) |
| 123 | + subject.close |
| 124 | + end |
| 125 | + |
| 126 | + subject do |
| 127 | + settings = { |
| 128 | + "hosts" => "node01", |
| 129 | + "ssl" => true, |
| 130 | + "tls_certificate" => tls_certificate, |
| 131 | + "tls_private_key" => tls_private_key, |
| 132 | + # just any file will do for this test |
| 133 | + "keystore" => tls_certificate |
| 134 | + } |
| 135 | + next LogStash::Outputs::ElasticSearch.new(settings) |
| 136 | + end |
| 137 | + |
| 138 | + it "should fail to load the plugin" do |
| 139 | + expect { subject.register }.to raise_error(LogStash::ConfigurationError) |
| 140 | + end |
| 141 | + end |
| 142 | + |
| 143 | + context "when configuring only tls_certificate but ommitting the private_key" do |
| 144 | + let(:tls_certificate) { Stud::Temporary.file.path } |
| 145 | + let(:tls_private_key) { Stud::Temporary.file.path } |
| 146 | + before do |
| 147 | + `openssl req -x509 -batch -nodes -newkey rsa:2048 -keyout #{tls_private_key} -out #{tls_certificate}` |
| 148 | + end |
| 149 | + |
| 150 | + after :each do |
| 151 | + File.delete(tls_private_key) |
| 152 | + File.delete(tls_certificate) |
| 153 | + subject.close |
| 154 | + end |
| 155 | + |
| 156 | + subject do |
| 157 | + settings = { |
| 158 | + "hosts" => "node01", |
| 159 | + "ssl" => true, |
| 160 | + "tls_certificate" => tls_certificate, |
| 161 | + } |
| 162 | + next LogStash::Outputs::ElasticSearch.new(settings) |
| 163 | + end |
| 164 | + |
| 165 | + it "should fail to load the plugin" do |
| 166 | + expect { subject.register }.to raise_error(LogStash::ConfigurationError) |
| 167 | + end |
| 168 | + end |
| 169 | + |
| 170 | + context "when configuring only private_key but ommitting the tls_certificate" do |
| 171 | + let(:tls_certificate) { Stud::Temporary.file.path } |
| 172 | + let(:tls_private_key) { Stud::Temporary.file.path } |
| 173 | + before do |
| 174 | + `openssl req -x509 -batch -nodes -newkey rsa:2048 -keyout #{tls_private_key} -out #{tls_certificate}` |
| 175 | + end |
| 176 | + |
| 177 | + after :each do |
| 178 | + File.delete(tls_private_key) |
| 179 | + File.delete(tls_certificate) |
| 180 | + subject.close |
| 181 | + end |
| 182 | + |
| 183 | + subject do |
| 184 | + settings = { |
| 185 | + "hosts" => "node01", |
| 186 | + "ssl" => true, |
| 187 | + "tls_private_key" => tls_private_key, |
| 188 | + } |
| 189 | + next LogStash::Outputs::ElasticSearch.new(settings) |
| 190 | + end |
| 191 | + |
| 192 | + it "should fail to load the plugin" do |
| 193 | + expect { subject.register }.to raise_error(LogStash::ConfigurationError) |
| 194 | + end |
| 195 | + end |
81 | 196 | end |
0 commit comments