-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #169 from leaonline/release-ios
Release 1.1.0 (Android)
- Loading branch information
Showing
752 changed files
with
56,163 additions
and
33,340 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ public/fonts/ | |
public/logos/ | ||
|
||
.deploy | ||
.staging | ||
|
||
# Logs | ||
logs | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { hasProp } from '../utils/hasProp' | ||
|
||
export const isBackendUser = (user = {}) => { | ||
const leaService = user.services?.lea | ||
if (!leaService) { return false } | ||
return ( | ||
hasProp(leaService, 'id') && | ||
hasProp(leaService, 'accessToken') | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { getUsersCollection } from '../collections/getUsersCollection' | ||
|
||
export const onAccountLoginHandler = function ({ user }) { | ||
const userId = user._id | ||
const lastLogin = new Date() | ||
getUsersCollection().update(userId, { $set: { lastLogin } }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { getUsersCollection } from '../collections/getUsersCollection' | ||
|
||
export const publishDefaultAccountFields = function () { | ||
const { userId } = this | ||
|
||
// skip this for non-logged in users | ||
if (!userId) return this.ready() | ||
|
||
return getUsersCollection().find(userId, { fields: { emails: 0, services: 0, device: 0 } }) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/* eslint-env mocha */ | ||
describe('accounts', function () { | ||
import './RestoreCodes.tests' | ||
import './UserEmail.tests' | ||
import './onAccountLoginHandler.tests' | ||
import './publishDefaultAccountFields.tests' | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* eslint-env mocha */ | ||
import { expect } from 'chai' | ||
import { restoreCollections, stubCollection } from '../../../tests/helpers/stubCollection' | ||
import { onAccountLoginHandler } from '../onAccountLoginHandler' | ||
import { getUsersCollection } from '../../collections/getUsersCollection' | ||
|
||
describe(onAccountLoginHandler.name, function () { | ||
before(() => { | ||
stubCollection([getUsersCollection()]) | ||
}) | ||
after(() => { | ||
restoreCollections() | ||
}) | ||
it('adds the timestamp to the current user', () => { | ||
const userId = getUsersCollection().insert({}) | ||
const user = { _id: userId } | ||
onAccountLoginHandler({ user }) | ||
const userDoc = getUsersCollection().findOne(userId) | ||
expect(userDoc.lastLogin).to.be.instanceOf(Date) | ||
}) | ||
}) |
30 changes: 30 additions & 0 deletions
30
backend/api/accounts/tests/publishDefaultAccountFields.tests.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* eslint-env mocha */ | ||
import { expect } from 'chai' | ||
import { publishDefaultAccountFields } from '../publishDefaultAccountFields' | ||
import { restoreCollections, stubCollection } from '../../../tests/helpers/stubCollection' | ||
import { getUsersCollection } from '../../collections/getUsersCollection' | ||
|
||
describe(publishDefaultAccountFields.name, function () { | ||
before(() => { | ||
stubCollection([getUsersCollection()]) | ||
}) | ||
after(() => { | ||
restoreCollections() | ||
}) | ||
it('skips if no user is authenticated', done => { | ||
publishDefaultAccountFields.call({ ready: done }) | ||
}) | ||
it('filters sensitive fields', () => { | ||
const userId = getUsersCollection().insert({ | ||
username: 'moo', | ||
emails: [{ address: 'foo@bar.com' }], | ||
services: { foo: 'bar' }, | ||
device: { platform: 'superOS' } | ||
}) | ||
const [userDoc] = publishDefaultAccountFields.call({ userId }).fetch() | ||
expect(userDoc).to.deep.equal({ | ||
_id: userId, | ||
username: 'moo' | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Meteor } from 'meteor/meteor' | ||
import { SHA256 } from 'meteor/sha' | ||
|
||
export const appTokenIsValid = ((src) => { | ||
const appToken = SHA256(src) | ||
return (token) => token === appToken | ||
})(Meteor.settings.app.token) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* eslint-env mocha */ | ||
import { expect } from 'chai' | ||
import { Meteor } from 'meteor/meteor' | ||
import { getUsersCollection } from '../getUsersCollection' | ||
|
||
describe(getUsersCollection.name, function () { | ||
it('returns the Meteor users collection', () => { | ||
expect(getUsersCollection()).to.equal(Meteor.users) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
import './LocalCollections.tests' | ||
/* eslint-env mocha */ | ||
describe('collections', function () { | ||
import './LocalCollections.tests' | ||
import './getUsersCollection.tests' | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { Meteor } from 'meteor/meteor' | ||
import crypto from 'node:crypto' | ||
|
||
/** | ||
* Represents User Email encrypt/decrypt functionality | ||
* @category api | ||
* @namespace | ||
*/ | ||
const SensitiveData = {} | ||
|
||
const { algorithm, key, outputFormat } = Meteor.settings.crypto | ||
|
||
SensitiveData.validate = value => { | ||
if (typeof value !== 'string' || value.length < 1) { | ||
throw new Error(`Expected valid string with min. length of 1, got ${value}`) | ||
} | ||
} | ||
|
||
/** | ||
* Encrypt an existing use ermail | ||
* @param data {string} | ||
* @return {string} | ||
*/ | ||
SensitiveData.encrypt = (data) => { | ||
SensitiveData.validate(data) | ||
const iv = crypto.randomBytes(16).toString('hex').slice(0, 16) | ||
const cipher = crypto.createCipheriv(algorithm, key, iv) | ||
let encrypted = cipher.update(data, 'utf8', outputFormat) | ||
encrypted += cipher.final(outputFormat) | ||
encrypted += ':' | ||
encrypted += iv | ||
return encrypted | ||
} | ||
|
||
/** | ||
* Decrypts and existing user email | ||
* @param data {string} | ||
* @return {string} | ||
*/ | ||
SensitiveData.decrypt = (data) => { | ||
const fields = data.split(':') | ||
const iv = fields[1] | ||
const encrypted = fields[0] | ||
const decipher = crypto.createDecipheriv(algorithm, key, iv) | ||
let decrypted = decipher.update(encrypted, outputFormat, 'utf-8') | ||
decrypted += decipher.final('utf8') | ||
return decrypted | ||
} | ||
|
||
export { SensitiveData } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* eslint-env mocha */ | ||
import { SensitiveData } from '../SensitiveData' | ||
import { expect } from 'chai' | ||
|
||
describe('SensitiveData', () => { | ||
it('throws if the input to encrypt is not a valid string', () => { | ||
[undefined, null, '', 1, [], {}, true, () => {}, new Date()].forEach(value => { | ||
expect(() => SensitiveData.encrypt(value)).to.throw(`Expected valid string with min. length of 1, got ${value}`) | ||
}) | ||
}) | ||
it('check if encryption and decryption works', () => { | ||
expect(SensitiveData.decrypt(SensitiveData.encrypt('a@a.de'))).to.equal('a@a.de') | ||
}) | ||
it('check if the IV of encryption is random', () => { | ||
const encryptedEmailWithIV = SensitiveData.encrypt('a@a.de') | ||
expect(SensitiveData.encrypt('a@a.de') === (encryptedEmailWithIV)).to.equal(false) | ||
}) | ||
}) |
Oops, something went wrong.