Commit 82d63a75 authored by Dallas Reedy's avatar Dallas Reedy

Only send gitlab_experiment context data allowed by the schema

parent e249f499
......@@ -12,7 +12,15 @@ function getExperimentsData() {
}
function convertExperimentDataToExperimentContext(experimentData) {
return { schema: TRACKING_CONTEXT_SCHEMA, data: experimentData };
// Bandaid to allow-list only the properties which the current gitlab_experiment context schema suppports.
// See TRACKING_CONTEXT_SCHEMA for current version (1-0-0)
// https://gitlab.com/gitlab-org/iglu/-/blob/master/public/schemas/com.gitlab/gitlab_experiment/jsonschema/1-0-0
const { experiment: experimentName, key, variant, migration_keys } = experimentData;
return {
schema: TRACKING_CONTEXT_SCHEMA,
data: { experiment: experimentName, key, variant, migration_keys },
};
}
export function getExperimentData(experimentName) {
......
......@@ -72,6 +72,19 @@ describe('experiment Utilities', () => {
it('returns an empty array if there are no experiments', () => {
expect(experimentUtils.getAllExperimentContexts()).toEqual([]);
});
it('only collects the data properties which are supported by the schema', () => {
origGl = window.gl;
window.gl.experiments = {
my_experiment: { experiment: 'my_experiment', variant: 'control', excluded: false },
};
expect(experimentUtils.getAllExperimentContexts()).toEqual([
{ schema, data: { experiment: 'my_experiment', variant: 'control' } },
]);
window.gl = origGl;
});
});
describe('isExperimentVariant', () => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment