Sha256: 9e4615dde3124b9eb5d388dbc8e488c30090beacf3b6b40d7459e02ab5d397ac
Contents?: true
Size: 1.44 KB
Versions: 1
Compression:
Stored size: 1.44 KB
Contents
module Rails module Auth module RSpec # RSpec helper methods module HelperMethods # Creates an Rails::Auth::X509::Principal instance double def x509_principal(cn: nil, ou: nil) subject = "" subject << "CN=#{cn}" if cn subject << "OU=#{ou}" if ou instance_double(X509::Principal, subject, cn: cn, ou: ou).tap do |principal| allow(principal).to receive(:[]) do |key| { "CN" => cn, "OU" => ou }[key.to_s.upcase] end end end # Creates a principals hash containing a single X.509 principal instance double def x509_principal_hash(**args) { "x509" => x509_principal(**args) } end Rails::Auth::ACL::Resource::HTTP_METHODS.each do |method| define_method("#{method.downcase}_request") do |principals: {}| path = self.class.description # Warn if methods are improperly used unless path.chars[0] == "/" fail ArgumentError, "expected #{path} to start with '/'" end env = { "REQUEST_METHOD" => method, "REQUEST_PATH" => self.class.description } principals.each do |type, value| Rails::Auth.add_principal(env, type.to_s, value) end env end end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rails-auth-0.0.1 | lib/rails/auth/rspec/helper_methods.rb |