3
3
require 'puppet_spec/compiler'
4
4
require 'puppet_spec/https'
5
5
6
- describe "apply" do
6
+ describe "apply" , unless : Puppet :: Util :: Platform . jruby? do
7
7
include PuppetSpec ::Files
8
8
9
9
before :each do
@@ -258,7 +258,7 @@ class mod {
258
258
expect ( @logs . map ( &:to_s ) ) . to include ( /{environment =>.*/ )
259
259
end
260
260
261
- it "applies a given file even when an ENC is configured" , :unless => Puppet ::Util ::Platform . windows? || RUBY_PLATFORM == 'java' do
261
+ it "applies a given file even when an ENC is configured" , :unless => Puppet ::Util ::Platform . windows? || Puppet :: Util :: Platform . jruby? do
262
262
manifest = file_containing ( "manifest.pp" , "notice('specific manifest applied')" )
263
263
enc = script_containing ( 'enc_script' ,
264
264
:windows => '@echo classes: []' + "\n " + '@echo environment: special' ,
@@ -379,7 +379,7 @@ def init_cli_args_and_apply_app(args, execute)
379
379
# External node script execution will fail, likely due to the tampering
380
380
# with the basic file descriptors.
381
381
# Workaround: Define a log destination and merely inspect logs.
382
- context "with an ENC" , :unless => RUBY_PLATFORM == 'java' do
382
+ context "with an ENC" do
383
383
let ( :logdest ) { tmpfile ( 'logdest' ) }
384
384
let ( :args ) { [ '-e' , execute , '--logdest' , logdest ] }
385
385
let ( :enc ) do
@@ -587,6 +587,14 @@ def bogus()
587
587
end
588
588
589
589
let ( :apply ) { Puppet ::Application [ :apply ] }
590
+ let ( :unknown_server ) do
591
+ unknown_ca_cert = cert_fixture ( 'unknown-ca.pem' )
592
+ PuppetSpec ::HTTPSServer . new (
593
+ ca_cert : unknown_ca_cert ,
594
+ server_cert : cert_fixture ( 'unknown-127.0.0.1.pem' ) ,
595
+ server_key : key_fixture ( 'unknown-127.0.0.1-key.pem' )
596
+ )
597
+ end
590
598
591
599
it 'submits a report via reporturl' do
592
600
report = nil
@@ -609,5 +617,50 @@ def bogus()
609
617
expect ( report . resource_statuses [ 'Notify[hi]' ] ) . to be_a ( Puppet ::Resource ::Status )
610
618
end
611
619
end
620
+
621
+ it 'rejects an HTTPS report server whose root cert is not the puppet CA' do
622
+ unknown_server . start_server do |https_port |
623
+ Puppet [ :reporturl ] = "https://127.0.0.1:#{ https_port } /reports/upload"
624
+
625
+ # processing the report happens after the transaction is finished,
626
+ # so we expect exit code 0, with a later failure on stderr
627
+ expect {
628
+ apply . command_line . args = [ '-e' , 'notify { "hi": }' ]
629
+ apply . run
630
+ } . to exit_with ( 0 )
631
+ . and output ( /Applied catalog/ ) . to_stdout
632
+ . and output ( /Report processor failed: certificate verify failed \[ self signed certificate in certificate chain for CN=Unknown CA\] / ) . to_stderr
633
+ end
634
+ end
635
+
636
+ it 'accepts an HTTPS report servers whose cert is in the system CA store' do
637
+ Puppet [ :report_include_system_store ] = true
638
+ report = nil
639
+
640
+ response_proc = -> ( req , res ) {
641
+ report = Puppet ::Transaction ::Report . convert_from ( :yaml , req . body )
642
+ }
643
+
644
+ # create a temp cacert bundle
645
+ ssl_file = tmpfile ( 'systemstore' )
646
+ File . write ( ssl_file , unknown_server . ca_cert . to_pem )
647
+
648
+ unknown_server . start_server ( response_proc : response_proc ) do |https_port |
649
+ Puppet [ :reporturl ] = "https://127.0.0.1:#{ https_port } /reports/upload"
650
+
651
+ # override path to system cacert bundle, this must be done before
652
+ # the SSLContext is created and the call to X509::Store.set_default_paths
653
+ Puppet ::Util . withenv ( "SSL_CERT_FILE" => ssl_file ) do
654
+ expect {
655
+ apply . command_line . args = [ '-e' , 'notify { "hi": }' ]
656
+ apply . run
657
+ } . to exit_with ( 0 )
658
+ . and output ( /Applied catalog/ ) . to_stdout
659
+ end
660
+
661
+ expect ( report ) . to be_a ( Puppet ::Transaction ::Report )
662
+ expect ( report . resource_statuses [ 'Notify[hi]' ] ) . to be_a ( Puppet ::Resource ::Status )
663
+ end
664
+ end
612
665
end
613
666
end
0 commit comments