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

[#2718] Migrate cookie consent from Klaro to Orejime #3199

Merged
merged 14 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cypress/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ before(() => {

// Runs once before the first test in each "block"
beforeEach(() => {
// Pre-agree to all Klaro cookies by setting the klaro-anonymous cookie
// Pre-agree to all Orejime cookies by setting the orejime-anonymous cookie
// This just ensures it doesn't get in the way of matching other objects in the page.
cy.setCookie('klaro-anonymous', '{%22authentication%22:true%2C%22preferences%22:true%2C%22acknowledgement%22:true%2C%22google-analytics%22:true%2C%22google-recaptcha%22:true}');
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}');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the anonymous orejime cookie is just named "orejime" (at least that's what I'm seeing in my cookies locally).

So, this line may need to replace 'orejime-anonymous' with 'orejime'. That might also fix the tests failures you are seeing, as I think these e2e tests are setting the wrong cookie, and the test failures are caused by the Orejime cookie popup getting in front of the page content.


// Remove any CSRF cookies saved from prior tests
cy.clearCookie(DSPACE_XSRF_COOKIE);
Expand Down
261 changes: 169 additions & 92 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@
"json5": "^2.2.3",
"jsonschema": "1.4.1",
"jwt-decode": "^3.1.2",
"klaro": "^0.7.18",
"lodash": "^4.17.21",
"lru-cache": "^7.14.1",
"markdown-it": "^13.0.1",
Expand All @@ -157,6 +156,7 @@
"ngx-pagination": "6.0.3",
"ngx-ui-switch": "^14.1.0",
"nouislider": "^15.7.1",
"orejime": "^2.3.0",
"pem": "1.14.8",
"reflect-metadata": "^0.2.2",
"rxjs": "^7.8.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('GoogleRecaptchaService', () => {
findByPropertyName: createSuccessfulRemoteDataObject$({ values: ['googleRecaptchaToken'] }),
});
cookieService = jasmine.createSpyObj('cookieService', {
get: '{%22token_item%22:true%2C%22impersonation%22:true%2C%22redirect%22:true%2C%22language%22:true%2C%22klaro%22:true%2C%22has_agreed_end_user%22:true%2C%22google-analytics%22:true}',
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}',
set: () => {
/* empty */
},
Expand Down
2 changes: 1 addition & 1 deletion src/app/core/google-recaptcha/google-recaptcha.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class GoogleRecaptchaService {
tap(([recaptchaVersionRD, recaptchaModeRD, recaptchaKeyRD]) => {

if (
this.cookieService.get('klaro-anonymous') && this.cookieService.get('klaro-anonymous')[CAPTCHA_NAME] &&
this.cookieService.get('orejime-anonymous') && this.cookieService.get('orejime-anonymous')[CAPTCHA_NAME] &&
tdonohue marked this conversation as resolved.
Show resolved Hide resolved
recaptchaKeyRD.hasSucceeded && recaptchaVersionRD.hasSucceeded &&
isNotEmpty(recaptchaVersionRD.payload?.values) && isNotEmpty(recaptchaKeyRD.payload?.values)
) {
Expand Down
4 changes: 2 additions & 2 deletions src/app/footer/footer.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
import { NotifyInfoService } from '../core/coar-notify/notify-info/notify-info.service';
import { AuthorizationDataService } from '../core/data/feature-authorization/authorization-data.service';
import { FeatureID } from '../core/data/feature-authorization/feature-id';
import { KlaroService } from '../shared/cookies/klaro.service';
import { OrejimeService } from '../shared/cookies/orejime.service';
import { hasValue } from '../shared/empty.util';

@Component({
Expand All @@ -46,7 +46,7 @@ export class FooterComponent implements OnInit {
coarLdnEnabled$: Observable<boolean>;

constructor(
@Optional() public cookies: KlaroService,
@Optional() public cookies: OrejimeService,
protected authorizationService: AuthorizationDataService,
protected notifyInfoService: NotifyInfoService,
@Inject(APP_CONFIG) protected appConfig: AppConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ <h1>{{MESSAGE_PREFIX + '.header'|translate}}</h1>

<ds-alert [type]="AlertTypeEnum.Warning" *ngIf="registrationVerification && !isRecaptchaCookieAccepted()">
<p class="m-0" [innerHTML]="MESSAGE_PREFIX + '.google-recaptcha.must-accept-cookies' | translate"></p>
<p class="m-0"><a href="javascript:void(0);" (click)="this.klaroService.showSettings()">{{ MESSAGE_PREFIX + '.google-recaptcha.open-cookie-settings' | translate }}</a></p>
<p class="m-0"><a href="javascript:void(0);" (click)="this.orejimeService.showSettings()">{{ MESSAGE_PREFIX + '.google-recaptcha.open-cookie-settings' | translate }}</a></p>
</ds-alert>

<div class="my-3" *ngIf="isRecaptchaCookieAccepted() && (googleRecaptchaService.captchaVersion() | async) === 'v2'">
Expand Down
8 changes: 4 additions & 4 deletions src/app/register-email-form/register-email-form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import {
import { Registration } from '../core/shared/registration.model';
import { AlertComponent } from '../shared/alert/alert.component';
import { AlertType } from '../shared/alert/alert-type';
import { KlaroService } from '../shared/cookies/klaro.service';
import { OrejimeService } from '../shared/cookies/orejime.service';
import { isNotEmpty } from '../shared/empty.util';
import { GoogleRecaptchaComponent } from '../shared/google-recaptcha/google-recaptcha.component';
import { NotificationsService } from '../shared/notifications/notifications.service';
Expand Down Expand Up @@ -126,7 +126,7 @@ export class RegisterEmailFormComponent implements OnDestroy, OnInit {
private configService: ConfigurationDataService,
public googleRecaptchaService: GoogleRecaptchaService,
public cookieService: CookieService,
@Optional() public klaroService: KlaroService,
@Optional() public orejimeService: OrejimeService,
private changeDetectorRef: ChangeDetectorRef,
private notificationsService: NotificationsService,
) {
Expand Down Expand Up @@ -247,8 +247,8 @@ export class RegisterEmailFormComponent implements OnDestroy, OnInit {
* Return true if the user has accepted the required cookies for reCaptcha
*/
isRecaptchaCookieAccepted(): boolean {
const klaroAnonymousCookie = this.cookieService.get('klaro-anonymous');
return isNotEmpty(klaroAnonymousCookie) ? klaroAnonymousCookie[CAPTCHA_NAME] : false;
const orejimeAnonymousCookie = this.cookieService.get('orejime-anonymous');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, the anonymous cookie seems to be named orejime.

return isNotEmpty(orejimeAnonymousCookie) ? orejimeAnonymousCookie[CAPTCHA_NAME] : false;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ import {
createSuccessfulRemoteDataObject$,
} from '../remote-data.utils';
import {
BrowserKlaroService,
BrowserOrejimeService,
COOKIE_MDFIELD,
} from './browser-klaro.service';
import { ANONYMOUS_STORAGE_NAME_KLARO } from './klaro-configuration';
} from './browser-orejime.service';
import { ANONYMOUS_STORAGE_NAME_OREJIME } from './orejime-configuration';

describe('BrowserKlaroService', () => {
describe('BrowserOrejimeService', () => {
const trackingIdProp = 'google.analytics.key';
const trackingIdTestValue = 'mock-tracking-id';
const googleAnalytics = 'google-analytics';
Expand All @@ -37,7 +37,7 @@ describe('BrowserKlaroService', () => {
let cookieService;

let user;
let service: BrowserKlaroService;
let service: BrowserOrejimeService;
let configurationDataService: ConfigurationDataService;
const createConfigSuccessSpy = (...values: string[]) => jasmine.createSpyObj('configurationDataService', {
findByPropertyName: createSuccessfulRemoteDataObject$({
Expand Down Expand Up @@ -70,15 +70,15 @@ describe('BrowserKlaroService', () => {
configurationDataService = createConfigSuccessSpy(recaptchaValue);
findByPropertyName = configurationDataService.findByPropertyName;
cookieService = jasmine.createSpyObj('cookieService', {
get: '{%22token_item%22:true%2C%22impersonation%22:true%2C%22redirect%22:true%2C%22language%22:true%2C%22klaro%22:true%2C%22has_agreed_end_user%22:true%2C%22google-analytics%22:true}',
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}',
set: () => {
/* empty */
},
});

TestBed.configureTestingModule({
providers: [
BrowserKlaroService,
BrowserOrejimeService,
{
provide: TranslateService,
useValue: translateService,
Expand All @@ -101,7 +101,7 @@ describe('BrowserKlaroService', () => {
},
],
});
service = TestBed.inject(BrowserKlaroService);
service = TestBed.inject(BrowserOrejimeService);
appName = 'testName';
purpose = 'test purpose';
testKey = 'this.is.a.fake.message.key';
Expand All @@ -115,7 +115,7 @@ describe('BrowserKlaroService', () => {
},
},
},
services: [{
apps: [{
name: appName,
purposes: [purpose],
}, {
Expand All @@ -125,7 +125,8 @@ describe('BrowserKlaroService', () => {

};

service.klaroConfig = mockConfig;
service.orejimeConfig = mockConfig;
service.createCategories();
});

it('should be created', () => {
Expand Down Expand Up @@ -248,7 +249,7 @@ describe('BrowserKlaroService', () => {
scheduler.schedule(() => service.getSavedPreferences().subscribe());
scheduler.flush();

expect(cookieService.get).toHaveBeenCalledWith(ANONYMOUS_STORAGE_NAME_KLARO);
expect(cookieService.get).toHaveBeenCalledWith(ANONYMOUS_STORAGE_NAME_OREJIME);
});
});

Expand All @@ -261,7 +262,7 @@ describe('BrowserKlaroService', () => {
scheduler.schedule(() => service.getSavedPreferences().subscribe());
scheduler.flush();

expect(cookieService.get).toHaveBeenCalledWith('klaro-' + user.uuid);
expect(cookieService.get).toHaveBeenCalledWith('orejime-' + user.uuid);
});
});
});
Expand Down Expand Up @@ -320,12 +321,12 @@ describe('BrowserKlaroService', () => {
configurationDataService.findByPropertyName = findByPropertyName;
});

it('should not filter googleAnalytics when servicesToHide are empty', () => {
const filteredConfig = (service as any).filterConfigServices([]);
it('should not filter googleAnalytics when appsToHide is empty', () => {
const filteredConfig = (service as any).filterConfigApps([]);
expect(filteredConfig).toContain(jasmine.objectContaining({ name: googleAnalytics }));
});
it('should filter services using names passed as servicesToHide', () => {
const filteredConfig = (service as any).filterConfigServices([googleAnalytics]);
it('should filter apps using names passed as appsToHide', () => {
const filteredConfig = (service as any).filterConfigApps([googleAnalytics]);
expect(filteredConfig).not.toContain(jasmine.objectContaining({ name: googleAnalytics }));
});
it('should have been initialized with googleAnalytics', () => {
Expand All @@ -337,7 +338,7 @@ describe('BrowserKlaroService', () => {
}),
);
service.initialize();
expect(service.klaroConfig.services).toContain(jasmine.objectContaining({ name: googleAnalytics }));
expect(service.orejimeConfig.apps).toContain(jasmine.objectContaining({ name: googleAnalytics }));
});
it('should filter googleAnalytics when empty configuration is retrieved', () => {
configurationDataService.findByPropertyName =
Expand All @@ -363,7 +364,7 @@ describe('BrowserKlaroService', () => {
);

service.initialize();
expect(service.klaroConfig.services).not.toContain(jasmine.objectContaining({ name: googleAnalytics }));
expect(service.orejimeConfig.apps).not.toContain(jasmine.objectContaining({ name: googleAnalytics }));
});
it('should filter googleAnalytics when an error occurs', () => {
configurationDataService.findByPropertyName =
Expand All @@ -381,7 +382,7 @@ describe('BrowserKlaroService', () => {
}),
);
service.initialize();
expect(service.klaroConfig.services).not.toContain(jasmine.objectContaining({ name: googleAnalytics }));
expect(service.orejimeConfig.apps).not.toContain(jasmine.objectContaining({ name: googleAnalytics }));
});
it('should filter googleAnalytics when an invalid payload is retrieved', () => {
configurationDataService.findByPropertyName =
Expand All @@ -399,7 +400,7 @@ describe('BrowserKlaroService', () => {
}),
);
service.initialize();
expect(service.klaroConfig.services).not.toContain(jasmine.objectContaining({ name: googleAnalytics }));
expect(service.orejimeConfig.apps).not.toContain(jasmine.objectContaining({ name: googleAnalytics }));
});
});
});
Loading
Loading