-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from ruby-passkeys/2023-06-23-refactor-add-rack…
…-helpers-module
- Loading branch information
Showing
5 changed files
with
75 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
## [Unreleased] | ||
|
||
- Refactor `relying_party_key` into `Warden::WebAuthn::RackHelpers` | ||
- https://github.com/ruby-passkeys/warden-webauthn/issues/4 | ||
|
||
## [0.1.0] - 2023-02-04 | ||
|
||
- Initial release |
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,17 @@ | ||
# frozen_string_literal: true | ||
|
||
module Warden | ||
module WebAuthn | ||
# Helpers that can be mixed in to any Rack middleware or application, in order | ||
# to setup the environment for `Warden::WebAuthn`, such as the Relying Party | ||
module RackHelpers | ||
def relying_party_key | ||
"warden.webauthn.relying_party" | ||
end | ||
|
||
def set_relying_party_in_request_env | ||
request.env[relying_party_key] = relying_party | ||
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
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,53 @@ | ||
# frozen_string_literal: true | ||
|
||
require "test_helper" | ||
|
||
class Warden::TestRackHelpers < Minitest::Test | ||
class TestClass | ||
include Warden::WebAuthn::RackHelpers | ||
|
||
attr_accessor :request | ||
|
||
def initialize | ||
self.request = Rack::Request.new({}) | ||
end | ||
end | ||
|
||
class CustomizedClass | ||
include Warden::WebAuthn::RackHelpers | ||
|
||
attr_accessor :request | ||
|
||
def initialize | ||
self.request = Rack::Request.new({}) | ||
end | ||
|
||
def relying_party_key | ||
"custom_relying_party" | ||
end | ||
|
||
def relying_party | ||
"dummy_relying_party_value" | ||
end | ||
end | ||
|
||
def test_default_keys | ||
assert_equal "warden.webauthn.relying_party", TestClass.new.relying_party_key | ||
end | ||
|
||
def test_custom_keys | ||
assert_equal "custom_relying_party", CustomizedClass.new.relying_party_key | ||
end | ||
|
||
def test_raises_name_error_if_no_relying_party_method | ||
assert_raises NameError do | ||
TestClass.new.set_relying_party_in_request_env | ||
end | ||
end | ||
|
||
def test_raises_uses_defined_relying_party_method | ||
instance = CustomizedClass.new | ||
instance.set_relying_party_in_request_env | ||
assert_equal "dummy_relying_party_value", instance.request.env["custom_relying_party"] | ||
end | ||
end |