Compare commits

...

1 Commits

Author SHA1 Message Date
Rick Carlino 35ae847fe9 Updates to help_customer helper 2020-03-25 14:56:43 -05:00
3 changed files with 12 additions and 5 deletions

View File

@ -46,9 +46,10 @@ class SessionToken < AbstractJwtToken
beta_os_update_server: BETA_OS_URL }])
end
def self.as_json(user, aud, fbos_version)
def self.as_json(user, aud, fbos_version, exp = EXPIRY.from_now.to_i)
{ token: SessionToken.issue_to(user, iss: $API_URL,
aud: aud,
exp: exp,
fbos_version: fbos_version),
user: user }
end

View File

@ -166,8 +166,12 @@ class Device < ApplicationRecord
# Used by sys admins to debug problems without performing a password reset.
def help_customer
Rollbar.error("Someone is creating a debug user token", { device: self.id })
token = SessionToken.as_json(users.first, "staff", fbos_version).to_json
return "localStorage['session'] = JSON.stringify(#{token});"
token = SessionToken.as_json(users.first,
"staff",
fbos_version,
9.hours.from_now.to_i)
puts "localStorage['session'] = JSON.stringify(#{token.to_json});"
token
end
TOO_MANY_CONNECTIONS =

View File

@ -5,8 +5,10 @@ describe Device do
let(:user) { device.users.first }
it "creates a token" do
jwt = device.help_customer
expect(jwt).to be_kind_of(String)
expect do
jwt = device.help_customer
expect(jwt[:token]).to be_kind_of(SessionToken)
end.to output(/localStorage\[\'session\'\]/).to_stdout
end
it "is associated with a user" do