bank_credentials 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.overcommit.yml +33 -0
- data/.rspec +2 -0
- data/.rubocop.yml +12 -0
- data/.ruby-version +1 -0
- data/.travis.yml +1 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +144 -0
- data/Rakefile +8 -0
- data/bank_credentials.gemspec +27 -0
- data/bin/console +15 -0
- data/bin/setup +7 -0
- data/lib/bank_credentials/base.rb +55 -0
- data/lib/bank_credentials/ebics.rb +26 -0
- data/lib/bank_credentials/errors/errors.rb +14 -0
- data/lib/bank_credentials/factory.rb +31 -0
- data/lib/bank_credentials/hbci.rb +24 -0
- data/lib/bank_credentials/version.rb +5 -0
- data/lib/bank_credentials.rb +15 -0
- data/spec/bank_credentials/base_spec.rb +47 -0
- data/spec/bank_credentials/ebics_spec.rb +102 -0
- data/spec/bank_credentials/errors_spec.rb +14 -0
- data/spec/bank_credentials/factory_spec.rb +112 -0
- data/spec/bank_credentials/hbci_spec.rb +99 -0
- data/spec/bank_credentials_spec.rb +9 -0
- data/spec/spec_helper.rb +6 -0
- data/spec/support/credentials.rb +37 -0
- metadata +129 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 845726d39c178f0e4b6289f3f98143a11599df7849740b081e2e2946e1c5b959
|
4
|
+
data.tar.gz: fffb808f6561b9ec92e23d742169ad22bf6f2ad449629eee99ebadd3e8d0923f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3a3b39fd343430da2b851e643baf3d18da0dd3d3c9395b036af7e8bd216f2da55d6b501151d045b0c523c96b0d666ea28fa6639aa4244faef974e608c11b8b88
|
7
|
+
data.tar.gz: f3069b6e5b3635a5f0846a7351c3e730a239f7ed1b8eb00769c8415ba681ce468292750ca606acb839c29e3b62899f0057fb1d1451e1d620e476021d72d5586a
|
data/.gitignore
ADDED
data/.overcommit.yml
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# Use this file to configure the Overcommit hooks you wish to use. This will
|
2
|
+
# extend the default configuration defined in:
|
3
|
+
# https://github.com/brigade/overcommit/blob/master/config/default.yml
|
4
|
+
#
|
5
|
+
# At the topmost level of this YAML file is a key representing type of hook
|
6
|
+
# being run (e.g. pre-commit, commit-msg, etc.). Within each type you can
|
7
|
+
# customize each hook, such as whether to only run it on certain files (via
|
8
|
+
# `include`), whether to only display output if it fails (via `quiet`), etc.
|
9
|
+
#
|
10
|
+
# For a complete list of hooks, see:
|
11
|
+
# https://github.com/brigade/overcommit/tree/master/lib/overcommit/hook
|
12
|
+
#
|
13
|
+
# For a complete list of options that you can use to customize hooks, see:
|
14
|
+
# https://github.com/brigade/overcommit#configuration
|
15
|
+
#
|
16
|
+
# Uncomment the following lines to make the configuration take effect.
|
17
|
+
|
18
|
+
PreCommit:
|
19
|
+
RuboCop:
|
20
|
+
enabled: true
|
21
|
+
on_warn: fail # Treat all warnings as failures
|
22
|
+
#
|
23
|
+
# TrailingWhitespace:
|
24
|
+
# enabled: true
|
25
|
+
# exclude:
|
26
|
+
# - '**/db/structure.sql' # Ignore trailing whitespace in generated files
|
27
|
+
#
|
28
|
+
#PostCheckout:
|
29
|
+
# ALL: # Special hook name that customizes all hooks of this type
|
30
|
+
# quiet: true # Change all post-checkout hooks to only display output on failure
|
31
|
+
#
|
32
|
+
# IndexTags:
|
33
|
+
# enabled: true # Generate a tags file with `ctags` each time HEAD changes
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.5.1
|
data/.travis.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
language: ruby
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Roman Lehnert
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
# BankCredentials
|
2
|
+
|
3
|
+
BankCredentials is a tiny wrapper for keeping together bank credentials for HBCI or Ebics.
|
4
|
+
|
5
|
+
- [Installation](#installation)
|
6
|
+
- [Usage with Ebics credentials](#ebics-credentials)
|
7
|
+
- [Usage with Hbci credentials](#hbci-credentials)
|
8
|
+
|
9
|
+
[](https://travis-ci.org/fintastic/bank_credentials)
|
10
|
+
[](https://depfu.com/github/fintastic/bank_credentials?project=Bundler)
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem 'bank_credentials'
|
18
|
+
```
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
|
22
|
+
$ bundle
|
23
|
+
|
24
|
+
Or install it yourself as:
|
25
|
+
|
26
|
+
$ gem install bank_credentials
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
### Ebics Credentials
|
31
|
+
|
32
|
+
Ebics credentials require the following attributes:
|
33
|
+
|
34
|
+
* key
|
35
|
+
* Host URL of the ebics server
|
36
|
+
* Host ID
|
37
|
+
* Partner ID
|
38
|
+
* Passphrase
|
39
|
+
|
40
|
+
#### Feeding with credentials hash
|
41
|
+
Take a credentials hash and initialize an `BankCredentials::Ebics` instance with it.
|
42
|
+
```ruby
|
43
|
+
credential_hash = {
|
44
|
+
key: "key",
|
45
|
+
url: "url",
|
46
|
+
host_id: "host_id",
|
47
|
+
user_id: "user_id",
|
48
|
+
partner_id: "partner_id"
|
49
|
+
passphrase: "passphrase",
|
50
|
+
}
|
51
|
+
|
52
|
+
credentials = BankCredentials::Ebics.new(credential_hash)
|
53
|
+
```
|
54
|
+
At initialization, the completeness of the attributes will be validated. If they are invalid, `BankCredentials::Error::Invalid` will be raised.
|
55
|
+
|
56
|
+
|
57
|
+
#### Feeding with a base64 encoded json hash
|
58
|
+
To create an instance from a base64 encoded json string, use `.from_encoded_json`:
|
59
|
+
```ruby
|
60
|
+
credential_hash = {
|
61
|
+
key: "key",
|
62
|
+
url: "url",
|
63
|
+
host_id: "host_id",
|
64
|
+
user_id: "user_id",
|
65
|
+
partner_id: "partner_id"
|
66
|
+
passphrase: "passphrase",
|
67
|
+
}
|
68
|
+
|
69
|
+
encoded_json = Base64.decode64(credential_hash.to_json)
|
70
|
+
|
71
|
+
credentials = BankCredentials::Ebics.from_encoded_json(encoded_json)
|
72
|
+
```
|
73
|
+
When the given argument is not valid json, `BankCredentials::Errors::Invalid` will be raised.
|
74
|
+
|
75
|
+
Attribute accessors are provided:
|
76
|
+
```ruby
|
77
|
+
credentials.key # => "key"
|
78
|
+
credentials.host_id # => "host_id"
|
79
|
+
credentials.partner_id # => "partner_id"
|
80
|
+
credentials.user_id # => "user_id"
|
81
|
+
credentials.passphrase # => "passphrase"
|
82
|
+
```
|
83
|
+
|
84
|
+
|
85
|
+
### HBCI Credentials
|
86
|
+
|
87
|
+
Ebics credentials require the following attributes:
|
88
|
+
|
89
|
+
* Host URL of the HBCI server
|
90
|
+
* Bank code
|
91
|
+
* user id
|
92
|
+
* pin
|
93
|
+
|
94
|
+
#### Feeding with credentials hash
|
95
|
+
Take a credentials hash and initialize an `BankCredentials::Hbci` instance with it.
|
96
|
+
```ruby
|
97
|
+
credential_hash = {
|
98
|
+
url: "url",
|
99
|
+
bank_code: "bank_code",
|
100
|
+
user_id: "user_id",
|
101
|
+
pin: "pin"
|
102
|
+
}
|
103
|
+
|
104
|
+
credentials = BankCredentials::Hbci.new(credential_hash)
|
105
|
+
```
|
106
|
+
At initialization, the completeness of the attributes will be validated. If they are invalid, `BankCredentials::Error::Invalid` will be raised.
|
107
|
+
|
108
|
+
|
109
|
+
#### Feeding with a base64 encoded json hash
|
110
|
+
To create an instance from a base64 encoded json string, use `.from_encoded_json`:
|
111
|
+
```ruby
|
112
|
+
credential_hash = {
|
113
|
+
url: "url",
|
114
|
+
user_id: "user_id",
|
115
|
+
bank_code: "bank_code",
|
116
|
+
pin: "pin"
|
117
|
+
}
|
118
|
+
|
119
|
+
encoded_json = Base64.decode64(credential_hash.to_json)
|
120
|
+
|
121
|
+
credentials = BankCredentials::Hbci.from_encoded_json(encoded_json)
|
122
|
+
```
|
123
|
+
When the given argument is not valid json, `BankCredentials::Errors::Invalid` will be raised.
|
124
|
+
|
125
|
+
Attribute accessors are provided:
|
126
|
+
```ruby
|
127
|
+
credentials.pin # => "pin"
|
128
|
+
credentials.url # => "url"
|
129
|
+
credentials.user_id # => "user_id"
|
130
|
+
```
|
131
|
+
|
132
|
+
## Development
|
133
|
+
|
134
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
135
|
+
|
136
|
+
## Contributing
|
137
|
+
|
138
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/bank_credentials.
|
139
|
+
|
140
|
+
|
141
|
+
## License
|
142
|
+
|
143
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
144
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'bank_credentials/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'bank_credentials'
|
9
|
+
spec.version = BankCredentials::VERSION
|
10
|
+
spec.authors = ['Roman Lehnert']
|
11
|
+
spec.email = ['roman.lehnert@gmail.com']
|
12
|
+
|
13
|
+
spec.summary = 'A tiny ruby container for ebics and hbci credentials.'
|
14
|
+
spec.description = 'Encapsulates and validates the completeness of banking credentials for ebics and hbci.'
|
15
|
+
spec.homepage = 'https://github.com/fintastic/bank_credentials'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0")
|
19
|
+
spec.bindir = 'exe'
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ['lib']
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.10'
|
24
|
+
spec.add_development_dependency 'byebug', '~> 5'
|
25
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
26
|
+
spec.add_development_dependency 'rspec', '~> 3'
|
27
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'bank_credentials'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BankCredentials
|
4
|
+
class Base
|
5
|
+
extend Forwardable
|
6
|
+
attr_reader :credentials
|
7
|
+
def_delegator :credentials, :to_h
|
8
|
+
|
9
|
+
def self.type
|
10
|
+
name.nil? ? 'base' : name.split('::').last.downcase
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.attributes
|
14
|
+
@attributes = [] if @attributes.nil?
|
15
|
+
@attributes
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.attribute(attribute)
|
19
|
+
@attributes = [] if @attributes.nil?
|
20
|
+
@attributes << attribute
|
21
|
+
def_delegator :@credentials, attribute
|
22
|
+
def_delegator :@credentials, "#{attribute}=".to_sym
|
23
|
+
end
|
24
|
+
|
25
|
+
def initialize(credential_hash, options = {})
|
26
|
+
credential_hash[:type] = credential_hash[:type] || self.class.type || nil
|
27
|
+
@credentials = OpenStruct.new(credential_hash)
|
28
|
+
validate! if options[:validate]
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_json
|
32
|
+
to_h.to_json
|
33
|
+
end
|
34
|
+
|
35
|
+
def encode
|
36
|
+
Base64.urlsafe_encode64(to_json)
|
37
|
+
end
|
38
|
+
|
39
|
+
def attributes
|
40
|
+
self.class.attributes
|
41
|
+
end
|
42
|
+
|
43
|
+
def valid?
|
44
|
+
attributes.each do |attribute|
|
45
|
+
return false if @credentials[attribute].nil? || @credentials[attribute].empty?
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def validate!
|
50
|
+
raise self.class::Errors::Invalid unless valid?
|
51
|
+
end
|
52
|
+
|
53
|
+
attribute :type
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BankCredentials
|
4
|
+
class Ebics < Base
|
5
|
+
attribute :key
|
6
|
+
attribute :passphrase
|
7
|
+
attribute :user_id
|
8
|
+
attribute :host_id
|
9
|
+
attribute :partner_id
|
10
|
+
attribute :url
|
11
|
+
|
12
|
+
module Errors
|
13
|
+
class Invalid < StandardError
|
14
|
+
def to_s
|
15
|
+
'Invalid Ebics credentials'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class Empty < StandardError
|
20
|
+
def to_s
|
21
|
+
'Empty Ebics credentials'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BankCredentials
|
4
|
+
class Factory
|
5
|
+
def self.from_hash(credentials)
|
6
|
+
raise Errors::Invalid unless credentials.is_a?(Hash)
|
7
|
+
raise Errors::Invalid unless credentials.key?(:type)
|
8
|
+
|
9
|
+
class_for_type(credentials[:type]).new(credentials)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.from_encoded_json(encoded_json)
|
13
|
+
raise Errors::Invalid if encoded_json.nil?
|
14
|
+
raise Errors::Invalid if encoded_json.empty?
|
15
|
+
raise Errors::Invalid unless encoded_json.is_a?(String)
|
16
|
+
|
17
|
+
credentials = JSON.parse(Base64.urlsafe_decode64(encoded_json), symbolize_names: true)
|
18
|
+
|
19
|
+
class_for_type(credentials[:type]).new(credentials)
|
20
|
+
rescue JSON::ParserError, ArgumentError
|
21
|
+
raise Errors::Invalid
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.class_for_type(type)
|
25
|
+
case type
|
26
|
+
when 'ebics' then Ebics
|
27
|
+
when 'hbci' then Hbci
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BankCredentials
|
4
|
+
class Hbci < Base
|
5
|
+
module Errors
|
6
|
+
class Invalid < StandardError
|
7
|
+
def to_s
|
8
|
+
'Invalid Hbci credentials'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class Empty < StandardError
|
13
|
+
def to_s
|
14
|
+
'Empty Hbci credentials'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
attribute :url
|
20
|
+
attribute :bank_code
|
21
|
+
attribute :user_id
|
22
|
+
attribute :pin
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bank_credentials/version'
|
4
|
+
|
5
|
+
require 'base64'
|
6
|
+
require 'json'
|
7
|
+
|
8
|
+
require 'bank_credentials/errors/errors'
|
9
|
+
require 'bank_credentials/factory'
|
10
|
+
require 'bank_credentials/base'
|
11
|
+
require 'bank_credentials/hbci'
|
12
|
+
require 'bank_credentials/ebics'
|
13
|
+
|
14
|
+
module BankCredentials
|
15
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe BankCredentials::Base do
|
6
|
+
describe '.attribute' do
|
7
|
+
let(:klass) { Class.new(described_class) }
|
8
|
+
|
9
|
+
it 'adds the attribute to the attributes' do
|
10
|
+
expect { klass.attribute(:test) }
|
11
|
+
.to change { klass.attributes }
|
12
|
+
.from([]).to([:test])
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'adds the reader delegator' do
|
16
|
+
klass.attribute(:test)
|
17
|
+
credentials_instance = klass.new(test: 'test')
|
18
|
+
expect(credentials_instance.credentials).to receive(:test).once
|
19
|
+
|
20
|
+
credentials_instance.test
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'adds the writer delegator' do
|
24
|
+
klass.attribute(:test)
|
25
|
+
credentials_instance = klass.new(test: 'test')
|
26
|
+
expect(credentials_instance.credentials).to receive(:test=).once
|
27
|
+
|
28
|
+
credentials_instance.test = 'asd'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '.attributes' do
|
33
|
+
let(:klass) { Class.new(described_class) }
|
34
|
+
subject { klass.attributes }
|
35
|
+
|
36
|
+
context 'when there are no attributes' do
|
37
|
+
it 'returns an empty array' do
|
38
|
+
expect(subject).to eql([])
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'returns the attributes' do
|
43
|
+
klass.attribute(:test)
|
44
|
+
expect(subject).to eql([:test])
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe BankCredentials::Ebics do
|
6
|
+
let(:credential_hash) { valid_ebics_credentials_without_type }
|
7
|
+
|
8
|
+
describe 'attribute readers' do
|
9
|
+
subject { described_class.new(credential_hash) }
|
10
|
+
|
11
|
+
it 'provides public access to the credentials' do
|
12
|
+
expect(subject.type).to eql('ebics')
|
13
|
+
expect(subject.key).to eql('key')
|
14
|
+
expect(subject.passphrase).to eql('passphrase')
|
15
|
+
expect(subject.host_id).to eql('host_id')
|
16
|
+
expect(subject.user_id).to eql('user_id')
|
17
|
+
expect(subject.partner_id).to eql('partner_id')
|
18
|
+
expect(subject.url).to eql('https://localhost')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#valid?' do
|
23
|
+
it 'returns false when one of the keys is missing' do
|
24
|
+
%i[key passphrase user_id host_id partner_id url].each do |key|
|
25
|
+
expect(described_class.new(credential_hash.merge!(key => nil))).to_not be_valid
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'returns true when none of the keys is missing' do
|
30
|
+
expect(described_class.new(credential_hash)).to be_valid
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#encode' do
|
35
|
+
subject { described_class.new(credential_hash).encode }
|
36
|
+
|
37
|
+
it 'returns the ursafe base64 encoded string' do
|
38
|
+
expect(subject).to eql(
|
39
|
+
Base64.urlsafe_encode64(described_class.new(credential_hash).to_json)
|
40
|
+
)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'validate!' do
|
45
|
+
it 'raises an error when one of the keys is missing' do
|
46
|
+
%i[key passphrase user_id host_id partner_id url].each do |key|
|
47
|
+
subject = described_class.new(credential_hash.merge!(key => nil), validate: false)
|
48
|
+
expect { subject.validate! }.to raise_error(BankCredentials::Ebics::Errors::Invalid)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '#to_h' do
|
54
|
+
subject { described_class.new(credential_hash).to_h }
|
55
|
+
|
56
|
+
context 'when credential hash includes the type' do
|
57
|
+
let(:credential_hash) { valid_ebics_credentials_with_type }
|
58
|
+
|
59
|
+
it { is_expected.to eql(credential_hash) }
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'when credential hash excludes the type' do
|
63
|
+
let(:credential_hash) { valid_ebics_credentials_without_type }
|
64
|
+
|
65
|
+
it { is_expected.to eql(valid_ebics_credentials_with_type) }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe '#to_json' do
|
70
|
+
subject { described_class.new(credential_hash).to_json }
|
71
|
+
|
72
|
+
context 'when credential hash includes the type' do
|
73
|
+
let(:credential_hash) { valid_ebics_credentials_with_type }
|
74
|
+
|
75
|
+
it { is_expected.to eql(credential_hash.to_json) }
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'when credential hash excludes the type' do
|
79
|
+
let(:credential_hash) { valid_ebics_credentials_without_type }
|
80
|
+
|
81
|
+
it { is_expected.to eql(valid_ebics_credentials_with_type.to_json) }
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe described_class::Errors do
|
86
|
+
describe described_class::Empty do
|
87
|
+
describe '#to_s' do
|
88
|
+
it 'responds correct' do
|
89
|
+
expect(subject.to_s).to eql('Empty Ebics credentials')
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe described_class::Invalid do
|
95
|
+
describe '#to_s' do
|
96
|
+
it 'responds correct' do
|
97
|
+
expect(subject.to_s).to eql('Invalid Ebics credentials')
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe BankCredentials::Errors::Base do
|
6
|
+
it 'has a message when given a message' do
|
7
|
+
expect do
|
8
|
+
raise described_class, 'oh no!'
|
9
|
+
end.to(raise_error do |error|
|
10
|
+
expect(error.message).to eql('oh no!')
|
11
|
+
expect(error.to_s).to eql('oh no!')
|
12
|
+
end)
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe BankCredentials::Factory do
|
6
|
+
describe '.from_hash' do
|
7
|
+
subject { described_class.from_hash(credentials) }
|
8
|
+
context 'given a valid hbci credential hash' do
|
9
|
+
let(:credentials) { valid_hbci_credentials_with_type }
|
10
|
+
|
11
|
+
it { is_expected.to be_a(BankCredentials::Hbci) }
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'given a valid hbci credential hash without type' do
|
15
|
+
let(:credentials) { valid_hbci_credentials_without_type }
|
16
|
+
|
17
|
+
specify { expect { subject }.to raise_error(BankCredentials::Errors::Invalid) }
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'given a valid ebics credential hash without type' do
|
21
|
+
let(:credentials) { valid_ebics_credentials_without_type }
|
22
|
+
|
23
|
+
specify { expect { subject }.to raise_error(BankCredentials::Errors::Invalid) }
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'given a valid hbci credential hash' do
|
27
|
+
let(:credentials) { valid_ebics_credentials_with_type }
|
28
|
+
|
29
|
+
it { is_expected.to be_a(BankCredentials::Ebics) }
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'given an empty hash' do
|
33
|
+
let(:credentials) { {} }
|
34
|
+
|
35
|
+
specify { expect { subject }.to raise_error(BankCredentials::Errors::Invalid) }
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'given nil' do
|
39
|
+
let(:credentials) { nil }
|
40
|
+
|
41
|
+
specify { expect { subject }.to raise_error(BankCredentials::Errors::Invalid) }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '.from_encoded_json' do
|
46
|
+
let(:encoded_json) { Base64.urlsafe_encode64(credential_hash.to_json) }
|
47
|
+
|
48
|
+
context 'given a valid ebics credential hash' do
|
49
|
+
let(:credential_hash) { valid_ebics_credentials }
|
50
|
+
|
51
|
+
it 'returns an ebics credential object' do
|
52
|
+
expect(described_class.from_encoded_json(encoded_json)).to be_a(BankCredentials::Ebics)
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'initializes the credential object with the credential hash' do
|
56
|
+
expect(BankCredentials::Ebics).to receive(:new).with(credential_hash)
|
57
|
+
|
58
|
+
described_class.from_encoded_json(encoded_json)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'given a hbci credential hash' do
|
63
|
+
let(:credential_hash) { valid_hbci_credentials }
|
64
|
+
|
65
|
+
it 'returns an hbci credential object' do
|
66
|
+
expect(described_class.from_encoded_json(encoded_json)).to be_a(BankCredentials::Hbci)
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'initializes the credential object with the credential hash' do
|
70
|
+
expect(BankCredentials::Hbci).to receive(:new).with(credential_hash)
|
71
|
+
|
72
|
+
described_class.from_encoded_json(encoded_json)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'given nil' do
|
77
|
+
let(:encoded_json) { nil }
|
78
|
+
|
79
|
+
it 'raises an error' do
|
80
|
+
expect { described_class.from_encoded_json(encoded_json) }
|
81
|
+
.to raise_error(BankCredentials::Errors::Invalid)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context 'given an empty string' do
|
86
|
+
let(:encoded_json) { '' }
|
87
|
+
|
88
|
+
it 'raises an error' do
|
89
|
+
expect { described_class.from_encoded_json(encoded_json) }
|
90
|
+
.to raise_error(BankCredentials::Errors::Invalid)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context 'given unparseable json' do
|
95
|
+
let(:encoded_json) { 'asd' }
|
96
|
+
|
97
|
+
it 'raises an error' do
|
98
|
+
expect { described_class.from_encoded_json(encoded_json) }
|
99
|
+
.to raise_error(BankCredentials::Errors::Invalid)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
context 'given a hash' do
|
104
|
+
let(:encoded_json) { { a: 'asd' } }
|
105
|
+
|
106
|
+
it 'raises an error' do
|
107
|
+
expect { described_class.from_encoded_json(encoded_json) }
|
108
|
+
.to raise_error(BankCredentials::Errors::Invalid)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe BankCredentials::Hbci do
|
6
|
+
let(:credential_hash) { valid_hbci_credentials_without_type }
|
7
|
+
|
8
|
+
describe 'attribute readers' do
|
9
|
+
subject { described_class.new(credential_hash) }
|
10
|
+
|
11
|
+
it 'provides public access to the credentials' do
|
12
|
+
expect(subject.url).to eql('url')
|
13
|
+
expect(subject.bank_code).to eql('bank_code')
|
14
|
+
expect(subject.user_id).to eql('user_id')
|
15
|
+
expect(subject.pin).to eql('pin')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#valid?' do
|
20
|
+
it 'returns false when one of the keys is missing' do
|
21
|
+
%i[url bank_code user_id pin].each do |key|
|
22
|
+
expect(described_class.new(credential_hash.merge!(key => nil))).to_not be_valid
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'returns true when none of the keys is missing' do
|
27
|
+
expect(described_class.new(credential_hash)).to be_valid
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe 'validate!' do
|
32
|
+
it 'raises an error when one of the keys is missing' do
|
33
|
+
%i[url bank_code user_id pin].each do |key|
|
34
|
+
subject = described_class.new(credential_hash.merge!(key => nil), validate: false)
|
35
|
+
expect { subject.validate! }.to raise_error(BankCredentials::Hbci::Errors::Invalid)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#to_h' do
|
41
|
+
subject { described_class.new(credential_hash).to_h }
|
42
|
+
|
43
|
+
context 'when credential hash includes the type' do
|
44
|
+
let(:credential_hash) { valid_hbci_credentials_with_type }
|
45
|
+
|
46
|
+
it { is_expected.to eql(credential_hash) }
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'when credential hash excludes the type' do
|
50
|
+
let(:credential_hash) { valid_hbci_credentials_without_type }
|
51
|
+
|
52
|
+
it { is_expected.to eql(valid_hbci_credentials_with_type) }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe '#to_json' do
|
57
|
+
subject { described_class.new(credential_hash).to_json }
|
58
|
+
|
59
|
+
context 'when credential hash includes the type' do
|
60
|
+
let(:credential_hash) { valid_hbci_credentials_with_type }
|
61
|
+
|
62
|
+
it { is_expected.to eql(credential_hash.to_json) }
|
63
|
+
end
|
64
|
+
|
65
|
+
context 'when credential hash excludes the type' do
|
66
|
+
let(:credential_hash) { valid_hbci_credentials_without_type }
|
67
|
+
|
68
|
+
it { is_expected.to eql(valid_hbci_credentials_with_type.to_json) }
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe '#encode' do
|
73
|
+
subject { described_class.new(credential_hash).encode }
|
74
|
+
|
75
|
+
it 'returns the ursafe base64 encoded string' do
|
76
|
+
expect(subject).to eql(
|
77
|
+
Base64.urlsafe_encode64(described_class.new(credential_hash).to_json)
|
78
|
+
)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe described_class::Errors do
|
83
|
+
describe described_class::Empty do
|
84
|
+
describe '#to_s' do
|
85
|
+
it 'responds correct' do
|
86
|
+
expect(subject.to_s).to eql('Empty Hbci credentials')
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe described_class::Invalid do
|
92
|
+
describe '#to_s' do
|
93
|
+
it 'responds correct' do
|
94
|
+
expect(subject.to_s).to eql('Invalid Hbci credentials')
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
def valid_ebics_credentials
|
4
|
+
valid_ebics_credentials_with_type
|
5
|
+
end
|
6
|
+
|
7
|
+
def valid_ebics_credentials_without_type
|
8
|
+
{
|
9
|
+
key: 'key',
|
10
|
+
passphrase: 'passphrase',
|
11
|
+
url: 'https://localhost',
|
12
|
+
host_id: 'host_id',
|
13
|
+
user_id: 'user_id',
|
14
|
+
partner_id: 'partner_id'
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
def valid_ebics_credentials_with_type
|
19
|
+
valid_ebics_credentials_without_type.merge(type: 'ebics')
|
20
|
+
end
|
21
|
+
|
22
|
+
def valid_hbci_credentials
|
23
|
+
valid_hbci_credentials_with_type
|
24
|
+
end
|
25
|
+
|
26
|
+
def valid_hbci_credentials_without_type
|
27
|
+
{
|
28
|
+
url: 'url',
|
29
|
+
bank_code: 'bank_code',
|
30
|
+
user_id: 'user_id',
|
31
|
+
pin: 'pin'
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
def valid_hbci_credentials_with_type
|
36
|
+
valid_hbci_credentials_without_type.merge(type: 'hbci')
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bank_credentials
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.7
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Roman Lehnert
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-06-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: byebug
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3'
|
69
|
+
description: Encapsulates and validates the completeness of banking credentials for
|
70
|
+
ebics and hbci.
|
71
|
+
email:
|
72
|
+
- roman.lehnert@gmail.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".overcommit.yml"
|
79
|
+
- ".rspec"
|
80
|
+
- ".rubocop.yml"
|
81
|
+
- ".ruby-version"
|
82
|
+
- ".travis.yml"
|
83
|
+
- Gemfile
|
84
|
+
- LICENSE.txt
|
85
|
+
- README.md
|
86
|
+
- Rakefile
|
87
|
+
- bank_credentials.gemspec
|
88
|
+
- bin/console
|
89
|
+
- bin/setup
|
90
|
+
- lib/bank_credentials.rb
|
91
|
+
- lib/bank_credentials/base.rb
|
92
|
+
- lib/bank_credentials/ebics.rb
|
93
|
+
- lib/bank_credentials/errors/errors.rb
|
94
|
+
- lib/bank_credentials/factory.rb
|
95
|
+
- lib/bank_credentials/hbci.rb
|
96
|
+
- lib/bank_credentials/version.rb
|
97
|
+
- spec/bank_credentials/base_spec.rb
|
98
|
+
- spec/bank_credentials/ebics_spec.rb
|
99
|
+
- spec/bank_credentials/errors_spec.rb
|
100
|
+
- spec/bank_credentials/factory_spec.rb
|
101
|
+
- spec/bank_credentials/hbci_spec.rb
|
102
|
+
- spec/bank_credentials_spec.rb
|
103
|
+
- spec/spec_helper.rb
|
104
|
+
- spec/support/credentials.rb
|
105
|
+
homepage: https://github.com/fintastic/bank_credentials
|
106
|
+
licenses:
|
107
|
+
- MIT
|
108
|
+
metadata: {}
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 2.7.6
|
126
|
+
signing_key:
|
127
|
+
specification_version: 4
|
128
|
+
summary: A tiny ruby container for ebics and hbci credentials.
|
129
|
+
test_files: []
|