Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed json stringify objects and storage #1083

Merged
merged 1 commit into from
May 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { ConfigurationProvider } from '../config/config.provider';
import { ConfigurationProviderMock } from '../config/config.provider-mock';
import { LoggerService } from '../logging/logger.service';
import { LoggerServiceMock } from '../logging/logger.service-mock';
import { StoragePersistenceService } from '../storage/storage-persistence.service';
import { StoragePersistenceServiceMock } from '../storage/storage-persistence-service-mock.service';
import { StoragePersistenceService } from '../storage/storage-persistence.service';
import { FlowsDataService } from './flows-data.service';
import { RandomService } from './random/random.service';

Expand Down Expand Up @@ -149,16 +149,15 @@ describe('Flows Data Service', () => {
state: 'running',
dateOfLaunchedProcessUtc: baseTime.toISOString(),
};
const storedJsonString = JSON.stringify(storageObject);

spyOn(storagePersistenceService, 'read').withArgs('storageSilentRenewRunning').and.returnValue(storedJsonString);
spyOn(storagePersistenceService, 'read').withArgs('storageSilentRenewRunning').and.returnValue(storageObject);
const spyWrite = spyOn(storagePersistenceService, 'write');

jasmine.clock().tick((openIDConfiguration.silentRenewTimeoutInSeconds + 1) * 1000);

const isSilentRenewRunningResult = service.isSilentRenewRunning();

expect(spyWrite).toHaveBeenCalledWith('storageSilentRenewRunning', '');
expect(spyWrite).toHaveBeenCalledWith('storageSilentRenewRunning', null);
expect(isSilentRenewRunningResult).toBeFalse();
});

Expand All @@ -177,9 +176,8 @@ describe('Flows Data Service', () => {
state: 'running',
dateOfLaunchedProcessUtc: baseTime.toISOString(),
};
const storedJsonString = JSON.stringify(storageObject);

spyOn(storagePersistenceService, 'read').withArgs('storageSilentRenewRunning').and.returnValue(storedJsonString);
spyOn(storagePersistenceService, 'read').withArgs('storageSilentRenewRunning').and.returnValue(storageObject);
const spyWrite = spyOn(storagePersistenceService, 'write');

const isSilentRenewRunningResult = service.isSilentRenewRunning();
Expand Down Expand Up @@ -207,19 +205,18 @@ describe('Flows Data Service', () => {
state: 'running',
dateOfLaunchedProcessUtc: baseTime.toISOString(),
};
const expectedJsonString = JSON.stringify(storageObject);

const spy = spyOn(storagePersistenceService, 'write');
service.setSilentRenewRunning();
expect(spy).toHaveBeenCalledWith('storageSilentRenewRunning', expectedJsonString);
expect(spy).toHaveBeenCalledWith('storageSilentRenewRunning', storageObject);
});
});

describe('resetSilentRenewRunning', () => {
it('set resetSilentRenewRunning to `` when called', () => {
it('set resetSilentRenewRunning to null when called', () => {
const spy = spyOn(storagePersistenceService, 'write');
service.resetSilentRenewRunning();
expect(spy).toHaveBeenCalledWith('storageSilentRenewRunning', ``);
expect(spy).toHaveBeenCalledWith('storageSilentRenewRunning', null);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class FlowsDataService {
}

isSilentRenewRunning() {
const storageObject = JSON.parse(this.storagePersistenceService.read('storageSilentRenewRunning'));
const storageObject = this.storagePersistenceService.read('storageSilentRenewRunning');

if (storageObject) {
const { silentRenewTimeoutInSeconds } = this.configurationProvider.getOpenIDConfiguration();
Expand Down Expand Up @@ -87,10 +87,10 @@ export class FlowsDataService {
dateOfLaunchedProcessUtc: new Date().toISOString(),
};

this.storagePersistenceService.write('storageSilentRenewRunning', JSON.stringify(storageObject));
this.storagePersistenceService.write('storageSilentRenewRunning', storageObject);
}

resetSilentRenewRunning() {
this.storagePersistenceService.write('storageSilentRenewRunning', '');
this.storagePersistenceService.write('storageSilentRenewRunning', null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -254,20 +254,20 @@ export class StateValidationService {

private handleSuccessfulValidation(): void {
const { autoCleanStateAfterAuthentication } = this.configurationProvider.getOpenIDConfiguration();
this.storagePersistenceService.write('authNonce', '');
this.storagePersistenceService.write('authNonce', null);

if (autoCleanStateAfterAuthentication) {
this.storagePersistenceService.write('authStateControl', '');
this.storagePersistenceService.write('authStateControl', null);
}
this.loggerService.logDebug('AuthorizedCallback token(s) validated, continue');
}

private handleUnsuccessfulValidation(): void {
const { autoCleanStateAfterAuthentication } = this.configurationProvider.getOpenIDConfiguration();
this.storagePersistenceService.write('authNonce', '');
this.storagePersistenceService.write('authNonce', null);

if (autoCleanStateAfterAuthentication) {
this.storagePersistenceService.write('authStateControl', '');
this.storagePersistenceService.write('authStateControl', null);
}
this.loggerService.logDebug('AuthorizedCallback token(s) invalid');
}
Expand Down