From 3ac47099031a1011a9ac80d648ed09808321ca20 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 28 Feb 2017 10:38:22 -0500 Subject: [PATCH] FIX: on initial token issue stop unmarking token as unseen prev and current are the same so we need special logic to bypass --- app/models/user_auth_token.rb | 2 +- spec/models/user_auth_token_spec.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/models/user_auth_token.rb b/app/models/user_auth_token.rb index 6e9d4e9d577..d020d861015 100644 --- a/app/models/user_auth_token.rb +++ b/app/models/user_auth_token.rb @@ -64,7 +64,7 @@ class UserAuthToken < ActiveRecord::Base return nil end - if user_token.prev_auth_token == token && user_token.auth_token_seen + if user_token.auth_token != token && user_token.prev_auth_token == token && user_token.auth_token_seen changed_rows = UserAuthToken .where(id: user_token.id, prev_auth_token: token) .update_all(auth_token_seen: false) diff --git a/spec/models/user_auth_token_spec.rb b/spec/models/user_auth_token_spec.rb index b7961d1d444..d516c29589f 100644 --- a/spec/models/user_auth_token_spec.rb +++ b/spec/models/user_auth_token_spec.rb @@ -251,4 +251,18 @@ describe UserAuthToken do end + it "will not mark token unseen when prev and current are the same" do + user = Fabricate(:user) + + token = UserAuthToken.generate!(user_id: user.id, + user_agent: "some user agent", + client_ip: "1.1.2.3") + + + lookup = UserAuthToken.lookup(token.unhashed_auth_token, seen: true) + lookup = UserAuthToken.lookup(token.unhashed_auth_token, seen: true) + lookup.reload + expect(lookup.auth_token_seen).to eq(true) + end + end