-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Capture request details for each new session
When logged into the application I want to be able to view all my active sessions so that I can determine if my account has been compromised based on the session data, user agent, and IP address. Issues ------ - Closes #69
- Loading branch information
1 parent
b055fc7
commit 1010370
Showing
9 changed files
with
152 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<td><%= active_session.user_agent %></td> | ||
<td><%= active_session.ip_address %></td> | ||
<td><%= active_session.created_at %></td> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
db/migrate/20220201102359_add_request_columns_to_active_sessions.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class AddRequestColumnsToActiveSessions < ActiveRecord::Migration[6.1] | ||
def change | ||
add_column :active_sessions, :user_agent, :string | ||
add_column :active_sessions, :ip_address, :string | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require "test_helper" | ||
|
||
class UserInterfaceTest < ActionDispatch::IntegrationTest | ||
setup do | ||
@confirmed_user = User.create!(email: "confirmed_user@example.com", password: "password", password_confirmation: "password", confirmed_at: Time.current) | ||
end | ||
|
||
test "should render active sessions on account page" do | ||
login @confirmed_user | ||
@confirmed_user.active_sessions.last.update!(user_agent: "Mozilla", ip_address: "123.457.789") | ||
|
||
get account_path | ||
|
||
assert_match "Mozilla", @response.body | ||
assert_match "123.457.789", @response.body | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require "application_system_test_case" | ||
|
||
class LoginsTest < ApplicationSystemTestCase | ||
setup do | ||
@confirmed_user = User.create!(email: "confirmed_user@example.com", password: "password", password_confirmation: "password", confirmed_at: Time.current) | ||
end | ||
|
||
test "should login and create active session if confirmed" do | ||
visit login_path | ||
|
||
fill_in "Email", with: @confirmed_user.email | ||
fill_in "Password", with: @confirmed_user.password | ||
click_on "Sign In" | ||
|
||
assert_not_nil @confirmed_user.active_sessions.last.user_agent | ||
assert_not_nil @confirmed_user.active_sessions.last.ip_address | ||
end | ||
end |