Sha256: 2ac051a14cdb96188cdfd055a0181560bacf441a53ef6de69fe7b6049e061d16
Contents?: true
Size: 1.12 KB
Versions: 8
Compression:
Stored size: 1.12 KB
Contents
require 'rails_helper' RSpec.describe ApplicationController, :type => :controller do after do ENV['HTTP_AUTH_USERNAME'] = nil ENV['HTTP_AUTH_PASSWORD'] = nil end controller do def index render body: "aok" end end it "should not have authentication if http_auth env are blank" do ENV['HTTP_AUTH_USERNAME'] = nil ENV['HTTP_AUTH_PASSWORD'] = nil get :index expect( response ).to be_success end it "should request authentication if http_auth is set" do ENV['HTTP_AUTH_USERNAME'] = "user" ENV['HTTP_AUTH_PASSWORD'] = "pass" get :index expect( response.status ).to eq( 401 ) ENV['HTTP_AUTH_USERNAME'] = nil ENV['HTTP_AUTH_PASSWORD'] = nil end it "should let people through if the correct pass is set" do ENV['HTTP_AUTH_USERNAME'] = "user" ENV['HTTP_AUTH_PASSWORD'] = "pass" credentials = ActionController::HttpAuthentication::Basic.encode_credentials 'user', 'pass' request.env['HTTP_AUTHORIZATION'] = credentials get :index expect( response ).to be_success ENV['HTTP_AUTH_USERNAME'] = nil ENV['HTTP_AUTH_PASSWORD'] = nil end end
Version data entries
8 entries across 8 versions & 1 rubygems