Sha256: 93f5f78d58a827f5395f971fd136c1888de7f78679f51401ba22cce1fe95af47

Contents?: true

Size: 1.8 KB

Versions: 1

Compression:

Stored size: 1.8 KB

Contents

# frozen_string_literal: true

require 'spec_helper'
require 'rack/test'

describe OmniAuth::MultiPassword::Base do # rubocop:disable RSpec/SpecFilePathFormat  subject { strategy }
  let(:app) { instance_double(Proc) }
  let(:strategy) do
    OmniAuth::Strategies::OneTest.new(app, *args, &block)
  end
  let(:args) { [] }
  let(:block) { nil }

  describe '#username_id' do
    subject(:username_id) { strategy.username_id }

    it 'defaults to :username' do
      expect(username_id).to eq :username
    end

    context 'when configured' do
      let(:args) { [{fields: %i[user pass]}] }

      it { is_expected.to eq :user }
    end
  end

  describe '#password_id' do
    subject(:password_id) { strategy.password_id }

    it 'defaults to :password' do
      expect(password_id).to eq :password
    end

    context 'when configured' do
      let(:args) { [{fields: %i[user pass]}] }

      it { is_expected.to eq :pass }
    end
  end

  describe 'single strategy' do
    include Rack::Test::Methods

    let(:app) do
      Rack::Builder.new do
        use OmniAuth::Test::PhonySession
        use OmniAuth::Strategies::OneTest
        run ->(env) { [404, {'Content-Type' => 'text/plain'}, [env.key?('omniauth.auth').to_s]] }
      end.to_app
    end

    it 'shows login FORM' do
      get '/auth/onetest'

      expect(last_response.body).to include '<form'
    end

    it 'redirect on wrong password' do
      post '/auth/onetest/callback', username: 'john', password: 'wrong'
      expect(last_response).to be_redirect
      expect(last_response.headers['Location']).to eq '/auth/failure?message=invalid_credentials&strategy=onetest'
    end

    it 'authenticates john with correct password' do
      post '/auth/onetest/callback', username: 'john', password: 'secret'
      expect(last_response.body).to eq 'true'
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
omniauth-multipassword-2.0.1 spec/omniauth/multipassword/base_spec.rb