question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

User expired property always true

See original GitHub issue

I recently ran into an issue where the user expired property was always true even just after receiving a new token from the identity server.

The current User.test.ts passes but if it is updated to use jest mock timers, it fails.

Example:

import { User } from "./User";

describe("User", () => {
    beforeEach(() => {
        jest.useFakeTimers(); // changed from jest.spyOn
    });

    afterEach(() => {
        jest.restoreAllMocks();
    });

    describe("expired", () => {
        it("should calculate how much time left", () => {
            const subject = new User({ expires_at: 100 } as never);
            expect(subject.expired).toEqual(false);

            // act
            jest.advanceTimersByTime(100); // changed from "now += 100"

            // assert
            expect(subject.expired).toEqual(true);
        });
    });

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
kherockcommented, Apr 4, 2022

@pamapa that code removed in the diff wasn’t setting expires_in, it was a redundant assignment ensuring that expires_in is stored as a number as opposed to a string. I removed it since we already cast it as a number in the setter.

The actual assignment occurs in the Object.assign when the code is exchanged: https://github.com/authts/oidc-client-ts/blob/8bf2b68629d9b48d79f28c8cfc88db2d5000d5b6/src/ResponseValidator.ts#L220-L228

The other one for refresh tokens is here: https://github.com/authts/oidc-client-ts/blob/8bf2b68629d9b48d79f28c8cfc88db2d5000d5b6/src/OidcClient.ts#L171-L177

0reactions
pamapacommented, Apr 11, 2022

As changing the time (in unit-test) after the expires_at was calculated has no impact on the expires_at i will soon close this issue, unless you report more info…

Read more comments on GitHub >

github_iconTop Results From Across the Web

If user password expired , any AD attributes change ? - TechNet
First, the pwdLastSet attribute is not changed to zero when a user password expires. The value remains unchanged, corresponding to the datetime ...
Read more >
IsAuthenticated stays true after expiry - Stack Overflow
When the user is authenticated, a ticket is issued. To save on DB queries, that ticket is revalidated on an interval (20 minutes...
Read more >
Account Expiration
If a user object in Active Directory has never had an expiration date, the accountExpires attribute is set to a huge number. The...
Read more >
Expired AD accounts remains active in Azure AD - blksthl
The 'Enabled' property of a user account is one of the properties that are always synced to Azure AD. This is on an...
Read more >
useSession({ required: true }), which always returns a non-null ...
A living session could be a requirement for specific pages. If it doesn't exist, then the user should be redirected to the sign...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found