add fxa_required option

This commit is contained in:
Danny Coates 2020-07-24 10:06:27 -07:00
parent 9891d1f0ba
commit 17057e725d
No known key found for this signature in database
GPG Key ID: 4C442633C62E00CB
7 changed files with 20 additions and 3 deletions

View File

@ -5,6 +5,9 @@ const modal = require('./modal');
const intro = require('./intro'); const intro = require('./intro');
module.exports = function(state, emit) { module.exports = function(state, emit) {
if (state.user.loginRequired && !state.user.loggedIn) {
emit('signup-cta', 'required');
}
const archives = state.storage.files const archives = state.storage.files
.filter(archive => !archive.expired) .filter(archive => !archive.expired)
.map(archive => archiveTile(state, emit, archive)); .map(archive => archiveTile(state, emit, archive));

View File

@ -94,6 +94,10 @@ export default class User {
: this.limits.ANON.MAX_DOWNLOADS; : this.limits.ANON.MAX_DOWNLOADS;
} }
get loginRequired() {
return this.authConfig.fxa_required;
}
async metricId() { async metricId() {
return this.loggedIn ? hashId(this.info.uid) : undefined; return this.loggedIn ? hashId(this.info.uid) : undefined;
} }

View File

@ -23,7 +23,7 @@
"release": "npm-run-all contributors changelog", "release": "npm-run-all contributors changelog",
"test": "npm-run-all test:*", "test": "npm-run-all test:*",
"test:backend": "nyc --reporter=lcovonly mocha --reporter=min test/backend", "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:report": "nyc report --reporter=html",
"test-integration": "cross-env NODE_ENV=development wdio test/wdio.docker.conf.js", "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'", "circleci-test-integration": "echo 'webdriverio tests need to be updated to node 12'",

View File

@ -155,6 +155,11 @@ const conf = convict({
default: `${tmpdir()}${path.sep}send-${randomBytes(4).toString('hex')}`, default: `${tmpdir()}${path.sep}send-${randomBytes(4).toString('hex')}`,
env: 'FILE_DIR' env: 'FILE_DIR'
}, },
fxa_required: {
format: Boolean,
default: true,
env: 'FXA_REQUIRED'
},
fxa_url: { fxa_url: {
format: 'url', format: 'url',
default: 'http://localhost:3030', default: 'http://localhost:3030',

View File

@ -117,7 +117,7 @@ module.exports = function(app) {
app.get(`/api/metadata/:id${ID_REGEX}`, auth.hmac, require('./metadata')); app.get(`/api/metadata/:id${ID_REGEX}`, auth.hmac, require('./metadata'));
app.get('/api/filelist/:id([\\w-]{16})', auth.fxa, filelist.get); 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/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/delete/:id${ID_REGEX}`, auth.owner, require('./delete'));
app.post(`/api/password/:id${ID_REGEX}`, auth.owner, require('./password')); app.post(`/api/password/:id${ID_REGEX}`, auth.owner, require('./password'));
app.post( app.post(

View File

@ -46,7 +46,8 @@ module.exports = function(ws, req) {
!auth || !auth ||
timeLimit <= 0 || timeLimit <= 0 ||
timeLimit > maxExpireSeconds || timeLimit > maxExpireSeconds ||
dlimit > maxDownloads dlimit > maxDownloads ||
(config.fxa_required && !user)
) { ) {
ws.send( ws.send(
JSON.stringify({ JSON.stringify({

View File

@ -15,7 +15,11 @@ module.exports = async function(req) {
try { try {
authConfig = await getFxaConfig(); authConfig = await getFxaConfig();
authConfig.client_id = config.fxa_client_id; authConfig.client_id = config.fxa_client_id;
authConfig.fxa_required = config.fxa_required;
} catch (e) { } catch (e) {
if (config.auth_required) {
throw new Error('fxa_required is set but no config was found');
}
// continue without accounts // continue without accounts
} }
} }