Skip to content

Commit

Permalink
Add spec for admin mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverguenther committed Nov 2, 2023
1 parent 6f6464c commit 46fc0f9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
24 changes: 24 additions & 0 deletions test/lib/omniauth/strategies/openid_connect_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,30 @@ def test_info_custom_mapping
assert_equal 'bar', info[:login]
end

def test_info_boolean_mapping_false
strategy.options.attribute_map = { admin: 'isAdmin' }

info = strategy.info

assert_equal user_info.name, info[:name]
assert_equal user_info.email, info[:email]
assert_equal false, info[:admin]
end

def test_info_boolean_mapping_true
azure_userinfo = ::OpenIDConnect::ResponseObject::UserInfo.new(
sub: SecureRandom.hex(16),
name: Faker::Name.name,
isAdmin: true
)
strategy.stubs(:user_info).returns(azure_userinfo)
strategy.options.attribute_map = { admin: 'isAdmin' }

info = strategy.info

assert_equal true, info[:admin]
end

def test_info_mail_unique_mapping
azure_userinfo = ::OpenIDConnect::ResponseObject::UserInfo.new(
sub: SecureRandom.hex(16),
Expand Down
5 changes: 3 additions & 2 deletions test/strategy_test_case.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class StrategyTestCase < MiniTest::Test
class StrategyTestCase < Minitest::Test
class DummyApp
def call(env); end
end
Expand Down Expand Up @@ -28,7 +28,8 @@ def user_info
phone_number: Faker::PhoneNumber.phone_number,
website: Faker::Internet.url,
# custom claim
foobar: 'bar'
foobar: 'bar',
isAdmin: false
)
end

Expand Down

0 comments on commit 46fc0f9

Please sign in to comment.