Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
medisco committed Mar 30, 2023
2 parents 6708b5f + 6b0efed commit 4052a8e
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 13 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -13,4 +16,4 @@
* Adds support for Trust Services Management

## 1.0.0 (2018-04-11)
* First publicly available version
* First publicly available version
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
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.

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
-------
Expand Down
21 changes: 17 additions & 4 deletions lib/pki_express/pki_express_config.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,38 @@
require 'pathname'

module PkiExpress

class PkiExpressConfig
attr_accessor :pki_express_home, :temp_folder, :transfer_data_folder
@@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')
end
@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
Expand Down
4 changes: 2 additions & 2 deletions lib/pki_express/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module PkiExpress
VERSION = '1.3.1'
end
VERSION = '1.3.2'
end
73 changes: 73 additions & 0 deletions spec/pki_express/pki_express_config_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4052a8e

Please sign in to comment.