campact_user_service 2.1.0 → 3.0.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3b0513f2476df68b252bde86d4c01cd15083a3b15d70b1271ea7cc7e91f561ca
4
- data.tar.gz: b7a5a2704358150a531a83c8eba2f35ed69a5c120909fb0934e678411bdf9363
3
+ metadata.gz: 0cd0c2841ffadf7445944b27cd650a6655159f0fb0ac9081929270709cc48028
4
+ data.tar.gz: 7717cd9eb790c374226fc69468dc369cea48f5b890bb75f2be6dce115114cec7
5
5
  SHA512:
6
- metadata.gz: 554fbdaddfd67c2f0202af102663e19410beaad922515cd26185c66eadf9a616c390ea3f332670d6fb2e5a1aaa1b9e6737f851d56603a6f11d3492885757789b
7
- data.tar.gz: 8634b8e0f32a8a6cea5381d2f3733bad46e885cf01fe4df5c68e60547f70a8a2dc2872fe640853542fe49a31978ab193e5a8df7981da7e6dfa25b926f6acddba
6
+ metadata.gz: 3b9faf2ed1c4e4a613dbf6535442531079bf682cd783dd6d837bf51fa8b491f473c32bcc147e47815eef1ebf0dec6f2eacd2e14f30bc150f56dd309de60f760a
7
+ data.tar.gz: 7d55743e0bc670e97423376fa151c1dae7e8a604a8cd66757bb2b05ae3ab9ac4e93d393eaf52cf86fc4743556f170b8b26dc811acf9690924630646e2fed4f2f
@@ -0,0 +1,26 @@
1
+ AllCops:
2
+ DisabledByDefault: true
3
+
4
+ Security:
5
+ Enabled: true
6
+
7
+ Bundler/DuplicatedGem:
8
+ Enabled: true
9
+ Bundler/InsecureProtocolSource:
10
+ Enabled: true
11
+ Layout/IndentationStyle:
12
+ Enabled: true
13
+ Layout/SpaceInsideRangeLiteral:
14
+ Enabled: true
15
+ Lint:
16
+ Enabled: true
17
+ Lint/RaiseException:
18
+ Enabled: true
19
+ Naming/AsciiIdentifiers:
20
+ Enabled: true
21
+ Naming/ClassAndModuleCamelCase:
22
+ Enabled: true
23
+ Naming/ConstantName:
24
+ Enabled: true
25
+ Naming/FileName:
26
+ Enabled: true
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.6
4
+ cache: bundler
5
+ before_install:
6
+ - gem install bundler
7
+ script:
8
+ - bundle exec rspec
9
+ - bundle exec rubocop
data/Gemfile CHANGED
@@ -1,7 +1,7 @@
1
1
  source "https://rubygems.org"
2
2
 
3
3
  gem 'base32', '~> 0.3.2'
4
- gem 'rotp', '~> 3.3', '>= 3.3.1'
4
+ gem 'rotp', '~> 6'
5
5
  gem 'faraday', '>= 0.12.2', '< 1.0'
6
6
  gem 'json', '~> 2.1'
7
7
 
@@ -11,9 +11,9 @@ group :development do
11
11
  gem 'shoulda', '>= 0'
12
12
  gem 'webmock', '>= 0'
13
13
  gem 'rdoc', '~> 6.0', '>= 6.0.4'
14
- gem 'bundler', '~> 1.16', '>= 1.16.2'
15
14
  gem 'juwelier', git: 'https://github.com/flajann2/juwelier.git'
16
15
  gem 'simplecov', '= 0.16.1'
17
16
  gem 'pry-byebug', '~> 3.6'
18
17
  gem 'faraday-detailed_logger', '~> 2.1', '>= 2.1.2'
18
+ gem 'rubocop'
19
19
  end
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
1
  # campact-user-service
2
+ [![Build Status](https://travis-ci.org/controlshift/campact-user-service.svg?branch=master)](https://travis-ci.org/controlshift/campact-user-service)
3
+
2
4
  a ruby gem that wraps the Campact user service API
3
5
 
4
6
  ## License
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.1.0
1
+ 3.0.0
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: campact_user_service 2.1.0 ruby lib
5
+ # stub: campact_user_service 3.0.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "campact_user_service".freeze
9
- s.version = "2.1.0"
9
+ s.version = "3.0.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
13
13
  s.authors = ["ControlShift".freeze]
14
- s.date = "2020-04-30"
14
+ s.date = "2020-06-25"
15
15
  s.description = "Ruby wrapper for Campact User Service".freeze
16
16
  s.email = "hello@controlshiftlabs.com".freeze
17
17
  s.extra_rdoc_files = [
@@ -19,8 +19,10 @@ Gem::Specification.new do |s|
19
19
  "README.md"
20
20
  ]
21
21
  s.files = [
22
+ ".rubocop.yml",
22
23
  ".ruby-gemset",
23
24
  ".ruby-version",
25
+ ".travis.yml",
24
26
  "Gemfile",
25
27
  "LICENSE",
26
28
  "README.md",
@@ -41,43 +43,28 @@ Gem::Specification.new do |s|
41
43
  ]
42
44
  s.homepage = "http://github.com/controlshift/campact_user_service".freeze
43
45
  s.licenses = ["MIT".freeze]
44
- s.rubygems_version = "3.0.8".freeze
46
+ s.rubygems_version = "3.1.2".freeze
45
47
  s.summary = "Ruby wrapper for Campact User Service".freeze
46
48
 
47
49
  if s.respond_to? :specification_version then
48
50
  s.specification_version = 4
51
+ end
49
52
 
50
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
51
- s.add_runtime_dependency(%q<base32>.freeze, ["~> 0.3.2"])
52
- s.add_runtime_dependency(%q<rotp>.freeze, ["~> 3.3", ">= 3.3.1"])
53
- s.add_runtime_dependency(%q<faraday>.freeze, [">= 0.12.2", "< 1.0"])
54
- s.add_runtime_dependency(%q<json>.freeze, ["~> 2.1"])
55
- s.add_development_dependency(%q<byebug>.freeze, [">= 0"])
56
- s.add_development_dependency(%q<rspec>.freeze, [">= 0"])
57
- s.add_development_dependency(%q<shoulda>.freeze, [">= 0"])
58
- s.add_development_dependency(%q<webmock>.freeze, [">= 0"])
59
- s.add_development_dependency(%q<rdoc>.freeze, ["~> 6.0", ">= 6.0.4"])
60
- s.add_development_dependency(%q<bundler>.freeze, ["~> 1.16", ">= 1.16.2"])
61
- s.add_development_dependency(%q<juwelier>.freeze, [">= 0"])
62
- s.add_development_dependency(%q<simplecov>.freeze, ["= 0.16.1"])
63
- s.add_development_dependency(%q<pry-byebug>.freeze, ["~> 3.6"])
64
- s.add_development_dependency(%q<faraday-detailed_logger>.freeze, ["~> 2.1", ">= 2.1.2"])
65
- else
66
- s.add_dependency(%q<base32>.freeze, ["~> 0.3.2"])
67
- s.add_dependency(%q<rotp>.freeze, ["~> 3.3", ">= 3.3.1"])
68
- s.add_dependency(%q<faraday>.freeze, [">= 0.12.2", "< 1.0"])
69
- s.add_dependency(%q<json>.freeze, ["~> 2.1"])
70
- s.add_dependency(%q<byebug>.freeze, [">= 0"])
71
- s.add_dependency(%q<rspec>.freeze, [">= 0"])
72
- s.add_dependency(%q<shoulda>.freeze, [">= 0"])
73
- s.add_dependency(%q<webmock>.freeze, [">= 0"])
74
- s.add_dependency(%q<rdoc>.freeze, ["~> 6.0", ">= 6.0.4"])
75
- s.add_dependency(%q<bundler>.freeze, ["~> 1.16", ">= 1.16.2"])
76
- s.add_dependency(%q<juwelier>.freeze, [">= 0"])
77
- s.add_dependency(%q<simplecov>.freeze, ["= 0.16.1"])
78
- s.add_dependency(%q<pry-byebug>.freeze, ["~> 3.6"])
79
- s.add_dependency(%q<faraday-detailed_logger>.freeze, ["~> 2.1", ">= 2.1.2"])
80
- end
53
+ if s.respond_to? :add_runtime_dependency then
54
+ s.add_runtime_dependency(%q<base32>.freeze, ["~> 0.3.2"])
55
+ s.add_runtime_dependency(%q<rotp>.freeze, ["~> 3.3", ">= 3.3.1"])
56
+ s.add_runtime_dependency(%q<faraday>.freeze, [">= 0.12.2", "< 1.0"])
57
+ s.add_runtime_dependency(%q<json>.freeze, ["~> 2.1"])
58
+ s.add_development_dependency(%q<byebug>.freeze, [">= 0"])
59
+ s.add_development_dependency(%q<rspec>.freeze, [">= 0"])
60
+ s.add_development_dependency(%q<shoulda>.freeze, [">= 0"])
61
+ s.add_development_dependency(%q<webmock>.freeze, [">= 0"])
62
+ s.add_development_dependency(%q<rdoc>.freeze, ["~> 6.0", ">= 6.0.4"])
63
+ s.add_development_dependency(%q<juwelier>.freeze, [">= 0"])
64
+ s.add_development_dependency(%q<simplecov>.freeze, ["= 0.16.1"])
65
+ s.add_development_dependency(%q<pry-byebug>.freeze, ["~> 3.6"])
66
+ s.add_development_dependency(%q<faraday-detailed_logger>.freeze, ["~> 2.1", ">= 2.1.2"])
67
+ s.add_development_dependency(%q<rubocop>.freeze, [">= 0"])
81
68
  else
82
69
  s.add_dependency(%q<base32>.freeze, ["~> 0.3.2"])
83
70
  s.add_dependency(%q<rotp>.freeze, ["~> 3.3", ">= 3.3.1"])
@@ -88,11 +75,11 @@ Gem::Specification.new do |s|
88
75
  s.add_dependency(%q<shoulda>.freeze, [">= 0"])
89
76
  s.add_dependency(%q<webmock>.freeze, [">= 0"])
90
77
  s.add_dependency(%q<rdoc>.freeze, ["~> 6.0", ">= 6.0.4"])
91
- s.add_dependency(%q<bundler>.freeze, ["~> 1.16", ">= 1.16.2"])
92
78
  s.add_dependency(%q<juwelier>.freeze, [">= 0"])
93
79
  s.add_dependency(%q<simplecov>.freeze, ["= 0.16.1"])
94
80
  s.add_dependency(%q<pry-byebug>.freeze, ["~> 3.6"])
95
81
  s.add_dependency(%q<faraday-detailed_logger>.freeze, ["~> 2.1", ">= 2.1.2"])
82
+ s.add_dependency(%q<rubocop>.freeze, [">= 0"])
96
83
  end
97
84
  end
98
85
 
data/example.rb CHANGED
@@ -3,7 +3,7 @@ $LOAD_PATH << File.join(File.dirname(__FILE__), 'lib')
3
3
  require 'campact_user_service'
4
4
  require 'faraday/detailed_logger'
5
5
 
6
- def instrument_connection_with_extended_logging(client, username, password)
6
+ def instrument_connection_with_extended_logging(client)
7
7
  default_options = {
8
8
  ssl: { verify: true },
9
9
  headers: {
@@ -15,12 +15,11 @@ def instrument_connection_with_extended_logging(client, username, password)
15
15
 
16
16
  faraday_builder = ->(faraday) do
17
17
  faraday.response :detailed_logger
18
- faraday.basic_auth username, password
19
18
  faraday.adapter Faraday.default_adapter
20
19
  end
21
20
 
22
21
  instrumented_connection = Faraday.new(
23
- "#{client.scheme}://#{client.host}:#{client.port}",
22
+ "https://#{client.host}",
24
23
  default_options,
25
24
  &faraday_builder
26
25
  )
@@ -33,14 +32,21 @@ end
33
32
  puts "Which user service are you going to use?\n\t1) session\n\t2) user"
34
33
  option = gets.chomp
35
34
 
36
- # Get username
37
- puts "I'll need your API credentials"
38
- puts "Enter your API username"
39
- username = gets.chomp
35
+ # Get TOTP credentials
36
+ username = if ENV['TOTP_USER'].nil?
37
+ puts "I'll need your API credentials"
38
+ puts "Enter your TOTP user"
39
+ gets.chomp
40
+ else
41
+ ENV['TOTP_USER']
42
+ end
40
43
 
41
- # Get password
42
- puts "I'll need your password now"
43
- password = gets.chomp
44
+ secret = if ENV['TOTP_SECRET'].nil?
45
+ puts "Enter your TOTP secret"
46
+ gets.chomp
47
+ else
48
+ ENV['TOTP_SECRET']
49
+ end
44
50
 
45
51
  # Now connect to the right API
46
52
  user_service = case option
@@ -49,11 +55,10 @@ when '1'
49
55
  token = gets.chomp
50
56
  session = CampactUserService.session(
51
57
  token,
52
- 'campact-demo-session',
58
+ 'campact-staging-session',
53
59
  {
54
- scheme: 'http',
55
- host: 'demo.campact.de',
56
- port: '10004'
60
+ host: 'weact-adapter.staging.campact.de',
61
+ topt_authorization: {user: username, secret: secret}
57
62
  }
58
63
  )
59
64
  when '2'
@@ -62,19 +67,18 @@ when '2'
62
67
  account = CampactUserService.account(
63
68
  user_id,
64
69
  {
65
- scheme: 'http',
66
- host: 'demo.campact.de',
67
- port: '10003'
70
+ host: 'weact-adapter.staging.campact.de',
71
+ topt_authorization: {user: username, secret: secret}
68
72
  }
69
73
  )
70
74
  else
71
75
  raise 'Invalid option'
72
76
  end
73
77
 
74
- instrument_connection_with_extended_logging(user_service.client, username, password)
78
+ instrument_connection_with_extended_logging(user_service.client)
75
79
 
76
80
  puts "Waiting for your command..."
77
81
  require 'pry-byebug'
78
- binding.pry
82
+ binding.pry # rubocop:disable Lint/Debugger
79
83
 
80
- puts 'Goodbye!'
84
+ puts 'Goodbye!'
@@ -8,7 +8,7 @@ module CampactUserService
8
8
  end
9
9
 
10
10
  def exists?
11
- account && account["id"]
11
+ account && !account["id"].nil?
12
12
  end
13
13
 
14
14
  def subscribed_to_newsletter?
@@ -37,15 +37,11 @@ module CampactUserService
37
37
  account['preferences']
38
38
  end
39
39
 
40
- def donor_info
41
- account['donorclass']
42
- end
43
-
44
40
  private
45
41
 
46
42
  def account
47
43
  escaped_user_id = CGI.escape(user_id)
48
- @account_info ||= (client.get_request("api/v1/accounts/#{escaped_user_id}") || {})
44
+ @account_info ||= (client.get_request("v1/accounts/#{escaped_user_id}") || {})
49
45
  end
50
46
  end
51
47
  end
@@ -8,19 +8,16 @@ module CampactUserService
8
8
  class Client
9
9
  TIMEOUT = 5.freeze
10
10
 
11
- attr_reader :connection, :scheme, :host, :port
11
+ attr_reader :connection, :host, :port, :topt_authorization
12
12
 
13
13
  def initialize(options)
14
- @scheme = options.fetch(:scheme, 'https')
15
14
  @host = options.fetch(:host)
16
15
  @port = options[:port]
16
+ @topt_authorization = options[:topt_authorization]
17
17
  faraday_options = default_faraday_options.merge(options.delete(:faraday) || {})
18
18
  adapter = faraday_options.delete(:adapter) || Faraday.default_adapter
19
19
 
20
20
  @connection = Faraday.new(endpoint, faraday_options) do |faraday|
21
- if options.has_key?(:enable_auth)
22
- faraday.basic_auth options[:username], options[:password]
23
- end
24
21
  faraday.adapter adapter
25
22
  end
26
23
  end
@@ -38,9 +35,13 @@ module CampactUserService
38
35
  req.url path
39
36
  req.options.timeout = TIMEOUT
40
37
  req.options.open_timeout = TIMEOUT
41
- if options.has_key?(:cookies)
38
+ if options.key?(:cookies)
42
39
  req.headers['Cookie'] = format_cookies(options[:cookies])
43
40
  end
41
+
42
+ if topt_authorization
43
+ req.headers['authorization'] = authorization(topt_authorization)
44
+ end
44
45
  end
45
46
 
46
47
  case response.status
@@ -70,7 +71,7 @@ module CampactUserService
70
71
  end
71
72
 
72
73
  def endpoint
73
- endpoint = "#{scheme}://#{host}"
74
+ endpoint = "https://#{host}"
74
75
  if !port.nil?
75
76
  endpoint << ":#{port}"
76
77
  end
@@ -86,5 +87,24 @@ module CampactUserService
86
87
  cookies.map {|k,v| "#{k}=#{v};" }.join
87
88
  end
88
89
  end
90
+
91
+ def authorization(totp_options)
92
+ user = totp_options.fetch(:user)
93
+ secret = totp_options.fetch(:secret)
94
+
95
+ token = [user, auth_pass(secret)].join(':')
96
+
97
+ "Token #{token}"
98
+ end
99
+
100
+ def auth_pass(secret)
101
+ totp_secret = ROTP::Base32.encode(secret)
102
+
103
+ ROTP::TOTP.new(totp_secret, {
104
+ digest: 'sha256',
105
+ digits: 8,
106
+ interval: 30
107
+ }).now
108
+ end
89
109
  end
90
110
  end
@@ -16,7 +16,7 @@ describe CampactUserService::Account do
16
16
 
17
17
  describe '#exists?' do
18
18
  it 'should return true where a valid user object is returned' do
19
- stub_request(:get, "https://test.com/api/v1/accounts/#{user_id}")
19
+ stub_request(:get, "https://test.com/v1/accounts/#{user_id}")
20
20
  .to_return(body: {
21
21
  "id": "id-123"
22
22
  }.to_json)
@@ -25,7 +25,7 @@ describe CampactUserService::Account do
25
25
  end
26
26
 
27
27
  it 'should not return true where an invalid user object is returned' do
28
- stub_request(:get, "https://test.com/api/v1/accounts/#{user_id}")
28
+ stub_request(:get, "https://test.com/v1/accounts/#{user_id}")
29
29
  .to_return(body: {
30
30
  "error": true
31
31
  }.to_json)
@@ -41,7 +41,7 @@ describe CampactUserService::Account do
41
41
  client,
42
42
  malicious_user_id
43
43
  )
44
- stub_request(:get, "https://test.com/api/v1/accounts/%09%0D")
44
+ stub_request(:get, "https://test.com/v1/accounts/%09%0D")
45
45
  .to_return(body: '', status: 404)
46
46
 
47
47
  expect(malicious_subject.exists?).to be_falsey
@@ -53,7 +53,7 @@ describe CampactUserService::Account do
53
53
  client,
54
54
  malicious_user_id
55
55
  )
56
- stub_request(:get, "https://test.com/api/v1/accounts/foo@example.com%2Fsecrets")
56
+ stub_request(:get, "https://test.com/v1/accounts/foo@example.com%2Fsecrets")
57
57
  .to_return(body: '', status: 404)
58
58
 
59
59
  expect(malicious_subject.exists?).to be_falsey
@@ -62,7 +62,7 @@ describe CampactUserService::Account do
62
62
 
63
63
  describe '#name' do
64
64
  it 'should retrieve all of the names and gender of the user' do
65
- stub_request(:get, "https://test.com/api/v1/accounts/#{user_id}")
65
+ stub_request(:get, "https://test.com/v1/accounts/#{user_id}")
66
66
  .to_return(body: {
67
67
  "name": {
68
68
  "firstname": "Alice",
@@ -84,7 +84,7 @@ describe CampactUserService::Account do
84
84
 
85
85
  describe '#email' do
86
86
  it 'should retrieve the email address of the user' do
87
- stub_request(:get, "https://test.com/api/v1/accounts/#{user_id}")
87
+ stub_request(:get, "https://test.com/v1/accounts/#{user_id}")
88
88
  .to_return(body: {
89
89
  "emailaddress": {
90
90
  "emailaddress": "foobar@example.com"
@@ -96,7 +96,7 @@ describe CampactUserService::Account do
96
96
  end
97
97
 
98
98
  it 'should return nil where no email address is set' do
99
- stub_request(:get, "https://test.com/api/v1/accounts/#{user_id}")
99
+ stub_request(:get, "https://test.com/v1/accounts/#{user_id}")
100
100
  .to_return(body: {
101
101
  "emailaddress": {}
102
102
  }.to_json)
@@ -108,7 +108,7 @@ describe CampactUserService::Account do
108
108
 
109
109
  describe '#address' do
110
110
  it 'should retrieve the address of the user' do
111
- stub_request(:get, "https://test.com/api/v1/accounts/#{user_id}")
111
+ stub_request(:get, "https://test.com/v1/accounts/#{user_id}")
112
112
  .to_return(body: {
113
113
  "postaladdress": {
114
114
  "street": "123 Fake Street",
@@ -125,7 +125,7 @@ describe CampactUserService::Account do
125
125
 
126
126
  describe '#subscribed_to_newsletter?' do
127
127
  it 'should be true where the user is subscribed' do
128
- stub_request(:get, "https://test.com/api/v1/accounts/#{user_id}")
128
+ stub_request(:get, "https://test.com/v1/accounts/#{user_id}")
129
129
  .to_return(body: {
130
130
  "emailaddress": {
131
131
  "emailaddress": "foobar@example.com",
@@ -137,7 +137,7 @@ describe CampactUserService::Account do
137
137
  end
138
138
 
139
139
  it 'should be false where the user is not subscribed' do
140
- stub_request(:get, "https://test.com/api/v1/accounts/#{user_id}")
140
+ stub_request(:get, "https://test.com/v1/accounts/#{user_id}")
141
141
  .to_return(body: {
142
142
  "emailaddress": {
143
143
  "emailaddress": "foobar@example.com",
@@ -149,7 +149,7 @@ describe CampactUserService::Account do
149
149
  end
150
150
 
151
151
  it 'should be false where user subscription is different than newsletter' do
152
- stub_request(:get, "https://test.com/api/v1/accounts/#{user_id}")
152
+ stub_request(:get, "https://test.com/v1/accounts/#{user_id}")
153
153
  .to_return(body: {
154
154
  "emailaddress": {
155
155
  "emailaddress": "foobar@example.com",
@@ -163,7 +163,7 @@ describe CampactUserService::Account do
163
163
 
164
164
  describe '#allow_prefill?' do
165
165
  it 'should allow prefilling where the user has opted-in' do
166
- stub_request(:get, "https://test.com/api/v1/accounts/#{user_id}")
166
+ stub_request(:get, "https://test.com/v1/accounts/#{user_id}")
167
167
  .to_return(body: {
168
168
  "preferences": {
169
169
  "prefill_forms": "allowed"
@@ -174,7 +174,7 @@ describe CampactUserService::Account do
174
174
  end
175
175
 
176
176
  it 'should not allow prefilling where the user has not decided' do
177
- stub_request(:get, "https://test.com/api/v1/accounts/#{user_id}")
177
+ stub_request(:get, "https://test.com/v1/accounts/#{user_id}")
178
178
  .to_return(body: {
179
179
  "preferences": {
180
180
  "prefill_forms": "undecided"
@@ -185,7 +185,7 @@ describe CampactUserService::Account do
185
185
  end
186
186
 
187
187
  it 'should not allow prefilling where the user has opted out' do
188
- stub_request(:get, "https://test.com/api/v1/accounts/#{user_id}")
188
+ stub_request(:get, "https://test.com/v1/accounts/#{user_id}")
189
189
  .to_return(body: {
190
190
  "preferences": {
191
191
  "prefill_forms": "disallowed"
@@ -4,7 +4,6 @@ describe CampactUserService::Client do
4
4
  describe 'initialization' do
5
5
  let(:options) {
6
6
  {
7
- scheme: 'https',
8
7
  host: 'demo.campact.de',
9
8
  port: '10003',
10
9
  faraday: { a_custom_option: 'foo', adapter: :an_adapter }
@@ -24,7 +23,7 @@ describe CampactUserService::Client do
24
23
  end
25
24
 
26
25
  it 'should use default faraday options for connection' do
27
- expect(Faraday).to receive(:new) do |endpoint, initialization_options|
26
+ expect(Faraday).to receive(:new) do |_endpoint, initialization_options|
28
27
  expect(initialization_options[:ssl][:verify]).to be_truthy
29
28
  expect(initialization_options[:headers]['Accept']).to eq "application/json;q=0.1"
30
29
  expect(initialization_options[:headers]['Accept-Charset']).to eq "utf-8"
@@ -38,7 +37,7 @@ describe CampactUserService::Client do
38
37
  options[:faraday][:ssl] = {verify: false}
39
38
  options[:faraday][:headers] = {'Accept'=>'custom-accept-header', 'Accept-Charset'=>'custom-accept-charset-header', 'User-Agent'=>'custom-user-agent-header'}
40
39
 
41
- expect(Faraday).to receive(:new) do |endpoint, initialization_options|
40
+ expect(Faraday).to receive(:new) do |_endpoint, initialization_options|
42
41
  expect(initialization_options[:ssl][:verify]).to be_falsey
43
42
  expect(initialization_options[:headers]['Accept']).to eq 'custom-accept-header'
44
43
  expect(initialization_options[:headers]['Accept-Charset']).to eq 'custom-accept-charset-header'
@@ -128,6 +127,23 @@ describe CampactUserService::Client do
128
127
  subject.get_request('/foo/bar', cookies: {'foo' => 'bar', 'xyz' => 'abc'})
129
128
  end
130
129
 
130
+ it 'should set TOTP authorization header' do
131
+ allow(response).to receive(:status).and_return(200)
132
+ allow(response).to receive(:body).and_return(nil)
133
+
134
+ totp_secret = Base32.encode('shh! a secret!').gsub('=', '')
135
+
136
+ totp = double
137
+ expect(totp).to receive(:now).and_return('totp_token')
138
+ expect(ROTP::TOTP).to receive(:new).with(totp_secret, hash_including(digest: 'sha256', digits: 8, interval: 30)).and_return(totp)
139
+
140
+ expect(headers_builder).to receive(:[]=).with('authorization', 'Token api_user:totp_token')
141
+
142
+ subject = CampactUserService::Client.new(host: 'demo.campact.de', topt_authorization: {user: 'api_user', secret: 'shh! a secret!'})
143
+
144
+ subject.get_request('/foo/bar')
145
+ end
146
+
131
147
  it 'should parse JSON response on successful response' do
132
148
  allow(response).to receive(:status).and_return(200)
133
149
  allow(response).to receive(:body).and_return({a_field: 'foo', another_field: 'bar'}.to_json)
@@ -4,7 +4,7 @@ require 'rspec'
4
4
  require 'webmock/rspec'
5
5
  require 'campact_user_service'
6
6
 
7
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
7
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each {|f| require f}
8
8
 
9
9
  RSpec.configure do |config|
10
10
  config.include WebMock::API
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: campact_user_service
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ControlShift
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-30 00:00:00.000000000 Z
11
+ date: 2020-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base32
@@ -154,26 +154,6 @@ dependencies:
154
154
  - - ">="
155
155
  - !ruby/object:Gem::Version
156
156
  version: 6.0.4
157
- - !ruby/object:Gem::Dependency
158
- name: bundler
159
- requirement: !ruby/object:Gem::Requirement
160
- requirements:
161
- - - "~>"
162
- - !ruby/object:Gem::Version
163
- version: '1.16'
164
- - - ">="
165
- - !ruby/object:Gem::Version
166
- version: 1.16.2
167
- type: :development
168
- prerelease: false
169
- version_requirements: !ruby/object:Gem::Requirement
170
- requirements:
171
- - - "~>"
172
- - !ruby/object:Gem::Version
173
- version: '1.16'
174
- - - ">="
175
- - !ruby/object:Gem::Version
176
- version: 1.16.2
177
157
  - !ruby/object:Gem::Dependency
178
158
  name: juwelier
179
159
  requirement: !ruby/object:Gem::Requirement
@@ -236,6 +216,20 @@ dependencies:
236
216
  - - ">="
237
217
  - !ruby/object:Gem::Version
238
218
  version: 2.1.2
219
+ - !ruby/object:Gem::Dependency
220
+ name: rubocop
221
+ requirement: !ruby/object:Gem::Requirement
222
+ requirements:
223
+ - - ">="
224
+ - !ruby/object:Gem::Version
225
+ version: '0'
226
+ type: :development
227
+ prerelease: false
228
+ version_requirements: !ruby/object:Gem::Requirement
229
+ requirements:
230
+ - - ">="
231
+ - !ruby/object:Gem::Version
232
+ version: '0'
239
233
  description: Ruby wrapper for Campact User Service
240
234
  email: hello@controlshiftlabs.com
241
235
  executables: []
@@ -244,8 +238,10 @@ extra_rdoc_files:
244
238
  - LICENSE
245
239
  - README.md
246
240
  files:
241
+ - ".rubocop.yml"
247
242
  - ".ruby-gemset"
248
243
  - ".ruby-version"
244
+ - ".travis.yml"
249
245
  - Gemfile
250
246
  - LICENSE
251
247
  - README.md