Skip to content

Commit

Permalink
First DraugiemId helper specs pass
Browse files Browse the repository at this point in the history
  • Loading branch information
Epigene committed Sep 24, 2015
1 parent 30696f1 commit 01230d6
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,7 @@ if @response.valid?
@response.message #=> Only present if code !"100"
@response.uuid #=> "7387bf5b-fa27-4fdd-add6-a6bfb2599f77" (the same you supplied)
```

### DraugiemID usage

Documentation is online at [Draugiem site](https://www.draugiem.lv/applications/dev/docs/draugiemid)
4 changes: 3 additions & 1 deletion lib/sacps/auth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
require 'sacps/auth/seb'
require 'sacps/auth/dnb'
require 'sacps/auth/citadele'
require 'sacps/auth/nordea'
require 'sacps/auth/nordea'

require 'sacps/auth/draugiem_id'
28 changes: 28 additions & 0 deletions lib/sacps/auth/draugiem_id.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'sacps/auth/draugiem_id/helper'
require 'sacps/auth/draugiem_id/notification'

module SacPS
module Auth
module DraugiemId
mattr_accessor :app_id, :return_url

def self.set_default_values
# SacPS::Auth::DraugiemId.app_id ||= "1"
end

def self.validate_config!
self.set_default_values
message = []
message << "No app_id!" if SacPS::Auth::DraugiemId.app_id.blank?
message << "No return_url!" if SacPS::Auth::DraugiemId.return_url.blank?

raise "DraugiemId init contains blank values, review README. Errors:\n#{message.join("\n")}" if message.any?
end

def self.helper
Helper.new
end

end
end
end
26 changes: 26 additions & 0 deletions lib/sacps/auth/draugiem_id/helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module SacPS
module Auth
module DraugiemId
class Helper
attr_accessor :authentication_url

def initialize
SacPS::Auth::DraugiemId.validate_config!
@authentication_url = build_authentication_url
end

def build_authentication_url
app = SacPS::Auth::DraugiemId.app_id
hash = build_control_code
redirect = SacPS::Auth::DraugiemId.return_url
"https://api.draugiem.lv/authorize/?app=#{app}&hash=#{hash}&redirect=#{redirect}"
end

def build_control_code
Digest::MD5.hexdigest("#{SacPS::Auth::DraugiemId.app_id}#{SacPS::Auth::DraugiemId.return_url}")
end

end
end
end
end
10 changes: 10 additions & 0 deletions lib/sacps/auth/draugiem_id/notification.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module SacPS
module Auth
module DraugiemId
class Notification
attr_reader :fields

end
end
end
end
31 changes: 31 additions & 0 deletions spec/auth/helpers/sacps_auth_draugiem_id_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# rspec spec/auth/helpers/sacps_auth_draugiem_id_helper_spec.rb

require 'spec_helper'

describe SacPS::Auth::DraugiemId::Helper do
before :all do
@helper = SacPS::Auth::DraugiemId.helper
end

describe "initialization" do
it "should have @authentication_url" do
expect(@helper.authentication_url.present?).to eq true
end
end

describe "#build_authentication_url" do
it "should match the format in documentation" do
# Autorizācijas lapas saites adrese veidojas šādā formā: https://api.draugiem.lv/authorize/?app=[aplikācijas_id]&hash=[kontroles_kods]&redirect=[pāradresācijas_adrese]
match_regex = /https\:\/\/api\.draugiem\.lv\/authorize\/\?app\=(.*?)\&hash\=(.*?)\&redirect\=(.*?)/
expect(@helper.build_authentication_url[match_regex].present?).to eq true
end
end

describe "#build_control_code" do
it "returns the 32 digit MD5 hash" do
expect(@helper.build_control_code.size).to eq 32
end
end


end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# rspec spec/auth/notifications/sacps_auth_draugiem_id_helper_spec.rb

require 'spec_helper'

describe SacPS::Auth::DraugiemId::Notification do

end
3 changes: 3 additions & 0 deletions spec/config.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
SacPS::Auth::DraugiemId.app_id = '7c437d28be62b492151788f6c827afd6'
SacPS::Auth::DraugiemId.return_url = 'http://example.com/draugiem_auth/'

SacPS::Auth::Swedbank.identifier = 'ACC1'
SacPS::Auth::Swedbank.service_url = 'https://ib.swedbank.lv'
SacPS::Auth::Swedbank.return_url = 'http://www.myplace.com'
Expand Down

0 comments on commit 01230d6

Please sign in to comment.