Skip to content
This repository was archived by the owner on Oct 14, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d16e84b
Added latest version of pioneer-utils as dependency
motin Aug 30, 2018
1e553ee
Made the tests run twice, one for each shieldType (shield, pioneer)
motin Aug 30, 2018
56523d2
Moved shield-study-type-specifics to separate class, added correspond…
motin Aug 31, 2018
82391f2
Imported relevant parts from pioneer-utils 1.0.10, no longer requirin…
motin Aug 31, 2018
9969751
Added browser.study.getDataPermissions() and using it to check eligib…
motin Aug 31, 2018
5d1dad6
Synced small-study and test-addon boilerplate code
motin Aug 31, 2018
8ec4325
Scripts to import/build and selenium instructions to install the pion…
motin Aug 31, 2018
69a221c
Added studySetup.telemetry.internalTelemetryArchive flag for internal…
motin Aug 31, 2018
fc5d830
Removed empty placeholders for tests that are already implemented
motin Aug 31, 2018
1828973
Implemented tests for browser.study.getDataPermissions()
motin Aug 31, 2018
ae20821
Internal telemetry archive stores ping id and is exposed to the tests
motin Sep 1, 2018
dd7190e
Telemetry-related tests simplified and restored
motin Sep 1, 2018
ee44340
Increased wait time for expiration test due to intermittent failures
motin Sep 1, 2018
79910c6
Minor cleanup
motin Sep 1, 2018
f9046d5
Moved bin/import-pioneer-opt-in.sh to pretest where it belongs
motin Sep 7, 2018
4343075
Restored tests
motin Sep 7, 2018
798790e
Fixed a race condition with the expiration-related tests
motin Sep 7, 2018
693db4e
Made internalTelemetryArchive nullable so that it is truly optional a…
motin Sep 7, 2018
8d2c880
Importing and building the Pioneer opt-in add-on in circle
motin Sep 10, 2018
aa1fded
Nits code style
motin Sep 11, 2018
0d5ee6a
Correct schema versions specified when sending pioneer telemetry
motin Sep 11, 2018
ee9bddb
Set import pioneer opt in script as binary in npm package
motin Oct 27, 2018
32229ab
Pioneer telemetry logged at debug level like other telemetry log events
motin Oct 28, 2018
11b28e3
Commented out a rogue console.log statement
motin Oct 28, 2018
162d06c
Make eslint happy
motin Oct 28, 2018
f28bf05
Add browser.study.calculateTelemetryPingSize
motin Oct 28, 2018
d91775c
Test for browser.study.calculateTelemetryPingSize
motin Oct 28, 2018
e367173
Clarified the requirements of the telemetry payload argument
motin Nov 15, 2018
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: 4 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ jobs:
path: "test-addon/dist"
destination: "test-addon/dist"

- run:
name: Import and build the Pioneer opt-in add-on
command: npm run import-pioneer-opt-in

# Needs signed add-on to work on branded releases
#- run:
# name: Test with Firefox Release
Expand Down
20 changes: 20 additions & 0 deletions bin/import-pioneer-opt-in.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

echo "$@"

set -eu
#set -o xtrace

BASE_DIR="$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")"

# download and build xpi for https://github.com/mozilla/pioneer-opt-in.git
if [ ! -d "pioneer-opt-in" ]; then
git clone https://github.com/mozilla/pioneer-opt-in.git
fi
cd pioneer-opt-in
bin/make-xpi.sh .
cd -

echo
echo "SUCCESS: pioneer-opt-in xpi available at pioneer-opt-in/pioneer-opt-in.xpi"
echo
3 changes: 3 additions & 0 deletions examples/small-study/src/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ module.exports = {
es6: true,
webextensions: true,
},
rules: {
"no-console": "off",
},
};
22 changes: 16 additions & 6 deletions examples/small-study/src/studySetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@ const baseStudySetup = {
// used for activeExperiments tagging (telemetryEnvironment.setActiveExperiment)
activeExperimentName: browser.runtime.id,

// uses shield sampling and telemetry semantics. Future: will support "pioneer"
// use either "shield" or "pioneer" telemetry semantics and data pipelines
studyType: "shield",

// telemetry
telemetry: {
// default false. Actually send pings.
// Actually submit the pings to Telemetry. [default if omitted: false]
send: true,
// Marks pings with testing=true. Set flag to `true` before final release
// Marks pings with testing=true. Set flag to `true` for pings are meant to be seen by analysts [default if omitted: false]
removeTestingFlag: false,
// Keep an internal telemetry archive. Useful for verifying payloads of Pioneer studies without risking actually sending any unencrypted payloads [default if omitted: false]
internalTelemetryArchive: false,
},

// endings with urls
Expand Down Expand Up @@ -99,10 +101,11 @@ const baseStudySetup = {
*
* This implementation caches in local storage to speed up second run.
*
* @param {object} studySetup A complete study setup object
* @returns {Promise<boolean>} answer An boolean answer about whether the user should be
* allowed to enroll in the study
*/
async function cachingFirstRunShouldAllowEnroll() {
async function cachingFirstRunShouldAllowEnroll(studySetup) {
// Cached answer. Used on 2nd run
let allowed = await browser.storage.local.get("allowedEnrollOnFirstRun");
if (allowed.allowedEnrollOnFirstRun === true) return true;
Expand All @@ -113,7 +116,13 @@ async function cachingFirstRunShouldAllowEnroll() {
*/

// could have other reasons to be eligible, such add-ons, prefs
allowed = true;
const dataPermissions = await browser.study.getDataPermissions();
if (studySetup.studyType === "shield") {
allowed = dataPermissions.shield;
}
if (studySetup.studyType === "pioneer") {
allowed = dataPermissions.pioneer;
}

// cache the answer
await browser.storage.local.set({ allowedEnrollOnFirstRun: allowed });
Expand All @@ -129,13 +138,14 @@ async function getStudySetup() {
// shallow copy
const studySetup = Object.assign({}, baseStudySetup);

studySetup.allowEnroll = await cachingFirstRunShouldAllowEnroll();
studySetup.allowEnroll = await cachingFirstRunShouldAllowEnroll(studySetup);

const testingOverrides = await browser.study.getTestingOverrides();
studySetup.testing = {
variationName: testingOverrides.variationName,
firstRunTimestamp: testingOverrides.firstRunTimestamp,
expired: testingOverrides.expired,
};

return studySetup;
}
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"version": "5.1.1",
"author": "Mozilla",
"bin": {
"copyStudyUtils": "bin/copyStudyUtils.js"
"copyStudyUtils": "bin/copyStudyUtils.js",
"importPioneerOptIn": "bin/import-pioneer-opt-in.sh"
},
"bugs": {
"url": "https://github.com/mozilla/shield-studies-addon-utils/issues"
Expand All @@ -13,6 +14,7 @@
"ajv": "^6.5.0",
"commander": "^2.15.1",
"fs-extra": "^6.0.1",
"jose-jwe-jws": "0.1.6",
"shield-study-schemas": "^0.8.3"
},
"devDependencies": {
Expand Down Expand Up @@ -41,6 +43,7 @@
},
"files": [
"bin/copyStudyUtils.js",
"bin/import-pioneer-opt-in.sh",
"testUtils",
"webExtensionApis/study/api.js",
"webExtensionApis/study/schema.json",
Expand Down Expand Up @@ -80,14 +83,15 @@
"generate:generateSchema:study": "cd webExtensionApis/study && yaml2json schema.yaml -p > schema.json",
"generate:generateStubApi:study": "cd webExtensionApis/study && generateStubApi ./schema.json > stubApi.js",
"generate:verifyWeeSchema:study": "cd webExtensionApis/study && verifyWeeSchema schema.json",
"import-pioneer-opt-in": "bin/import-pioneer-opt-in.sh",
"lint": "npm-run-all lint:*",
"lint:eslint": "npm run eslint",
"lint:fixpack": "fixpack # cleans up package.json",
"postbuild": "if [ -z ${SKIPLINT} ]; then npm run format; fi",
"postformat": "run-p lint:fixpack eslint-fix",
"prebuild": "if [ -z ${SKIPLINT} ]; then npm run lint; fi",
"prepare": "export SKIPLINT=1 && fixpack && npm run build",
"pretest": "npm run build && npm run test-addon:bundle-utils && npm run test-addon:build",
"pretest": "npm run build && npm run test-addon:bundle-utils && npm run test-addon:build && npm run import-pioneer-opt-in",
"pretest-addon": "npm run pretest",
"small-study": "cd examples/small-study && npm run rebuild && npm start",
"test": "npm run test:func",
Expand Down
28 changes: 21 additions & 7 deletions test-addon/src/studySetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@ const baseStudySetup = {
// used for activeExperiments tagging (telemetryEnvironment.setActiveExperiment)
activeExperimentName: browser.runtime.id,

// uses shield sampling and telemetry semantics. Future: will support "pioneer"
studyType: "shield",
// use either "shield" or "pioneer" telemetry semantics and data pipelines
studyType: null, // set by internal test override below in getStudySetup()

// telemetry
telemetry: {
// default false. Actually send pings.
// Actually submit the pings to Telemetry. [default if omitted: false]
send: true,
// Marks pings with testing=true. Set flag to `true` before final release
// Marks pings with testing=true. Set flag to `true` for pings are meant to be seen by analysts [default if omitted: false]
removeTestingFlag: false,
// Keep an internal telemetry archive. Useful for verifying payloads of Pioneer studies without risking actually sending any unencrypted payloads [default if omitted: false]
internalTelemetryArchive: true,
},

// endings with urls
Expand Down Expand Up @@ -99,10 +101,11 @@ const baseStudySetup = {
*
* This implementation caches in local storage to speed up second run.
*
* @param {object} studySetup A complete study setup object
* @returns {Promise<boolean>} answer An boolean answer about whether the user should be
* allowed to enroll in the study
*/
async function cachingFirstRunShouldAllowEnroll() {
async function cachingFirstRunShouldAllowEnroll(studySetup) {
// Cached answer. Used on 2nd run
let allowed = await browser.storage.local.get("allowedEnrollOnFirstRun");
if (allowed.allowedEnrollOnFirstRun === true) return true;
Expand All @@ -113,7 +116,13 @@ async function cachingFirstRunShouldAllowEnroll() {
*/

// could have other reasons to be eligible, such add-ons, prefs
allowed = true;
const dataPermissions = await browser.study.getDataPermissions();
if (studySetup.studyType === "shield") {
allowed = dataPermissions.shield;
}
if (studySetup.studyType === "pioneer") {
allowed = dataPermissions.pioneer;
}

// cache the answer
await browser.storage.local.set({ allowedEnrollOnFirstRun: allowed });
Expand All @@ -129,13 +138,18 @@ async function getStudySetup() {
// shallow copy
const studySetup = Object.assign({}, baseStudySetup);

studySetup.allowEnroll = await cachingFirstRunShouldAllowEnroll();
// internal testing override necessary to be able to test all study types
const internalTestingOverrides = await browser.studyDebug.getInternalTestingOverrides();
studySetup.studyType = internalTestingOverrides.studyType;

studySetup.allowEnroll = await cachingFirstRunShouldAllowEnroll(studySetup);

const testingOverrides = await browser.study.getTestingOverrides();
studySetup.testing = {
variationName: testingOverrides.variationName,
firstRunTimestamp: testingOverrides.firstRunTimestamp,
expired: testingOverrides.expired,
};

return studySetup;
}
Loading