Skip to content

Commit 5bd99a1

Browse files
author
Andrea Barbasso
committed
[CST-15593] fix authenticated orejime cookie encoding
1 parent 6257718 commit 5bd99a1

4 files changed

Lines changed: 15 additions & 3 deletions

File tree

cypress/support/e2e.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ before(() => {
5656
beforeEach(() => {
5757
// Pre-agree to all Orejime cookies by setting the orejime-anonymous cookie
5858
// This just ensures it doesn't get in the way of matching other objects in the page.
59-
cy.setCookie('orejime-anonymous', '{%22authentication%22:true%2C%22preferences%22:true%2C%22acknowledgement%22:true%2C%22google-analytics%22:true%2C%22google-recaptcha%22:true}');
59+
cy.setCookie('orejime-anonymous', '{"authentication":true,"preferences":true,"acknowledgement":true,"google-analytics":true}');
6060

6161
// Remove any CSRF cookies saved from prior tests
6262
cy.clearCookie(DSPACE_XSRF_COOKIE);

src/app/shared/cookies/browser-orejime.service.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ describe('BrowserOrejimeService', () => {
7070
configurationDataService = createConfigSuccessSpy(recaptchaValue);
7171
findByPropertyName = configurationDataService.findByPropertyName;
7272
cookieService = jasmine.createSpyObj('cookieService', {
73-
get: '{%22token_item%22:true%2C%22impersonation%22:true%2C%22redirect%22:true%2C%22language%22:true%2C%22orejime%22:true%2C%22has_agreed_end_user%22:true%2C%22google-analytics%22:true}',
73+
get: '{"authentication":true,"preferences":true,"acknowledgement":true,"google-analytics":true}',
7474
set: () => {
7575
/* empty */
7676
},

src/app/shared/cookies/browser-orejime.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ export class BrowserOrejimeService extends OrejimeService {
207207
*/
208208
private initializeUser(user: EPerson) {
209209
this.orejimeConfig.callback = debounce((consent, app) => this.updateSettingsForUsers(user), updateDebounce);
210-
this.orejimeConfig.storageName = this.getStorageName(user.uuid);
210+
this.orejimeConfig.cookieName = this.getStorageName(user.uuid);
211211

212212
const anonCookie = this.cookieService.get(ANONYMOUS_STORAGE_NAME_OREJIME);
213213
if (hasValue(this.getSettingsForUser(user))) {

src/app/shared/cookies/orejime-configuration.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ export function getOrejimeConfiguration(_window: NativeWindowRef): any {
4444
*/
4545
appElement: 'ds-app',
4646

47+
stringifyCookie: (contents: any) => {
48+
return (typeof contents === 'string') ? contents : JSON.stringify(contents);
49+
},
50+
51+
parseCookie: (cookie: string) => {
52+
if (typeof cookie === 'string') {
53+
cookie = decodeURIComponent(cookie);
54+
return JSON.parse(cookie);
55+
}
56+
return cookie;
57+
},
58+
4759
/*
4860
You can overwrite existing translations and add translations for your app
4961
descriptions and purposes. See `src/translations/` for a full list of

0 commit comments

Comments
 (0)