repo
stringlengths
5
92
file_url
stringlengths
80
287
file_path
stringlengths
5
197
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 15:37:27
2026-01-04 17:58:21
truncated
bool
2 classes
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/app/controllers/action_auth/registrations_controller.rb
app/controllers/action_auth/registrations_controller.rb
module ActionAuth class RegistrationsController < ApplicationController before_action :validate_pwned_password, only: :create rate_limit to: 3, within: 60.seconds, only: :create, name: "registration-throttle", with: -> { redirect_to new_user_registration_path, alert: "Too many registration attempts. Try again later." } def new @user = User.new end def create @user = User.new(user_params) if @user.save if ActionAuth.configuration.verify_email_on_sign_in send_email_verification redirect_to sign_in_path, notice: "Welcome! You have signed up successfully. Please check your email to verify your account." else session_record = @user.sessions.create! cookie_options = { value: session_record.id, httponly: true } cookie_options[:secure] = Rails.env.production? if Rails.env.production? cookie_options[:same_site] = :lax unless Rails.env.test? cookies.signed.permanent[:session_token] = cookie_options redirect_to sign_in_path, notice: "Welcome! You have signed up successfully" end else render :new, status: :unprocessable_entity end end private def user_params params.permit(:email, :password, :password_confirmation) end def send_email_verification UserMailer.with(user: @user).email_verification.deliver_later end def validate_pwned_password return unless ActionAuth.configuration.pwned_enabled? if params[:password].present? && !Rails.env.test? && (params[:password] !~ /[A-Z]/ || params[:password] !~ /[a-z]/ || params[:password] !~ /[0-9]/ || params[:password] !~ /[^A-Za-z0-9]/) @user = User.new(email: params[:email]) @user.errors.add(:password, "must include at least one uppercase letter, one lowercase letter, one number, and one special character.") render :new, status: :unprocessable_entity and return end pwned = Pwned::Password.new(params[:password]) if pwned.pwned? @user = User.new(email: params[:email]) @user.errors.add(:password, "has been pwned #{pwned.pwned_count} times. Please choose a different password.") render :new, status: :unprocessable_entity end end end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/app/controllers/action_auth/sessions_controller.rb
app/controllers/action_auth/sessions_controller.rb
module ActionAuth class SessionsController < ApplicationController before_action :set_current_request_details before_action :authenticate_user!, only: [:index, :destroy] rate_limit to: 5, within: 20.seconds, only: :create, name: "slow-throttle", with: -> { redirect_to sign_in_path, alert: "Try again later." } def index @action_auth_wide = true @sessions = Current.user.sessions.order(created_at: :desc) end def new end def create if user = User.authenticate_by(email: params[:email], password: params[:password]) if user.second_factor_enabled? session[:webauthn_user_id] = user.id redirect_to new_webauthn_credential_authentications_path else return if check_if_email_is_verified(user) @session = user.sessions.create session_token_hash = { value: @session.id, httponly: true } session_token_hash[:secure] = Rails.env.production? if Rails.env.production? session_token_hash[:same_site] = :lax unless Rails.env.test? session_token_hash[:domain] = :all if ActionAuth.configuration.insert_cookie_domain cookies.signed.permanent[:session_token] = session_token_hash redirect_to main_app.root_path, notice: "Signed in successfully" end else redirect_to sign_in_path(email_hint: params[:email]), alert: "That email or password is incorrect" end end def destroy session = Current.user.sessions.find(params[:id]) session.destroy cookie_options = {} cookie_options[:secure] = Rails.env.production? if Rails.env.production? cookie_options[:same_site] = :lax unless Rails.env.test? cookies.delete(:session_token, cookie_options) response.headers["Clear-Site-Data"] = '"cache","storage"' redirect_to main_app.root_path, notice: "That session has been logged out" end private def check_if_email_is_verified(user) return false unless ActionAuth.configuration.verify_email_on_sign_in return false if user.verified? redirect_to sign_in_path(email_hint: params[:email]), alert: "You must verify your email before you sign in." end end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/app/controllers/action_auth/application_controller.rb
app/controllers/action_auth/application_controller.rb
module ActionAuth class ApplicationController < ActionController::Base end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/app/controllers/action_auth/magics/requests_controller.rb
app/controllers/action_auth/magics/requests_controller.rb
module ActionAuth class Magics::RequestsController < ApplicationController def new end def create user = User.find_or_initialize_by(email: params[:email]) if user.new_record? password = SecureRandom.hex(32) user.password = password user.password_confirmation = password user.save! end UserMailer.with(user: user).magic_link.deliver_later redirect_to sign_in_path, notice: "Check your email for a magic link." end end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/app/controllers/action_auth/magics/sign_ins_controller.rb
app/controllers/action_auth/magics/sign_ins_controller.rb
module ActionAuth class Magics::SignInsController < ApplicationController def show user = ActionAuth::User.find_by_token_for(:magic_token, params[:token]) if user @session = user.sessions.create cookies.signed.permanent[:session_token] = { value: @session.id, httponly: true } user.update(verified: true) redirect_to main_app.root_path, notice: "Signed In" else redirect_to sign_in_path, alert: "Authentication failed, please try again." end end end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/app/controllers/action_auth/sms_auths/requests_controller.rb
app/controllers/action_auth/sms_auths/requests_controller.rb
module ActionAuth class SmsAuths::RequestsController < ApplicationController def new end def create @user = User.find_or_initialize_by(phone_number: params[:phone_number]) if @user.new_record? password = SecureRandom.hex(32) @user.email = "#{SecureRandom.hex(32)}@smsauth" @user.password = password @user.password_confirmation = password @user.verified = false @user.save! end code = rand(100_000..999_999) @user.update!(sms_code: code, sms_code_sent_at: Time.current) cookies.signed[:sms_auth_phone_number] = { value: @user.phone_number, httponly: true } if defined?(ActionAuth.configuration.sms_send_class) && ActionAuth.configuration.sms_send_class.respond_to?(:send_code) ActionAuth.configuration.sms_send_class.send_code(@user.phone_number, code) end redirect_to sms_auths_sign_ins_path, notice: "Check your phone for a SMS Code." end end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/app/controllers/action_auth/sms_auths/sign_ins_controller.rb
app/controllers/action_auth/sms_auths/sign_ins_controller.rb
module ActionAuth class SmsAuths::SignInsController < ApplicationController def show @user = ActionAuth::User.find_by(phone_number: params[:phone_number]) end def create user = ActionAuth::User.find_by( phone_number: cookies.signed[:sms_auth_phone_number], sms_code: params[:sms_code], sms_code_sent_at: 5.minutes.ago..Time.current ) if user @session = user.sessions.create cookies.signed.permanent[:session_token] = { value: @session.id, httponly: true } user.update( verified: true, sms_code: nil, sms_code_sent_at: nil ) redirect_to main_app.root_path, notice: "Signed In" else redirect_to sign_in_path, alert: "Authentication failed, please try again." end end end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/app/controllers/action_auth/sessions/passkeys_controller.rb
app/controllers/action_auth/sessions/passkeys_controller.rb
module ActionAuth module Sessions class PasskeysController < ApplicationController def new get_options = WebAuthn::Credential.options_for_get session[:current_challenge] = get_options.challenge @options = get_options end def create webauthn_credential = WebAuthn::Credential.from_get(params) credential = WebauthnCredential.find_by(external_id: webauthn_credential.id) user = User.find_by(id: credential&.user_id) if credential && user session = user.sessions.create cookies.signed.permanent[:session_token] = { value: session.id, httponly: true } redirect_to main_app.root_path(format: :html), notice: "Signed in successfully" else redirect_to sign_in_path(format: :html), alert: "That passkey is incorrect" and return end end end end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/app/controllers/action_auth/identity/emails_controller.rb
app/controllers/action_auth/identity/emails_controller.rb
module ActionAuth module Identity class EmailsController < ApplicationController before_action :set_user def edit end def update if @user.update(user_params) redirect_to_root else render :edit, status: :unprocessable_entity end end private def set_user @user = Current.user end def user_params params.permit(:email, :password_challenge).with_defaults(password_challenge: "") end def redirect_to_root if @user.email_previously_changed? resend_email_verification redirect_to sign_in_path, notice: "Your email has been changed. Check your email to verify your email." else redirect_to sign_in_path end end def resend_email_verification UserMailer.with(user: @user).email_verification.deliver_later end end end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/app/controllers/action_auth/identity/email_verifications_controller.rb
app/controllers/action_auth/identity/email_verifications_controller.rb
module ActionAuth module Identity class EmailVerificationsController < ApplicationController before_action :set_user, only: :show def show @user.update! verified: true redirect_to sign_in_path, notice: "Thank you for verifying your email address" end def create user = ActionAuth::User.find_by(email: params[:email]) UserMailer.with(user: user).email_verification.deliver_later if user redirect_to sign_in_path, notice: "We sent a verification email to your email address" end private def set_user @user = ActionAuth::User.find_by_token_for!(:email_verification, params[:sid]) rescue StandardError redirect_to edit_identity_email_path, alert: "That email verification link is invalid" end end end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/app/controllers/action_auth/identity/password_resets_controller.rb
app/controllers/action_auth/identity/password_resets_controller.rb
module ActionAuth module Identity class PasswordResetsController < ApplicationController before_action :set_user, only: %i[ edit update ] before_action :validate_pwned_password, only: :update def new end def edit end def create if @user = ActionAuth::User.find_by(email: params[:email], verified: true) send_password_reset_email redirect_to sign_in_path, notice: "Check your email for reset instructions" else redirect_to sign_in_path, alert: "You can't reset your password until you verify your email" end end def update if @user.update(user_params) redirect_to sign_in_path, notice: "Your password was reset successfully. Please sign in" else render :edit, status: :unprocessable_entity end end private def set_user @user = ActionAuth::User.find_by_token_for!(:password_reset, params[:sid]) rescue StandardError redirect_to new_identity_password_reset_path, alert: "That password reset link is invalid" end def user_params params.permit(:password, :password_confirmation) end def send_password_reset_email UserMailer.with(user: @user).password_reset.deliver_later end def validate_pwned_password return unless ActionAuth.configuration.pwned_enabled? pwned = Pwned::Password.new(params[:password]) if pwned.pwned? @user.errors.add(:password, "has been pwned #{pwned.pwned_count} times. Please choose a different password.") render :edit, status: :unprocessable_entity end end end end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/app/models/action_auth/current.rb
app/models/action_auth/current.rb
module ActionAuth class Current < ActiveSupport::CurrentAttributes attribute :session attribute :user_agent, :ip_address delegate :user, to: :session, allow_nil: true end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/app/models/action_auth/session.rb
app/models/action_auth/session.rb
module ActionAuth class Session < ApplicationRecord self.table_name = "sessions" belongs_to :user, class_name: "ActionAuth::User", foreign_key: "user_id" before_create do self.user_agent = Current.user_agent self.ip_address = Current.ip_address end end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/app/models/action_auth/application_record.rb
app/models/action_auth/application_record.rb
module ActionAuth class ApplicationRecord < ActiveRecord::Base self.abstract_class = true end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/app/models/action_auth/webauthn_credential.rb
app/models/action_auth/webauthn_credential.rb
module ActionAuth class WebauthnCredential < ApplicationRecord self.table_name = "webauthn_credentials" validates :external_id, :public_key, :nickname, :sign_count, presence: true validates :external_id, uniqueness: true validates :sign_count, numericality: { only_integer: true, greater_than_or_equal_to: 0, less_than_or_equal_to: 2**32 - 1 } enum :key_type, { unknown: 0, passkey: 1, hardware: 2, wireless: 3 } end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/app/models/action_auth/user.rb
app/models/action_auth/user.rb
module ActionAuth class User < ApplicationRecord self.table_name = "users" has_secure_password has_many :sessions, dependent: :destroy, class_name: "ActionAuth::Session", foreign_key: "user_id" if ActionAuth.configuration.webauthn_enabled? has_many :webauthn_credentials, dependent: :destroy, class_name: "ActionAuth::WebauthnCredential", foreign_key: "user_id" end generates_token_for :email_verification, expires_in: 2.days do email end generates_token_for :password_reset, expires_in: 20.minutes do password_salt.last(10) end generates_token_for :magic_token, expires_in: 20.minutes do password_salt.last(10) end validates :email, presence: true, uniqueness: true, format: { with: URI::MailTo::EMAIL_REGEXP } validates :password, allow_nil: true, length: { minimum: 12 } validate :password_complexity, if: -> { ActionAuth.configuration.password_complexity_check? && password.present? && !Rails.env.test? } validates :phone_number, allow_nil: true, uniqueness: true, format: { with: /\A\+\d+\z/, message: "must be a valid international phone number with digits only after the country code" } normalizes :phone_number, with: -> phone_number { phone_number.gsub(/[^+\d]/, '') } normalizes :email, with: -> email { email.strip.downcase } before_validation if: :email_changed?, on: :update do self.verified = false end after_update if: :password_digest_previously_changed? do sessions.where.not(id: Current.session).delete_all end def second_factor_enabled? return false unless ActionAuth.configuration.webauthn_enabled? webauthn_credentials.any? end private def password_complexity return if password.blank? unless password =~ /[A-Z]/ && password =~ /[a-z]/ && password =~ /[0-9]/ && password =~ /[^A-Za-z0-9]/ errors.add(:password, "must include at least one uppercase letter, one lowercase letter, one number, and one special character") end end end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/app/mailers/action_auth/application_mailer.rb
app/mailers/action_auth/application_mailer.rb
module ActionAuth class ApplicationMailer < ActionMailer::Base default from: ActionAuth.configuration.default_from_email layout "mailer" end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/app/mailers/action_auth/user_mailer.rb
app/mailers/action_auth/user_mailer.rb
module ActionAuth class UserMailer < ApplicationMailer def password_reset @user = params[:user] @signed_id = @user.generate_token_for(:password_reset) mail to: @user.email, subject: "Reset your password" end def email_verification @user = params[:user] @signed_id = @user.generate_token_for(:email_verification) mail to: @user.email, subject: "Verify your email" end def magic_link @user = params[:user] @signed_id = @user.generate_token_for(:magic_token) mail to: @user.email, subject: "Sign in to your account" end end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/db/migrate/20231107170349_create_action_auth_sessions.rb
db/migrate/20231107170349_create_action_auth_sessions.rb
class CreateActionAuthSessions < ActiveRecord::Migration[7.1] def change create_table :sessions do |t| t.references :user, null: false, foreign_key: true t.string :user_agent t.string :ip_address t.timestamps end end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/db/migrate/20240818032321_add_type_to_webauthn_credentials.rb
db/migrate/20240818032321_add_type_to_webauthn_credentials.rb
class AddTypeToWebauthnCredentials < ActiveRecord::Migration[7.2] def change add_column :webauthn_credentials, :key_type, :integer, default: 0, limit: 2 end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/db/migrate/20240111125859_add_webauthn_credentials.rb
db/migrate/20240111125859_add_webauthn_credentials.rb
class AddWebauthnCredentials < ActiveRecord::Migration[7.1] def change create_table :webauthn_credentials do |t| t.string :external_id, null: false t.string :public_key, null: false t.string :nickname, null: false t.bigint :sign_count, null: false, default: 0 t.index :external_id, unique: true t.references :user, foreign_key: true t.timestamps end end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/db/migrate/20231107165548_create_action_auth_users.rb
db/migrate/20231107165548_create_action_auth_users.rb
class CreateActionAuthUsers < ActiveRecord::Migration[7.1] def change create_table :users do |t| t.string :email t.string :password_digest t.boolean :verified t.timestamps end add_index :users, :email, unique: true end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/db/migrate/20240111142545_add_webauthn_id_to_users.rb
db/migrate/20240111142545_add_webauthn_id_to_users.rb
class AddWebauthnIdToUsers < ActiveRecord::Migration[7.1] def change add_column :users, :webauthn_id, :string end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/db/migrate/20241020172209_add_phone_number_to_users.rb
db/migrate/20241020172209_add_phone_number_to_users.rb
class AddPhoneNumberToUsers < ActiveRecord::Migration[7.2] def change add_column :users, :phone_number, :string add_column :users, :sms_code, :string add_column :users, :sms_code_sent_at, :datetime end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/action_auth_test.rb
test/action_auth_test.rb
require 'test_helper' # Test Engine isolation class EngineIsolationTest < ActiveSupport::TestCase test "engine is isolated" do assert ActionAuth::Engine.isolated? end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/test_helper.rb
test/test_helper.rb
# Configure Rails Environment ENV["RAILS_ENV"] = "test" require 'simplecov' SimpleCov.start "rails" do add_filter '/test/' end require_relative "../test/dummy/config/environment" ActiveRecord::Migrator.migrations_paths = [File.expand_path("../test/dummy/db/migrate", __dir__)] ActiveRecord::Migrator.migrations_paths << File.expand_path("../db/migrate", __dir__) require_relative "../test/support/sign_in_as_helper.rb" require "rails/test_help" require 'bcrypt' # Load fixtures from the engine if ActiveSupport::TestCase.respond_to?(:fixture_paths=) ActiveSupport::TestCase.fixture_paths = [File.expand_path("fixtures", __dir__)] ActionDispatch::IntegrationTest.fixture_paths = ActiveSupport::TestCase.fixture_paths ActiveSupport::TestCase.file_fixture_path = File.expand_path("fixtures", __dir__) + "/files" ActiveSupport::TestCase.fixtures :all end class SmsSender def self.send_code(phone_number, code) true end end class ActionDispatch::IntegrationTest include SignInAsHelper def create_user_with_credential(email: 'user@example.com', password: 'Password123456', credential_nickname: 'USB Key', webauthn_credential: nil) if webauthn_credential.blank? raw_challenge = SecureRandom.random_bytes(32) challenge = WebAuthn.configuration.encoder.encode(raw_challenge) public_key_credential = WebAuthn::FakeClient.new("http://localhost:3000").create(challenge: challenge) webauthn_credential = WebAuthn::Credential.from_create(public_key_credential) end ActionAuth::User.create!( email: email, password: password, webauthn_credentials: [ ActionAuth::WebauthnCredential.new( external_id: webauthn_credential.id, nickname: credential_nickname, public_key: webauthn_credential.public_key, sign_count: webauthn_credential.sign_count ) ] ) end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/support/sign_in_as_helper.rb
test/support/sign_in_as_helper.rb
module SignInAsHelper def sign_in_as(user) session = user.sessions.create signed_cookies = ActionDispatch::Request.new(Rails.application.env_config.deep_dup).cookie_jar signed_cookies.signed[:session_token] = { value: session.id, httponly: true } cookies[:session_token] = signed_cookies[:session_token] session end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/integration/navigation_test.rb
test/integration/navigation_test.rb
require "test_helper" class NavigationTest < ActionDispatch::IntegrationTest # test "the truth" do # assert true # end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/controllers/action_auth/sessions_controller_test.rb
test/controllers/action_auth/sessions_controller_test.rb
require "test_helper" module ActionAuth class SessionsControllerTest < ActionDispatch::IntegrationTest include Engine.routes.url_helpers setup do @user = action_auth_users(:one) end test "should get index" do sign_in_as(@user) get sessions_url assert_response :success end test "should get new" do get sign_in_url assert_response :success end test "should sign in" do post sign_in_url, params: { email: @user.email, password: "123456789012" } assert_response :redirect end test "should not sign in with wrong credentials" do post sign_in_url, params: { email: @user.email, password: "SecretWrong1*3" } assert_redirected_to sign_in_url(email_hint: @user.email) assert_equal "That email or password is incorrect", flash[:alert] assert_response :redirect end test "should sign out" do sign_in_as(@user) delete session_url(@user.sessions.last) assert_response :redirect end test "session should timeout after a period of inactivity" do session = ActionAuth::Session.new session.updated_at = 3.hours.ago assert_not session.updated_at < 2.weeks.ago, "Session should not timeout after just 3 hours" session.updated_at = 3.weeks.ago assert session.updated_at < 2.weeks.ago, "Session should timeout after 3 weeks" end test "should implement rate limiting for sign in" do controller = ActionAuth::SessionsController.new def controller.test_rate_limit(attempts) max_attempts = 5 attempts > max_attempts end assert_not controller.test_rate_limit(5), "Should not rate limit with 5 attempts" assert controller.test_rate_limit(6), "Should rate limit with 6 attempts" end end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/controllers/action_auth/webauthn_credentials_controller_test.rb
test/controllers/action_auth/webauthn_credentials_controller_test.rb
require 'test_helper' require "webauthn/fake_client" class WebauthnCredentialsControllerTest < ActionDispatch::IntegrationTest setup do @user = action_auth_users(:one) end test 'new should require authentication' do get action_auth.new_webauthn_credential_path assert_redirected_to action_auth.sign_in_path sign_in_as(@user) get action_auth.new_webauthn_credential_path assert_response :success end test 'options should require authentication' do post action_auth.options_for_webauthn_credentials_path, params: { credentials: { nickname: 'USB Key' }, format: :json } assert_redirected_to action_auth.sign_in_path end test 'create should require authentication' do post action_auth.webauthn_credentials_path, params: { credentials: { nickname: 'USB Key' }, format: :json } assert_redirected_to action_auth.sign_in_path end test 'should initiate credential creation successfully' do sign_in_as(@user) post action_auth.options_for_webauthn_credentials_path, params: { credentials: { nickname: 'USB Key' }, format: :json } assert_response :success end test "should return error if registering existing credential" do raw_challenge = SecureRandom.random_bytes(32) challenge = WebAuthn.configuration.encoder.encode(raw_challenge) sign_in_as(@user) WebAuthn::PublicKeyCredential::CreationOptions.stub_any_instance(:raw_challenge, raw_challenge) do post action_auth.options_for_webauthn_credentials_path, params: { format: :json } assert_response :success end public_key_credential = WebAuthn::FakeClient.new("http://localhost:3000").create(challenge: challenge) webauthn_credential = WebAuthn::Credential.from_create(public_key_credential) create_user_with_credential(credential_nickname: 'USB Key', webauthn_credential: webauthn_credential) post( action_auth.webauthn_credentials_path, params: { credential_nickname: 'Android Phone' }.merge(public_key_credential) ) assert_response :unprocessable_entity assert_equal "Couldn't add your Security Key", response.body end test 'destroy should require authentication' do delete action_auth.webauthn_credential_path('1') assert_redirected_to action_auth.sign_in_path end test 'destroy should work' do raw_registration_challenge = SecureRandom.random_bytes(32) registration_challenge = WebAuthn.configuration.encoder.encode(raw_registration_challenge) fake_client = WebAuthn::FakeClient.new("http://localhost:3000") public_key_credential = fake_client.create(challenge: registration_challenge) webauthn_credential = WebAuthn::Credential.from_create(public_key_credential) user = create_user_with_credential(webauthn_credential: webauthn_credential) sign_in_as(user) raw_authentication_challenge = SecureRandom.random_bytes(32) authentication_challenge = WebAuthn.configuration.encoder.encode(raw_authentication_challenge) public_key_credential = fake_client.get(challenge: authentication_challenge) post(action_auth.webauthn_credential_authentications_path, params: public_key_credential) delete action_auth.webauthn_credential_path(user.webauthn_credentials.first.id) assert_redirected_to action_auth.sessions_path assert_empty user.reload.webauthn_credentials end private def user @user ||= User.create!(username: 'alice', password: 'foo') end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/controllers/action_auth/webauthn_credential_authentications_controller_test.rb
test/controllers/action_auth/webauthn_credential_authentications_controller_test.rb
require "test_helper" class ActionAuth::WebauthnCredentialAuthenticationsControllerTest < ActionDispatch::IntegrationTest include ActionAuth::Engine.routes.url_helpers test "should implement rate limiting for WebAuthn authentication" do controller = ActionAuth::WebauthnCredentialAuthenticationsController.new def controller.test_rate_limit(attempts) max_attempts = 5 attempts > max_attempts end assert_not controller.test_rate_limit(5), "Should not rate limit with 5 attempts" assert controller.test_rate_limit(6), "Should rate limit with 6 attempts" end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/controllers/action_auth/registrations_controller_test.rb
test/controllers/action_auth/registrations_controller_test.rb
require "test_helper" module ActionAuth class RegistrationsControllerTest < ActionDispatch::IntegrationTest include Engine.routes.url_helpers test "should get new" do get sign_up_path assert_response :success end test "should sign up" do assert_difference("ActionAuth::User.count") do email = "#{SecureRandom.hex}@#{SecureRandom.hex}.com" post sign_up_path, params: { email: email, password: email, password_confirmation: email } end assert_response :redirect end test "should not sign up" do assert_no_difference("ActionAuth::User.count") do email = "#{SecureRandom.hex}@#{SecureRandom.hex}.com" post sign_up_path, params: { email: email, password: email, password_confirmation: "123456789012" } end assert_response :unprocessable_entity end test "should not sign up with pwned password" do assert_no_difference("ActionAuth::User.count") do email = "#{SecureRandom.hex}@#{SecureRandom.hex}.com" post sign_up_path, params: { email: email, password: "Password1234", password_confirmation: "Password1234" } end assert_response :unprocessable_entity end end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/controllers/action_auth/webauthn_credential_authentication_controllers_test.rb
test/controllers/action_auth/webauthn_credential_authentication_controllers_test.rb
require 'test_helper' require "webauthn/fake_client" module ActionAuth class WebauthnCredentialAuthenticationsControllerTest < ActionDispatch::IntegrationTest setup do @user = action_auth_users(:one) end test 'new should require initiated login and 2FA enabled' do get action_auth.new_webauthn_credential_authentications_path assert_redirected_to action_auth.sign_in_path end test 'new should require user not authenticated' do sign_in_as(@user) get action_auth.new_webauthn_credential_authentications_path assert_redirected_to "/" end test 'new renders sucessfully' do user = create_user_with_credential fake_session = { webauthn_user_id: user.id } WebauthnCredentialAuthenticationsController.stub_any_instance(:session, fake_session) do get action_auth.new_webauthn_credential_authentications_path assert_response :success end end test 'create should require initiated login' do post action_auth.webauthn_credential_authentications_path assert_redirected_to action_auth.sign_in_path end test 'create should require user not authenticated' do sign_in_as(@user) post action_auth.webauthn_credential_authentications_path assert_redirected_to "/" end test "successful second factor authentication" do raw_challenge = SecureRandom.random_bytes(32) challenge = WebAuthn.configuration.encoder.encode(raw_challenge) fake_client = WebAuthn::FakeClient.new("http://localhost:3000") public_key_credential = fake_client.create(challenge: challenge) webauthn_credential = WebAuthn::Credential.from_create(public_key_credential) user = create_user_with_credential(webauthn_credential: webauthn_credential) fake_session = { webauthn_user_id: user.id, current_challenge: challenge } WebauthnCredentialAuthenticationsController.stub_any_instance(:session, fake_session) do public_key_credential = fake_client.get(challenge: challenge) post( action_auth.webauthn_credential_authentications_path, params: public_key_credential ) assert_response :success end end end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/controllers/action_auth/users_controller_test.rb
test/controllers/action_auth/users_controller_test.rb
require "test_helper" module ActionAuth class UsersControllerTest < ActionDispatch::IntegrationTest include Engine.routes.url_helpers setup do @user = sign_in_as(action_auth_users(:one)) end test "destroys user" do assert_difference("User.count", -1) do delete users_url(@user) end assert_response :redirect follow_redirect! assert_match "Your account has been deleted.", response.body end end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/controllers/action_auth/passwords_controller_test.rb
test/controllers/action_auth/passwords_controller_test.rb
require "test_helper" module ActionAuth class PasswordsControllerTest < ActionDispatch::IntegrationTest include Engine.routes.url_helpers setup do @user = sign_in_as(action_auth_users(:one)) end test "should get edit" do get edit_password_path assert_response :success end test "should update password" do patch password_path, params: { password_challenge: "123456789012", password: "MyV3ry$ecureP@ssw0rd!", password_confirmation: "MyV3ry$ecureP@ssw0rd!" } assert_response :redirect end test "should not update password with wrong password challenge" do patch password_path, params: { password_challenge: "SecretWrong1*3", password: "MyV3ry$ecureP@ssw0rd!", password_confirmation: "MyV3ry$ecureP@ssw0rd!" } assert_response :unprocessable_entity assert_select "li", /Password challenge is invalid/ end end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/controllers/action_auth/magics/sign_ins_controller_test.rb
test/controllers/action_auth/magics/sign_ins_controller_test.rb
require "test_helper" module ActionAuth class Magics::SignInsControllerTest < ActionDispatch::IntegrationTest include Engine.routes.url_helpers test "should sign in user with valid token" do user = action_auth_users(:one) valid_token = user.generate_token_for(:magic_token) assert_difference("Session.count", 1) do get magics_sign_ins_url(token: valid_token) end assert user.reload.verified end test "should not sign in user with invalid token" do assert_difference("Session.count", 0) do get magics_sign_ins_url(token: 'invalid_token') end assert_redirected_to sign_in_path end end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/controllers/action_auth/magics/requests_controller_test.rb
test/controllers/action_auth/magics/requests_controller_test.rb
require "test_helper" module ActionAuth class Magics::RequestsControllerTest < ActionDispatch::IntegrationTest include Engine.routes.url_helpers test "should get new" do get new_magics_requests_path assert_response :success end # Test the 'create' action test "should create user and send magic link" do assert_difference('User.count', 1) do post magics_requests_url, params: { email: 'newuser@example.com' } end user = User.find_by(email: 'newuser@example.com') assert_not_nil user assert_enqueued_emails 1 assert_redirected_to sign_in_path end test "should send magic link to existing user" do existing_user = action_auth_users(:one) assert_no_difference('User.count') do post magics_requests_url, params: { email: existing_user.email } end assert_enqueued_emails 1 assert_redirected_to sign_in_path end test "should not create user with invalid email" do assert_no_difference('User.count') do post magics_requests_url, params: { email: '' } end assert_response :unprocessable_entity end end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/controllers/action_auth/sms_auths/sign_ins_controller_test.rb
test/controllers/action_auth/sms_auths/sign_ins_controller_test.rb
require 'test_helper' class ActionAuth::SmsAuths::SignInsControllerTest < ActionDispatch::IntegrationTest include ActionAuth::Engine.routes.url_helpers def setup @user = action_auth_users(:one) @user.update(phone_number: '1234567890', sms_code: '123456', sms_code_sent_at: 2.minutes.ago) @signed_cookies = ActionDispatch::Request.new(Rails.application.env_config.deep_dup).cookie_jar end test "should show user for valid phone number" do get sms_auths_sign_ins_path, params: { phone_number: @user.phone_number } assert_response :success end test "should not find user for invalid phone number" do get sms_auths_sign_ins_path, params: { phone_number: '9876543210' } assert_response :success end test "should sign in user with correct SMS code" do @signed_cookies.signed[:sms_auth_phone_number] = @user.phone_number assert_not_nil @user.sms_code assert_not_nil @user.sms_code_sent_at post sms_auths_sign_ins_path, params: { sms_code: @user.sms_code } @user.reload assert_nil @user.sms_code assert_nil @user.sms_code_sent_at end test "should fail to sign in with incorrect SMS code" do @signed_cookies.signed[:sms_auth_phone_number] = @user.phone_number post sms_auths_sign_ins_path, params: { sms_code: 'wrong_code' } assert_equal 'Authentication failed, please try again.', flash[:alert] assert_redirected_to sign_in_path assert_nil @signed_cookies.signed[:session_token] end test "should fail to sign in with expired SMS code" do @user.update(sms_code_sent_at: 10.minutes.ago) @signed_cookies.signed[:sms_auth_phone_number] = @user.phone_number post sms_auths_sign_ins_path, params: { sms_code: @user.sms_code } assert_equal 'Authentication failed, please try again.', flash[:alert] assert_redirected_to sign_in_path assert_nil @signed_cookies.signed[:session_token] end test "should redirect to sign in path if phone number is not in cookies" do post sms_auths_sign_ins_path, params: { sms_code: @user.sms_code } assert_equal 'Authentication failed, please try again.', flash[:alert] assert_redirected_to sign_in_path end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/controllers/action_auth/sms_auths/requests_controller_test.rb
test/controllers/action_auth/sms_auths/requests_controller_test.rb
require 'test_helper' class ActionAuth::SmsAuths::RequestsControllerTest < ActionDispatch::IntegrationTest include ActionAuth::Engine.routes.url_helpers def setup assert ActionAuth.configuration.sms_auth_enabled? @existing_user = action_auth_users(:one) @existing_user.update(phone_number: '+11234567890', verified: true) @signed_cookies = ActionDispatch::Request.new(Rails.application.env_config.deep_dup).cookie_jar end test "should get new" do get new_sms_auths_requests_path assert_response :success end test "should create a new user and send SMS code" do assert_difference('User.count', 1) do post sms_auths_requests_path, params: { phone_number: '+19876543210' } end new_user = User.find_by(phone_number: '+19876543210') assert_not_nil new_user assert_not_nil new_user.sms_code assert_not_nil new_user.sms_code_sent_at assert_equal 'Check your phone for a SMS Code.', flash[:notice] assert_redirected_to sms_auths_sign_ins_path end test "should update existing user and send SMS code" do post sms_auths_requests_path, params: { phone_number: @existing_user.phone_number } @existing_user.reload assert_not_nil @existing_user.sms_code assert_not_nil @existing_user.sms_code_sent_at assert_equal 'Check your phone for a SMS Code.', flash[:notice] assert_redirected_to sms_auths_sign_ins_path end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/controllers/action_auth/identity/password_resets_controller_test.rb
test/controllers/action_auth/identity/password_resets_controller_test.rb
require "test_helper" class ActionAuth::Identity::PasswordResetsControllerTest < ActionDispatch::IntegrationTest include ActionAuth::Engine.routes.url_helpers setup do @user = action_auth_users(:one) end test "should get new" do get new_identity_password_reset_url assert_response :success end test "should get edit" do sid = @user.generate_token_for(:password_reset) get edit_identity_password_reset_url(sid: sid) assert_response :success end test "should send a password reset email" do @user.update(verified: true) post identity_password_reset_url, params: { email: @user.email } assert_redirected_to sign_in_url end test "should not send a password reset email" do @user.update(verified: false) post identity_password_reset_url, params: { email: @user.email } assert_redirected_to sign_in_url end test "should not send a password reset email to a nonexistent email" do assert_no_enqueued_emails do post identity_password_reset_url, params: { email: "invalid_email@hey.com" } end assert_redirected_to sign_in_url assert_equal "You can't reset your password until you verify your email", flash[:alert] end test "should not send a password reset email to a unverified email" do @user.update! verified: false assert_no_enqueued_emails do post identity_password_reset_url, params: { email: @user.email } end assert_redirected_to sign_in_url assert_equal "You can't reset your password until you verify your email", flash[:alert] end test "should update password" do sid = @user.generate_token_for(:password_reset) patch identity_password_reset_url, params: { sid: sid, password: "Secret6*4*2*", password_confirmation: "Secret6*4*2*" } assert_redirected_to sign_in_url end test "should not update password with expired token" do sid = @user.generate_token_for(:password_reset) travel 30.minutes patch identity_password_reset_url, params: { sid: sid, password: "Secret6*4*2*", password_confirmation: "Secret6*4*2*" } assert_redirected_to new_identity_password_reset_url assert_equal "That password reset link is invalid", flash[:alert] end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/controllers/action_auth/identity/emails_controller_test.rb
test/controllers/action_auth/identity/emails_controller_test.rb
require "test_helper" class ActionAuth::Identity::EmailsControllerTest < ActionDispatch::IntegrationTest include ActionAuth::Engine.routes.url_helpers setup do @user = action_auth_users(:one) sign_in_as(@user) end test "should get edit" do get edit_identity_email_url assert_response :success end test "should update email" do patch identity_email_url, params: { email: "new_email@hey.com", password_challenge: "123456789012" } assert_response :redirect end test "should not update email with wrong password challenge" do patch identity_email_url, params: { email: "new_email@hey.com", password_challenge: "SecretWrong1*3" } assert_response :unprocessable_entity assert_match "Password challenge is invalid", response.body end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/controllers/action_auth/identity/email_verifications_controller_test.rb
test/controllers/action_auth/identity/email_verifications_controller_test.rb
require "test_helper" class ActionAuth::Identity::EmailVerificationsControllerTest < ActionDispatch::IntegrationTest include ActionAuth::Engine.routes.url_helpers setup do @user = action_auth_users(:one) sign_in_as(@user) @user.update!(verified: false) end test "should send a verification email" do post identity_email_verification_url assert_redirected_to sign_in_url end test "should verify email" do sid = @user.generate_token_for(:email_verification) get identity_email_verification_url(sid: sid, email: @user.email) assert_redirected_to sign_in_url end test "should not verify email with expired token" do sid = @user.generate_token_for(:email_verification) travel 3.days get identity_email_verification_url(sid: sid, email: @user.email) assert_redirected_to edit_identity_email_url assert_equal "That email verification link is invalid", flash[:alert] end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/models/action_auth/session_test.rb
test/models/action_auth/session_test.rb
require "test_helper" module ActionAuth class SessionTest < ActiveSupport::TestCase def setup @user = action_auth_users(:one) end test "should belong to user" do session = @user.sessions.new assert_respond_to session, :user end test "should set user_agent and ip_address before create" do Current.user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3" Current.ip_address = "192.168.1.1" session = @user.sessions.create assert_equal Current.user_agent, session.user_agent assert_equal Current.ip_address, session.ip_address end end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/models/action_auth/user_test.rb
test/models/action_auth/user_test.rb
require "test_helper" module ActionAuth class UserTest < ActiveSupport::TestCase def setup @user = ActionAuth::User.new(email: "test@example.com", password: "123456789012") end test "should be valid" do assert @user.valid? end test "email should be present" do @user.email = " " assert_not @user.valid? end test "password should be present" do user = User.new(email: "john.mcgee@example.com") assert_not user.valid? end test "email should be unique" do duplicate_user = @user.dup duplicate_user.email = @user.email.upcase @user.save assert_not duplicate_user.valid? end test "email should be saved as lowercase" do mixed_case_email = "Foo@ExAMPle.CoM" @user.email = mixed_case_email @user.save assert_equal mixed_case_email.downcase, @user.reload.email end test "email should be valid format" do valid_addresses = %w[user@example.com USER@foo.COM A_US-ER@foo.bar.org first.last@foo.jp alice+bob@baz.cn] valid_addresses.each do |valid_address| @user.email = valid_address assert @user.valid?, "#{valid_address.inspect} should be valid" end end test "email should be invalid format" do invalid_addresses = %w[user@example,com user_at_foo.org user.name@example. foo@bar_baz.com foo@bar+baz.com] invalid_addresses.each do |invalid_address| @user.email = invalid_address assert_not @user.valid?, "#{invalid_address.inspect} should be invalid" end end test "password should have a minimum length" do @user.password = @user.password_confirmation = "a" * 11 assert_not @user.valid? end test "password should be saved as a digest" do @user.save assert_not_nil @user.password_digest end test "should generate email verification token" do @user.save token = @user.generate_token_for(:email_verification) assert_not_nil token subject = User.find_by_token_for(:email_verification, token) assert_equal @user, subject end test "should generate password reset token" do @user.save token = @user.generate_token_for(:password_reset) assert_not_nil token subject = User.find_by_token_for(:password_reset, token) assert_equal @user, subject end test "should verify email" do @user.toggle!(:verified) assert @user.verified? end test "should not verify email if email has not changed" do @user.save @user.update(email: "john.smith1@example.com") assert_not @user.verified? end test "should delete sessions after password change" do @user.save session = @user.sessions.create @user.update(password: "newpassword123") assert_not Session.exists?(session.id) end test "should validate password complexity with complex passwords" do user = ActionAuth::User.new(email: "test@example.com", password: "Password123!") def user.test_password(password) return if password.blank? errors.clear unless password =~ /[A-Z]/ && password =~ /[a-z]/ && password =~ /[0-9]/ && password =~ /[^A-Za-z0-9]/ errors.add(:password, "must include at least one uppercase letter, one lowercase letter, one number, and one special character") end errors[:password] end errors = user.test_password("password123!") assert_not_empty errors, "Password missing uppercase should be invalid" errors = user.test_password("PASSWORD123!") assert_not_empty errors, "Password missing lowercase should be invalid" errors = user.test_password("PasswordABC!") assert_not_empty errors, "Password missing number should be invalid" errors = user.test_password("Password123") assert_not_empty errors, "Password missing special character should be invalid" user.errors.clear errors = user.test_password("Password123!") assert_empty errors, "Complex password should be valid" end end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/dummy/app/jobs/application_job.rb
test/dummy/app/jobs/application_job.rb
class ApplicationJob < ActiveJob::Base # Automatically retry jobs that encountered a deadlock # retry_on ActiveRecord::Deadlocked # Most jobs are safe to ignore if the underlying records are no longer available # discard_on ActiveJob::DeserializationError end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/dummy/app/helpers/posts_helper.rb
test/dummy/app/helpers/posts_helper.rb
module PostsHelper end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/dummy/app/helpers/application_helper.rb
test/dummy/app/helpers/application_helper.rb
module ApplicationHelper end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/dummy/app/helpers/welcome_helper.rb
test/dummy/app/helpers/welcome_helper.rb
module WelcomeHelper end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/dummy/app/controllers/posts_controller.rb
test/dummy/app/controllers/posts_controller.rb
class PostsController < ApplicationController before_action :set_post, only: %i[ show edit update destroy ] # GET /posts def index @posts = Post.all end # GET /posts/1 def show end # GET /posts/new def new @post = Current.user.posts.new end # GET /posts/1/edit def edit end # POST /posts def create @post = Current.user.posts.new(post_params) if @post.save redirect_to @post, notice: "Post was successfully created." else render :new, status: :unprocessable_entity end end # PATCH/PUT /posts/1 def update if @post.update(post_params) redirect_to @post, notice: "Post was successfully updated.", status: :see_other else render :edit, status: :unprocessable_entity end end # DELETE /posts/1 def destroy @post.destroy! redirect_to posts_url, notice: "Post was successfully destroyed.", status: :see_other end private # Use callbacks to share common setup or constraints between actions. def set_post @post = Post.find(params[:id]) end # Only allow a list of trusted parameters through. def post_params params.require(:post).permit(:title) end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/dummy/app/controllers/welcome_controller.rb
test/dummy/app/controllers/welcome_controller.rb
class WelcomeController < ApplicationController def index end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/dummy/app/controllers/application_controller.rb
test/dummy/app/controllers/application_controller.rb
class ApplicationController < ActionController::Base end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/dummy/app/models/current.rb
test/dummy/app/models/current.rb
class Current < ActiveSupport::CurrentAttributes def user return unless ActionAuth::Current.user ActionAuth::Current.user.becomes(User) end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/dummy/app/models/sms_sender.rb
test/dummy/app/models/sms_sender.rb
require 'twilio-ruby' class SmsSender def self.send_code(phone_number, code) client = Twilio::REST::Client.new( ENV['TWILIO_ACCOUNT_SID'], ENV['TWILIO_AUTH_TOKEN'] ) client.messages.create( from: ENV['TWILIO_PHONE_NUMBER'], to: phone_number, body: "Your verification code is #{code}" ) end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/dummy/app/models/post.rb
test/dummy/app/models/post.rb
class Post < ApplicationRecord belongs_to :user end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/dummy/app/models/application_record.rb
test/dummy/app/models/application_record.rb
class ApplicationRecord < ActiveRecord::Base primary_abstract_class end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/dummy/app/models/user.rb
test/dummy/app/models/user.rb
class User < ActionAuth::User has_many :posts, dependent: :destroy end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/dummy/app/mailers/application_mailer.rb
test/dummy/app/mailers/application_mailer.rb
class ApplicationMailer < ActionMailer::Base default from: "from@example.com" layout "mailer" end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/dummy/app/channels/application_cable/channel.rb
test/dummy/app/channels/application_cable/channel.rb
module ApplicationCable class Channel < ActionCable::Channel::Base end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/dummy/app/channels/application_cable/connection.rb
test/dummy/app/channels/application_cable/connection.rb
module ApplicationCable class Connection < ActionCable::Connection::Base end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/dummy/db/schema.rb
test/dummy/db/schema.rb
# This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. # # This file is the source Rails uses to define your schema when running `bin/rails # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to # be faster and is potentially less error prone than running all of your # migrations from scratch. Old migrations may fail to apply correctly if those # migrations use external dependencies or application code. # # It's strongly recommended that you check this file into your version control system. ActiveRecord::Schema[7.2].define(version: 2024_10_20_172209) do create_table "posts", force: :cascade do |t| t.integer "user_id", null: false t.string "title" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["user_id"], name: "index_posts_on_user_id" end create_table "sessions", force: :cascade do |t| t.integer "user_id", null: false t.string "user_agent" t.string "ip_address" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["user_id"], name: "index_sessions_on_user_id" end create_table "users", force: :cascade do |t| t.string "email" t.string "password_digest" t.boolean "verified" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "webauthn_id" t.string "phone_number" t.string "sms_code" t.datetime "sms_code_sent_at" t.index ["email"], name: "index_users_on_email", unique: true end create_table "webauthn_credentials", force: :cascade do |t| t.string "external_id", null: false t.string "public_key", null: false t.string "nickname", null: false t.bigint "sign_count", default: 0, null: false t.integer "user_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.integer "key_type", limit: 2, default: 0 t.index ["external_id"], name: "index_webauthn_credentials_on_external_id", unique: true t.index ["user_id"], name: "index_webauthn_credentials_on_user_id" end add_foreign_key "posts", "users" add_foreign_key "sessions", "users" add_foreign_key "webauthn_credentials", "users" end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/dummy/db/migrate/20240114051355_create_posts.rb
test/dummy/db/migrate/20240114051355_create_posts.rb
class CreatePosts < ActiveRecord::Migration[7.1] def change create_table :posts do |t| t.belongs_to :user, null: false, foreign_key: true t.string :title t.timestamps end end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/dummy/test/system/posts_test.rb
test/dummy/test/system/posts_test.rb
require "application_system_test_case" class PostsTest < ApplicationSystemTestCase setup do @post = posts(:one) end test "visiting the index" do visit posts_url assert_selector "h1", text: "Posts" end test "should create post" do visit posts_url click_on "New post" fill_in "Title", with: @post.title fill_in "User", with: @post.user_id click_on "Create Post" assert_text "Post was successfully created" click_on "Back" end test "should update Post" do visit post_url(@post) click_on "Edit this post", match: :first fill_in "Title", with: @post.title fill_in "User", with: @post.user_id click_on "Update Post" assert_text "Post was successfully updated" click_on "Back" end test "should destroy Post" do visit post_url(@post) click_on "Destroy this post", match: :first assert_text "Post was successfully destroyed" end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/dummy/test/controllers/posts_controller_test.rb
test/dummy/test/controllers/posts_controller_test.rb
require "test_helper" class PostsControllerTest < ActionDispatch::IntegrationTest setup do @post = posts(:one) end test "should get index" do get posts_url assert_response :success end test "should get new" do get new_post_url assert_response :success end test "should create post" do assert_difference("Post.count") do post posts_url, params: { post: { title: @post.title, user_id: @post.user_id } } end assert_redirected_to post_url(Post.last) end test "should show post" do get post_url(@post) assert_response :success end test "should get edit" do get edit_post_url(@post) assert_response :success end test "should update post" do patch post_url(@post), params: { post: { title: @post.title, user_id: @post.user_id } } assert_redirected_to post_url(@post) end test "should destroy post" do assert_difference("Post.count", -1) do delete post_url(@post) end assert_redirected_to posts_url end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/dummy/test/controllers/welcome_controller_test.rb
test/dummy/test/controllers/welcome_controller_test.rb
require "test_helper" class WelcomeControllerTest < ActionDispatch::IntegrationTest test "should get index" do get welcome_index_url assert_response :success end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/dummy/test/models/post_test.rb
test/dummy/test/models/post_test.rb
require "test_helper" class PostTest < ActiveSupport::TestCase # test "the truth" do # assert true # end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/dummy/config/application.rb
test/dummy/config/application.rb
require_relative "boot" require "rails/all" # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) module Dummy class Application < Rails::Application config.load_defaults Rails::VERSION::STRING.to_f # For compatibility with applications that use this config config.action_controller.include_all_helpers = false # Please, add to the `ignore` list any other `lib` subdirectories that do # not contain `.rb` files, or that should not be reloaded or eager loaded. # Common ones are `templates`, `generators`, or `middleware`, for example. config.autoload_lib(ignore: %w(assets tasks)) # Configuration for the application, engines, and railties goes here. # # These settings can be overridden in specific environments using the files # in config/environments, which are processed later. # # config.time_zone = "Central Time (US & Canada)" # config.eager_load_paths << Rails.root.join("extras") end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/dummy/config/environment.rb
test/dummy/config/environment.rb
# Load the Rails application. require_relative "application" # Initialize the Rails application. Rails.application.initialize!
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/dummy/config/puma.rb
test/dummy/config/puma.rb
# This configuration file will be evaluated by Puma. The top-level methods that # are invoked here are part of Puma's configuration DSL. For more information # about methods provided by the DSL, see https://puma.io/puma/Puma/DSL.html. # Puma can serve each request in a thread from an internal thread pool. # The `threads` method setting takes two numbers: a minimum and maximum. # Any libraries that use thread pools should be configured to match # the maximum value specified for Puma. Default is set to 5 threads for minimum # and maximum; this matches the default thread size of Active Record. max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count } threads min_threads_count, max_threads_count # Specifies that the worker count should equal the number of processors in production. if ENV["RAILS_ENV"] == "production" require "concurrent-ruby" worker_count = Integer(ENV.fetch("WEB_CONCURRENCY") { Concurrent.physical_processor_count }) workers worker_count if worker_count > 1 end # Specifies the `worker_timeout` threshold that Puma will use to wait before # terminating a worker in development environments. worker_timeout 3600 if ENV.fetch("RAILS_ENV", "development") == "development" # Specifies the `port` that Puma will listen on to receive requests; default is 3000. port ENV.fetch("PORT") { 3000 } # Specifies the `environment` that Puma will run in. environment ENV.fetch("RAILS_ENV") { "development" } # Specifies the `pidfile` that Puma will use. pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" } # Allow puma to be restarted by `bin/rails restart` command. plugin :tmp_restart
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/dummy/config/routes.rb
test/dummy/config/routes.rb
Rails.application.routes.draw do resources :posts mount ActionAuth::Engine => 'action_auth' root 'welcome#index' end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/dummy/config/boot.rb
test/dummy/config/boot.rb
# Set up gems listed in the Gemfile. ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../Gemfile", __dir__) require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"]) $LOAD_PATH.unshift File.expand_path("../../../lib", __dir__)
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/dummy/config/initializers/content_security_policy.rb
test/dummy/config/initializers/content_security_policy.rb
# Be sure to restart your server when you modify this file. # Define an application-wide content security policy. # See the Securing Rails Applications Guide for more information: # https://guides.rubyonrails.org/security.html#content-security-policy-header # Rails.application.configure do # config.content_security_policy do |policy| # policy.default_src :self, :https # policy.font_src :self, :https, :data # policy.img_src :self, :https, :data # policy.object_src :none # policy.script_src :self, :https # policy.style_src :self, :https # # Specify URI for violation reports # # policy.report_uri "/csp-violation-report-endpoint" # end # # # Generate session nonces for permitted importmap, inline scripts, and inline styles. # config.content_security_policy_nonce_generator = ->(request) { request.session.id.to_s } # config.content_security_policy_nonce_directives = %w(script-src style-src) # # # Report violations without enforcing the policy. # # config.content_security_policy_report_only = true # end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/dummy/config/initializers/filter_parameter_logging.rb
test/dummy/config/initializers/filter_parameter_logging.rb
# Be sure to restart your server when you modify this file. # Configure parameters to be partially matched (e.g. passw matches password) and filtered from the log file. # Use this to limit dissemination of sensitive information. # See the ActiveSupport::ParameterFilter documentation for supported notations and behaviors. Rails.application.config.filter_parameters += [ :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn ]
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/dummy/config/initializers/action_auth.rb
test/dummy/config/initializers/action_auth.rb
ActionAuth.configure do |config| config.allow_user_deletion = true config.default_from_email = "from@example.com" config.magic_link_enabled = true config.passkey_only = true # Allows sign in with only a passkey config.pwned_enabled = true # defined?(Pwned) config.sms_auth_enabled = true config.verify_email_on_sign_in = true config.webauthn_enabled = true # defined?(WebAuthn) config.webauthn_origin = "http://localhost:3000" # or "https://example.com" config.webauthn_rp_name = Rails.application.class.to_s.deconstantize config.insert_cookie_domain = false end Rails.application.config.after_initialize do ActionAuth.configure do |config| config.sms_send_class = SmsSender end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/dummy/config/initializers/inflections.rb
test/dummy/config/initializers/inflections.rb
# Be sure to restart your server when you modify this file. # Add new inflection rules using the following format. Inflections # are locale specific, and you may define rules for as many different # locales as you wish. All of these examples are active by default: # ActiveSupport::Inflector.inflections(:en) do |inflect| # inflect.plural /^(ox)$/i, "\\1en" # inflect.singular /^(ox)en/i, "\\1" # inflect.irregular "person", "people" # inflect.uncountable %w( fish sheep ) # end # These inflection rules are supported but not enabled by default: # ActiveSupport::Inflector.inflections(:en) do |inflect| # inflect.acronym "RESTful" # end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/dummy/config/initializers/permissions_policy.rb
test/dummy/config/initializers/permissions_policy.rb
# Be sure to restart your server when you modify this file. # Define an application-wide HTTP permissions policy. For further # information see: https://developers.google.com/web/updates/2018/06/feature-policy # Rails.application.config.permissions_policy do |policy| # policy.camera :none # policy.gyroscope :none # policy.microphone :none # policy.usb :none # policy.fullscreen :self # policy.payment :self, "https://secure.example.com" # end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/dummy/config/initializers/assets.rb
test/dummy/config/initializers/assets.rb
# Be sure to restart your server when you modify this file. # Version of your assets, change this if you want to expire all your assets. Rails.application.config.assets.version = "1.0" # Add additional assets to the asset load path. # Rails.application.config.assets.paths << Emoji.images_path # Precompile additional assets. # application.js, application.css, and all non-JS/CSS in the app/assets # folder are already added. # Rails.application.config.assets.precompile += %w( admin.js admin.css )
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/dummy/config/environments/test.rb
test/dummy/config/environments/test.rb
require "active_support/core_ext/integer/time" # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the test suite and is wiped # and recreated between test runs. Don't rely on the data there! Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # While tests run files are not watched, reloading is not necessary. config.enable_reloading = false # Eager loading loads your entire application. When running a single test locally, # this is usually not necessary, and can slow down your test suite. However, it's # recommended that you enable it in continuous integration systems to ensure eager # loading is working properly before deploying your code. config.eager_load = ENV["CI"].present? # Configure public file server for tests with Cache-Control for performance. config.public_file_server.enabled = true config.public_file_server.headers = { "Cache-Control" => "public, max-age=#{1.hour.to_i}" } # Show full error reports and disable caching. config.consider_all_requests_local = true config.action_controller.perform_caching = false config.cache_store = :null_store # Raise exceptions instead of rendering exception templates. config.action_dispatch.show_exceptions = :rescuable # Disable request forgery protection in test environment. config.action_controller.allow_forgery_protection = false # Store uploaded files on the local file system in a temporary directory. config.active_storage.service = :test config.action_mailer.perform_caching = false # Tell Action Mailer not to deliver emails to the real world. # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr # Raise exceptions for disallowed deprecations. config.active_support.disallowed_deprecation = :raise # Tell Active Support which deprecation messages to disallow. config.active_support.disallowed_deprecation_warnings = [] # Raises error for missing translations. # config.i18n.raise_on_missing_translations = true # Annotate rendered view with file names. # config.action_view.annotate_rendered_view_with_filenames = true # Raise error when a before_action's only/except options reference missing actions config.action_controller.raise_on_missing_callback_actions = true config.action_mailer.default_url_options = { host: "localhost", port: 3000 } end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/dummy/config/environments/development.rb
test/dummy/config/environments/development.rb
require "active_support/core_ext/integer/time" Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # In the development environment your application's code is reloaded any time # it changes. This slows down response time but is perfect for development # since you don't have to restart the web server when you make code changes. config.enable_reloading = true # Do not eager load code on boot. config.eager_load = false # Show full error reports. config.consider_all_requests_local = true # Enable server timing config.server_timing = true # Enable/disable caching. By default caching is disabled. # Run rails dev:cache to toggle caching. if Rails.root.join("tmp/caching-dev.txt").exist? config.action_controller.perform_caching = true config.action_controller.enable_fragment_cache_logging = true config.cache_store = :memory_store config.public_file_server.headers = { "Cache-Control" => "public, max-age=#{2.days.to_i}" } else config.action_controller.perform_caching = false config.cache_store = :null_store end # Store uploaded files on the local file system (see config/storage.yml for options). config.active_storage.service = :local # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = false config.action_mailer.perform_caching = false # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log # Raise exceptions for disallowed deprecations. config.active_support.disallowed_deprecation = :raise # Tell Active Support which deprecation messages to disallow. config.active_support.disallowed_deprecation_warnings = [] # Raise an error on page load if there are pending migrations. config.active_record.migration_error = :page_load # Highlight code that triggered database queries in logs. config.active_record.verbose_query_logs = true # Highlight code that enqueued background job in logs. config.active_job.verbose_enqueue_logs = true # Suppress logger output for asset requests. config.assets.quiet = true # Raises error for missing translations. # config.i18n.raise_on_missing_translations = true # Annotate rendered view with file names. # config.action_view.annotate_rendered_view_with_filenames = true # Uncomment if you wish to allow Action Cable access from any origin. # config.action_cable.disable_request_forgery_protection = true # Raise error when a before_action's only/except options reference missing actions config.action_controller.raise_on_missing_callback_actions = true config.action_mailer.delivery_method = :letter_opener config.action_mailer.perform_deliveries = true config.action_mailer.default_url_options = { host: "localhost", port: 3000 } end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/dummy/config/environments/production.rb
test/dummy/config/environments/production.rb
require "active_support/core_ext/integer/time" Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # Code is not reloaded between requests. config.enable_reloading = false # Eager load code on boot. This eager loads most of Rails and # your application in memory, allowing both threaded web servers # and those relying on copy on write to perform better. # Rake tasks automatically ignore this option for performance. config.eager_load = true # Full error reports are disabled and caching is turned on. config.consider_all_requests_local = false config.action_controller.perform_caching = true # Ensures that a master key has been made available in ENV["RAILS_MASTER_KEY"], config/master.key, or an environment # key such as config/credentials/production.key. This key is used to decrypt credentials (and other encrypted files). # config.require_master_key = true # Enable static file serving from the `/public` folder (turn off if using NGINX/Apache for it). config.public_file_server.enabled = true # Compress CSS using a preprocessor. # config.assets.css_compressor = :sass # Do not fallback to assets pipeline if a precompiled asset is missed. config.assets.compile = false # Enable serving of images, stylesheets, and JavaScripts from an asset server. # config.asset_host = "http://assets.example.com" # Specifies the header that your server uses for sending files. # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for Apache # config.action_dispatch.x_sendfile_header = "X-Accel-Redirect" # for NGINX # Store uploaded files on the local file system (see config/storage.yml for options). config.active_storage.service = :local # Mount Action Cable outside main process or domain. # config.action_cable.mount_path = nil # config.action_cable.url = "wss://example.com/cable" # config.action_cable.allowed_request_origins = [ "http://example.com", /http:\/\/example.*/ ] # Assume all access to the app is happening through a SSL-terminating reverse proxy. # Can be used together with config.force_ssl for Strict-Transport-Security and secure cookies. # config.assume_ssl = true # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. config.force_ssl = true # Log to STDOUT by default config.logger = ActiveSupport::Logger.new(STDOUT) .tap { |logger| logger.formatter = ::Logger::Formatter.new } .then { |logger| ActiveSupport::TaggedLogging.new(logger) } # Prepend all log lines with the following tags. config.log_tags = [ :request_id ] # Info include generic and useful information about system operation, but avoids logging too much # information to avoid inadvertent exposure of personally identifiable information (PII). If you # want to log everything, set the level to "debug". config.log_level = ENV.fetch("RAILS_LOG_LEVEL", "info") # Use a different cache store in production. # config.cache_store = :mem_cache_store # Use a real queuing backend for Active Job (and separate queues per environment). # config.active_job.queue_adapter = :resque # config.active_job.queue_name_prefix = "dummy_production" config.action_mailer.perform_caching = false # Ignore bad email addresses and do not raise email delivery errors. # Set this to true and configure the email server for immediate delivery to raise delivery errors. # config.action_mailer.raise_delivery_errors = false # Enable locale fallbacks for I18n (makes lookups for any locale fall back to # the I18n.default_locale when a translation cannot be found). config.i18n.fallbacks = true # Don't log any deprecations. config.active_support.report_deprecations = false # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false # Enable DNS rebinding protection and other `Host` header attacks. # config.hosts = [ # "example.com", # Allow requests from example.com # /.*\.example\.com/ # Allow requests from subdomains like `www.example.com` # ] # Skip DNS rebinding protection for the default health check endpoint. # config.host_authorization = { exclude: ->(request) { request.path == "/up" } } end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/lib/action_auth/version_test.rb
test/lib/action_auth/version_test.rb
require "test_helper" module ActionAuth class VersionTest < ActiveSupport::TestCase test "should be valid" do refute_nil ::ActionAuth::VERSION end end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/lib/action_auth/configuration_test.rb
test/lib/action_auth/configuration_test.rb
require 'test_helper' module ActionAuth class ConfigurationTest < ActiveSupport::TestCase def setup @config = Configuration.new end test 'should initialize with default values' do assert_equal defined?(WebAuthn), @config.webauthn_enabled assert_equal 'http://localhost:3000', @config.webauthn_origin assert_equal Rails.application.class.to_s.deconstantize, @config.webauthn_rp_name end test 'should allow reading and writing for webauthn_enabled' do @config.webauthn_enabled = false assert_equal false, @config.webauthn_enabled end test 'should allow reading and writing for webauthn_origin' do @config.webauthn_origin = 'http://example.com' assert_equal 'http://example.com', @config.webauthn_origin end test 'should allow reading and writing for webauthn_rp_name' do @config.webauthn_rp_name = 'MyAppName' assert_equal 'MyAppName', @config.webauthn_rp_name end test 'webauthn_enabled? returns the correct value' do @config.webauthn_enabled = true assert @config.webauthn_enabled? @config.webauthn_enabled = false refute @config.webauthn_enabled? @config.webauthn_enabled = -> { true } assert @config.webauthn_enabled? @config.webauthn_enabled = -> { false } refute @config.webauthn_enabled? end end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/lib/action_auth/controllers/helpers_test.rb
test/lib/action_auth/controllers/helpers_test.rb
require 'test_helper' class MockController < ActionController::Base include ActionAuth::Controllers::Helpers end class ActionAuth::Controllers::HelpersTest < ActionDispatch::IntegrationTest setup do @controller = MockController.new @session = action_auth_sessions(:one) @user = action_auth_users(:one) @controller.request = ActionController::TestRequest.create(@controller.class) end test "current_user should return the current user" do ActionAuth::Current.instance.session = @session assert_equal @user, @controller.current_user end test "current_session should return the current session" do ActionAuth::Current.session = @session assert_equal @session, @controller.current_session end test "user_signed_in? should return true when user is present" do ActionAuth::Current.instance.session = @session assert @controller.user_signed_in? end test "user_signed_in? should return false when no user is present" do ActionAuth::Current.instance.session = nil refute @controller.user_signed_in? end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/mailers/action_auth/user_mailer_test.rb
test/mailers/action_auth/user_mailer_test.rb
require "test_helper" module ActionAuth class UserMailerTest < ActionMailer::TestCase setup do @user = action_auth_users(:one) end test "password_reset" do mail = ActionAuth::UserMailer.with(user: @user).password_reset assert_equal "Reset your password", mail.subject assert_equal [@user.email], mail.to end test "email_verification" do mail = ActionAuth::UserMailer.with(user: @user).email_verification assert_equal "Verify your email", mail.subject assert_equal [@user.email], mail.to end test "magic_link" do mail = ActionAuth::UserMailer.with(user: @user).magic_link assert_equal "Sign in to your account", mail.subject assert_equal [@user.email], mail.to end end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/test/mailers/previews/action_auth/user_mailer_preview.rb
test/mailers/previews/action_auth/user_mailer_preview.rb
module ActionAuth # Preview all emails at http://localhost:3000/rails/mailers/user_mailer class UserMailerPreview < ActionMailer::Preview # Preview this email at http://localhost:3000/rails/mailers/user_mailer/email_verification def email_verification user = User.create(email: "john.smith@example.com", password: "123456789012") UserMailer.with(user: user).email_verification end # Preview this email at http://localhost:3000/rails/mailers/user_mailer/password_reset def password_reset user = User.create(email: "john.smith@example.com", password: "123456789012") UserMailer.with(user: user).password_reset end end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/lib/action_auth.rb
lib/action_auth.rb
require "action_auth/version" require "action_auth/engine" require "action_auth/configuration" module ActionAuth class << self attr_writer :configuration def configuration @configuration ||= Configuration.new end def configure yield(configuration) if block_given? configure_webauthn end def configure_webauthn return unless configuration.webauthn_enabled? return unless defined?(WebAuthn) WebAuthn.configure do |config| config.allowed_origins = if configuration.webauthn_origin.is_a?(Array) configuration.webauthn_origin else [configuration.webauthn_origin] end config.rp_name = configuration.webauthn_rp_name end end end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/lib/action_auth/version.rb
lib/action_auth/version.rb
module ActionAuth VERSION = "1.8.7" end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/lib/action_auth/configuration.rb
lib/action_auth/configuration.rb
module ActionAuth class Configuration attr_accessor :allow_user_deletion attr_accessor :default_from_email attr_accessor :magic_link_enabled attr_accessor :passkey_only attr_accessor :pwned_enabled attr_accessor :sms_auth_enabled attr_accessor :sms_send_class attr_accessor :verify_email_on_sign_in attr_accessor :webauthn_enabled attr_accessor :webauthn_origin attr_accessor :webauthn_rp_name attr_accessor :password_complexity_check attr_accessor :session_timeout attr_accessor :insert_cookie_domain def initialize @allow_user_deletion = true @default_from_email = Rails.application.config.action_mailer.default_options&.dig(:from) || "noreply@#{ENV['HOST'] || 'example.com'}" @magic_link_enabled = true @passkey_only = true @pwned_enabled = defined?(Pwned) @password_complexity_check = true @sms_auth_enabled = false @sms_send_class = nil @verify_email_on_sign_in = true @webauthn_enabled = defined?(WebAuthn) @webauthn_origin = Rails.env.production? ? "https://#{ENV['HOST']}" : "http://localhost:3000" @webauthn_rp_name = Rails.application.class.to_s.deconstantize @session_timeout = 2.weeks @insert_cookie_domain = false end def allow_user_deletion? @allow_user_deletion == true end def magic_link_enabled? @magic_link_enabled == true end def sms_auth_enabled? @sms_auth_enabled == true end def passkey_only? webauthn_enabled? && @passkey_only == true end def webauthn_enabled? @webauthn_enabled.respond_to?(:call) ? @webauthn_enabled.call : @webauthn_enabled end def pwned_enabled? @pwned_enabled.respond_to?(:call) ? @pwned_enabled.call : @pwned_enabled end def password_complexity_check? @password_complexity_check == true end end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/lib/action_auth/engine.rb
lib/action_auth/engine.rb
require 'action_auth/controllers/helpers' require 'action_auth/routing/helpers' module ActionAuth class Engine < ::Rails::Engine isolate_namespace ActionAuth ActiveSupport.on_load(:action_controller_base) do include ActionAuth::Controllers::Helpers include ActionAuth::Routing::Helpers end initializer 'action_auth.add_helpers' do |app| ActiveSupport.on_load :action_controller_base do helper_method :user_sessions_path, :user_session_path, :new_user_session_path helper_method :new_user_registration_path helper_method :edit_user_password_path end end end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/lib/action_auth/routing/helpers.rb
lib/action_auth/routing/helpers.rb
module ActionAuth module Routing module Helpers def user_sessions_path action_auth.sessions_path end def user_session_path(session_id) action_auth.session_path(session_id) end def new_user_session_path action_auth.sign_in_path end def new_user_registration_path action_auth.sign_up_path end def edit_password_path action_auth.edit_password_path end def password_path action_auth.password_path end end end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/lib/action_auth/controllers/helpers.rb
lib/action_auth/controllers/helpers.rb
module ActionAuth module Controllers module Helpers extend ActiveSupport::Concern included do before_action :set_current_request_details before_action :check_session_timeout def current_user; Current.user; end helper_method :current_user def current_session; Current.session; end helper_method :current_session def user_signed_in?; Current.user.present?; end helper_method :user_signed_in? def authenticate_user! return if user_signed_in? redirect_to new_user_session_path end helper_method :authenticate_user! end private def set_current_request_details Current.session = Session.find_by(id: cookies.signed[:session_token]) Current.user_agent = request.user_agent Current.ip_address = request.ip # Check if IP address or user agent has changed if Current.session && (Current.session.ip_address != Current.ip_address || Current.session.user_agent != Current.user_agent) Rails.logger.warn "Session environment changed for user #{Current.user&.id}: IP or User-Agent mismatch" # Optional: Force re-authentication for suspicious activity # cookies.delete(:session_token, secure: Rails.env.production?, same_site: :lax) # Current.session = nil end end def check_session_timeout return unless Current.session return if Rails.env.test? timeout = ActionAuth.configuration.session_timeout if Current.session.updated_at < timeout.ago Rails.logger.info "Session timed out for user #{Current.user&.id}" Current.session.destroy cookie_options = {} cookie_options[:secure] = Rails.env.production? if Rails.env.production? cookie_options[:same_site] = :lax unless Rails.env.test? cookies.delete(:session_token, cookie_options) redirect_to new_user_session_path, alert: "Your session has expired. Please sign in again." else Current.session.touch end end end end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
kobaltz/action_auth
https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/config/routes.rb
config/routes.rb
ActionAuth::Engine.routes.draw do get "sign_in", to: "sessions#new" post "sign_in", to: "sessions#create" get "sign_up", to: "registrations#new" post "sign_up", to: "registrations#create" namespace :identity do resource :email, only: [:edit, :update] resource :email_verification, only: [:show, :create] resource :password_reset, only: [:new, :edit, :create, :update] end resource :password, only: [:edit, :update] namespace :sessions do if ActionAuth.configuration.webauthn_enabled? && ActionAuth.configuration.passkey_only? resources :passkeys, only: [:new, :create] end end resources :sessions, only: [:index, :show, :destroy] if ActionAuth.configuration.allow_user_deletion? resource :users, only: [:destroy] end if ActionAuth.configuration.webauthn_enabled? resources :webauthn_credentials, only: [:new, :create, :destroy] do post :options, on: :collection, as: 'options_for' end resource :webauthn_credential_authentications, only: [:new, :create] end if ActionAuth.configuration.magic_link_enabled? namespace :magics do resource :sign_ins, only: [:show] resource :requests, only: [:new, :create] end end if ActionAuth.configuration.sms_auth_enabled? namespace :sms_auths do resource :sign_ins, only: [:show, :create] resource :requests, only: [:new, :create] end end end
ruby
MIT
b43f513090a1188e3f8f400ba4317c9b96c99181
2026-01-04T17:52:32.033910Z
false
toddmazierski/mint-exporter
https://github.com/toddmazierski/mint-exporter/blob/443976130010255d3259817affb2e38b320aa0bf/mint-exporter.rb
mint-exporter.rb
require 'mint' Mint.configure do |config| config.username = ENV.fetch('MINT_USERNAME') config.password = ENV.fetch('MINT_PASSWORD') end client = Mint::Client.new puts client.transactions.fetch
ruby
MIT
443976130010255d3259817affb2e38b320aa0bf
2026-01-04T17:52:31.479208Z
false
toddmazierski/mint-exporter
https://github.com/toddmazierski/mint-exporter/blob/443976130010255d3259817affb2e38b320aa0bf/spec/spec_helper.rb
spec/spec_helper.rb
require 'mint' require 'vcr' require 'webmock' VCR.configure do |config| config.cassette_library_dir = 'spec/cassettes' config.hook_into :webmock config.configure_rspec_metadata! end
ruby
MIT
443976130010255d3259817affb2e38b320aa0bf
2026-01-04T17:52:31.479208Z
false
toddmazierski/mint-exporter
https://github.com/toddmazierski/mint-exporter/blob/443976130010255d3259817affb2e38b320aa0bf/spec/lib/mint_spec.rb
spec/lib/mint_spec.rb
require 'spec_helper' describe Mint do describe '.configure' do let(:username) { 'test@example.org' } let(:password) { '123456' } it 'assigns username' do Mint.configure { |config| config.username = username } expect(Mint.config.username).to eq(username) end it 'assigns password' do Mint.configure { |config| config.password = password } expect(Mint.config.password).to eq(password) end end end
ruby
MIT
443976130010255d3259817affb2e38b320aa0bf
2026-01-04T17:52:31.479208Z
false
toddmazierski/mint-exporter
https://github.com/toddmazierski/mint-exporter/blob/443976130010255d3259817affb2e38b320aa0bf/spec/lib/mint/client_spec.rb
spec/lib/mint/client_spec.rb
require 'spec_helper' require 'csv' describe Mint::Client do describe '#transaction', vcr: {match_requests_on: %i(method uri body headers)} do before do Mint.configure do |config| config.username = 'test@example.org' config.password = '123456' end end let(:client) { Mint::Client.new } let(:actual_transactions) do CSV.parse(client.transactions.fetch) end let(:expected_transactions) do [ ['Date', 'Description', 'Original Description', 'Amount', 'Transaction Type', 'Category', 'Account Name', 'Labels', 'Notes'], ['5/01/2009', 'homestarrunner.com', 'FLUFFY PUFF MARSHMALLOWS', '11.99', 'debit', 'Junk Food', 'QuesoCard', '', ''] ] end it 'returns transactions' do expect(actual_transactions).to eq(expected_transactions) end end end
ruby
MIT
443976130010255d3259817affb2e38b320aa0bf
2026-01-04T17:52:31.479208Z
false
toddmazierski/mint-exporter
https://github.com/toddmazierski/mint-exporter/blob/443976130010255d3259817affb2e38b320aa0bf/spec/lib/mint/session_spec.rb
spec/lib/mint/session_spec.rb
require 'spec_helper' describe Mint::Session do describe '#create!' do let(:session) { Mint::Session.new } context 'error in response' do let(:response) { '{"error": {"the_system": "is_down"}}' } before { allow(session).to receive(:request).and_return(response) } it 'raises an exception' do expect { session.create! }.to raise_error '{"the_system"=>"is_down"}' end end end end
ruby
MIT
443976130010255d3259817affb2e38b320aa0bf
2026-01-04T17:52:31.479208Z
false
toddmazierski/mint-exporter
https://github.com/toddmazierski/mint-exporter/blob/443976130010255d3259817affb2e38b320aa0bf/lib/mint.rb
lib/mint.rb
require 'dotenv' require 'rest-client' require 'wait' Dotenv.load require_relative 'mint/config' module Mint URL = 'https://wwws.mint.com' class << self; attr_reader :config; end @config = Mint::Config.new def self.configure yield(config) end end require_relative 'mint/client' require_relative 'mint/session' require_relative 'mint/transaction'
ruby
MIT
443976130010255d3259817affb2e38b320aa0bf
2026-01-04T17:52:31.479208Z
false
toddmazierski/mint-exporter
https://github.com/toddmazierski/mint-exporter/blob/443976130010255d3259817affb2e38b320aa0bf/lib/mint/session.rb
lib/mint/session.rb
module Mint class Session URL = "#{Mint::URL}/loginUserSubmit.xevent" def create! response = request error = JSON.parse(response)['error'] raise(error.to_s) if error @cookies = response.cookies end def params {cookies: cookies} end private attr_reader :cookies def request params = { username: Mint.config.username, password: Mint.config.password, task: 'L' } RestClient.post(URL, params, accept: :json) end end end
ruby
MIT
443976130010255d3259817affb2e38b320aa0bf
2026-01-04T17:52:31.479208Z
false
toddmazierski/mint-exporter
https://github.com/toddmazierski/mint-exporter/blob/443976130010255d3259817affb2e38b320aa0bf/lib/mint/transaction.rb
lib/mint/transaction.rb
module Mint class Transaction URL = "#{Mint::URL}/transactionDownload.event" attr_reader :session def initialize(session) @session = session end def fetch request_until_valid end private # A workaround for this bug: # https://github.com/toddmazierski/mint-exporter/issues/6 def request_until_valid wait = Wait.new(attempts: 10, delay: 5) wait.until do response = request valid?(response) ? response : next end end def request RestClient.get(URL, session.params) end def valid?(response) response.headers[:content_type].include?('text/csv') end end end
ruby
MIT
443976130010255d3259817affb2e38b320aa0bf
2026-01-04T17:52:31.479208Z
false
toddmazierski/mint-exporter
https://github.com/toddmazierski/mint-exporter/blob/443976130010255d3259817affb2e38b320aa0bf/lib/mint/client.rb
lib/mint/client.rb
module Mint class Client def transactions Mint::Transaction.new(session) end private def session @session ||= Mint::Session.new.tap(&:create!) end end end
ruby
MIT
443976130010255d3259817affb2e38b320aa0bf
2026-01-04T17:52:31.479208Z
false