summaryrefslogtreecommitdiffstats
path: root/config_gen.rb
blob: c6ad4bc7c4c05a2f91566272176ebac760cd7ceb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/ruby
#Simple script that generates kuvert's config
#files with different possbile combinations of defaultaction
#and recipent specyfic actions and run kuvert againt them

require 'parseconfig'
require 'fileutils'

config=ParseConfig.new('config_gen.rc')
template_config=config['template_config'] #File with template config that we will base on
testing_config=config['testing_config'] #File with config that we will be testing
kuvert_launch_cmd=config['kuvert_launch_cmd'] #Command to launch kuvert
kuvert_stop_cmd=config['kuvert_stop_cmd'] #Command to stop kuvert
mail_dir=config['mail_dir'] #Directory where we will put test mail
log_file=config['log_file'] #File with kuvert logs
from=config['from'] #We are sending mails as who?

recipent0=config['recipent0'] #Recipent that we have key for
recipent1=config['recipent1'] #Recipent that we don't have key for

actions=['none','signonly','fallback','encrypt'] #Array with all possible acions that we want to test
iterations=0 #Number of iterations

actions.each do |defaultaction|
	actions.each do |recipentaction|
		FileUtils.cp(template_config,testing_config)
		conf=File.open(testing_config,'a')
		conf.puts("defaultaction #{defaultaction}")
		conf.puts(" #{recipent0} #{recipentaction}")
		conf.fsync
		conf.close
		
		mail=File.open("#{mail_dir}/#{iterations}",'w')
		mail.puts("From: #{from}")
		mail.puts("To: #{recipent0}, #{recipent1}")
		mail.puts("Subject: Kuvert test default: #{defaultaction} ; recipent: #{recipentaction} #{iterations}")
		mail.puts("Lorem ipsum dolor sit amet, consectetur adipiscing elit.")
		mail.fsync
		mail.close
		
		puts "Staring kuvert"
		puts "defaultaction #{defaultaction}"
		puts "#{recipent0} #{recipentaction}"
		puts "Iteration #{iterations}"
		#Start kuvert
		fork do
			system(kuvert_launch_cmd)
		end
		
		#Ugly busy waiting loop
		while ((`tail -n 1 #{log_file}` =~ /.*done handling file \d*.*/)==nil) do
			sleep 2
			puts "Waiting until kuvert finish his job"
		end

		#Stop kuvert
		#system(kuvert_stop_cmd)
		pid=spawn(kuvert_stop_cmd)
		Process.wait(pid)
		sleep 5
		iterations+=1
	end
end