libis-services 0.1.13 → 0.1.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dd75c079899e08571582664c3c087ef2ff54f0e1
4
- data.tar.gz: 9ebb2a369af921f3bfc12ed9aa5581b9dbefd375
3
+ metadata.gz: 7db38a4eb15196da5b842234c33bef90de3a7cd4
4
+ data.tar.gz: 0c490da8e73129303e3da02979bbbb5df12c0e36
5
5
  SHA512:
6
- metadata.gz: 26cfe9bf38251f9bc4b2d0e734ee0d034d24123973be61e30151123b26e4dcd2babd3cd6fc6892ff56260d0353adf3e4b4f8751d593f278e92481cf4c5238a9c
7
- data.tar.gz: b9074b9884c100fb78caaceb7ea8093228be2c15742298b039f75f4109a7a8f43fce76117a26323064e2e8cb68787b6df3c05deb14a3fd80f7cc11c3c0e7d341
6
+ metadata.gz: cbd5bc933be2b7ff6b44575f363be498c6d3ebcb28968c34b12384500721a0f6b3b8e92733d3b1d32d8eb7770aeb30c5551eb00dbc4d69e13dd5b650f7ff3134
7
+ data.tar.gz: f19c32dc6ca5e041c6e4a8e1c237e2e9ad2793803e65c88099e6979ce94b42012584e69d3fe7f14a9d5163b0972baadcac3a6a475067979dfb918188b38808ba
@@ -19,6 +19,13 @@ module Libis
19
19
  include ::Libis::Tools::Logger
20
20
 
21
21
  def initialize(section, service, options = {})
22
+ basic_auth = options.delete(:basic_auth)
23
+ if basic_auth
24
+ options[:basic_auth] = [
25
+ "#{basic_auth[:user]}-institutionCode-#{basic_auth[:institution]}",
26
+ basic_auth[:password]
27
+ ]
28
+ end
22
29
  opts = {strip_namespaces: true, logger: ::Libis::Tools::Config.logger}.merge options
23
30
  base_url = opts.delete(:url) || 'http://depot.lias.be'
24
31
  configure "#{base_url}/dpsws/#{section}/#{service}?wsdl", opts
@@ -29,7 +36,8 @@ module Libis
29
36
  end
30
37
 
31
38
  def authenticate(user, password, institution)
32
- @basic_auth = Base64.encode64 "#{user}-institutionCode-#{institution}:#{password}"
39
+ code = Base64.encode64("#{user}-institutionCode-#{institution}:#{password}").gsub("\n", '')
40
+ @auth = "Basic #{code}"
33
41
  end
34
42
 
35
43
  def get_heart_bit
@@ -39,8 +47,8 @@ module Libis
39
47
  protected
40
48
 
41
49
  def call_raw(operation, args = {})
42
- data = if @basic_auth
43
- request operation.to_s.to_sym, args, headers: ['Authenticate', @basic_auth]
50
+ data = if @auth
51
+ request operation.to_s.to_sym, args, headers: {'Authorization' => @auth}
44
52
  else
45
53
  request operation.to_s.to_sym, args
46
54
  end
@@ -65,7 +73,7 @@ module Libis
65
73
  empty_tag_value: nil,
66
74
  delete_namespace_attributes: true,
67
75
  strip_namespaces: true,
68
- convert_tags_to: lambda { |tag| tag.to_sym }
76
+ convert_tags_to: lambda {|tag| tag.to_sym}
69
77
  )
70
78
  data = xml_data unless xml_data.empty?
71
79
  end
@@ -108,7 +116,7 @@ module Libis
108
116
 
109
117
  def request_object_array(method, klass, args = {})
110
118
  data = request_array(method, args)
111
- data.map { |x| klass.new(x) }
119
+ data.map {|x| klass.new(x)}
112
120
  end
113
121
 
114
122
  end
@@ -1,5 +1,5 @@
1
1
  module Libis
2
2
  module Services
3
- VERSION = '0.1.13'
3
+ VERSION = '0.1.14'
4
4
  end
5
5
  end
@@ -9,6 +9,19 @@ require 'libis/services/rosetta/producer_handler'
9
9
 
10
10
  describe 'Rosetta Services' do
11
11
 
12
+ def protected_call(handler, producer_id, producer_name)
13
+ result = handler.producer(producer_id)
14
+ expect(result.authoritative_name).to eq producer_name
15
+ end
16
+
17
+ def failed_protected_call(handler, producer_id)
18
+ expect {handler.producer(producer_id)}.to raise_error(Libis::Services::ServiceError, /^Incorrect username or password/)
19
+ end
20
+
21
+ def invalid_protected_call(handler, producer_id)
22
+ expect {handler.producer(producer_id)}.to raise_error(Libis::Services::ServiceError)
23
+ end
24
+
12
25
  let!(:credentials) {Libis::Tools::ConfigFile.new File.join(File.dirname(__FILE__), 'credentials-test.yml')}
13
26
 
14
27
  # noinspection RubyResolve
@@ -24,51 +37,61 @@ describe 'Rosetta Services' do
24
37
 
25
38
  let(:bad_cred) { 'deadbeaf' }
26
39
 
27
- let(:handler) do
28
- # noinspection RubyResolve
29
- handler = Libis::Services::Rosetta::ProducerHandler.new(
30
- credentials.rosetta_url,
31
- log: credentials.debug,
32
- log_level: credentials.debug_level
33
- )
34
- handler
35
- end
36
-
37
40
  describe 'basic authentication' do
38
41
 
42
+ let(:handler) do
43
+ # noinspection RubyResolve
44
+ handler = Libis::Services::Rosetta::ProducerHandler.new(
45
+ credentials.rosetta_url,
46
+ # log: credentials.debug,
47
+ # log_level: credentials.debug_level
48
+ )
49
+ handler
50
+ end
51
+
39
52
  let(:user_name) {admin_usr}
40
53
  let(:user_id) {admin_uid}
54
+ let(:producer_id) {credentials.producer.id}
55
+ let(:producer_name) {credentials.producer.data.authoritative_name}
41
56
 
42
57
  it 'should allow protected call with correct login' do
43
58
  handler.authenticate(admin_usr, admin_pwd, admin_ins)
44
- result = handler.user_id(user_name)
45
- expect(result).to eq user_id
59
+ protected_call(handler, producer_id, producer_name)
46
60
  end
47
61
 
48
62
  it 'should fail protected call with wrong password' do
49
63
  handler.authenticate(admin_usr, bad_cred, admin_ins)
50
- result = handler.user_id(user_name)
51
- expect(result).to eq user_id
64
+ failed_protected_call(handler, producer_id)
52
65
  end
53
66
 
54
67
  it 'should fail protected call with wrong institution' do
55
68
  handler.authenticate(admin_usr, admin_pwd, bad_cred)
56
- result = handler.user_id(user_name)
57
- expect(result).to eq user_id
69
+ failed_protected_call(handler, producer_id)
58
70
  end
59
71
 
60
72
  it 'should fail protected call with wrong user name' do
61
73
  handler.authenticate(bad_cred, admin_pwd, admin_ins)
62
- result = handler.user_id(user_name)
63
- expect(result).to eq user_id
74
+ failed_protected_call(handler, producer_id)
64
75
  end
65
76
 
66
77
  end
67
78
 
68
79
  describe 'PDS authentication' do
69
80
 
81
+ let(:handler) do
82
+ # noinspection RubyResolve
83
+ handler = Libis::Services::Rosetta::ProducerHandler.new(
84
+ credentials.rosetta_url,
85
+ # log: credentials.debug,
86
+ # log_level: credentials.debug_level
87
+ )
88
+ handler
89
+ end
90
+
70
91
  let(:user_name) {admin_usr}
71
92
  let(:user_id) {admin_uid}
93
+ let(:producer_id) {credentials.producer.id}
94
+ let(:producer_name) {credentials.producer.data.authoritative_name}
72
95
 
73
96
  let!(:pds_handler) do
74
97
  # noinspection RubyResolve
@@ -92,8 +115,7 @@ describe 'Rosetta Services' do
92
115
 
93
116
  it 'should allow protected call' do
94
117
  handler.pds_handle = handle
95
- result = handler.user_id(user_name)
96
- expect(result).to eq user_id
118
+ protected_call(handler, producer_id, producer_name)
97
119
  end
98
120
 
99
121
  it 'should logout using a valid handle' do
@@ -111,8 +133,7 @@ describe 'Rosetta Services' do
111
133
 
112
134
  it 'should fail protected call' do
113
135
  handler.pds_handle = handle
114
- result = handler.user_id(user_name)
115
- expect(result).to eq user_id
136
+ invalid_protected_call(handler, producer_id)
116
137
  end
117
138
 
118
139
  it 'should logout using a invalid handle' do
@@ -130,8 +151,7 @@ describe 'Rosetta Services' do
130
151
 
131
152
  it 'should fail protected call' do
132
153
  handler.pds_handle = handle
133
- result = handler.user_id(user_name)
134
- expect(result).to eq user_id
154
+ invalid_protected_call(handler, producer_id)
135
155
  end
136
156
 
137
157
  it 'should logout using a invalid handle' do
@@ -150,8 +170,7 @@ describe 'Rosetta Services' do
150
170
 
151
171
  it 'should fail protected call' do
152
172
  handler.pds_handle = handle
153
- result = handler.user_id(user_name)
154
- expect(result).to eq user_id
173
+ invalid_protected_call(handler, producer_id)
155
174
  end
156
175
 
157
176
  it 'should logout using a invalid handle' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libis-services
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.13
4
+ version: 0.1.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kris Dekeyser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-23 00:00:00.000000000 Z
11
+ date: 2018-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler