Sha256: 6948ab595fb3418f12670bb29dbcd1eebca07d3b0b699430cf47db32baa97c65

Contents?: true

Size: 1.03 KB

Versions: 7

Compression:

Stored size: 1.03 KB

Contents

require 'rails_helper'

RSpec.describe ApplicationController, :type => :controller do
  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

7 entries across 7 versions & 1 rubygems

Version Path
happy_seed-0.0.12 lib/generators/happy_seed/base/templates/spec/controllers/application_controller_spec.rb
happy_seed-0.0.11 lib/generators/happy_seed/base/templates/spec/controllers/application_controller_spec.rb
happy_seed-0.0.10 lib/generators/happy_seed/base/templates/spec/controllers/application_controller_spec.rb
happy_seed-0.0.9 lib/generators/happy_seed/base/templates/spec/controllers/application_controller_spec.rb
happy_seed-0.0.8 lib/generators/happy_seed/base/templates/spec/controllers/application_controller_spec.rb
happy_seed-0.0.7 lib/generators/happy_seed/base/templates/spec/controllers/application_controller_spec.rb
happy_seed-0.0.6 lib/generators/happy_seed/foreman/templates/spec/controllers/application_controller_spec.rb