switched device_name to devices
This commit is contained in:
parent
18e0809a99
commit
cc6fa48a44
@ -202,6 +202,8 @@ User:
|
|||||||
location:
|
location:
|
||||||
type: string
|
type: string
|
||||||
example: Rng
|
example: Rng
|
||||||
device_name:
|
devices:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
type: string
|
type: string
|
||||||
example: Alpha II
|
example: Alpha II
|
||||||
|
@ -66,7 +66,9 @@
|
|||||||
location:
|
location:
|
||||||
type: string
|
type: string
|
||||||
example: Rng
|
example: Rng
|
||||||
device_name:
|
devices:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
type: string
|
type: string
|
||||||
example: Alpha II
|
example: Alpha II
|
||||||
responses:
|
responses:
|
||||||
@ -212,7 +214,7 @@
|
|||||||
- pass
|
- pass
|
||||||
- level
|
- level
|
||||||
- location
|
- location
|
||||||
- device_name
|
- devices
|
||||||
allOf:
|
allOf:
|
||||||
- $ref: 'api.yaml#/components/schemas/User'
|
- $ref: 'api.yaml#/components/schemas/User'
|
||||||
responses:
|
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": {
|
"dependencies": {
|
||||||
"@apidevtools/json-schema-ref-parser": "^8.0.0",
|
"@apidevtools/json-schema-ref-parser": "^8.0.0",
|
||||||
"@apidevtools/swagger-parser": "^9.0.1",
|
"@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",
|
"axios": "^0.19.2",
|
||||||
"basic-auth": "^2.0.1",
|
"basic-auth": "^2.0.1",
|
||||||
"bcryptjs": "^2.4.3",
|
"bcryptjs": "^2.4.3",
|
||||||
@ -33,6 +34,7 @@
|
|||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"helmet": "^3.22.0",
|
"helmet": "^3.22.0",
|
||||||
|
"joi": "^17.1.1",
|
||||||
"json-schema": "^0.2.5",
|
"json-schema": "^0.2.5",
|
||||||
"json2csv": "^5.0.1",
|
"json2csv": "^5.0.1",
|
||||||
"lodash": "^4.17.15",
|
"lodash": "^4.17.15",
|
||||||
@ -46,7 +48,7 @@
|
|||||||
"@types/lodash": "^4.14.150",
|
"@types/lodash": "^4.14.150",
|
||||||
"@types/mocha": "^5.2.7",
|
"@types/mocha": "^5.2.7",
|
||||||
"@types/mongoose": "^5.7.12",
|
"@types/mongoose": "^5.7.12",
|
||||||
"@types/node": "^13.1.6",
|
"@types/node": "13.1.6",
|
||||||
"@types/qs": "^6.9.1",
|
"@types/qs": "^6.9.1",
|
||||||
"@types/serve-static": "^1.13.3",
|
"@types/serve-static": "^1.13.3",
|
||||||
"csv-parser": "^2.3.3",
|
"csv-parser": "^2.3.3",
|
||||||
|
@ -8,7 +8,7 @@ const UserSchema = new mongoose.Schema({
|
|||||||
key: String,
|
key: String,
|
||||||
level: String,
|
level: String,
|
||||||
location: String,
|
location: String,
|
||||||
device_name: String
|
devices: [String]
|
||||||
});
|
});
|
||||||
|
|
||||||
// changelog query helper
|
// changelog query helper
|
||||||
|
@ -426,7 +426,7 @@ describe('/material', () => {
|
|||||||
auth: {basic: 'janedoe'},
|
auth: {basic: 'janedoe'},
|
||||||
httpStatus: 400,
|
httpStatus: 400,
|
||||||
req: {properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: -5, carbon_fiber: 0}},
|
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 => {
|
it('rejects a properties parameter above maximum range', done => {
|
||||||
@ -925,7 +925,7 @@ describe('/material', () => {
|
|||||||
auth: {basic: 'janedoe'},
|
auth: {basic: 'janedoe'},
|
||||||
httpStatus: 400,
|
httpStatus: 400,
|
||||||
req: {name: 'Crastin CE 2510', supplier: 'Du Pont', group: 'PBT', properties: {material_template: '130000000000000000000003', glass_fiber: -0.3}, numbers: ['5515798402']},
|
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 => {
|
it('rejects a properties parameter above maximum range', done => {
|
||||||
|
@ -211,7 +211,7 @@ describe('/measurement', () => {
|
|||||||
auth: {basic: 'janedoe'},
|
auth: {basic: 'janedoe'},
|
||||||
httpStatus: 400,
|
httpStatus: 400,
|
||||||
req: {values: {'weight %': -1, 'standard deviation': 0.3}},
|
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 => {
|
it('rejects a value above maximum range', done => {
|
||||||
@ -698,7 +698,7 @@ describe('/measurement', () => {
|
|||||||
auth: {basic: 'janedoe'},
|
auth: {basic: 'janedoe'},
|
||||||
httpStatus: 400,
|
httpStatus: 400,
|
||||||
req: {sample_id: '400000000000000000000001', values: {'weight %': -1, 'standard deviation': 0.1}, measurement_template: '300000000000000000000002'},
|
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 => {
|
it('rejects a value above maximum range', done => {
|
||||||
|
@ -81,7 +81,7 @@ describe('/', () => {
|
|||||||
url: '/changelog/1879-07-28T06:04:51.000Z/10/2',
|
url: '/changelog/1879-07-28T06:04:51.000Z/10/2',
|
||||||
auth: {basic: 'admin'},
|
auth: {basic: 'admin'},
|
||||||
httpStatus: 400,
|
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 => {
|
it('rejects invalid timestamps', done => {
|
||||||
@ -99,7 +99,7 @@ describe('/', () => {
|
|||||||
url: '/changelog/1979-07-28T06:04:51.000Z/-10/2',
|
url: '/changelog/1979-07-28T06:04:51.000Z/-10/2',
|
||||||
auth: {basic: 'admin'},
|
auth: {basic: 'admin'},
|
||||||
httpStatus: 400,
|
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 => {
|
it('rejects negative pagesizes', done => {
|
||||||
@ -108,7 +108,7 @@ describe('/', () => {
|
|||||||
url: '/changelog/1979-07-28T06:04:51.000Z/10/-2',
|
url: '/changelog/1979-07-28T06:04:51.000Z/10/-2',
|
||||||
auth: {basic: 'admin'},
|
auth: {basic: 'admin'},
|
||||||
httpStatus: 400,
|
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 => {
|
it('rejects request from a write user', done => {
|
||||||
|
@ -499,7 +499,7 @@ describe('/sample', () => {
|
|||||||
url: '/samples?page-size=-3',
|
url: '/samples?page-size=-3',
|
||||||
auth: {basic: 'janedoe'},
|
auth: {basic: 'janedoe'},
|
||||||
httpStatus: 400,
|
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 => {
|
it('rejects an invalid from-id', done => {
|
||||||
@ -1047,7 +1047,7 @@ describe('/sample', () => {
|
|||||||
auth: {basic: 'janedoe'},
|
auth: {basic: 'janedoe'},
|
||||||
httpStatus: 400,
|
httpStatus: 400,
|
||||||
req: {condition: {material: 'copper', weeks: 0, condition_template: '200000000000000000000001'}},
|
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 => {
|
it('rejects a condition parameter above maximum range', done => {
|
||||||
|
@ -23,13 +23,15 @@ describe('/user', () => {
|
|||||||
const json = require('../test/db.json');
|
const json = require('../test/db.json');
|
||||||
should(res.body).have.lengthOf(json.collections.users.length);
|
should(res.body).have.lengthOf(json.collections.users.length);
|
||||||
should(res.body).matchEach(user => {
|
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('_id').be.type('string');
|
||||||
should(user).have.property('email').be.type('string');
|
should(user).have.property('email').be.type('string');
|
||||||
should(user).have.property('name').be.type('string');
|
should(user).have.property('name').be.type('string');
|
||||||
should(user).have.property('level').be.type('string');
|
should(user).have.property('level').be.type('string');
|
||||||
should(user).have.property('location').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();
|
done();
|
||||||
});
|
});
|
||||||
@ -68,13 +70,13 @@ describe('/user', () => {
|
|||||||
httpStatus: 200
|
httpStatus: 200
|
||||||
}).end((err, res) => {
|
}).end((err, res) => {
|
||||||
if (err) return done (err);
|
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('_id').be.type('string');
|
||||||
should(res.body).have.property('email', 'jane.doe@bosch.com');
|
should(res.body).have.property('email', 'jane.doe@bosch.com');
|
||||||
should(res.body).have.property('name', 'janedoe');
|
should(res.body).have.property('name', 'janedoe');
|
||||||
should(res.body).have.property('level', 'write');
|
should(res.body).have.property('level', 'write');
|
||||||
should(res.body).have.property('location', 'Rng');
|
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();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -86,13 +88,13 @@ describe('/user', () => {
|
|||||||
httpStatus: 200
|
httpStatus: 200
|
||||||
}).end((err, res) => {
|
}).end((err, res) => {
|
||||||
if (err) return done (err);
|
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('_id').be.type('string');
|
||||||
should(res.body).have.property('email', 'jane.doe@bosch.com');
|
should(res.body).have.property('email', 'jane.doe@bosch.com');
|
||||||
should(res.body).have.property('name', 'janedoe');
|
should(res.body).have.property('name', 'janedoe');
|
||||||
should(res.body).have.property('level', 'write');
|
should(res.body).have.property('level', 'write');
|
||||||
should(res.body).have.property('location', 'Rng');
|
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();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -147,13 +149,13 @@ describe('/user', () => {
|
|||||||
req: {}
|
req: {}
|
||||||
}).end((err, res) => {
|
}).end((err, res) => {
|
||||||
if (err) return done (err);
|
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('_id').be.type('string');
|
||||||
should(res.body).have.property('email', 'jane.doe@bosch.com');
|
should(res.body).have.property('email', 'jane.doe@bosch.com');
|
||||||
should(res.body).have.property('name', 'janedoe');
|
should(res.body).have.property('name', 'janedoe');
|
||||||
should(res.body).have.property('level', 'write');
|
should(res.body).have.property('level', 'write');
|
||||||
should(res.body).have.property('location', 'Rng');
|
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();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -166,13 +168,13 @@ describe('/user', () => {
|
|||||||
req: {}
|
req: {}
|
||||||
}).end((err, res) => {
|
}).end((err, res) => {
|
||||||
if (err) return done (err);
|
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('_id').be.type('string');
|
||||||
should(res.body).have.property('email', 'jane.doe@bosch.com');
|
should(res.body).have.property('email', 'jane.doe@bosch.com');
|
||||||
should(res.body).have.property('name', 'janedoe');
|
should(res.body).have.property('name', 'janedoe');
|
||||||
should(res.body).have.property('level', 'write');
|
should(res.body).have.property('level', 'write');
|
||||||
should(res.body).have.property('location', 'Rng');
|
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();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -182,20 +184,20 @@ describe('/user', () => {
|
|||||||
url: '/user',
|
url: '/user',
|
||||||
auth: {basic: 'admin'},
|
auth: {basic: 'admin'},
|
||||||
httpStatus: 200,
|
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 => {
|
}).end(err => {
|
||||||
if (err) return done (err);
|
if (err) return done (err);
|
||||||
UserModel.find({name: 'adminnew'}).lean().exec( (err, data) => {
|
UserModel.find({name: 'adminnew'}).lean().exec( (err, data) => {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
should(data).have.lengthOf(1);
|
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('_id');
|
||||||
should(data[0]).have.property('name', 'adminnew');
|
should(data[0]).have.property('name', 'adminnew');
|
||||||
should(data[0]).have.property('email', 'adminnew@bosch.com');
|
should(data[0]).have.property('email', 'adminnew@bosch.com');
|
||||||
should(data[0]).have.property('pass').not.eql('Abc123##');
|
should(data[0]).have.property('pass').not.eql('Abc123##');
|
||||||
should(data[0]).have.property('level', 'admin');
|
should(data[0]).have.property('level', 'admin');
|
||||||
should(data[0]).have.property('location', 'Abt');
|
should(data[0]).have.property('location', 'Abt');
|
||||||
should(data[0]).have.property('device_name', 'test');
|
should(data[0]).have.property('devices', ['test']);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -206,7 +208,7 @@ describe('/user', () => {
|
|||||||
url: '/user',
|
url: '/user',
|
||||||
auth: {basic: 'admin'},
|
auth: {basic: 'admin'},
|
||||||
httpStatus: 200,
|
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: {
|
log: {
|
||||||
collection: 'users',
|
collection: 'users',
|
||||||
dataIgn: ['pass']
|
dataIgn: ['pass']
|
||||||
@ -271,7 +273,7 @@ describe('/user', () => {
|
|||||||
url: '/user/new',
|
url: '/user/new',
|
||||||
auth: {basic: 'admin'},
|
auth: {basic: 'admin'},
|
||||||
httpStatus: 400, default: false,
|
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'}
|
res: {status: 'Username already taken'}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -281,7 +283,7 @@ describe('/user', () => {
|
|||||||
url: '/user',
|
url: '/user',
|
||||||
auth: {basic: 'admin'},
|
auth: {basic: 'admin'},
|
||||||
httpStatus: 400,
|
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'}
|
res: {status: 'Invalid body format', details: '"location" must be a string'}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -470,16 +472,16 @@ describe('/user', () => {
|
|||||||
url: '/user/new',
|
url: '/user/new',
|
||||||
auth: {basic: 'admin'},
|
auth: {basic: 'admin'},
|
||||||
httpStatus: 200,
|
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) => {
|
}).end((err, res) => {
|
||||||
if (err) return done (err);
|
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('_id').be.type('string');
|
||||||
should(res.body).have.property('email', 'john.doe@bosch.com');
|
should(res.body).have.property('email', 'john.doe@bosch.com');
|
||||||
should(res.body).have.property('name', 'johndoe');
|
should(res.body).have.property('name', 'johndoe');
|
||||||
should(res.body).have.property('level', 'read');
|
should(res.body).have.property('level', 'read');
|
||||||
should(res.body).have.property('location', 'Rng');
|
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();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -489,20 +491,20 @@ describe('/user', () => {
|
|||||||
url: '/user/new',
|
url: '/user/new',
|
||||||
auth: {basic: 'admin'},
|
auth: {basic: 'admin'},
|
||||||
httpStatus: 200,
|
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 => {
|
}).end(err => {
|
||||||
if (err) return done (err);
|
if (err) return done (err);
|
||||||
UserModel.find({name: 'johndoe'}).lean().exec( (err, data) => {
|
UserModel.find({name: 'johndoe'}).lean().exec( (err, data) => {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
should(data).have.lengthOf(1);
|
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('_id');
|
||||||
should(data[0]).have.property('name', 'johndoe');
|
should(data[0]).have.property('name', 'johndoe');
|
||||||
should(data[0]).have.property('email', 'john.doe@bosch.com');
|
should(data[0]).have.property('email', 'john.doe@bosch.com');
|
||||||
should(data[0]).have.property('pass').not.eql('Abc123!#');
|
should(data[0]).have.property('pass').not.eql('Abc123!#');
|
||||||
should(data[0]).have.property('level', 'read');
|
should(data[0]).have.property('level', 'read');
|
||||||
should(data[0]).have.property('location', 'Rng');
|
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();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -513,7 +515,7 @@ describe('/user', () => {
|
|||||||
url: '/user/new',
|
url: '/user/new',
|
||||||
auth: {basic: 'admin'},
|
auth: {basic: 'admin'},
|
||||||
httpStatus: 200,
|
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: {
|
log: {
|
||||||
collection: 'users',
|
collection: 'users',
|
||||||
dataIgn: ['pass', 'key']
|
dataIgn: ['pass', 'key']
|
||||||
@ -526,7 +528,7 @@ describe('/user', () => {
|
|||||||
url: '/user/new',
|
url: '/user/new',
|
||||||
auth: {basic: 'admin'},
|
auth: {basic: 'admin'},
|
||||||
httpStatus: 400, default: false,
|
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) => {
|
}).end((err, res) => {
|
||||||
if (err) return done (err);
|
if (err) return done (err);
|
||||||
should(res.body).be.eql({status: 'Username already taken'});
|
should(res.body).be.eql({status: 'Username already taken'});
|
||||||
@ -543,7 +545,7 @@ describe('/user', () => {
|
|||||||
url: '/user/new',
|
url: '/user/new',
|
||||||
auth: {basic: 'admin'},
|
auth: {basic: 'admin'},
|
||||||
httpStatus: 400, default: false,
|
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'}
|
res: {status: 'Username already taken'}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -553,7 +555,7 @@ describe('/user', () => {
|
|||||||
url: '/user/new',
|
url: '/user/new',
|
||||||
auth: {basic: 'admin'},
|
auth: {basic: 'admin'},
|
||||||
httpStatus: 400,
|
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'}
|
res: {status: 'Invalid body format', details: '"location" must be a string'}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -563,7 +565,7 @@ describe('/user', () => {
|
|||||||
url: '/user/new',
|
url: '/user/new',
|
||||||
auth: {basic: 'admin'},
|
auth: {basic: 'admin'},
|
||||||
httpStatus: 400,
|
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]'}
|
res: {status: 'Invalid body format', details: '"level" must be one of [read, write, dev, admin]'}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -573,7 +575,7 @@ describe('/user', () => {
|
|||||||
url: '/user/new',
|
url: '/user/new',
|
||||||
auth: {basic: 'admin'},
|
auth: {basic: 'admin'},
|
||||||
httpStatus: 400,
|
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'}
|
res: {status: 'Invalid body format', details: '"email" must be a valid email'}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -583,7 +585,7 @@ describe('/user', () => {
|
|||||||
url: '/user/new',
|
url: '/user/new',
|
||||||
auth: {basic: 'admin'},
|
auth: {basic: 'admin'},
|
||||||
httpStatus: 400,
|
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|}~'}
|
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',
|
url: '/user/new',
|
||||||
auth: {basic: 'janedoe'},
|
auth: {basic: 'janedoe'},
|
||||||
httpStatus: 403,
|
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 => {
|
it('rejects requests from an admin API key', done => {
|
||||||
@ -602,7 +604,7 @@ describe('/user', () => {
|
|||||||
url: '/user/new',
|
url: '/user/new',
|
||||||
auth: {key: 'admin'},
|
auth: {key: 'admin'},
|
||||||
httpStatus: 401,
|
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 => {
|
it('rejects unauthorized requests', done => {
|
||||||
@ -610,7 +612,7 @@ describe('/user', () => {
|
|||||||
method: 'post',
|
method: 'post',
|
||||||
url: '/user/new',
|
url: '/user/new',
|
||||||
httpStatus: 401,
|
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']}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import Joi from '@hapi/joi';
|
import Joi from 'joi';
|
||||||
|
|
||||||
export default class IdValidate {
|
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'});
|
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';
|
import IdValidate from './id';
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import Joi from '@hapi/joi';
|
import Joi from 'joi';
|
||||||
|
|
||||||
import IdValidate from './id';
|
import IdValidate from './id';
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import Joi from '@hapi/joi';
|
import Joi from 'joi';
|
||||||
|
|
||||||
export default class NoteFieldValidate {
|
export default class NoteFieldValidate {
|
||||||
private static note_field = {
|
private static note_field = {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import Joi from '@hapi/joi';
|
import Joi from 'joi';
|
||||||
|
|
||||||
export default class ParametersValidate {
|
export default class ParametersValidate {
|
||||||
static input (data, parameters, param) { // data to validate, parameters from template, param: 'new', 'change', 'null'(null values are allowed)
|
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';
|
import IdValidate from './id';
|
||||||
|
|
||||||
export default class RootValidate { // validate input for root methods
|
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 IdValidate from './id';
|
||||||
import UserValidate from './user';
|
import UserValidate from './user';
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import Joi from '@hapi/joi';
|
import Joi from 'joi';
|
||||||
import IdValidate from './id';
|
import IdValidate from './id';
|
||||||
|
|
||||||
// TODO: do not allow a . in the name !!!
|
// 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 globals from '../../globals';
|
||||||
|
|
||||||
import IdValidate from './id';
|
import IdValidate from './id';
|
||||||
@ -28,12 +28,14 @@ export default class UserValidate { // validate input for user
|
|||||||
.alphanum()
|
.alphanum()
|
||||||
.max(128),
|
.max(128),
|
||||||
|
|
||||||
device_name: Joi.string()
|
devices: Joi.array()
|
||||||
|
.items(Joi.string()
|
||||||
.allow('')
|
.allow('')
|
||||||
.max(128),
|
.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
|
static input (data, param) { // validate input, set param to 'new' to make all attributes required
|
||||||
if (param === 'new') {
|
if (param === 'new') {
|
||||||
@ -43,7 +45,7 @@ export default class UserValidate { // validate input for user
|
|||||||
pass: this.user.pass.required(),
|
pass: this.user.pass.required(),
|
||||||
level: this.user.level.required(),
|
level: this.user.level.required(),
|
||||||
location: this.user.location.required(),
|
location: this.user.location.required(),
|
||||||
device_name: this.user.device_name.required()
|
devices: this.user.devices.required()
|
||||||
}).validate(data);
|
}).validate(data);
|
||||||
}
|
}
|
||||||
else if (param === 'change') {
|
else if (param === 'change') {
|
||||||
@ -52,7 +54,7 @@ export default class UserValidate { // validate input for user
|
|||||||
email: this.user.email,
|
email: this.user.email,
|
||||||
pass: this.user.pass,
|
pass: this.user.pass,
|
||||||
location: this.user.location,
|
location: this.user.location,
|
||||||
device_name: this.user.device_name
|
devices: this.user.devices
|
||||||
}).validate(data);
|
}).validate(data);
|
||||||
}
|
}
|
||||||
else if (param === 'changeadmin') {
|
else if (param === 'changeadmin') {
|
||||||
@ -62,7 +64,7 @@ export default class UserValidate { // validate input for user
|
|||||||
pass: this.user.pass,
|
pass: this.user.pass,
|
||||||
level: this.user.level,
|
level: this.user.level,
|
||||||
location: this.user.location,
|
location: this.user.location,
|
||||||
device_name: this.user.device_name
|
devices: this.user.devices
|
||||||
}).validate(data);
|
}).validate(data);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -78,8 +80,9 @@ export default class UserValidate { // validate input for user
|
|||||||
email: this.user.email,
|
email: this.user.email,
|
||||||
level: this.user.level,
|
level: this.user.level,
|
||||||
location: this.user.location,
|
location: this.user.location,
|
||||||
device_name: this.user.device_name
|
devices: this.user.devices
|
||||||
}).validate(data, {stripUnknown: true});
|
}).validate(data, {stripUnknown: true});
|
||||||
|
console.log(data);
|
||||||
return error !== undefined? null : value;
|
return error !== undefined? null : value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -686,7 +686,7 @@
|
|||||||
"pass": "$2a$10$di26XKF63OG0V00PL1kSK.ceCcTxDExBMOg.jkHiCnXcY7cN7DlPi",
|
"pass": "$2a$10$di26XKF63OG0V00PL1kSK.ceCcTxDExBMOg.jkHiCnXcY7cN7DlPi",
|
||||||
"level": "read",
|
"level": "read",
|
||||||
"location": "Rng",
|
"location": "Rng",
|
||||||
"device_name": "Alpha I",
|
"devices": ["Alpha I"],
|
||||||
"key": "000000000000000000001001",
|
"key": "000000000000000000001001",
|
||||||
"__v": 0
|
"__v": 0
|
||||||
},
|
},
|
||||||
@ -697,7 +697,7 @@
|
|||||||
"pass": "$2a$10$di26XKF63OG0V00PL1kSK.ceCcTxDExBMOg.jkHiCnXcY7cN7DlPi",
|
"pass": "$2a$10$di26XKF63OG0V00PL1kSK.ceCcTxDExBMOg.jkHiCnXcY7cN7DlPi",
|
||||||
"level": "write",
|
"level": "write",
|
||||||
"location": "Rng",
|
"location": "Rng",
|
||||||
"device_name": "Alpha I",
|
"devices": ["Alpha I"],
|
||||||
"key": "000000000000000000001002",
|
"key": "000000000000000000001002",
|
||||||
"__v": 0
|
"__v": 0
|
||||||
},
|
},
|
||||||
@ -708,7 +708,7 @@
|
|||||||
"pass": "$2a$10$i872o3qR5V3JnbDArD8Z.eDo.BNPDBaR7dUX9KSEtl9pUjLyucy2K",
|
"pass": "$2a$10$i872o3qR5V3JnbDArD8Z.eDo.BNPDBaR7dUX9KSEtl9pUjLyucy2K",
|
||||||
"level": "admin",
|
"level": "admin",
|
||||||
"location": "Rng",
|
"location": "Rng",
|
||||||
"device_name": "",
|
"devices": [""],
|
||||||
"key": "000000000000000000001003",
|
"key": "000000000000000000001003",
|
||||||
"__v": "0"
|
"__v": "0"
|
||||||
},
|
},
|
||||||
@ -719,7 +719,7 @@
|
|||||||
"pass": "$2a$10$di26XKF63OG0V00PL1kSK.ceCcTxDExBMOg.jkHiCnXcY7cN7DlPi",
|
"pass": "$2a$10$di26XKF63OG0V00PL1kSK.ceCcTxDExBMOg.jkHiCnXcY7cN7DlPi",
|
||||||
"level": "write",
|
"level": "write",
|
||||||
"location": "Fe",
|
"location": "Fe",
|
||||||
"device_name": "Alpha I",
|
"devices": ["Alpha I"],
|
||||||
"key": "000000000000000000001004",
|
"key": "000000000000000000001004",
|
||||||
"__v": 0
|
"__v": 0
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user