Skip to content

Commit

Permalink
Merge pull request #89 from getyoti/release-1.6.2
Browse files Browse the repository at this point in the history
Release 1.6.2
  • Loading branch information
davidgrayston authored Feb 13, 2020
2 parents 6ba09c0 + f26aefe commit 69302fa
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 250 deletions.
18 changes: 5 additions & 13 deletions lib/yoti/data_type/document_details.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module Yoti
class DocumentDetails
#
# The values of the Document Details are in the format and order as defined in this pattern
# e.g PASS_CARD GBR 22719564893 - CITIZENCARD, the last two are optionals
# @deprecated 2.0.0 pattern is no longer used for validation.
#
VALIDATION_PATTERN = '^([A-Za-z_]*) ([A-Za-z]{3}) ([A-Za-z0-9]{1}).*$'

TYPE_INDEX = 0
COUNTRY_INDEX = 1
NUMBER_INDEX = 2
Expand Down Expand Up @@ -51,28 +51,20 @@ class DocumentDetails
# @param [String] value
#
def initialize(value)
validate_value(value)
parse_value(value)
end

private

#
# Asserts provided matches VALIDATION_PATTERN
#
# @param [String] value
#
def validate_value(value)
raise(ArgumentError, "Invalid value for #{self.class.name}") unless /#{VALIDATION_PATTERN}/.match?(value)
end

#
# Parses provided value into separate attributes
#
# @param [String] value
#
def parse_value(value)
attributes = value.split(' ')
attributes = value.split(/ /)
raise(ArgumentError, "Invalid value for #{self.class.name}") if attributes.length < 3 || attributes.include?('')

@type = attributes[TYPE_INDEX]
@issuing_country = attributes[COUNTRY_INDEX]
@document_number = attributes[NUMBER_INDEX]
Expand Down
1 change: 0 additions & 1 deletion lib/yoti/sandbox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
require_relative 'sandbox/attribute'
require_relative 'sandbox/profile'
require_relative 'sandbox/sandbox_client'
require_relative 'sandbox/sandbox'
105 changes: 0 additions & 105 deletions lib/yoti/sandbox/sandbox.rb

This file was deleted.

11 changes: 3 additions & 8 deletions lib/yoti/sandbox/sandbox_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@
module Sandbox
# Client is responsible for setting up test data in the sandbox instance
class Client
attr_accessor :app_id
attr_accessor :key
attr_accessor :base_url

def initialize(app_id:, private_key:, base_url:)
@app_id = app_id
def initialize(base_url:)
@base_url = base_url
@key = OpenSSL::PKey::RSA.new(Base64.decode64(private_key))
end

def setup_sharing_profile(profile)
endpoint = "/apps/#{app_id}/tokens?\
endpoint = "/apps/#{Yoti.configuration.client_sdk_id}/tokens?\
nonce=#{SecureRandom.uuid}&timestamp=#{Time.now.to_i}"
uri = URI(
"#{@base_url}/#{endpoint}"
Expand All @@ -23,8 +19,7 @@ def setup_sharing_profile(profile)
response = Net::HTTP.start(
uri.hostname,
uri.port,
use_ssl: true,
verify_mode: OpenSSL::SSL::VERIFY_NONE
use_ssl: true
) do |http|
unsigned = Net::HTTP::Post.new uri
unsigned.body = profile.to_json
Expand Down
1 change: 1 addition & 0 deletions lib/yoti/ssl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def decipher(key, user_iv, text)
end

# Reset and reload the Private Key used for SSL functions
# @deprecated 2.0.0
def reload!
@private_key = nil
@pem = nil
Expand Down
2 changes: 1 addition & 1 deletion lib/yoti/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Yoti
# @return [String] the gem's current version
VERSION = '1.6.1'.freeze
VERSION = '1.6.2'.freeze
end
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
sonar.projectKey = yoti-web-sdk:ruby
sonar.projectName = ruby-sdk
sonar.projectVersion = 1.6.1
sonar.projectVersion = 1.6.2
sonar.language=ruby
sonar.exclusions = **/protobuf/**.rb, coverage/**, spec/sample-data/**
sonar.links.scm = https://github.com/getyoti/yoti-ruby-sdk
Expand Down
53 changes: 39 additions & 14 deletions spec/yoti/data_type/document_details_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
require 'spec_helper'

describe 'Yoti::DocumentDetails' do
context 'when an empty value is provided' do
it 'should raise an error' do
expect { Yoti::DocumentDetails.new('') }
.to raise_error(ArgumentError, 'Invalid value for Yoti::DocumentDetails')
end
end

context 'when there is one optional attribute' do
document_details = Yoti::DocumentDetails.new('PASSPORT GBR 01234567 2020-01-01')
describe '.type' do
Expand Down Expand Up @@ -89,20 +96,6 @@
end
end

context 'when the country is invalid' do
it 'should raise ArgumentError' do
expect { Yoti::DocumentDetails.new('PASSPORT 13 1234abc 2016-05-01') }
.to raise_error(ArgumentError, 'Invalid value for Yoti::DocumentDetails')
end
end

context 'when the document number is invalid' do
it 'should raise ArgumentError' do
expect { Yoti::DocumentDetails.new('PASSPORT GBR $%^$%^£ 2016-05-01') }
.to raise_error(ArgumentError, 'Invalid value for Yoti::DocumentDetails')
end
end

context 'when the expiration date is missing' do
document_details = Yoti::DocumentDetails.new('PASS_CARD GBR 22719564893 - CITIZENCARD')
describe '.expiration_date' do
Expand Down Expand Up @@ -140,4 +133,36 @@
expect(document_details.expiration_date.to_s).to eql('2016-05-01T00:00:00+00:00')
end
end

context 'when the document number is valid' do
[
'****',
'~!@#$%^&*()-_=+[]{}|;\':,./<>?',
'""',
'\\',
'"',
'\'\'',
'\'',
"\t"
].each do |value|
it "#{value} should be allowed as document number" do
document_details = Yoti::DocumentDetails.new("some-type some-country #{value} - some-authority")
expect(document_details.document_number).to eql(value)
end
end
end

context 'when the value contains extra spaces' do
[
'some-type some-country some-doc-number - some-authority',
'some-type some-country some-doc-number - some-authority',
'some-type some-country some-doc-number - some-authority',
'some-type some-country some-doc-number - some-authority'
].each do |value|
it "should raise an ArgumentError for '#{value}''" do
expect { Yoti::DocumentDetails.new(value) }
.to raise_error(ArgumentError, 'Invalid value for Yoti::DocumentDetails')
end
end
end
end
11 changes: 1 addition & 10 deletions spec/yoti/sandbox/sandbox_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,17 @@
require 'spec_helper'

describe 'Sandbox::Client' do
let :app_id do
'0000-0000-0000-0000'
end
let :base_url do
'https://example.com'
end
let :private_key do
key = OpenSSL::PKey::RSA.new 1024
Base64.encode64(key.to_der)
end
let :profile do
{}
end
let :client do
Sandbox::Client.new(app_id: app_id, private_key: private_key, base_url: base_url)
Sandbox::Client.new(base_url: base_url)
end
describe '.initialize' do
it 'Creates a client' do
expect(client.app_id).to eql app_id
expect(client.key).not_to be_nil
expect(client.base_url).to eql base_url
end
end
Expand Down
Loading

0 comments on commit 69302fa

Please sign in to comment.