Skip to content

Commit

Permalink
Merge pull request #1083 from damienbod/fabiangosebrink/#1081-fixing-…
Browse files Browse the repository at this point in the history
…storage-json-issue

fixed json stringify objects and storage
  • Loading branch information
damienbod committed May 1, 2021
2 parents 24f2b87 + 50370d5 commit 8743658
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
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

0 comments on commit 8743658

Please sign in to comment.