-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
112 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
7 changes: 7 additions & 0 deletions
7
spec/auth/notifications/sacps_auth_draugiem_id_notification_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters