summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOskar Nyberg <oskar@mullvad.net>2021-07-06 19:07:34 +0200
committerOskar Nyberg <oskar@mullvad.net>2021-07-08 13:23:30 +0200
commit0623490815c5b9377be1c1bb266c4e34d2fc1980 (patch)
treec7791e2c65169e28a4ce88a3718aaf515e0393b1
parent91a30f07505eaea3f4669ba874ee497af43d89a3 (diff)
downloadmullvadvpn-0623490815c5b9377be1c1bb266c4e34d2fc1980.tar.xz
mullvadvpn-0623490815c5b9377be1c1bb266c4e34d2fc1980.zip
Remove periodic account data fetch when account has expired
-rw-r--r--gui/src/main/account-data-cache.ts8
-rw-r--r--gui/test/account-data-cache.spec.ts35
2 files changed, 2 insertions, 41 deletions
diff --git a/gui/src/main/account-data-cache.ts b/gui/src/main/account-data-cache.ts
index 8b81a29472..74e89b923a 100644
--- a/gui/src/main/account-data-cache.ts
+++ b/gui/src/main/account-data-cache.ts
@@ -1,4 +1,4 @@
-import { closeToExpiry, hasExpired } from '../shared/account-expiry';
+import { closeToExpiry } from '../shared/account-expiry';
import { AccountToken, IAccountData, VoucherResponse } from '../shared/daemon-rpc-types';
import { DateComponent, dateByAddingComponent } from '../shared/date-helper';
import log from '../shared/logging';
@@ -6,8 +6,6 @@ import consumePromise from '../shared/promise';
import { Scheduler } from '../shared/scheduler';
import { InvalidAccountError } from './errors';
-const EXPIRED_ACCOUNT_REFRESH_PERIOD = 60_000;
-
interface IAccountFetchWatcher {
onFinish: () => void;
onError: (error: Error) => void;
@@ -113,9 +111,7 @@ export default class AccountDataCache {
const currentDate = new Date();
const oneMinuteBeforeExpiry = dateByAddingComponent(accountExpiry, DateComponent.minute, -1);
- if (hasExpired(accountExpiry)) {
- return EXPIRED_ACCOUNT_REFRESH_PERIOD;
- } else if (oneMinuteBeforeExpiry >= currentDate && closeToExpiry(accountExpiry)) {
+ if (oneMinuteBeforeExpiry >= currentDate && closeToExpiry(accountExpiry)) {
return oneMinuteBeforeExpiry.getTime() - currentDate.getTime();
} else {
return undefined;
diff --git a/gui/test/account-data-cache.spec.ts b/gui/test/account-data-cache.spec.ts
index c482e16a5d..fd79a2a697 100644
--- a/gui/test/account-data-cache.spec.ts
+++ b/gui/test/account-data-cache.spec.ts
@@ -135,41 +135,6 @@ describe('IAccountData cache', () => {
});
});
- it('should refetch if account has expired', async () => {
- const expiredSpy = spy();
- const nonExpiredSpy = spy();
-
- const update = new Promise<void>((resolve, reject) => {
- let firstAttempt = true;
- const fetch = () => {
- if (firstAttempt) {
- expiredSpy();
- firstAttempt = false;
- setTimeout(() => clock.tick(60_000), 0);
- return Promise.resolve({
- expiry: new Date('1969-01-01').toISOString(),
- });
- } else {
- nonExpiredSpy();
- resolve();
- return Promise.resolve(dummyAccountData);
- }
- };
-
- const cache = new AccountDataCache(fetch, () => {});
-
- cache.fetch(dummyAccountToken, {
- onFinish: () => {},
- onError: (_error: Error) => reject(),
- });
- });
-
- return expect(update).to.eventually.be.fulfilled.then(() => {
- expect(expiredSpy).to.have.been.called.once;
- expect(nonExpiredSpy).to.have.been.called.once;
- });
- });
-
it('should clear scheduled retry if another fetch is performed', async () => {
const firstError = spy();
const secondSuccess = spy();