Module: Rails::Auth::RSpec::HelperMethods
- Defined in:
- lib/rails/auth/rspec/helper_methods.rb
Overview
RSpec helper methods
Instance Method Summary collapse
-
#test_credentials ⇒ Object
Credentials to be injected into the request during tests.
-
#with_credentials(credentials = {}) ⇒ Object
Perform a test with the given credentials NOTE: Credentials will be cleared after the block.
-
#x509_certificate(cn: nil, ou: nil) ⇒ Object
Creates an Rails::Auth::X509::Certificate instance double.
-
#x509_certificate_hash(**args) ⇒ Object
Creates a certificates hash containing a single X.509 certificate instance double.
Instance Method Details
#test_credentials ⇒ Object
Credentials to be injected into the request during tests
9 10 11 |
# File 'lib/rails/auth/rspec/helper_methods.rb', line 9 def test_credentials Rails.configuration.x.rails_auth.test_credentials end |
#with_credentials(credentials = {}) ⇒ Object
Perform a test with the given credentials NOTE: Credentials will be cleared after the block. Nesting is not allowed.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rails/auth/rspec/helper_methods.rb', line 15 def with_credentials(credentials = {}) raise TypeError, "expected Hash of credentials, got #{credentials.class}" unless credentials.is_a?(Hash) test_credentials.clear credentials.each do |type, value| test_credentials[type.to_s] = value end ensure test_credentials.clear end |
#x509_certificate(cn: nil, ou: nil) ⇒ Object
Creates an Rails::Auth::X509::Certificate instance double
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rails/auth/rspec/helper_methods.rb', line 28 def x509_certificate(cn: nil, ou: nil) subject = "" subject += "CN=#{cn}" if cn subject += "OU=#{ou}" if ou instance_double(Rails::Auth::X509::Certificate, subject, cn: cn, ou: ou).tap do |certificate| allow(certificate).to receive(:[]) do |key| { "CN" => cn, "OU" => ou }[key.to_s.upcase] end end end |
#x509_certificate_hash(**args) ⇒ Object
Creates a certificates hash containing a single X.509 certificate instance double
44 45 46 |
# File 'lib/rails/auth/rspec/helper_methods.rb', line 44 def x509_certificate_hash(**args) { "x509" => x509_certificate(**args) } end |