Only allow new token to be viewed within 10 seconds

This commit is contained in:
David Heinemeier Hansson
2025-12-02 15:03:17 +01:00
committed by Stanko K.R.
parent d2bdd13909
commit 96b62d6ec4
3 changed files with 46 additions and 2 deletions
@@ -0,0 +1,30 @@
require "test_helper"
class My::AccessTokensControllerTest < ActionDispatch::IntegrationTest
setup do
sign_in_as :kevin
end
test "create new token" do
get my_access_tokens_path
assert_response :success
get new_my_access_token_path
assert_response :success
assert_changes -> { identities(:kevin).access_tokens.count }, +1 do
post my_access_tokens_path, params: { access_token: { description: "GitHub", permission: "read" } }
follow_redirect!
assert_in_body identities(:kevin).access_tokens.last.token
end
end
test "accessing new token after reveal window redirects to index" do
assert_changes -> { identities(:kevin).access_tokens.count }, +1 do
post my_access_tokens_path, params: { access_token: { description: "GitHub", permission: "read" } }
travel_to 15.seconds.from_now
follow_redirect!
assert_equal "Token is no longer visible", flash[:alert]
end
end
end