-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use global signed ID for magic link auth
- Handle valid and invalid sgid in magic link - Handle expired resource so that end users can request a new magic link if previous link has expired
- Loading branch information
1 parent
b680675
commit 8bf75da
Showing
11 changed files
with
139 additions
and
30 deletions.
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
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
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
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
# frozen_string_literal: true | ||
|
||
BopsCore::Engine.routes.draw do | ||
get "magic_link", to: "magic_links#show", as: :magic_link | ||
end |
43 changes: 43 additions & 0 deletions
43
engines/bops_core/spec/models/bops_core/magic_linkable_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,43 @@ | ||
# frozen_string_literal: true | ||
|
||
require "bops_core_helper" | ||
|
||
RSpec.describe BopsCore::MagicLinkable, type: :model do | ||
let(:consultation) { create(:consultation) } | ||
let(:consultee) { create(:consultee, consultation:) } | ||
|
||
describe "#sgid" do | ||
it "generates a signed global ID with expiration time" do | ||
sgid = consultee.sgid(expires_in: 1.day, for: "magic_link") | ||
decoded = GlobalID::Locator.locate_signed(sgid, for: "magic_link") | ||
|
||
expect(decoded).to eq(consultee) | ||
end | ||
|
||
it "returns nil if SGID has expired" do | ||
sgid = consultee.sgid(expires_in: 1.second, for: "magic_link") | ||
travel 1.minute | ||
|
||
expect(GlobalID::Locator.locate_signed(sgid, for: "magic_link")).to be_nil | ||
end | ||
|
||
it "returns nil an error if the SGID is expired" do | ||
sgid = consultee.sgid(expires_in: 1.minute, for: "magic_link") | ||
travel 1.minute | ||
|
||
expect(GlobalID::Locator.locate_signed(sgid, for: "magic_link")).to be_nil | ||
Base64.decode64(sgid) | ||
end | ||
end | ||
|
||
describe "#sgid_expired_resource" do | ||
it "returns the resource if SGID is expired" do | ||
sgid = consultee.sgid(expires_in: 1.second, for: "magic_link") | ||
travel 1.minute | ||
|
||
binding.pry | ||
expect(GlobalID::Locator.locate_signed(sgid, for: "magic_link")).to be_nil | ||
Base64.decode64(sgid) | ||
end | ||
end | ||
end |