From 17057e725db1295b05cb23e44b474b42ce7a8757 Mon Sep 17 00:00:00 2001 From: Danny Coates Date: Fri, 24 Jul 2020 10:06:27 -0700 Subject: [PATCH] add fxa_required option --- app/ui/home.js | 3 +++ app/user.js | 4 ++++ package.json | 2 +- server/config.js | 5 +++++ server/routes/index.js | 2 +- server/routes/ws.js | 3 ++- server/state.js | 4 ++++ 7 files changed, 20 insertions(+), 3 deletions(-) diff --git a/app/ui/home.js b/app/ui/home.js index cfa38564..aa12bedc 100644 --- a/app/ui/home.js +++ b/app/ui/home.js @@ -5,6 +5,9 @@ const modal = require('./modal'); const intro = require('./intro'); module.exports = function(state, emit) { + if (state.user.loginRequired && !state.user.loggedIn) { + emit('signup-cta', 'required'); + } const archives = state.storage.files .filter(archive => !archive.expired) .map(archive => archiveTile(state, emit, archive)); diff --git a/app/user.js b/app/user.js index c4303941..419f98e3 100644 --- a/app/user.js +++ b/app/user.js @@ -94,6 +94,10 @@ export default class User { : this.limits.ANON.MAX_DOWNLOADS; } + get loginRequired() { + return this.authConfig.fxa_required; + } + async metricId() { return this.loggedIn ? hashId(this.info.uid) : undefined; } diff --git a/package.json b/package.json index 58decd9b..c7456b91 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "release": "npm-run-all contributors changelog", "test": "npm-run-all test:*", "test:backend": "nyc --reporter=lcovonly mocha --reporter=min test/backend", - "test:frontend": "cross-env NODE_ENV=development node test/frontend/runner.js", + "test:frontend": "cross-env NODE_ENV=development FXA_REQUIRED=false node test/frontend/runner.js", "test:report": "nyc report --reporter=html", "test-integration": "cross-env NODE_ENV=development wdio test/wdio.docker.conf.js", "circleci-test-integration": "echo 'webdriverio tests need to be updated to node 12'", diff --git a/server/config.js b/server/config.js index db392ecd..a6cd0c4b 100644 --- a/server/config.js +++ b/server/config.js @@ -155,6 +155,11 @@ const conf = convict({ default: `${tmpdir()}${path.sep}send-${randomBytes(4).toString('hex')}`, env: 'FILE_DIR' }, + fxa_required: { + format: Boolean, + default: true, + env: 'FXA_REQUIRED' + }, fxa_url: { format: 'url', default: 'http://localhost:3030', diff --git a/server/routes/index.js b/server/routes/index.js index 52cc7c85..c5c27c8d 100644 --- a/server/routes/index.js +++ b/server/routes/index.js @@ -117,7 +117,7 @@ module.exports = function(app) { app.get(`/api/metadata/:id${ID_REGEX}`, auth.hmac, require('./metadata')); app.get('/api/filelist/:id([\\w-]{16})', auth.fxa, filelist.get); app.post('/api/filelist/:id([\\w-]{16})', auth.fxa, filelist.post); - app.post('/api/upload', auth.fxa, require('./upload')); + // app.post('/api/upload', auth.fxa, require('./upload')); app.post(`/api/delete/:id${ID_REGEX}`, auth.owner, require('./delete')); app.post(`/api/password/:id${ID_REGEX}`, auth.owner, require('./password')); app.post( diff --git a/server/routes/ws.js b/server/routes/ws.js index 32ea7905..4d89d875 100644 --- a/server/routes/ws.js +++ b/server/routes/ws.js @@ -46,7 +46,8 @@ module.exports = function(ws, req) { !auth || timeLimit <= 0 || timeLimit > maxExpireSeconds || - dlimit > maxDownloads + dlimit > maxDownloads || + (config.fxa_required && !user) ) { ws.send( JSON.stringify({ diff --git a/server/state.js b/server/state.js index 6947a721..914ffe31 100644 --- a/server/state.js +++ b/server/state.js @@ -15,7 +15,11 @@ module.exports = async function(req) { try { authConfig = await getFxaConfig(); authConfig.client_id = config.fxa_client_id; + authConfig.fxa_required = config.fxa_required; } catch (e) { + if (config.auth_required) { + throw new Error('fxa_required is set but no config was found'); + } // continue without accounts } }