class Gruf::Rspec::AuthenticationHydrators::Basic

Automatically hydrate request metadata with basic authentication options

Public Instance Methods

hydrate(metadata) click to toggle source

@param [Hash] metadata The incoming request metadata @return [Hash] The hydrated metadata

# File lib/gruf/rspec/authentication_hydrators/basic.rb, line 31
def hydrate(metadata)
  username = auth_opts.fetch(:username, '')
  password = auth_opts.fetch(:password, '')
  auth_string = username.to_s.empty? ? password : "#{username}:#{password}"
  metadata[auth_opts.fetch(:header_key, 'authorization').to_s] = "Basic #{::Base64.encode64(auth_string)}" unless auth_string.empty?
  metadata
end

Private Instance Methods

auth_opts() click to toggle source
# File lib/gruf/rspec/authentication_hydrators/basic.rb, line 41
def auth_opts
  @auth_opts ||= @options.fetch(:authentication_options, {})
end