infobip-twofactor 0.0.1 → 1.0.0

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: 41581f09d3bbc3d26820c141227e9d8918c1c532
4
- data.tar.gz: 1bdc983a1d8a0a7c6ed496317fc70cbf4d0f4a4a
3
+ metadata.gz: 56411b5a553e4bcc955e3abec3ed2df44288b9fc
4
+ data.tar.gz: a061f0e44d3817e056da19acd18afe88f4924171
5
5
  SHA512:
6
- metadata.gz: 524e8b3d13211a654befaaba03f8e8c072dc4f3cb04ae3ed54991876aa8182f7fb3a7b98cccd7173e6c6774cc84fd6e5af09a9a24795d7a0afaacdc7d25072cb
7
- data.tar.gz: 61aec90ac96c3a2bc041e2588810b1ca1060e4cae061615ecfe721ed67c99c72485d381691eaf859a8cd34b26fc649a6889ffceb1f3d341638b5e450b172ce9e
6
+ metadata.gz: 0044a5643747128a98f1c7168dabe980c78af53da75eca534f5c7800735e1dc25589657a8cd1c49a8045f03eba833b3520f05f288081c94c06e3dc15993b0625
7
+ data.tar.gz: d3ba9d5131c5206bcbe1aa1251ca05a9d5a02f4fd8f492c5779309738560c7ef482720f57b6e7ba19f019d5754f28bc62e26c0f35b887f17c166c2ea1532874c
data/.travis.yml ADDED
@@ -0,0 +1,13 @@
1
+ language: ruby
2
+ cache: bundler
3
+
4
+ rvm:
5
+ - ruby
6
+ - 2.1.2
7
+
8
+ notifications:
9
+ email:
10
+ recipients:
11
+ - knx@digitalheads.pl
12
+ on_failure: change
13
+ on_success: never
data/README.md CHANGED
@@ -1,3 +1,7 @@
1
+ [![Build Status](https://travis-ci.org/visualitypl/infobip-twofactor.svg?branch=master)](https://travis-ci.org/visualitypl/infobip-twofactor.svg?branch=master)
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/infobip-twofactor.svg)](http://badge.fury.io/rb/infobip-twofactor)
4
+
1
5
  # Infobip::Twofactor
2
6
 
3
7
  Simple wrapper gem for Infobip two factor authentication service
@@ -22,17 +26,17 @@ Or install it yourself as:
22
26
 
23
27
  ```ruby
24
28
  require 'infobip/twofactor'
25
- @twofactor = Infobip::Twofactor::API.new("username", "password", "http://oneapi-test.infobip.com/2fa/1")
29
+ @twofactor = Infobip::Twofactor::API.new("username", "password", "http://oneapi-test.infobip.com/2fa/1", "message_id", "application_id")
26
30
 
27
- => #<Infobip::Twofactor::API:0x007fcce1e7efe0 @authorization_string="aXBwZG9rOjRAU2tLMipf", @auth=#<Crib::API:0x007fcce1e7ee78 @_agent=<Sawyer::Agent http://oneapi-test.infobip.com/2fa/1>, @_last_response=#<Sawyer::Response: 200 @rels={} @data="\"d02f4d9a2d9fb5a70b827819823254b8-9d48e592-db4a-4a70-95f0-59b5a49f48d4\"">>, @api_key="d02f4d9a2d9fb5a70b827819823254b8-9d48e592-db4a-4a70-95f0-59b5a49f4edd4", @api=#<Crib::API:0x007fcce1f8c0b8 @_agent=<Sawyer::Agent http://oneapi-test.infobip.com/2fa/1>>>
31
+ => #<Infobip::Twofactor::API:0x007fcce1e7efe0 @authorization_string="aXBwZ4r3rOjRA34tLMipf", @auth=#<Crib::API:0x007fcce1e7ee78 @_agent=<Sawyer::Agent http://oneapi-test.infobip.com/2fa/1>, @_last_response=#<Sawyer::Response: 200 @rels={} @data="\"d02f4d9a2d9fb5a70b827819823254b8-9d48e592-db4a-4a70-95f0-59b3449f48d4\"">>, @api_key="d02f4d9a2d9fb5a723827819823254b8-9d48e592-db4a-4a70-95f0-59b5a49f4edd4", @api=#<Crib::API:0x007fcce1f8c0b8 @_agent=<Sawyer::Agent http://oneapi-test.infobip.com/2fa/1>>>
28
32
 
29
- @twofactor.send_pin("application_id","message_id", "phone")
33
+ @twofactor.send_pin("phone")
30
34
 
31
- => {:pinId=>"C2390DD39E0E1E39252D34BE796885FD", :to=>"48790409242", :ncStatus=>"NC_DESTINATION_UNKNOWN", :smsStatus=>"MESSAGE_SENT"}
35
+ => {:pinId=>"C2390DD39E0E1E39252D34BE796885FD", :to=>"48738288288", :ncStatus=>"NC_DESTINATION_UNKNOWN", :smsStatus=>"MESSAGE_SENT"}
32
36
 
33
- @twofactor.verify_pin("C2390DD39E0E1E39252D34BE796885FD", "pin")
37
+ @twofactor.verify_pin("pin")
34
38
 
35
- => {:pinId=>"C2390DD39E0E1EA9252D34BE796885FD", :msisdn=>"48790809242", :verified=>true, :attemptsRemaining=>0}
39
+ => {:pinId=>"C2390DD39E0E1EA9252D34BE796885FD", :msisdn=>"48738288288", :verified=>true, :attemptsRemaining=>0}
36
40
 
37
41
  ```
38
42
 
@@ -6,12 +6,17 @@ module Infobip
6
6
  class API
7
7
 
8
8
  attr_reader :api_key
9
- # attr_reader :api
10
- # attr_reader :auth
9
+ attr_reader :pin_id
10
+ attr_reader :application_id
11
+ attr_reader :message_id
11
12
 
12
- def initialize(username, password, url)
13
+ def initialize(username, password, url, message_id, application_id)
14
+ raise "Missing message_id" unless message_id
15
+ raise "Missing application_id" unless application_id
13
16
  #send auth reqest
14
17
  @authorization_string = Base64.strict_encode64("#{username}:#{password}")
18
+ @message_id = message_id
19
+ @application_id = application_id
15
20
 
16
21
  @auth = Crib.api(url) do |http|
17
22
  http.headers[:authorization] = "Basic #{@authorization_string}"
@@ -27,12 +32,23 @@ module Infobip
27
32
  end
28
33
 
29
34
 
30
- def send_pin(application_id, message_id, phone)
31
- @api.pin._post(applicationId: application_id, messageId: message_id, to: phone)
35
+ def send_pin(phone)
36
+ raise "Missing phone number" unless phone
37
+ raise "Missing message_id" unless @message_id
38
+ raise "Missing application_id" unless @application_id
39
+ response = @api.pin._post(applicationId: @application_id, messageId: @message_id, to: phone)
40
+ raise "Malformed two factor API response - no sms status field" unless (response.respond_to?(:smsStatus))
41
+ raise "Malformed two factor API response - no pin Id field" unless (response.respond_to?(:pinId))
42
+ raise "SMS not sent" unless (response.smsStatus == "MESSAGE_SENT")
43
+ @pin_id = response[:pinId]
44
+ response
32
45
  end
33
46
 
34
- def verify_pin(pin_id, pin)
35
- @api.pin(pin_id).verify._post(pin: pin)
47
+ def verify_pin(pin)
48
+ raise "Missing pin id" unless @pin_id
49
+ response = @api.pin(@pin_id).verify._post(pin: pin)
50
+ raise "Malformed two factor API response - no verified field" unless (response.respond_to?(:verified))
51
+ response
36
52
  end
37
53
 
38
54
  end
@@ -1,5 +1,5 @@
1
1
  module Infobip
2
2
  module Twofactor
3
- VERSION = "0.0.1"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
@@ -2,10 +2,61 @@ def api_key_response_body
2
2
  "\"fc6112a4559b5b44dafe5a943771b53b-020887ca-c56d-42c4-80b0-33a16ea23610\""
3
3
  end
4
4
 
5
- def api_send_pin_response_body
6
- '{pinId: "2B29B71922B37D3C93F8CEBB85B9E3CF", to: "48790809242", ncStatus: "NC_DESTINATION_UNKNOWN", smsStatus: "MESSAGE_SENT"}'
5
+ def api_send_pin_response
6
+ %q{HTTP/1.1 200 OK
7
+ Server: Apache-Coyote/1.1
8
+ Access-Control-Allow-Origin: *
9
+ Access-Control-Allow-Methods: GET, POST, PUT, PATCH, DELETE, COPY, HEAD, OPTIONS, LINK, UNLINK, PURGE
10
+ Access-Control-Allow-Headers: Authorization, Content-Type
11
+ Content-Type: application/json;charset=UTF-8
12
+ Content-Length: 126
13
+ Date: Wed, 21 Jan 2015 13:58:15 GMT
14
+ Connection: close
15
+
16
+ {"pinId":"2B29B71922B37D3C93F8CEBB85B9E3CF","to":"48790809242","ncStatus":"NC_DESTINATION_UNKNOWN","smsStatus":"MESSAGE_SENT"}
17
+ }
18
+ end
19
+
20
+ def api_verify_pin_response
21
+ %q{HTTP/1.1 200 OK
22
+ Server: Apache-Coyote/1.1
23
+ Access-Control-Allow-Origin: *
24
+ Access-Control-Allow-Methods: GET, POST, PUT, PATCH, DELETE, COPY, HEAD, OPTIONS, LINK, UNLINK, PURGE
25
+ Access-Control-Allow-Headers: Authorization, Content-Type
26
+ Content-Type: application/json;charset=UTF-8
27
+ Content-Length: 105
28
+ Date: Wed, 21 Jan 2015 14:06:38 GMT
29
+ Connection: close
30
+
31
+ {"pinId":"2B29B71922B37D3C93F8CEBB85B9E3CF","msisdn":"48790809242","verified":true,"attemptsRemaining":0}
32
+ }
7
33
  end
8
34
 
9
- def api_verify_pin_response_body
10
- '{pinId: "0099939F5D1FC903B8A8A3990E452892",msisdn: "48790809242", verified: "true", attemptsRemaining: "0"}'
35
+ def api_verify_pin_failed_response
36
+ %q{HTTP/1.1 200 OK
37
+ Server: Apache-Coyote/1.1
38
+ Access-Control-Allow-Origin: *
39
+ Access-Control-Allow-Methods: GET, POST, PUT, PATCH, DELETE, COPY, HEAD, OPTIONS, LINK, UNLINK, PURGE
40
+ Access-Control-Allow-Headers: Authorization, Content-Type
41
+ Content-Type: application/json;charset=UTF-8
42
+ Content-Length: 129
43
+ Date: Wed, 21 Jan 2015 14:06:38 GMT
44
+ Connection: close
45
+
46
+ {"pinId":"1129B71922B37D3C93F8CEBB85B9E3CF","msisdn":"48790809242","verified":false,"attemptsRemaining":2}
47
+ }
48
+ end
49
+
50
+ def error_response
51
+ %q{HTTP/1.1 400 Bad Request
52
+ Server: Apache-Coyote/1.1
53
+ Access-Control-Allow-Origin: *
54
+ Access-Control-Allow-Methods: GET, POST, PUT, PATCH, DELETE, COPY, HEAD, OPTIONS, LINK, UNLINK, PURGE
55
+ Access-Control-Allow-Headers: Authorization, Content-Type
56
+ Content-Length: 96
57
+ Date: Thu, 22 Jan 2015 16:14:27 GMT
58
+ Connection: close
59
+
60
+ {"requestError":{"serviceException":{"messageId":"INVALID_ARGUMENT","text":"Invalid argument"}}}
61
+ }
11
62
  end
@@ -8,41 +8,49 @@ describe Infobip::Twofactor::API do
8
8
 
9
9
  before do
10
10
  @configuration = YAML.load_file("configuration.yml")
11
+
11
12
  FakeWeb.register_uri(:post, "http://ippdok:4%40SkK2*_@oneapi-test.infobip.com/2fa/1/api-key", status: ["200", "OK"], body: api_key_response_body)
12
- FakeWeb.register_uri(:post, "http://oneapi-test.infobip.com/2fa/1/pin", status: ["200", "OK"], body: api_send_pin_response_body)
13
- FakeWeb.register_uri(:post, "http://oneapi-test.infobip.com/2fa/1/pin/C6634467BFDB5E0BDCC1408B5315E84A/verify", status: ["200", "OK"], body: api_verify_pin_response_body)
14
- @twofactor = Infobip::Twofactor::API.new(@configuration["username"], @configuration["password"], @configuration["url"])
13
+ FakeWeb.register_uri(:post, "http://oneapi-test.infobip.com/2fa/1/pin", response: api_send_pin_response)
14
+ FakeWeb.register_uri(:post, "http://oneapi-test.infobip.com/2fa/1/pin/2B29B71922B37D3C93F8CEBB85B9E3CF/verify", response: api_verify_pin_response)
15
+
16
+ @twofactor = Infobip::Twofactor::API.new(@configuration["username"], @configuration["password"], @configuration["url"], @configuration["message_id"], @configuration["application_id"])
15
17
  end
16
18
 
17
19
  subject { @twofactor }
18
20
 
19
21
  it "should return valid api key" do
20
- expect(@twofactor.api_key.class).to eq String
21
- expect(@twofactor.api_key.length).to eq 69
22
+ expect(subject.api_key.class).to eq String
23
+ expect(subject.api_key.length).to eq 69
22
24
  end
23
25
 
24
26
  it "should create a valid Send PIN request, given valid params" do
25
- response = @twofactor.send_pin(@configuration["application_id"], @configuration["message_id"], "48790809242")
26
- if response.class == String
27
- response_hash = eval(response)
28
- else
29
- response_hash = response
30
- end
31
- expect(response_hash[:smsStatus]).to eq "MESSAGE_SENT"
27
+ response = subject.send_pin("48790809242")
28
+ expect(response[:smsStatus]).to eq "MESSAGE_SENT"
29
+ end
30
+
31
+ it "should store pin_id value" do
32
+ response = subject.send_pin("48790809242")
33
+ expect(subject.pin_id).to eq "2B29B71922B37D3C93F8CEBB85B9E3CF"
32
34
  end
33
35
 
34
36
  it "should create a valid Verify PIN request, given valid params" do
35
- response = @twofactor.verify_pin("C6634467BFDB5E0BDCC1408B5315E84A", "1234")
36
- if response.class == String
37
- response_hash = eval(response)
38
- else
39
- response_hash = response
40
- end
41
- expect(response_hash[:verified]).to eq "true"
37
+ response = subject.send_pin("48790809242")
38
+ response = subject.verify_pin("1234")
39
+ expect(response[:verified]).to eq true
42
40
  end
43
41
 
44
- end
42
+ context "error handling" do
43
+
44
+ it "new should raise an error when missing params"
45
45
 
46
+ it "send pin should raise an error when missing params"
47
+
48
+ it "verify pin should raise an error when missing params"
49
+
50
+ it "should raise an error when received invalid response"
51
+
52
+ it "should raise an error when received error object"
53
+
54
+ end
46
55
 
47
- # FakeWeb.register_uri(:post, "https://apitest.authorize.net/xml/v1/request.api", status: ["200", "OK"], body: successful_purchase_response)
48
- # request = Hash.from_xml(FakeWeb.last_request.body.gsub("\n", ""))["createTransactionRequest"]["transactionRequest"]
56
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infobip-twofactor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - knx
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-20 00:00:00.000000000 Z
11
+ date: 2015-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: crib
@@ -159,6 +159,7 @@ extra_rdoc_files: []
159
159
  files:
160
160
  - ".gitignore"
161
161
  - ".rspec"
162
+ - ".travis.yml"
162
163
  - Gemfile
163
164
  - Guardfile
164
165
  - LICENSE