minor styling change to authenticationtoken model, changed the expire_at column of AuthenticationToken form date to datetime
This commit is contained in:

committed by
Sebastian Serth

parent
1a987a65d4
commit
6e213f754f
@ -4,6 +4,7 @@ require 'securerandom'
|
|||||||
|
|
||||||
class AuthenticationToken < ApplicationRecord
|
class AuthenticationToken < ApplicationRecord
|
||||||
include Creation
|
include Creation
|
||||||
|
|
||||||
def self.generate!(user)
|
def self.generate!(user)
|
||||||
create!(
|
create!(
|
||||||
shared_secret: SecureRandom.hex(32),
|
shared_secret: SecureRandom.hex(32),
|
||||||
|
@ -5,7 +5,7 @@ class CreateAuthenticationTokens < ActiveRecord::Migration[6.1]
|
|||||||
create_table :authentication_tokens, id: :uuid do |t|
|
create_table :authentication_tokens, id: :uuid do |t|
|
||||||
t.string :shared_secret, null: false, index: {unique: true}
|
t.string :shared_secret, null: false, index: {unique: true}
|
||||||
t.references :user, polymorphic: true, null: false
|
t.references :user, polymorphic: true, null: false
|
||||||
t.date :expire_at, null: false
|
t.datetime :expire_at, null: false
|
||||||
t.timestamps
|
t.timestamps
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -34,7 +34,7 @@ ActiveRecord::Schema.define(version: 2022_07_21_131946) do
|
|||||||
t.string "shared_secret", null: false
|
t.string "shared_secret", null: false
|
||||||
t.string "user_type", null: false
|
t.string "user_type", null: false
|
||||||
t.bigint "user_id", null: false
|
t.bigint "user_id", null: false
|
||||||
t.date "expire_at", null: false
|
t.datetime "expire_at", null: false
|
||||||
t.datetime "created_at", precision: 6, null: false
|
t.datetime "created_at", precision: 6, null: false
|
||||||
t.datetime "updated_at", precision: 6, null: false
|
t.datetime "updated_at", precision: 6, null: false
|
||||||
t.index ["shared_secret"], name: "index_authentication_tokens_on_shared_secret", unique: true
|
t.index ["shared_secret"], name: "index_authentication_tokens_on_shared_secret", unique: true
|
||||||
|
@ -35,12 +35,13 @@ describe 'Authentication' do
|
|||||||
|
|
||||||
context 'with no authentication token' do
|
context 'with no authentication token' do
|
||||||
let(:request_for_comment) { create(:rfc_with_comment, user: user) }
|
let(:request_for_comment) { create(:rfc_with_comment, user: user) }
|
||||||
|
let(:rfc_path) { request_for_comment_url(request_for_comment) }
|
||||||
|
|
||||||
it 'denies access to the request for comment' do
|
it 'denies access to the request for comment' do
|
||||||
mail.deliver_now
|
visit(rfc_path)
|
||||||
visit(rfc_link)
|
expect(page).not_to have_current_path(rfc_path)
|
||||||
expect(page).not_to have_content(request_for_comment.exercise.title)
|
expect(page).not_to have_content(request_for_comment.exercise.title)
|
||||||
expect(response).to redirect_to(root_path)
|
expect(page).to have_current_path(root_path)
|
||||||
expect(page).to have_content(I18n.t('application.not_authorized'))
|
expect(page).to have_content(I18n.t('application.not_authorized'))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -60,8 +61,7 @@ describe 'Authentication' do
|
|||||||
it 'allows access to the request for comment' do
|
it 'allows access to the request for comment' do
|
||||||
mail.deliver_now
|
mail.deliver_now
|
||||||
visit(rfc_link)
|
visit(rfc_link)
|
||||||
expect(current_url).to be(rfc_link)
|
expect(page).to have_current_path(rfc_link)
|
||||||
expect(response).to have_http_status :ok
|
|
||||||
expect(page).to have_content(request_for_comment.exercise.title)
|
expect(page).to have_content(request_for_comment.exercise.title)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -72,8 +72,9 @@ describe 'Authentication' do
|
|||||||
it 'denies access to the request for comment' do
|
it 'denies access to the request for comment' do
|
||||||
mail.deliver_now
|
mail.deliver_now
|
||||||
visit(rfc_link)
|
visit(rfc_link)
|
||||||
|
expect(page).not_to have_current_path(rfc_link)
|
||||||
expect(page).not_to have_content(request_for_comment.exercise.title)
|
expect(page).not_to have_content(request_for_comment.exercise.title)
|
||||||
expect(response).to redirect_to(root_path)
|
expect(page).to have_current_path(root_path)
|
||||||
expect(page).to have_content(I18n.t('application.not_authorized'))
|
expect(page).to have_content(I18n.t('application.not_authorized'))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user