From 3ea51dccbf28f989773e38e6cbfc25b093390d24 Mon Sep 17 00:00:00 2001 From: Ismael Medeiros Date: Thu, 30 Mar 2023 13:46:15 -0300 Subject: [PATCH 1/3] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index db5de52..0ec3014 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ PKI Express for Ruby ============================ -[![Gem Version](https://badge.fury.io/rb/rest_pki.svg)](https://badge.fury.io/rb/rest_pki) +[![Gem Version](https://badge.fury.io/rb/pki_express.svg)](https://badge.fury.io/rb/pki_express) This library contains classes that encapsulate the calls to PKI Express. From e830e439df8bb290ee982a12af56cc2a8c80a983 Mon Sep 17 00:00:00 2001 From: Ismael Medeiros Date: Thu, 30 Mar 2023 16:33:46 -0300 Subject: [PATCH 2/3] Add tests and input validation for PkiExpressConfig constructor inputs --- Gemfile | 3 +- lib/pki_express/pki_express_config.rb | 21 ++++-- spec/pki_express/pki_express_config_spec.rb | 73 +++++++++++++++++++++ 3 files changed, 92 insertions(+), 5 deletions(-) create mode 100644 spec/pki_express/pki_express_config_spec.rb diff --git a/Gemfile b/Gemfile index 68b5a54..b518920 100644 --- a/Gemfile +++ b/Gemfile @@ -4,5 +4,6 @@ source 'https://rubygems.org' gemspec group :development, :test do - gem 'rspec' + gem 'rspec', '~> 3.12' + gem 'faker', '~> 3.1', '>= 3.1.1' end \ No newline at end of file diff --git a/lib/pki_express/pki_express_config.rb b/lib/pki_express/pki_express_config.rb index 468a57e..1e3a7a4 100644 --- a/lib/pki_express/pki_express_config.rb +++ b/lib/pki_express/pki_express_config.rb @@ -1,3 +1,5 @@ +require 'pathname' + module PkiExpress class PkiExpressConfig @@ -5,8 +7,12 @@ class PkiExpressConfig @@single_temp_folder = nil def initialize(pki_express_home = nil, temp_folder = nil, transfer_data_folder = nil) - if not temp_folder.nil? and Pathname.new(temp_folder).exist? - @temp_folder = temp_folder + if not temp_folder.nil? + if Pathname.new(temp_folder).exist? + @temp_folder = temp_folder + else + raise ArgumentError.new "the provided temp_folder is not valid" + end else if @@single_temp_folder.nil? @@single_temp_folder = Dir.mktmpdir('pkie') @@ -14,12 +20,19 @@ def initialize(pki_express_home = nil, temp_folder = nil, transfer_data_folder = @temp_folder = @@single_temp_folder end - if not transfer_data_folder.nil? and Pathname.new(transfer_data_folder).exist? - @transfer_data_folder = transfer_data_folder + if not transfer_data_folder.nil? + if Pathname.new(transfer_data_folder).exist? + @transfer_data_folder = transfer_data_folder + else + raise ArgumentError.new "the provided transfer_data_folder is not valid" + end else @transfer_data_folder = @temp_folder end + if not pki_express_home.nil? and not File.directory?(pki_express_home) + raise ArgumentError.new "the provided pki_express_home is not valid" + end @pki_express_home = pki_express_home end end diff --git a/spec/pki_express/pki_express_config_spec.rb b/spec/pki_express/pki_express_config_spec.rb new file mode 100644 index 0000000..d9aa2d2 --- /dev/null +++ b/spec/pki_express/pki_express_config_spec.rb @@ -0,0 +1,73 @@ +require 'faker' + +require_relative '../spec_helper' + +module PkiExpress + describe PkiExpressConfig do + it 'should set valid default values when no value is passed in contructor' do + config = PkiExpressConfig.new + expect(config.pki_express_home).to be_nil + expect(File.directory?(config.temp_folder)).to be(true) + expect(File.directory?(config.transfer_data_folder)).to be(true) + end + + it 'should set pki_express_home folder when a valid path is passed' do + fake_pki_express_home = Dir.mktmpdir('pkie') + config = PkiExpressConfig.new(fake_pki_express_home) + expect(config.pki_express_home).to equal(fake_pki_express_home) + Dir.rmdir(fake_pki_express_home) + end + + it 'should raise ArgumentError when an invalid path is passed' do + expect { PkiExpressConfig.new(Faker::String.random) }.to raise_error(ArgumentError) + end + + it 'should raise ArgumentError when a path is passed but doesn\'t exist' do + fake_pki_express_home = Faker::File.dir + expect { PkiExpressConfig.new(fake_pki_express_home) }.to raise_error(ArgumentError) + end + + it 'should set temp_folder when a valid path is passed' do + fake_temp_folder = Dir.mktmpdir('pkie') + config = PkiExpressConfig.new(nil, fake_temp_folder) + expect(config.temp_folder).to equal(fake_temp_folder) + Dir.rmdir(fake_temp_folder) + end + + it 'should set temp_folder with a default folder when no path is passed' do + config1 = PkiExpressConfig.new + config2 = PkiExpressConfig.new + expect(config1.temp_folder).to equal(config2.temp_folder) + end + + it 'should raise ArgumentError when an invalid path is passed' do + expect { PkiExpressConfig.new(nil, Faker::String.random) }.to raise_error(ArgumentError) + end + + it 'should raise ArgumentError when a path is passed but doesn\'t exist' do + fake_pki_express_home = Faker::File.dir + expect { PkiExpressConfig.new(nil, fake_pki_express_home) }.to raise_error(ArgumentError) + end + + it 'should set transfer_data_folder when a valid path is passed' do + fake_transfer_data_folder = Dir.mktmpdir('pkie') + config = PkiExpressConfig.new(nil, nil, fake_transfer_data_folder) + expect(config.transfer_data_folder).to equal(fake_transfer_data_folder) + Dir.rmdir(fake_transfer_data_folder) + end + + it 'should set transfer_data_folder with temp_folder value when no path is passed' do + config = PkiExpressConfig.new + expect(config.transfer_data_folder).to equal(config.temp_folder) + end + + it 'should raise ArgumentError when an invalid path is passed' do + expect { PkiExpressConfig.new(nil, nil, Faker::String.random) }.to raise_error(ArgumentError) + end + + it 'should raise ArgumentError when a path is passed but doesn\'t exist' do + fake_pki_express_home = Faker::File.dir + expect { PkiExpressConfig.new(nil, nil, fake_pki_express_home) }.to raise_error(ArgumentError) + end + end +end \ No newline at end of file From 3805891b966c816f6e6a1ddbd4d233a85c85505e Mon Sep 17 00:00:00 2001 From: Ismael Medeiros Date: Thu, 30 Mar 2023 16:48:29 -0300 Subject: [PATCH 3/3] Bumped version to 1.3.2 --- CHANGELOG.md | 5 ++++- README.md | 8 ++++---- lib/pki_express/version.rb | 4 ++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 50fa18f..501ab7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 1.3.2 (2023-03-30) +* Improve valdiation of PkiExpressConfig's contructor parameters + ## 1.3.1 (2023-03-30) * Fix pki express operator finalizer * Improve pathname call with exists @@ -13,4 +16,4 @@ * Adds support for Trust Services Management ## 1.0.0 (2018-04-11) -* First publicly available version \ No newline at end of file +* First publicly available version diff --git a/README.md b/README.md index 0ec3014..0cb554d 100644 --- a/README.md +++ b/README.md @@ -7,16 +7,16 @@ This library contains classes that encapsulate the calls to PKI Express. The recommended way to install **PKI Expresss lib** is through setting in your Gemfile: ````ruby -gem 'pki_express', '~> 1.3.1' +gem 'pki_express', '~> 1.3.2' ```` And with installing via [Bundler](http://bundler.io/) on your project root folder: - + bundle install - + Alternatively, You can install this gem globally by executing the following command: - gem install pki_express + gem install pki_express Samples ------- diff --git a/lib/pki_express/version.rb b/lib/pki_express/version.rb index 8c49e74..4cf2545 100644 --- a/lib/pki_express/version.rb +++ b/lib/pki_express/version.rb @@ -1,3 +1,3 @@ module PkiExpress - VERSION = '1.3.1' -end \ No newline at end of file + VERSION = '1.3.2' +end