Skip to content

Commit 440ea41

Browse files
authored
Merge pull request #9071 from joshcooper/refresh_fixture_11871
(PUP-11871) Copy CA/CRL fixtures
2 parents 96528b4 + 452b69f commit 440ea41

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

spec/integration/application/agent_spec.rb

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,24 @@
1515
let(:node) { Puppet::Node.new(Puppet[:certname], environment: 'production')}
1616
let(:formatter) { Puppet::Network::FormatHandler.format(:rich_data_json) }
1717

18+
# Create temp fixtures since the agent will attempt to refresh the CA/CRL
19+
before do
20+
Puppet[:localcacert] = ca = tmpfile('ca')
21+
Puppet[:hostcrl] = crl = tmpfile('crl')
22+
23+
copy_fixtures(%w[ca.pem intermediate.pem], ca)
24+
copy_fixtures(%w[crl.pem intermediate-crl.pem], crl)
25+
end
26+
27+
def copy_fixtures(sources, dest)
28+
ssldir = File.join(PuppetSpec::FIXTURE_DIR, 'ssl')
29+
File.open(dest, 'w') do |f|
30+
sources.each do |s|
31+
f.write(File.read(File.join(ssldir, s)))
32+
end
33+
end
34+
end
35+
1836
context 'server_list' do
1937
it "uses the first server in the list" do
2038
Puppet[:server_list] = '127.0.0.1'
@@ -835,23 +853,10 @@ def with_another_agent_running(&block)
835853
end
836854
end
837855

838-
def copy_fixtures(sources, dest)
839-
ssldir = File.join(PuppetSpec::FIXTURE_DIR, 'ssl')
840-
File.open(dest, 'w') do |f|
841-
sources.each do |s|
842-
f.write(File.read(File.join(ssldir, s)))
843-
end
844-
end
845-
end
846-
847856
it "reloads the CRL between runs" do
848-
Puppet[:localcacert] = ca = tmpfile('ca')
849-
Puppet[:hostcrl] = crl = tmpfile('crl')
850857
Puppet[:hostcert] = cert = tmpfile('cert')
851858
Puppet[:hostprivkey] = key = tmpfile('key')
852859

853-
copy_fixtures(%w[ca.pem intermediate.pem], ca)
854-
copy_fixtures(%w[crl.pem intermediate-crl.pem], crl)
855860
copy_fixtures(%w[127.0.0.1.pem], cert)
856861
copy_fixtures(%w[127.0.0.1-key.pem], key)
857862

@@ -898,15 +903,10 @@ def copy_fixtures(sources, dest)
898903
end
899904

900905
it "refreshes the CA and CRL" do
901-
Puppet[:localcacert] = ca = tmpfile('ca')
902-
Puppet[:hostcrl] = crl = tmpfile('crl')
903-
copy_fixtures(%w[ca.pem intermediate.pem], ca)
904-
copy_fixtures(%w[crl.pem intermediate-crl.pem], crl)
905-
906906
now = Time.now
907907
yesterday = now - (60 * 60 * 24)
908-
Puppet::FileSystem.touch(ca, mtime: yesterday)
909-
Puppet::FileSystem.touch(crl, mtime: yesterday)
908+
Puppet::FileSystem.touch(Puppet[:localcacert], mtime: yesterday)
909+
Puppet::FileSystem.touch(Puppet[:hostcrl], mtime: yesterday)
910910

911911
server.start_server do |port|
912912
Puppet[:serverport] = port
@@ -920,17 +920,17 @@ def copy_fixtures(sources, dest)
920920
end
921921

922922
# If the CA is updated, then the CRL must be updated too
923-
expect(Puppet::FileSystem.stat(ca).mtime).to be >= now
924-
expect(Puppet::FileSystem.stat(crl).mtime).to be >= now
923+
expect(Puppet::FileSystem.stat(Puppet[:localcacert]).mtime).to be >= now
924+
expect(Puppet::FileSystem.stat(Puppet[:hostcrl]).mtime).to be >= now
925925
end
926926

927927
it "refreshes only the CRL" do
928-
Puppet[:hostcrl] = crl = tmpfile('crl')
929-
copy_fixtures(%w[crl.pem intermediate-crl.pem], crl)
930-
931928
now = Time.now
929+
tomorrow = now + (60 * 60 * 24)
930+
Puppet::FileSystem.touch(Puppet[:localcacert], mtime: tomorrow)
931+
932932
yesterday = now - (60 * 60 * 24)
933-
Puppet::FileSystem.touch(crl, mtime: yesterday)
933+
Puppet::FileSystem.touch(Puppet[:hostcrl], mtime: yesterday)
934934

935935
server.start_server do |port|
936936
Puppet[:serverport] = port
@@ -943,7 +943,7 @@ def copy_fixtures(sources, dest)
943943
.and output(/Info: Refreshed CRL: /).to_stdout
944944
end
945945

946-
expect(Puppet::FileSystem.stat(crl).mtime).to be >= now
946+
expect(Puppet::FileSystem.stat(Puppet[:hostcrl]).mtime).to be >= now
947947
end
948948
end
949949

0 commit comments

Comments
 (0)