Skip to content

Commit

Permalink
Add RackHelpers.set_relying_party_in_request_env
Browse files Browse the repository at this point in the history
* In order to streamline standard setups, we can provide the
	`set_relying_party_in_request_env` helper method; which can be
	included via `Warden::WebAuthn::RackHelpers` and used as needed
  • Loading branch information
tcannonfodder committed Jun 24, 2023
1 parent 22ac597 commit 80d2101
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/warden/webauthn/rack_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ 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
28 changes: 28 additions & 0 deletions test/warden/test_rack_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,30 @@
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
Expand All @@ -22,4 +38,16 @@ def test_default_keys
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

0 comments on commit 80d2101

Please sign in to comment.