Commit 357d189

mokha <mokha@cisco.com>
2018-09-22 21:07:15
remove authentication model.
1 parent 8922e7e
app/models/authentication.rb
@@ -1,5 +0,0 @@
-# frozen_string_literal: true
-
-class Authentication < ApplicationRecord
-  belongs_to :user
-end
app/models/password_authentication.rb
@@ -1,7 +0,0 @@
-# frozen_string_literal: true
-
-class PasswordAuthentication < Authentication
-  def authenticate(password)
-    user.authenticate(password)
-  end
-end
app/models/totp_authentication.rb
@@ -1,7 +0,0 @@
-# frozen_string_literal: true
-
-class TotpAuthentication < Authentication
-  def authenticate(code)
-    user.mfa.authenticate(code) ? user : false
-  end
-end
app/models/user.rb
@@ -3,7 +3,6 @@
 class User < ApplicationRecord
   has_secure_password
   has_many :sessions, foreign_key: "user_id", class_name: UserSession.name
-  has_many :authentications
 
   validates :email, presence: true, email: true, uniqueness: {
     case_sensitive: false
db/migrate/20180922174543_create_authentications.rb
@@ -1,12 +0,0 @@
-# frozen_string_literal: true
-
-class CreateAuthentications < ActiveRecord::Migration[5.2]
-  def change
-    create_table :authentications do |t|
-      t.references :user, foreign_key: true
-      t.string :type, null: false
-
-      t.timestamps
-    end
-  end
-end
db/schema.rb
@@ -12,14 +12,6 @@
 
 ActiveRecord::Schema.define(version: 2018_09_22_174543) do
 
-  create_table "authentications", force: :cascade do |t|
-    t.integer "user_id"
-    t.string "type", null: false
-    t.datetime "created_at", null: false
-    t.datetime "updated_at", null: false
-    t.index ["user_id"], name: "index_authentications_on_user_id"
-  end
-
   create_table "authorizations", force: :cascade do |t|
     t.integer "user_id"
     t.integer "client_id"
spec/factories/authentication.rb
@@ -1,8 +0,0 @@
-FactoryBot.define do
-  factory :authentication do
-    user
-
-    factory :password_authentication, class: PasswordAuthentication
-    factory :totp_authentication, class: TotpAuthentication
-  end
-end
spec/models/authentication_spec.rb
@@ -1,29 +0,0 @@
-require 'rails_helper'
-
-RSpec.describe Authentication do
-  describe PasswordAuthentication do
-    describe "#authenticate" do
-      subject { create(:password_authentication, user: user) }
-      let(:user) { create(:user, password: password) }
-      let(:password) { generate(:password) }
-      let(:invalid) { SecureRandom.hex(20) }
-
-      specify { expect(subject.authenticate(password)).to eql(user) }
-      specify { expect(subject.authenticate(invalid)).to be(false) }
-    end
-  end
-
-  describe TotpAuthentication do
-    describe "#authenticate" do
-      subject { create(:totp_authentication, user: user) }
-      let(:user) { create(:user, :mfa_configured) }
-      let(:current_totp) { ROTP::TOTP.new(user.mfa_secret).now }
-      let(:invalid_totp) { rand(99_999).to_s }
-
-      before { freeze_time }
-
-      specify { expect(subject.authenticate(current_totp)).to eql(user) }
-      specify { expect(subject.authenticate(invalid_totp)).to be(false) }
-    end
-  end
-end