From c3429b6308ec60ddd4990e5a300a24bd2a8beef6 Mon Sep 17 00:00:00 2001 From: cranix Date: Thu, 2 Mar 2017 23:23:12 +0100 Subject: [PATCH] Added quick 'n' dirty script for generation of configs with various combinations of defaultaction/recipent-specyfic action pairs --- config_gen.rb | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++ config_gen.rc | 10 ++++++++ 2 files changed, 74 insertions(+) create mode 100755 config_gen.rb create mode 100644 config_gen.rc diff --git a/config_gen.rb b/config_gen.rb new file mode 100755 index 0000000..c6ad4bc --- /dev/null +++ b/config_gen.rb @@ -0,0 +1,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 + diff --git a/config_gen.rc b/config_gen.rc new file mode 100644 index 0000000..2810f35 --- /dev/null +++ b/config_gen.rc @@ -0,0 +1,10 @@ +template_config='config/kuvert.conf_template' +testing_config='config/kuvert.conf' +kuvert_launch_cmd='sh start' +kuvert_stop_cmd='docker stop kuvert' +mail_dir='queue' +log_file='logs/log' +from='' +recipent0='' +recipent1='' +