authenticator-client 0.0.2 → 0.0.3

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: cd9129412c0abea844885d8fe90ace9b3d54a979
4
- data.tar.gz: 032fc0192b99e8c46778bff82b2463545dc7bccb
3
+ metadata.gz: dbaa8e7cfeea1e5718a076cb8bf72cd0996f33ba
4
+ data.tar.gz: 015a2237645d0f68f8a22af8ce4b3fbd1342b36f
5
5
  SHA512:
6
- metadata.gz: 29cf3f15a440e926218eb9a5be081250237ba7049149267780498c2b17651fb0c1c7053ad0207d94abc0912c0cae9d1f9476d20f267cb3ccf2b93ab8fcc3675b
7
- data.tar.gz: e30fc2bb3983fc6be64aabf729535e38eb72209ed0529fa8c0e9aac581d46541c8b84c90a49e1f8c68ecade932a789beea74e2758d49e21467eaa80a122666ca
6
+ metadata.gz: e2ad6ddf6a152d13ca28b5557626eed8ccd0606428a4021bd7414655c11cac04da83e41ba2c3f8c14396a9063c9d2a62ffa34dd0314b0158dd11108fa885592e
7
+ data.tar.gz: 72f81a5850d9d434bb930c3ee3ce2e84334f996f52c57e5be836b811b53566ce2aeb440978ef3ff8ce5c73b75a96c29b480d04f0347c89dd11656b2174398f5f
@@ -9,12 +9,26 @@ end
9
9
  module Authenticator
10
10
  module Client
11
11
  @@configs = {}
12
+ @@stubbed_account = nil
13
+
12
14
  def self.register_config(key, config)
13
15
  @@configs[key] = config
14
16
  end
15
17
 
16
18
  def self.new(key)
17
- Base.new(@@configs[key])
19
+ if @@stubbed_account
20
+ Mock.new(@@stubbed_account)
21
+ else
22
+ Base.new(@@configs[key], @@stubbed_account)
23
+ end
24
+ end
25
+
26
+ def self.reset!
27
+ @@stubbed_account = nil
28
+ end
29
+
30
+ def self.authenticate_with!(account)
31
+ @@stubbed_account = account
18
32
  end
19
33
  end
20
34
  end
@@ -2,11 +2,34 @@ module Authenticator
2
2
  module Client
3
3
  class Account
4
4
  attr_accessor :id, :username, :password, :created_at, :updated_at
5
- def initialize(username, password)
5
+ def initialize(params, password=nil)
6
+ if password.nil?
7
+ new_initialize(params)
8
+ else
9
+ old_initialize(params, password)
10
+ end
11
+ end
12
+
13
+ def new_initialize(params)
14
+ @id = params[:id]
15
+ @username = params[:username]
16
+ @password = params[:password]
17
+ @created_at = params[:created_at]
18
+ @updated_at = params[:updated_at]
19
+ end
20
+
21
+ def old_initialize(username, password)
6
22
  @username = username
7
23
  @password = password
8
24
  end
9
25
 
26
+ def self.from_json(json)
27
+ params = json.each_with_object({}) do |(key, value), hash|
28
+ hash[key.to_sym] = value
29
+ end
30
+ new(params)
31
+ end
32
+
10
33
  def to_params
11
34
  {
12
35
  account: {
@@ -7,9 +7,17 @@ module Authenticator
7
7
  super
8
8
  end
9
9
 
10
- def auth_success?
10
+ def account
11
+ Account.from_json(json)
12
+ end
13
+
14
+ def authenticated?
11
15
  json['authenticated'] == true
12
16
  end
17
+
18
+ def auth_success?
19
+ authenticated?
20
+ end
13
21
  end
14
22
  end
15
23
  end
@@ -5,7 +5,7 @@ require_relative 'authenticate_response'
5
5
  module Authenticator
6
6
  module Client
7
7
  class Base < JsonClient::Base
8
- def initialize(config)
8
+ def initialize(config, account)
9
9
  super(
10
10
  JsonClient::Pather.new(config[:host], 'api/v1', 'accounts'),
11
11
  config
@@ -13,6 +13,12 @@ module Authenticator
13
13
  end
14
14
 
15
15
  def authenticate(account)
16
+ request_authentication(account)
17
+ end
18
+
19
+ protected
20
+
21
+ def request_authentication(account)
16
22
  uri = authenticate_path
17
23
  response = RestClient.post(
18
24
  uri,
@@ -23,8 +29,6 @@ module Authenticator
23
29
  AuthenticateResponse.new(response.body, response.code)
24
30
  end
25
31
 
26
- protected
27
-
28
32
  def authenticate_path
29
33
  "#{pather.host}/api/v1/authentications/authenticate"
30
34
  end
@@ -0,0 +1,26 @@
1
+ require 'json'
2
+ require_relative 'authenticate_response'
3
+
4
+ module Authenticator
5
+ module Client
6
+ class Mock
7
+ attr_reader :params
8
+ def initialize(params)
9
+ @params = params
10
+ end
11
+
12
+ def authenticate(_account)
13
+ mock_response
14
+ end
15
+
16
+ protected
17
+
18
+ def mock_response
19
+ AuthenticateResponse.new(
20
+ params.merge({ authenticated: true }).to_json,
21
+ 200
22
+ )
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,5 +1,5 @@
1
1
  module Authenticator
2
2
  module Client
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -55,6 +55,13 @@ describe Authenticator::Client::Base do
55
55
 
56
56
  expect(response.json['authenticated']).to eq true
57
57
  expect(response.auth_success?).to eq true
58
+
59
+ account = response.account
60
+
61
+ expect(account.username).to eq 'new_username'
62
+ expect(account.id).to be 1
63
+ expect(account.created_at).to eq '2015-01-08T05:02:05.699Z'
64
+ expect(account.updated_at).to eq '2015-01-08T05:02:05.699Z'
58
65
  end
59
66
  end
60
67
  end
@@ -75,12 +82,13 @@ describe Authenticator::Client::Base do
75
82
  describe '#show' do
76
83
  it 'fetches the account' do
77
84
  VCR.use_cassette('show_success') do
78
- response = subject.show(6).json
85
+ response = subject.show(1)
86
+ json = response.json
79
87
 
80
- expect(response['username']).to eq 'new_username'
81
- expect(response['id']).to be 6
82
- expect(response['created_at']).to eq '2015-01-04T20:36:28.339Z'
83
- expect(response['updated_at']).to eq '2015-01-04T20:36:28.339Z'
88
+ expect(json['username']).to eq 'new_username'
89
+ expect(json['id']).to be 1
90
+ expect(json['created_at']).to eq '2015-01-08T05:02:05.699Z'
91
+ expect(json['updated_at']).to eq '2015-01-08T05:02:05.699Z'
84
92
  end
85
93
  end
86
94
  end
@@ -17,6 +17,10 @@ describe Authenticator::Client do
17
17
  }
18
18
  end
19
19
 
20
+ let(:client) do
21
+ described_class.new(:test)
22
+ end
23
+
20
24
  describe '::register' do
21
25
  it 'registers a configuration to be used when invoked with ::new' do
22
26
  described_class.register_config(:test, config)
@@ -26,4 +30,14 @@ describe Authenticator::Client do
26
30
  expect(client.api_password).to eq config[:api_password]
27
31
  end
28
32
  end
33
+
34
+ describe '::authenticate_with!' do
35
+ it 'forces the authenticate client to return the param passed in' do
36
+ described_class.authenticate_with!(username: 'hello')
37
+ client = described_class.new(:test)
38
+
39
+ expect(client.authenticate(nil).authenticated?).to be true
40
+ expect(client.authenticate(nil).account.username).to eq 'hello'
41
+ end
42
+ end
29
43
  end
@@ -21,7 +21,7 @@ http_interactions:
21
21
  Server:
22
22
  - Cowboy
23
23
  Date:
24
- - Sun, 04 Jan 2015 20:36:27 GMT
24
+ - Thu, 08 Jan 2015 05:02:04 GMT
25
25
  Connection:
26
26
  - keep-alive
27
27
  X-Frame-Options:
@@ -37,9 +37,9 @@ http_interactions:
37
37
  Cache-Control:
38
38
  - max-age=0, private, must-revalidate
39
39
  X-Request-Id:
40
- - 0c59d284-8ebb-4bbc-9077-a4485d9a5762
40
+ - 2569aa6a-5e15-44e3-a33d-01ec77d9d407
41
41
  X-Runtime:
42
- - '0.102701'
42
+ - '0.110975'
43
43
  Transfer-Encoding:
44
44
  - chunked
45
45
  Via:
@@ -48,5 +48,5 @@ http_interactions:
48
48
  encoding: UTF-8
49
49
  string: '{"accounts":[]}'
50
50
  http_version:
51
- recorded_at: Sun, 04 Jan 2015 20:36:28 GMT
51
+ recorded_at: Thu, 08 Jan 2015 05:02:05 GMT
52
52
  recorded_with: VCR 2.9.3
@@ -25,7 +25,7 @@ http_interactions:
25
25
  Server:
26
26
  - Cowboy
27
27
  Date:
28
- - Mon, 05 Jan 2015 01:23:42 GMT
28
+ - Fri, 09 Jan 2015 04:12:09 GMT
29
29
  Connection:
30
30
  - keep-alive
31
31
  X-Frame-Options:
@@ -37,22 +37,22 @@ http_interactions:
37
37
  Content-Type:
38
38
  - application/json; charset=utf-8
39
39
  Etag:
40
- - '"29a332b9c56931be8b665c71c76164f8"'
40
+ - '"325c5f8d5ad864f87bf6934a9235559a"'
41
41
  Cache-Control:
42
42
  - max-age=0, private, must-revalidate
43
43
  Set-Cookie:
44
44
  - request_method=POST; path=/
45
45
  X-Request-Id:
46
- - aa1a198c-8128-4be7-a69a-6bfafd673aac
46
+ - cead9f36-d992-4375-878d-a0707546fd9d
47
47
  X-Runtime:
48
- - '0.387137'
48
+ - '0.355233'
49
49
  Transfer-Encoding:
50
50
  - chunked
51
51
  Via:
52
52
  - 1.1 vegur
53
53
  body:
54
54
  encoding: UTF-8
55
- string: '{"authenticated":true}'
55
+ string: '{"authenticated":true,"id":1,"username":"new_username","created_at":"2015-01-08T05:02:05.699Z","updated_at":"2015-01-08T05:02:05.699Z"}'
56
56
  http_version:
57
- recorded_at: Mon, 05 Jan 2015 01:09:52 GMT
57
+ recorded_at: Fri, 09 Jan 2015 04:12:09 GMT
58
58
  recorded_with: VCR 2.9.3
@@ -25,7 +25,7 @@ http_interactions:
25
25
  Server:
26
26
  - Cowboy
27
27
  Date:
28
- - Sun, 04 Jan 2015 20:36:27 GMT
28
+ - Thu, 08 Jan 2015 05:02:04 GMT
29
29
  Connection:
30
30
  - keep-alive
31
31
  X-Frame-Options:
@@ -37,22 +37,22 @@ http_interactions:
37
37
  Content-Type:
38
38
  - application/json; charset=utf-8
39
39
  Etag:
40
- - '"f26adbb79ceaf5aaa609ed1819b600b6"'
40
+ - '"8057cbf6e90518e77b2027186382122f"'
41
41
  Cache-Control:
42
42
  - max-age=0, private, must-revalidate
43
43
  Set-Cookie:
44
44
  - request_method=POST; path=/
45
45
  X-Request-Id:
46
- - b554584e-ac2f-45ee-859e-d89f414c7aed
46
+ - 847f447b-1db6-4b80-8497-2de72c544ff4
47
47
  X-Runtime:
48
- - '0.201978'
48
+ - '0.249002'
49
49
  Transfer-Encoding:
50
50
  - chunked
51
51
  Via:
52
52
  - 1.1 vegur
53
53
  body:
54
54
  encoding: UTF-8
55
- string: '{"id":6,"username":"new_username","created_at":"2015-01-04T20:36:28.339Z","updated_at":"2015-01-04T20:36:28.339Z"}'
55
+ string: '{"id":1,"username":"new_username","created_at":"2015-01-08T05:02:05.699Z","updated_at":"2015-01-08T05:02:05.699Z"}'
56
56
  http_version:
57
- recorded_at: Sun, 04 Jan 2015 20:36:28 GMT
57
+ recorded_at: Thu, 08 Jan 2015 05:02:05 GMT
58
58
  recorded_with: VCR 2.9.3
@@ -25,7 +25,7 @@ http_interactions:
25
25
  Server:
26
26
  - Cowboy
27
27
  Date:
28
- - Sun, 04 Jan 2015 20:48:55 GMT
28
+ - Thu, 08 Jan 2015 05:02:06 GMT
29
29
  Connection:
30
30
  - keep-alive
31
31
  X-Frame-Options:
@@ -37,27 +37,27 @@ http_interactions:
37
37
  Content-Type:
38
38
  - application/json; charset=utf-8
39
39
  Etag:
40
- - '"03258793b9ebad43ea73e9565d861f80"'
40
+ - '"e3a82fc4a2329d6412e62d7a03c86cf4"'
41
41
  Cache-Control:
42
42
  - max-age=0, private, must-revalidate
43
43
  Set-Cookie:
44
44
  - request_method=POST; path=/
45
45
  X-Request-Id:
46
- - a764b58c-eda2-4770-9ef3-87fb2bf7854c
46
+ - 2076a75d-d263-41f9-a20b-dab310168144
47
47
  X-Runtime:
48
- - '0.201380'
48
+ - '0.206475'
49
49
  Transfer-Encoding:
50
50
  - chunked
51
51
  Via:
52
52
  - 1.1 vegur
53
53
  body:
54
54
  encoding: UTF-8
55
- string: '{"id":10,"username":"new_username_2","created_at":"2015-01-04T20:48:55.695Z","updated_at":"2015-01-04T20:48:55.695Z"}'
55
+ string: '{"id":3,"username":"new_username_2","created_at":"2015-01-08T05:02:07.620Z","updated_at":"2015-01-08T05:02:07.620Z"}'
56
56
  http_version:
57
- recorded_at: Sun, 04 Jan 2015 20:48:55 GMT
57
+ recorded_at: Thu, 08 Jan 2015 05:02:07 GMT
58
58
  - request:
59
59
  method: delete
60
- uri: http://account-authenticator.herokuapp.com/api/v1/accounts/10?api_key=124ecd49-07fd-4553-a5cd-0178b7fa8b3f&api_password=IIoclO7kmQqJ1wixWrAuOA
60
+ uri: http://account-authenticator.herokuapp.com/api/v1/accounts/3?api_key=124ecd49-07fd-4553-a5cd-0178b7fa8b3f&api_password=IIoclO7kmQqJ1wixWrAuOA
61
61
  body:
62
62
  encoding: US-ASCII
63
63
  string: ''
@@ -76,7 +76,7 @@ http_interactions:
76
76
  Server:
77
77
  - Cowboy
78
78
  Date:
79
- - Sun, 04 Jan 2015 20:48:55 GMT
79
+ - Thu, 08 Jan 2015 05:02:07 GMT
80
80
  Connection:
81
81
  - keep-alive
82
82
  X-Frame-Options:
@@ -88,22 +88,22 @@ http_interactions:
88
88
  Content-Type:
89
89
  - application/json; charset=utf-8
90
90
  Etag:
91
- - '"db2883d5f032d326e56b7f4d896e51e9"'
91
+ - '"a7f153d21e6c7effbc234f3242315d32"'
92
92
  Cache-Control:
93
93
  - max-age=0, private, must-revalidate
94
94
  Set-Cookie:
95
95
  - request_method=DELETE; path=/
96
96
  X-Request-Id:
97
- - a4863ea3-30e9-48b1-91c9-628a1b10a858
97
+ - eabdea88-dd5c-492a-8103-934b96e3071c
98
98
  X-Runtime:
99
- - '0.119341'
99
+ - '0.119036'
100
100
  Transfer-Encoding:
101
101
  - chunked
102
102
  Via:
103
103
  - 1.1 vegur
104
104
  body:
105
105
  encoding: UTF-8
106
- string: '{"id":10}'
106
+ string: '{"id":3}'
107
107
  http_version:
108
- recorded_at: Sun, 04 Jan 2015 20:48:55 GMT
108
+ recorded_at: Thu, 08 Jan 2015 05:02:07 GMT
109
109
  recorded_with: VCR 2.9.3
@@ -2,7 +2,7 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: get
5
- uri: http://account-authenticator.herokuapp.com/api/v1/accounts/6?api_key=124ecd49-07fd-4553-a5cd-0178b7fa8b3f&api_password=IIoclO7kmQqJ1wixWrAuOA
5
+ uri: http://account-authenticator.herokuapp.com/api/v1/accounts/1?api_key=124ecd49-07fd-4553-a5cd-0178b7fa8b3f&api_password=IIoclO7kmQqJ1wixWrAuOA
6
6
  body:
7
7
  encoding: US-ASCII
8
8
  string: ''
@@ -21,7 +21,7 @@ http_interactions:
21
21
  Server:
22
22
  - Cowboy
23
23
  Date:
24
- - Sun, 04 Jan 2015 20:37:35 GMT
24
+ - Fri, 09 Jan 2015 02:43:59 GMT
25
25
  Connection:
26
26
  - keep-alive
27
27
  X-Frame-Options:
@@ -33,20 +33,20 @@ http_interactions:
33
33
  Content-Type:
34
34
  - application/json; charset=utf-8
35
35
  Etag:
36
- - '"f26adbb79ceaf5aaa609ed1819b600b6"'
36
+ - '"8057cbf6e90518e77b2027186382122f"'
37
37
  Cache-Control:
38
38
  - max-age=0, private, must-revalidate
39
39
  X-Request-Id:
40
- - 31c54ba5-3226-4433-9950-ddd9fadc1c64
40
+ - 4428c126-bf71-434b-a2ae-21f6f670726f
41
41
  X-Runtime:
42
- - '0.105063'
42
+ - '0.163582'
43
43
  Transfer-Encoding:
44
44
  - chunked
45
45
  Via:
46
46
  - 1.1 vegur
47
47
  body:
48
48
  encoding: UTF-8
49
- string: '{"id":6,"username":"new_username","created_at":"2015-01-04T20:36:28.339Z","updated_at":"2015-01-04T20:36:28.339Z"}'
49
+ string: '{"id":1,"username":"new_username","created_at":"2015-01-08T05:02:05.699Z","updated_at":"2015-01-08T05:02:05.699Z"}'
50
50
  http_version:
51
- recorded_at: Sun, 04 Jan 2015 20:37:35 GMT
51
+ recorded_at: Fri, 09 Jan 2015 02:43:59 GMT
52
52
  recorded_with: VCR 2.9.3
@@ -25,7 +25,7 @@ http_interactions:
25
25
  Server:
26
26
  - Cowboy
27
27
  Date:
28
- - Sun, 04 Jan 2015 20:36:28 GMT
28
+ - Thu, 08 Jan 2015 05:02:05 GMT
29
29
  Connection:
30
30
  - keep-alive
31
31
  X-Frame-Options:
@@ -37,27 +37,27 @@ http_interactions:
37
37
  Content-Type:
38
38
  - application/json; charset=utf-8
39
39
  Etag:
40
- - '"f21a93c307ee794341d6e751a83b5c44"'
40
+ - '"33556d94e07273e44b663a6dec89c743"'
41
41
  Cache-Control:
42
42
  - max-age=0, private, must-revalidate
43
43
  Set-Cookie:
44
44
  - request_method=POST; path=/
45
45
  X-Request-Id:
46
- - 60e75ec5-53eb-4552-8e86-29f2271351ee
46
+ - 042fd587-9b01-4522-84d6-3ac26f399954
47
47
  X-Runtime:
48
- - '0.199750'
48
+ - '0.212409'
49
49
  Transfer-Encoding:
50
50
  - chunked
51
51
  Via:
52
52
  - 1.1 vegur
53
53
  body:
54
54
  encoding: UTF-8
55
- string: '{"id":7,"username":"new_username_1","created_at":"2015-01-04T20:36:28.949Z","updated_at":"2015-01-04T20:36:28.949Z"}'
55
+ string: '{"id":2,"username":"new_username_1","created_at":"2015-01-08T05:02:06.362Z","updated_at":"2015-01-08T05:02:06.362Z"}'
56
56
  http_version:
57
- recorded_at: Sun, 04 Jan 2015 20:36:28 GMT
57
+ recorded_at: Thu, 08 Jan 2015 05:02:06 GMT
58
58
  - request:
59
59
  method: put
60
- uri: http://account-authenticator.herokuapp.com/api/v1/accounts/7
60
+ uri: http://account-authenticator.herokuapp.com/api/v1/accounts/2
61
61
  body:
62
62
  encoding: UTF-8
63
63
  string: '{"api_key":"124ecd49-07fd-4553-a5cd-0178b7fa8b3f","api_password":"IIoclO7kmQqJ1wixWrAuOA","account":{"username":"updated_username","password":"updated_password"}}'
@@ -80,7 +80,7 @@ http_interactions:
80
80
  Server:
81
81
  - Cowboy
82
82
  Date:
83
- - Sun, 04 Jan 2015 20:36:28 GMT
83
+ - Thu, 08 Jan 2015 05:02:06 GMT
84
84
  Connection:
85
85
  - keep-alive
86
86
  X-Frame-Options:
@@ -92,22 +92,22 @@ http_interactions:
92
92
  Content-Type:
93
93
  - application/json; charset=utf-8
94
94
  Etag:
95
- - '"80904310aa88a944d24696f6d4c81fa1"'
95
+ - '"36e97d567c634ce708473564e82064b0"'
96
96
  Cache-Control:
97
97
  - max-age=0, private, must-revalidate
98
98
  Set-Cookie:
99
99
  - request_method=PUT; path=/
100
100
  X-Request-Id:
101
- - c82ee34e-2392-4999-a65b-e646f09a8495
101
+ - fac33722-9476-49c6-afeb-e8cb24c02e25
102
102
  X-Runtime:
103
- - '0.253034'
103
+ - '0.223449'
104
104
  Transfer-Encoding:
105
105
  - chunked
106
106
  Via:
107
107
  - 1.1 vegur
108
108
  body:
109
109
  encoding: UTF-8
110
- string: '{"id":7,"username":"updated_username","created_at":"2015-01-04T20:36:28.949Z","updated_at":"2015-01-04T20:36:29.353Z"}'
110
+ string: '{"id":2,"username":"updated_username","created_at":"2015-01-08T05:02:06.362Z","updated_at":"2015-01-08T05:02:06.719Z"}'
111
111
  http_version:
112
- recorded_at: Sun, 04 Jan 2015 20:36:29 GMT
112
+ recorded_at: Thu, 08 Jan 2015 05:02:06 GMT
113
113
  recorded_with: VCR 2.9.3
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authenticator-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - johnmcconnell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-08 00:00:00.000000000 Z
11
+ date: 2015-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -154,6 +154,7 @@ files:
154
154
  - lib/authenticator/client/account.rb
155
155
  - lib/authenticator/client/authenticate_response.rb
156
156
  - lib/authenticator/client/base.rb
157
+ - lib/authenticator/client/mock.rb
157
158
  - lib/authenticator/client/version.rb
158
159
  - spec/authenticator/client/base_spec.rb
159
160
  - spec/authenticator/client_spec.rb