Merge pull request #22 in ~VLE2FE/dfop-api from develop to master
* commit 'cc6fa48a44794197f7ec85174de93dfc4cc84127': switched device_name to devices fixed mail in user.ts
This commit is contained in:
commit
bb5bb957a3
@ -202,6 +202,8 @@ User:
|
||||
location:
|
||||
type: string
|
||||
example: Rng
|
||||
device_name:
|
||||
type: string
|
||||
example: Alpha II
|
||||
devices:
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
example: Alpha II
|
||||
|
@ -66,9 +66,11 @@
|
||||
location:
|
||||
type: string
|
||||
example: Rng
|
||||
device_name:
|
||||
type: string
|
||||
example: Alpha II
|
||||
devices:
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
example: Alpha II
|
||||
responses:
|
||||
200:
|
||||
description: user details
|
||||
@ -212,7 +214,7 @@
|
||||
- pass
|
||||
- level
|
||||
- location
|
||||
- device_name
|
||||
- devices
|
||||
allOf:
|
||||
- $ref: 'api.yaml#/components/schemas/User'
|
||||
responses:
|
||||
|
2432
package-lock.json
generated
2432
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -22,7 +22,8 @@
|
||||
"dependencies": {
|
||||
"@apidevtools/json-schema-ref-parser": "^8.0.0",
|
||||
"@apidevtools/swagger-parser": "^9.0.1",
|
||||
"@hapi/joi": "^17.1.1",
|
||||
"@jsdevtools/ono": "^7.1.3",
|
||||
"@szmarczak/http-timer": "^4.0.5",
|
||||
"axios": "^0.19.2",
|
||||
"basic-auth": "^2.0.1",
|
||||
"bcryptjs": "^2.4.3",
|
||||
@ -33,6 +34,7 @@
|
||||
"cors": "^2.8.5",
|
||||
"express": "^4.17.1",
|
||||
"helmet": "^3.22.0",
|
||||
"joi": "^17.1.1",
|
||||
"json-schema": "^0.2.5",
|
||||
"json2csv": "^5.0.1",
|
||||
"lodash": "^4.17.15",
|
||||
@ -46,7 +48,7 @@
|
||||
"@types/lodash": "^4.14.150",
|
||||
"@types/mocha": "^5.2.7",
|
||||
"@types/mongoose": "^5.7.12",
|
||||
"@types/node": "^13.1.6",
|
||||
"@types/node": "13.1.6",
|
||||
"@types/qs": "^6.9.1",
|
||||
"@types/serve-static": "^1.13.3",
|
||||
"csv-parser": "^2.3.3",
|
||||
|
@ -55,7 +55,7 @@ export default class Mail{
|
||||
});
|
||||
}
|
||||
|
||||
static send (mailAddress, subject, content, f = () => {}) { // callback, executed empty or with error
|
||||
static send (mailAddress, subject, content, f: (x?) => void = () => {}) { // callback, executed empty or with error
|
||||
if (process.env.NODE_ENV === 'production') { // only send mails in production
|
||||
axios({
|
||||
method: 'post',
|
||||
|
@ -8,7 +8,7 @@ const UserSchema = new mongoose.Schema({
|
||||
key: String,
|
||||
level: String,
|
||||
location: String,
|
||||
device_name: String
|
||||
devices: [String]
|
||||
});
|
||||
|
||||
// changelog query helper
|
||||
|
@ -426,7 +426,7 @@ describe('/material', () => {
|
||||
auth: {basic: 'janedoe'},
|
||||
httpStatus: 400,
|
||||
req: {properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: -5, carbon_fiber: 0}},
|
||||
res: {status: 'Invalid body format', details: '"glass_fiber" must be larger than or equal to 0'}
|
||||
res: {status: 'Invalid body format', details: '"glass_fiber" must be greater than or equal to 0'}
|
||||
});
|
||||
});
|
||||
it('rejects a properties parameter above maximum range', done => {
|
||||
@ -925,7 +925,7 @@ describe('/material', () => {
|
||||
auth: {basic: 'janedoe'},
|
||||
httpStatus: 400,
|
||||
req: {name: 'Crastin CE 2510', supplier: 'Du Pont', group: 'PBT', properties: {material_template: '130000000000000000000003', glass_fiber: -0.3}, numbers: ['5515798402']},
|
||||
res: {status: 'Invalid body format', details: '"glass_fiber" must be larger than or equal to 0'}
|
||||
res: {status: 'Invalid body format', details: '"glass_fiber" must be greater than or equal to 0'}
|
||||
});
|
||||
});
|
||||
it('rejects a properties parameter above maximum range', done => {
|
||||
|
@ -211,7 +211,7 @@ describe('/measurement', () => {
|
||||
auth: {basic: 'janedoe'},
|
||||
httpStatus: 400,
|
||||
req: {values: {'weight %': -1, 'standard deviation': 0.3}},
|
||||
res: {status: 'Invalid body format', details: '"weight %" must be larger than or equal to 0'}
|
||||
res: {status: 'Invalid body format', details: '"weight %" must be greater than or equal to 0'}
|
||||
});
|
||||
});
|
||||
it('rejects a value above maximum range', done => {
|
||||
@ -698,7 +698,7 @@ describe('/measurement', () => {
|
||||
auth: {basic: 'janedoe'},
|
||||
httpStatus: 400,
|
||||
req: {sample_id: '400000000000000000000001', values: {'weight %': -1, 'standard deviation': 0.1}, measurement_template: '300000000000000000000002'},
|
||||
res: {status: 'Invalid body format', details: '"weight %" must be larger than or equal to 0'}
|
||||
res: {status: 'Invalid body format', details: '"weight %" must be greater than or equal to 0'}
|
||||
});
|
||||
});
|
||||
it('rejects a value above maximum range', done => {
|
||||
|
@ -81,7 +81,7 @@ describe('/', () => {
|
||||
url: '/changelog/1879-07-28T06:04:51.000Z/10/2',
|
||||
auth: {basic: 'admin'},
|
||||
httpStatus: 400,
|
||||
res: {status: 'Invalid body format', details: '"timestamp" must be larger than or equal to "1970-01-01T00:00:00.000Z"'}
|
||||
res: {status: 'Invalid body format', details: '"timestamp" must be greater than or equal to "1970-01-01T00:00:00.000Z"'}
|
||||
});
|
||||
});
|
||||
it('rejects invalid timestamps', done => {
|
||||
@ -99,7 +99,7 @@ describe('/', () => {
|
||||
url: '/changelog/1979-07-28T06:04:51.000Z/-10/2',
|
||||
auth: {basic: 'admin'},
|
||||
httpStatus: 400,
|
||||
res: {status: 'Invalid body format', details: '"page" must be larger than or equal to 0'}
|
||||
res: {status: 'Invalid body format', details: '"page" must be greater than or equal to 0'}
|
||||
});
|
||||
});
|
||||
it('rejects negative pagesizes', done => {
|
||||
@ -108,7 +108,7 @@ describe('/', () => {
|
||||
url: '/changelog/1979-07-28T06:04:51.000Z/10/-2',
|
||||
auth: {basic: 'admin'},
|
||||
httpStatus: 400,
|
||||
res: {status: 'Invalid body format', details: '"pagesize" must be larger than or equal to 0'}
|
||||
res: {status: 'Invalid body format', details: '"pagesize" must be greater than or equal to 0'}
|
||||
});
|
||||
});
|
||||
it('rejects request from a write user', done => {
|
||||
|
@ -499,7 +499,7 @@ describe('/sample', () => {
|
||||
url: '/samples?page-size=-3',
|
||||
auth: {basic: 'janedoe'},
|
||||
httpStatus: 400,
|
||||
res: {status: 'Invalid body format', details: '"page-size" must be larger than or equal to 1'}
|
||||
res: {status: 'Invalid body format', details: '"page-size" must be greater than or equal to 1'}
|
||||
});
|
||||
});
|
||||
it('rejects an invalid from-id', done => {
|
||||
@ -1047,7 +1047,7 @@ describe('/sample', () => {
|
||||
auth: {basic: 'janedoe'},
|
||||
httpStatus: 400,
|
||||
req: {condition: {material: 'copper', weeks: 0, condition_template: '200000000000000000000001'}},
|
||||
res: {status: 'Invalid body format', details: '"weeks" must be larger than or equal to 1'}
|
||||
res: {status: 'Invalid body format', details: '"weeks" must be greater than or equal to 1'}
|
||||
});
|
||||
});
|
||||
it('rejects a condition parameter above maximum range', done => {
|
||||
|
@ -23,13 +23,15 @@ describe('/user', () => {
|
||||
const json = require('../test/db.json');
|
||||
should(res.body).have.lengthOf(json.collections.users.length);
|
||||
should(res.body).matchEach(user => {
|
||||
should(user).have.only.keys('_id', 'email', 'name', 'level', 'location', 'device_name');
|
||||
should(user).have.only.keys('_id', 'email', 'name', 'level', 'location', 'devices');
|
||||
should(user).have.property('_id').be.type('string');
|
||||
should(user).have.property('email').be.type('string');
|
||||
should(user).have.property('name').be.type('string');
|
||||
should(user).have.property('level').be.type('string');
|
||||
should(user).have.property('location').be.type('string');
|
||||
should(user).have.property('device_name').be.type('string');
|
||||
should(user.devices).matchEach(device => {
|
||||
should(device).be.type('string');
|
||||
});
|
||||
});
|
||||
done();
|
||||
});
|
||||
@ -68,13 +70,13 @@ describe('/user', () => {
|
||||
httpStatus: 200
|
||||
}).end((err, res) => {
|
||||
if (err) return done (err);
|
||||
should(res.body).have.only.keys('_id', 'email', 'name', 'level', 'location', 'device_name');
|
||||
should(res.body).have.only.keys('_id', 'email', 'name', 'level', 'location', 'devices');
|
||||
should(res.body).have.property('_id').be.type('string');
|
||||
should(res.body).have.property('email', 'jane.doe@bosch.com');
|
||||
should(res.body).have.property('name', 'janedoe');
|
||||
should(res.body).have.property('level', 'write');
|
||||
should(res.body).have.property('location', 'Rng');
|
||||
should(res.body).have.property('device_name', 'Alpha I');
|
||||
should(res.body).have.property('devices', ['Alpha I']);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@ -86,13 +88,13 @@ describe('/user', () => {
|
||||
httpStatus: 200
|
||||
}).end((err, res) => {
|
||||
if (err) return done (err);
|
||||
should(res.body).have.only.keys('_id', 'email', 'name', 'level', 'location', 'device_name');
|
||||
should(res.body).have.only.keys('_id', 'email', 'name', 'level', 'location', 'devices');
|
||||
should(res.body).have.property('_id').be.type('string');
|
||||
should(res.body).have.property('email', 'jane.doe@bosch.com');
|
||||
should(res.body).have.property('name', 'janedoe');
|
||||
should(res.body).have.property('level', 'write');
|
||||
should(res.body).have.property('location', 'Rng');
|
||||
should(res.body).have.property('device_name', 'Alpha I');
|
||||
should(res.body).have.property('devices', ['Alpha I']);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@ -147,13 +149,13 @@ describe('/user', () => {
|
||||
req: {}
|
||||
}).end((err, res) => {
|
||||
if (err) return done (err);
|
||||
should(res.body).have.only.keys('_id', 'email', 'name', 'level', 'location', 'device_name');
|
||||
should(res.body).have.only.keys('_id', 'email', 'name', 'level', 'location', 'devices');
|
||||
should(res.body).have.property('_id').be.type('string');
|
||||
should(res.body).have.property('email', 'jane.doe@bosch.com');
|
||||
should(res.body).have.property('name', 'janedoe');
|
||||
should(res.body).have.property('level', 'write');
|
||||
should(res.body).have.property('location', 'Rng');
|
||||
should(res.body).have.property('device_name', 'Alpha I');
|
||||
should(res.body).have.property('devices', ['Alpha I']);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@ -166,13 +168,13 @@ describe('/user', () => {
|
||||
req: {}
|
||||
}).end((err, res) => {
|
||||
if (err) return done (err);
|
||||
should(res.body).have.only.keys('_id', 'email', 'name', 'level', 'location', 'device_name');
|
||||
should(res.body).have.only.keys('_id', 'email', 'name', 'level', 'location', 'devices');
|
||||
should(res.body).have.property('_id').be.type('string');
|
||||
should(res.body).have.property('email', 'jane.doe@bosch.com');
|
||||
should(res.body).have.property('name', 'janedoe');
|
||||
should(res.body).have.property('level', 'write');
|
||||
should(res.body).have.property('location', 'Rng');
|
||||
should(res.body).have.property('device_name', 'Alpha I');
|
||||
should(res.body).have.property('devices', ['Alpha I']);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@ -182,20 +184,20 @@ describe('/user', () => {
|
||||
url: '/user',
|
||||
auth: {basic: 'admin'},
|
||||
httpStatus: 200,
|
||||
req: {name: 'adminnew', email: 'adminnew@bosch.com', pass: 'Abc123##', location: 'Abt', device_name: 'test'}
|
||||
req: {name: 'adminnew', email: 'adminnew@bosch.com', pass: 'Abc123##', location: 'Abt', devices: ['test']}
|
||||
}).end(err => {
|
||||
if (err) return done (err);
|
||||
UserModel.find({name: 'adminnew'}).lean().exec( (err, data) => {
|
||||
if (err) return done(err);
|
||||
should(data).have.lengthOf(1);
|
||||
should(data[0]).have.only.keys('_id', 'name', 'pass', 'email', 'level', 'location', 'device_name', 'key', '__v');
|
||||
should(data[0]).have.only.keys('_id', 'name', 'pass', 'email', 'level', 'location', 'devices', 'key', '__v');
|
||||
should(data[0]).have.property('_id');
|
||||
should(data[0]).have.property('name', 'adminnew');
|
||||
should(data[0]).have.property('email', 'adminnew@bosch.com');
|
||||
should(data[0]).have.property('pass').not.eql('Abc123##');
|
||||
should(data[0]).have.property('level', 'admin');
|
||||
should(data[0]).have.property('location', 'Abt');
|
||||
should(data[0]).have.property('device_name', 'test');
|
||||
should(data[0]).have.property('devices', ['test']);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@ -206,7 +208,7 @@ describe('/user', () => {
|
||||
url: '/user',
|
||||
auth: {basic: 'admin'},
|
||||
httpStatus: 200,
|
||||
req: {name: 'adminnew', email: 'adminnew@bosch.com', pass: 'Abc123##', location: 'Abt', device_name: 'test'},
|
||||
req: {name: 'adminnew', email: 'adminnew@bosch.com', pass: 'Abc123##', location: 'Abt', devices: ['test']},
|
||||
log: {
|
||||
collection: 'users',
|
||||
dataIgn: ['pass']
|
||||
@ -271,7 +273,7 @@ describe('/user', () => {
|
||||
url: '/user/new',
|
||||
auth: {basic: 'admin'},
|
||||
httpStatus: 400, default: false,
|
||||
req: {email: 'j.doe@bosch.com', name: 'passreset', pass: 'Abc123!#', level: 'read', location: 'Rng', device_name: 'Alpha II'},
|
||||
req: {email: 'j.doe@bosch.com', name: 'passreset', pass: 'Abc123!#', level: 'read', location: 'Rng', devices: ['Alpha II']},
|
||||
res: {status: 'Username already taken'}
|
||||
});
|
||||
});
|
||||
@ -281,7 +283,7 @@ describe('/user', () => {
|
||||
url: '/user',
|
||||
auth: {basic: 'admin'},
|
||||
httpStatus: 400,
|
||||
req: {email: 'john.doe@bosch.com', name: 'johndoe', pass: 'Abc123!#', location: 44, device_name: 'Alpha II'},
|
||||
req: {email: 'john.doe@bosch.com', name: 'johndoe', pass: 'Abc123!#', location: 44, devices: ['Alpha II']},
|
||||
res: {status: 'Invalid body format', details: '"location" must be a string'}
|
||||
});
|
||||
});
|
||||
@ -470,16 +472,16 @@ describe('/user', () => {
|
||||
url: '/user/new',
|
||||
auth: {basic: 'admin'},
|
||||
httpStatus: 200,
|
||||
req: {email: 'john.doe@bosch.com', name: 'johndoe', pass: 'Abc123!#', level: 'read', location: 'Rng', device_name: 'Alpha II'}
|
||||
req: {email: 'john.doe@bosch.com', name: 'johndoe', pass: 'Abc123!#', level: 'read', location: 'Rng', devices: ['Alpha II']}
|
||||
}).end((err, res) => {
|
||||
if (err) return done (err);
|
||||
should(res.body).have.only.keys('_id', 'email', 'name', 'level', 'location', 'device_name');
|
||||
should(res.body).have.only.keys('_id', 'email', 'name', 'level', 'location', 'devices');
|
||||
should(res.body).have.property('_id').be.type('string');
|
||||
should(res.body).have.property('email', 'john.doe@bosch.com');
|
||||
should(res.body).have.property('name', 'johndoe');
|
||||
should(res.body).have.property('level', 'read');
|
||||
should(res.body).have.property('location', 'Rng');
|
||||
should(res.body).have.property('device_name', 'Alpha II');
|
||||
should(res.body).have.property('devices', ['Alpha II']);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@ -489,20 +491,20 @@ describe('/user', () => {
|
||||
url: '/user/new',
|
||||
auth: {basic: 'admin'},
|
||||
httpStatus: 200,
|
||||
req: {email: 'john.doe@bosch.com', name: 'johndoe', pass: 'Abc123!#', level: 'read', location: 'Rng', device_name: 'Alpha II'}
|
||||
req: {email: 'john.doe@bosch.com', name: 'johndoe', pass: 'Abc123!#', level: 'read', location: 'Rng', devices: ['Alpha II']}
|
||||
}).end(err => {
|
||||
if (err) return done (err);
|
||||
UserModel.find({name: 'johndoe'}).lean().exec( (err, data) => {
|
||||
if (err) return done(err);
|
||||
should(data).have.lengthOf(1);
|
||||
should(data[0]).have.only.keys('_id', 'name', 'pass', 'email', 'level', 'location', 'device_name', 'key', '__v');
|
||||
should(data[0]).have.only.keys('_id', 'name', 'pass', 'email', 'level', 'location', 'devices', 'key', '__v');
|
||||
should(data[0]).have.property('_id');
|
||||
should(data[0]).have.property('name', 'johndoe');
|
||||
should(data[0]).have.property('email', 'john.doe@bosch.com');
|
||||
should(data[0]).have.property('pass').not.eql('Abc123!#');
|
||||
should(data[0]).have.property('level', 'read');
|
||||
should(data[0]).have.property('location', 'Rng');
|
||||
should(data[0]).have.property('device_name', 'Alpha II');
|
||||
should(data[0]).have.property('devices', ['Alpha II']);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@ -513,7 +515,7 @@ describe('/user', () => {
|
||||
url: '/user/new',
|
||||
auth: {basic: 'admin'},
|
||||
httpStatus: 200,
|
||||
req: {email: 'john.doe@bosch.com', name: 'johndoe', pass: 'Abc123!#', level: 'read', location: 'Rng', device_name: 'Alpha II'},
|
||||
req: {email: 'john.doe@bosch.com', name: 'johndoe', pass: 'Abc123!#', level: 'read', location: 'Rng', devices: ['Alpha II']},
|
||||
log: {
|
||||
collection: 'users',
|
||||
dataIgn: ['pass', 'key']
|
||||
@ -526,7 +528,7 @@ describe('/user', () => {
|
||||
url: '/user/new',
|
||||
auth: {basic: 'admin'},
|
||||
httpStatus: 400, default: false,
|
||||
req: {email: 'j.doe@bosch.com', name: 'janedoe', pass: 'Abc123!#', level: 'read', location: 'Rng', device_name: 'Alpha II'}
|
||||
req: {email: 'j.doe@bosch.com', name: 'janedoe', pass: 'Abc123!#', level: 'read', location: 'Rng', devices: ['Alpha II']}
|
||||
}).end((err, res) => {
|
||||
if (err) return done (err);
|
||||
should(res.body).be.eql({status: 'Username already taken'});
|
||||
@ -543,7 +545,7 @@ describe('/user', () => {
|
||||
url: '/user/new',
|
||||
auth: {basic: 'admin'},
|
||||
httpStatus: 400, default: false,
|
||||
req: {email: 'j.doe@bosch.com', name: 'passreset', pass: 'Abc123!#', level: 'read', location: 'Rng', device_name: 'Alpha II'},
|
||||
req: {email: 'j.doe@bosch.com', name: 'passreset', pass: 'Abc123!#', level: 'read', location: 'Rng', devices: ['Alpha II']},
|
||||
res: {status: 'Username already taken'}
|
||||
});
|
||||
});
|
||||
@ -553,7 +555,7 @@ describe('/user', () => {
|
||||
url: '/user/new',
|
||||
auth: {basic: 'admin'},
|
||||
httpStatus: 400,
|
||||
req: {email: 'john.doe@bosch.com', name: 'johndoe', pass: 'Abc123!#', level: 'read', location: 44, device_name: 'Alpha II'},
|
||||
req: {email: 'john.doe@bosch.com', name: 'johndoe', pass: 'Abc123!#', level: 'read', location: 44, devices: ['Alpha II']},
|
||||
res: {status: 'Invalid body format', details: '"location" must be a string'}
|
||||
});
|
||||
});
|
||||
@ -563,7 +565,7 @@ describe('/user', () => {
|
||||
url: '/user/new',
|
||||
auth: {basic: 'admin'},
|
||||
httpStatus: 400,
|
||||
req: {email: 'john.doe@bosch.com', name: 'johndoe', pass: 'Abc123!#', level: 'xxx', location: 'Rng', device_name: 'Alpha II'},
|
||||
req: {email: 'john.doe@bosch.com', name: 'johndoe', pass: 'Abc123!#', level: 'xxx', location: 'Rng', devices: ['Alpha II']},
|
||||
res: {status: 'Invalid body format', details: '"level" must be one of [read, write, dev, admin]'}
|
||||
});
|
||||
});
|
||||
@ -573,7 +575,7 @@ describe('/user', () => {
|
||||
url: '/user/new',
|
||||
auth: {basic: 'admin'},
|
||||
httpStatus: 400,
|
||||
req: {email: 'john.doe', name: 'johndoe', pass: 'Abc123!#', level: 'read', location: 'Rng', device_name: 'Alpha II'},
|
||||
req: {email: 'john.doe', name: 'johndoe', pass: 'Abc123!#', level: 'read', location: 'Rng', devices: ['Alpha II']},
|
||||
res: {status: 'Invalid body format', details: '"email" must be a valid email'}
|
||||
});
|
||||
});
|
||||
@ -583,7 +585,7 @@ describe('/user', () => {
|
||||
url: '/user/new',
|
||||
auth: {basic: 'admin'},
|
||||
httpStatus: 400,
|
||||
req: {email: 'john.doe@bosch.com', name: 'johndoe', pass: 'password', level: 'read', location: 'Rng', device_name: 'Alpha II'},
|
||||
req: {email: 'john.doe@bosch.com', name: 'johndoe', pass: 'password', level: 'read', location: 'Rng', devices: ['Alpha II']},
|
||||
res: {status: 'Invalid body format', details: 'password must have at least 8 characters, one uppercase and one lowercase character, one number and at least one of the following characters: !\"\\#%&\'()*+,-.\\/:;<=>?@[]^_`\u0000|}~'}
|
||||
});
|
||||
});
|
||||
@ -593,7 +595,7 @@ describe('/user', () => {
|
||||
url: '/user/new',
|
||||
auth: {basic: 'janedoe'},
|
||||
httpStatus: 403,
|
||||
req: {email: 'john.doe@bosch.com', name: 'johndoe', pass: 'Abc123!#', level: 'read', location: 'Rng', device_name: 'Alpha II'}
|
||||
req: {email: 'john.doe@bosch.com', name: 'johndoe', pass: 'Abc123!#', level: 'read', location: 'Rng', devices: ['Alpha II']}
|
||||
});
|
||||
});
|
||||
it('rejects requests from an admin API key', done => {
|
||||
@ -602,7 +604,7 @@ describe('/user', () => {
|
||||
url: '/user/new',
|
||||
auth: {key: 'admin'},
|
||||
httpStatus: 401,
|
||||
req: {email: 'john.doe@bosch.com', name: 'johndoe', pass: 'Abc123!#', level: 'read', location: 'Rng', device_name: 'Alpha II'}
|
||||
req: {email: 'john.doe@bosch.com', name: 'johndoe', pass: 'Abc123!#', level: 'read', location: 'Rng', devices: ['Alpha II']}
|
||||
});
|
||||
});
|
||||
it('rejects unauthorized requests', done => {
|
||||
@ -610,7 +612,7 @@ describe('/user', () => {
|
||||
method: 'post',
|
||||
url: '/user/new',
|
||||
httpStatus: 401,
|
||||
req: {email: 'john.doe@bosch.com', name: 'johndoe', pass: 'Abc123!#', level: 'read', location: 'Rng', device_name: 'Alpha II'}
|
||||
req: {email: 'john.doe@bosch.com', name: 'johndoe', pass: 'Abc123!#', level: 'read', location: 'Rng', devices: ['Alpha II']}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -5,7 +5,7 @@ import _ from 'lodash';
|
||||
|
||||
import UserValidate from './validate/user';
|
||||
import UserModel from '../models/user';
|
||||
import mail from '../helpers/mail';
|
||||
import Mail from '../helpers/mail';
|
||||
import res400 from './validate/res400';
|
||||
import db from '../db';
|
||||
|
||||
@ -133,7 +133,7 @@ router.post('/user/passreset', (req, res, next) => {
|
||||
if (err) return next(err);
|
||||
|
||||
// send email
|
||||
mail(data[0].email, 'Your new password for the DeFinMa database',
|
||||
Mail.send(data[0].email, 'Your new password for the DeFinMa database',
|
||||
'Hi, <br><br> You requested to reset your password.<br>Your new password is:<br><br>' + newPass + '' +
|
||||
'<br><br>If you did not request a password reset, talk to the sysadmin quickly!<br><br>Have a nice day.' +
|
||||
'<br><br>The DeFinMa team', err => {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import Joi from '@hapi/joi';
|
||||
import Joi from 'joi';
|
||||
|
||||
export default class IdValidate {
|
||||
private static id = Joi.string().pattern(new RegExp('[0-9a-f]{24}')).length(24).messages({'string.pattern.base': 'Invalid object id'});
|
||||
|
@ -1,4 +1,4 @@
|
||||
import Joi from '@hapi/joi';
|
||||
import Joi from 'joi';
|
||||
|
||||
import IdValidate from './id';
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import Joi from '@hapi/joi';
|
||||
import Joi from 'joi';
|
||||
|
||||
import IdValidate from './id';
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import Joi from '@hapi/joi';
|
||||
import Joi from 'joi';
|
||||
|
||||
export default class NoteFieldValidate {
|
||||
private static note_field = {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import Joi from '@hapi/joi';
|
||||
import Joi from 'joi';
|
||||
|
||||
export default class ParametersValidate {
|
||||
static input (data, parameters, param) { // data to validate, parameters from template, param: 'new', 'change', 'null'(null values are allowed)
|
||||
|
@ -1,4 +1,4 @@
|
||||
import Joi from '@hapi/joi';
|
||||
import Joi from 'joi';
|
||||
import IdValidate from './id';
|
||||
|
||||
export default class RootValidate { // validate input for root methods
|
||||
|
@ -1,4 +1,4 @@
|
||||
import Joi from '@hapi/joi';
|
||||
import Joi from 'joi';
|
||||
|
||||
import IdValidate from './id';
|
||||
import UserValidate from './user';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import Joi from '@hapi/joi';
|
||||
import Joi from 'joi';
|
||||
import IdValidate from './id';
|
||||
|
||||
// TODO: do not allow a . in the name !!!
|
||||
|
@ -1,4 +1,4 @@
|
||||
import Joi from '@hapi/joi';
|
||||
import Joi from 'joi';
|
||||
import globals from '../../globals';
|
||||
|
||||
import IdValidate from './id';
|
||||
@ -28,12 +28,14 @@ export default class UserValidate { // validate input for user
|
||||
.alphanum()
|
||||
.max(128),
|
||||
|
||||
device_name: Joi.string()
|
||||
.allow('')
|
||||
.max(128),
|
||||
devices: Joi.array()
|
||||
.items(Joi.string()
|
||||
.allow('')
|
||||
.max(128)
|
||||
)
|
||||
};
|
||||
|
||||
private static specialUsernames = ['admin', 'user', 'key', 'new', 'passreset']; // names a user cannot take
|
||||
private static specialUsernames: string[] = ['admin', 'user', 'key', 'new', 'passreset']; // names a user cannot take
|
||||
|
||||
static input (data, param) { // validate input, set param to 'new' to make all attributes required
|
||||
if (param === 'new') {
|
||||
@ -43,7 +45,7 @@ export default class UserValidate { // validate input for user
|
||||
pass: this.user.pass.required(),
|
||||
level: this.user.level.required(),
|
||||
location: this.user.location.required(),
|
||||
device_name: this.user.device_name.required()
|
||||
devices: this.user.devices.required()
|
||||
}).validate(data);
|
||||
}
|
||||
else if (param === 'change') {
|
||||
@ -52,7 +54,7 @@ export default class UserValidate { // validate input for user
|
||||
email: this.user.email,
|
||||
pass: this.user.pass,
|
||||
location: this.user.location,
|
||||
device_name: this.user.device_name
|
||||
devices: this.user.devices
|
||||
}).validate(data);
|
||||
}
|
||||
else if (param === 'changeadmin') {
|
||||
@ -62,7 +64,7 @@ export default class UserValidate { // validate input for user
|
||||
pass: this.user.pass,
|
||||
level: this.user.level,
|
||||
location: this.user.location,
|
||||
device_name: this.user.device_name
|
||||
devices: this.user.devices
|
||||
}).validate(data);
|
||||
}
|
||||
else {
|
||||
@ -78,8 +80,9 @@ export default class UserValidate { // validate input for user
|
||||
email: this.user.email,
|
||||
level: this.user.level,
|
||||
location: this.user.location,
|
||||
device_name: this.user.device_name
|
||||
devices: this.user.devices
|
||||
}).validate(data, {stripUnknown: true});
|
||||
console.log(data);
|
||||
return error !== undefined? null : value;
|
||||
}
|
||||
|
||||
|
@ -686,7 +686,7 @@
|
||||
"pass": "$2a$10$di26XKF63OG0V00PL1kSK.ceCcTxDExBMOg.jkHiCnXcY7cN7DlPi",
|
||||
"level": "read",
|
||||
"location": "Rng",
|
||||
"device_name": "Alpha I",
|
||||
"devices": ["Alpha I"],
|
||||
"key": "000000000000000000001001",
|
||||
"__v": 0
|
||||
},
|
||||
@ -697,7 +697,7 @@
|
||||
"pass": "$2a$10$di26XKF63OG0V00PL1kSK.ceCcTxDExBMOg.jkHiCnXcY7cN7DlPi",
|
||||
"level": "write",
|
||||
"location": "Rng",
|
||||
"device_name": "Alpha I",
|
||||
"devices": ["Alpha I"],
|
||||
"key": "000000000000000000001002",
|
||||
"__v": 0
|
||||
},
|
||||
@ -708,7 +708,7 @@
|
||||
"pass": "$2a$10$i872o3qR5V3JnbDArD8Z.eDo.BNPDBaR7dUX9KSEtl9pUjLyucy2K",
|
||||
"level": "admin",
|
||||
"location": "Rng",
|
||||
"device_name": "",
|
||||
"devices": [""],
|
||||
"key": "000000000000000000001003",
|
||||
"__v": "0"
|
||||
},
|
||||
@ -719,7 +719,7 @@
|
||||
"pass": "$2a$10$di26XKF63OG0V00PL1kSK.ceCcTxDExBMOg.jkHiCnXcY7cN7DlPi",
|
||||
"level": "write",
|
||||
"location": "Fe",
|
||||
"device_name": "Alpha I",
|
||||
"devices": ["Alpha I"],
|
||||
"key": "000000000000000000001004",
|
||||
"__v": 0
|
||||
}
|
||||
|
Reference in New Issue
Block a user