@tiledesk/tiledesk-server 2.10.15 → 2.10.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/app.js +2 -1
  3. package/models/request.js +8 -0
  4. package/package.json +4 -3
  5. package/pubmodules/activities/test/activityRoute.js +6 -2
  6. package/pubmodules/events/test/eventRoute.js +7 -3
  7. package/pubmodules/pubModulesManager.js +24 -0
  8. package/pubmodules/voice-twilio/index.js +6 -0
  9. package/pubmodules/voice-twilio/listener.js +59 -0
  10. package/routes/campaigns.js +1 -1
  11. package/routes/files.js +6 -4
  12. package/routes/images.js +0 -2
  13. package/routes/kb.js +7 -1
  14. package/routes/users.js +2 -2
  15. package/services/fileGridFsService.js +12 -10
  16. package/services/requestService.js +2 -1
  17. package/test/app-test.js +36 -1
  18. package/test/authentication.js +662 -796
  19. package/test/authenticationJwt.js +213 -315
  20. package/test/authorization.js +53 -72
  21. package/test/campaignsRoute.js +42 -47
  22. package/test/cannedRoute.js +30 -16
  23. package/test/departmentService.js +222 -274
  24. package/test/example.json +31 -1
  25. package/test/faqRoute.js +713 -622
  26. package/test/faqService.js +124 -159
  27. package/test/faqkbRoute.js +128 -100
  28. package/test/fileRoute.js +50 -46
  29. package/test/imageRoute.js +263 -254
  30. package/test/jwtRoute.js +128 -153
  31. package/test/kbRoute.js +40 -17
  32. package/test/kbsettingsRoute.js +78 -54
  33. package/test/keysRoute.js +6 -7
  34. package/test/labelRoute.js +591 -696
  35. package/test/labelService.js +40 -47
  36. package/test/leadService.js +100 -115
  37. package/test/logsRoute.js +13 -7
  38. package/test/messageRootRoute.js +112 -102
  39. package/test/messageRoute.js +1171 -1419
  40. package/test/messageService.js +41 -43
  41. package/test/openaiRoute.js +5 -1
  42. package/test/projectRoute.js +23 -4
  43. package/test/projectService.js +3 -1
  44. package/test/quoteManager.js +36 -13
  45. package/test/requestRoute.js +103 -72
  46. package/test/requestService.js +51 -51
  47. package/test/userRoute.js +37 -8
  48. package/test/userService.js +34 -31
  49. package/utils/promiseUtil.js +1 -1
@@ -1,6 +1,7 @@
1
1
  //During the test the env variable is set to test
2
2
  process.env.NODE_ENV = 'test';
3
3
  process.env.ADMIN_EMAIL = "admin@tiledesk.com";
4
+ process.env.LOG_LEVEL = 'critical';
4
5
  //var User = require('../models/user');
5
6
  var projectService = require('../services/projectService');
6
7
  var requestService = require('../services/requestService');
@@ -21,6 +22,8 @@ var jwt = require('jsonwebtoken');
21
22
 
22
23
  var config = require('../config/database');
23
24
 
25
+ let log = false;
26
+
24
27
  var mongoose = require('mongoose');
25
28
  mongoose.connect(config.databasetest);
26
29
 
@@ -29,1041 +32,904 @@ chai.use(chaiHttp);
29
32
 
30
33
  describe('Authentication', () => {
31
34
 
32
- // mocha test/authentication.js --grep 'signinOk'
35
+ // mocha test/authentication.js --grep 'signinOk'
33
36
 
34
- describe('/signin', () => {
35
-
36
-
37
+ describe('/signin', () => {
37
38
 
38
- it('signinOk', (done) => {
39
39
 
40
-
41
- // this.timeout();
40
+ it('signinOk', (done) => {
42
41
 
43
- var email = "test-signin-" + Date.now() + "@email.com";
44
- var pwd = "pwd";
42
+ var email = "test-signin-" + Date.now() + "@email.com";
43
+ var pwd = "pwd";
45
44
 
46
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
47
-
48
- chai.request(server)
49
- .post('/auth/signin' )
50
- .send({"email":email, "password":pwd})
51
- .end((err, res) => {
52
- //console.log("res", res);
53
- console.log("res.body", res.body);
54
- res.should.have.status(200);
55
- res.body.should.be.a('object');
56
- expect(res.body.success).to.equal(true);
57
- expect(res.body.token).to.not.equal(null);
58
- expect(res.body.user.email).to.equal(email);
59
- expect(res.body.user.password).to.equal(undefined);
60
-
61
- done();
62
- });
45
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
46
+
47
+ chai.request(server)
48
+ .post('/auth/signin')
49
+ .send({ "email": email, "password": pwd })
50
+ .end((err, res) => {
51
+
52
+ if (err) { console.error("err: ", err); }
53
+ if (log) { console.log("res.body", res.body); }
54
+
55
+ res.should.have.status(200);
56
+ res.body.should.be.a('object');
57
+ expect(res.body.success).to.equal(true);
58
+ expect(res.body.token).to.not.equal(null);
59
+ expect(res.body.user.email).to.equal(email);
60
+ expect(res.body.user.password).to.equal(undefined);
61
+
62
+ done();
63
+ });
64
+
65
+ });
66
+ });
63
67
 
64
-
68
+
69
+ it('signinkO', (done) => {
70
+
71
+ var email = "test-signinko-" + Date.now() + "@email.com";
72
+ var pwd = "pwd";
73
+
74
+ chai.request(server)
75
+ .post('/auth/signin')
76
+ .send({ "email": email, "password": pwd })
77
+ .end((err, res) => {
78
+
79
+ if (err) { console.error("err: ", err); }
80
+ if (log) { console.log("res.body", res.body); }
81
+
82
+ res.should.have.status(401);
83
+
84
+ done();
65
85
  });
66
- });
67
86
 
87
+ });
68
88
 
69
89
 
70
- it('signinkO', (done) => {
90
+ it('signinValidation', (done) => {
71
91
 
72
-
73
- // this.timeout();
74
-
75
- var email = "test-signinko-" + Date.now() + "@email.com";
76
- var pwd = "pwd";
77
-
78
-
79
- chai.request(server)
80
- .post('/auth/signin' )
81
- .send({"email":email, "password":pwd})
82
- .end((err, res) => {
83
- //console.log("res", res);
84
- console.log("res.body", res.body);
85
- res.should.have.status(401);
86
-
87
-
88
- done();
89
- });
90
-
91
-
92
- });
93
-
92
+ var email = "test-signinko-" + Date.now() + "@email.com";
93
+ var pwd = "pwd";
94
94
 
95
+ chai.request(server)
96
+ .post('/auth/signin')
97
+ .send()
98
+ .end((err, res) => {
95
99
 
100
+ if (err) { console.error("err: ", err); }
101
+ if (log) { console.log("res.body", res.body); }
96
102
 
103
+ res.should.have.status(422);
97
104
 
105
+ done();
106
+ });
98
107
 
99
- it('signinValidation', (done) => {
108
+ });
100
109
 
101
-
102
- // this.timeout();
103
-
104
- var email = "test-signinko-" + Date.now() + "@email.com";
105
- var pwd = "pwd";
106
-
107
-
108
- chai.request(server)
109
- .post('/auth/signin' )
110
- .send()
111
- .end((err, res) => {
112
- //console.log("res", res);
113
- console.log("res.body", res.body);
114
- res.should.have.status(422);
115
-
116
-
117
- done();
118
- });
119
-
120
-
121
- });
122
-
123
110
 
124
- // mocha test/authentication.js --grep 'signinLowercase'
111
+ // mocha test/authentication.js --grep 'signinLowercase'
112
+ it('signinLowercase', (done) => {
113
+
114
+ var email = "Test-SigninKO-" + Date.now() + "@email.com";
115
+ var pwd = "pwd";
125
116
 
126
- it('signinLowercase', (done) => {
117
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
127
118
 
128
-
129
- // this.timeout();
130
-
131
- var email = "Test-SigninKO-" + Date.now() + "@email.com";
132
- var pwd = "pwd";
133
-
134
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
119
+ chai.request(server)
120
+ .post('/auth/signin')
121
+ .send({ "email": email, "password": pwd })
122
+ .end((err, res) => {
123
+
124
+ if (err) { console.error("err: ", err); }
125
+ if (log) { console.log("res.body", res.body); }
126
+
127
+ res.should.have.status(200);
128
+ res.body.should.be.a('object');
129
+ expect(res.body.success).to.equal(true);
130
+ expect(res.body.token).to.not.equal(null);
131
+ expect(res.body.user.email).to.equal(email.toLowerCase());
132
+ expect(res.body.user.password).to.equal(undefined);
135
133
 
136
134
  chai.request(server)
137
- .post('/auth/signin' )
138
- .send({"email":email, "password":pwd})
135
+ .get('/users/')
136
+ .auth(email, pwd)
139
137
  .end((err, res) => {
140
- console.log("res.body", res.body);
138
+
139
+ if (err) { console.error("err: ", err); }
140
+ if (log) { console.log("res.body", res.body); }
141
+
141
142
  res.should.have.status(200);
142
143
  res.body.should.be.a('object');
143
- expect(res.body.success).to.equal(true);
144
- expect(res.body.token).to.not.equal(null);
145
- expect(res.body.user.email).to.equal(email.toLowerCase());
146
- expect(res.body.user.password).to.equal(undefined);
147
-
148
-
149
-
150
- chai.request(server)
151
- .get('/users/' )
152
- .auth(email, pwd)
153
- .end((err, res) => {
154
- console.log("res.body", res.body);
155
- res.should.have.status(200);
156
- res.body.should.be.a('object');
157
-
158
- done();
159
- });
160
-
161
- });
162
144
 
145
+ done();
163
146
  });
164
-
165
- });
166
147
  });
167
-
168
-
169
- });
148
+ });
149
+ });
170
150
 
151
+ });
171
152
 
153
+ describe('/signup', () => {
172
154
 
173
155
 
156
+ it('signupOk', (done) => {
174
157
 
158
+ var email = "test-signuook-" + Date.now() + "@email.com";
159
+ var pwd = "Pwd1234!";
175
160
 
161
+ chai.request(server)
162
+ .post('/auth/signup')
163
+ .send({ email: email, password: pwd, lastname: "lastname", firstname: "firstname", disableEmail: true }) // whi disableEmail true?
164
+ .end((err, res) => {
176
165
 
166
+ if (err) { console.error("err: ", err); }
167
+ if (log) { console.log("res.body", res.body); }
177
168
 
169
+ res.should.have.status(200);
170
+ res.body.should.be.a('object');
171
+ expect(res.body.success).to.equal(true);
172
+ expect(res.body.user.email).to.equal(email);
173
+ expect(res.body.user.password).to.equal(undefined);
178
174
 
179
- describe('/signup', () => {
180
-
181
-
175
+ done();
176
+ });
177
+ });
182
178
 
183
- it('signupOk', (done) => {
184
179
 
185
-
186
- // this.timeout();
180
+ // it('verifyemail', (done) => {
187
181
 
188
- var email = "test-signuook-" + Date.now() + "@email.com";
189
- var pwd = "Pwd1234!";
182
+ // let user_id = "670e55c8187b430e793d644e";
183
+ // let code = "4fx6e1hfcm2admb4a";
184
+ // chai.request(server)
185
+ // .put('/auth/verifyemail/' + user_id + '/' + code)
186
+ // .send({ emailVerified: true })
187
+ // .end((err, res) => {
190
188
 
191
-
192
- chai.request(server)
193
- .post('/auth/signup' )
194
- .send({email:email, password:pwd, lastname:"lastname", firstname: "firstname", disableEmail: true}) // whi disableEmail true?
195
- .end((err, res) => {
196
- //console.log("res", res);
197
- console.log("res.body", res.body);
198
- res.should.have.status(200);
199
- res.body.should.be.a('object');
200
- expect(res.body.success).to.equal(true);
201
- expect(res.body.user.email).to.equal(email);
202
- expect(res.body.user.password).to.equal(undefined);
203
-
204
- done();
205
- });
189
+ // console.error("err: ", err)
190
+ // console.log("res.body: ", res.body)
191
+ // done();
192
+ // })
206
193
 
207
-
208
-
209
- });
210
194
 
211
195
 
212
- // it('verifyemail', (done) => {
196
+ // });
213
197
 
214
- // let user_id = "670e55c8187b430e793d644e";
215
- // let code = "4fx6e1hfcm2admb4a";
216
- // chai.request(server)
217
- // .put('/auth/verifyemail/' + user_id + '/' + code)
218
- // .send({ emailVerified: true })
219
- // .end((err, res) => {
220
198
 
221
- // console.error("err: ", err)
222
- // console.log("res.body: ", res.body)
223
- // done();
224
- // })
225
199
 
226
200
 
201
+ // it('signUpAdminNoVerificationEmail', (done) => {
227
202
 
228
- // });
203
+ // var email = "test-signup-" + Date.now() + "@email.com";
204
+ // var pwd = "pwd";
229
205
 
206
+ // chai.request(server)
207
+ // .post("/auth/signin")
208
+ // .send({ email: "admin@tiledesk.com", password: "adminadmin" })
209
+ // .end((err, res) => {
230
210
 
231
-
211
+ // // console.log("login with superadmin res.body: ", res.body)
212
+ // let superadmin_token = res.body.token;
232
213
 
233
- // it('signUpAdminNoVerificationEmail', (done) => {
214
+ // chai.request(server)
215
+ // .post("/auth/signup")
216
+ // .set('Authorization', superadmin_token)
217
+ // .send({ email: email, password: pwd, lastname: "lastname", firstname: "firstname", disableEmail: true })
218
+ // .end((err, res) => {
234
219
 
235
- // var email = "test-signup-" + Date.now() + "@email.com";
236
- // var pwd = "pwd";
220
+ // // console.log("res.body: ", res.body);
221
+ // done();
222
+ // })
223
+ // })
237
224
 
238
- // chai.request(server)
239
- // .post("/auth/signin")
240
- // .send({ email: "admin@tiledesk.com", password: "adminadmin" })
241
- // .end((err, res) => {
242
225
 
243
- // // console.log("login with superadmin res.body: ", res.body)
244
- // let superadmin_token = res.body.token;
226
+ // })
245
227
 
246
- // chai.request(server)
247
- // .post("/auth/signup")
248
- // .set('Authorization', superadmin_token)
249
- // .send({ email: email, password: pwd, lastname: "lastname", firstname: "firstname", disableEmail: true })
250
- // .end((err, res) => {
228
+ // mocha test/authentication.js --grep 'signupUpperCaseEmail'
251
229
 
252
- // // console.log("res.body: ", res.body);
253
- // done();
254
- // })
255
- // })
256
230
 
231
+ it('signupUpperCaseEmail', (done) => {
257
232
 
258
- // })
233
+ var now = Date.now();
234
+ var email = "test-signupUpperCaseEmail-" + now + "@email.com";
235
+ var pwd = "Pwd1234!";
259
236
 
260
- // mocha test/authentication.js --grep 'signupUpperCaseEmail'
237
+ chai.request(server)
238
+ .post('/auth/signup')
239
+ .send({ email: email, password: pwd, lastname: "lastname", firstname: "firstname", disableEmail: true })
240
+ .end((err, res) => {
261
241
 
242
+ if (err) { console.error("err: ", err); }
243
+ if (log) { console.log("res.body", res.body); }
262
244
 
263
- it('signupUpperCaseEmail', (done) => {
245
+ res.should.have.status(200);
246
+ res.body.should.be.a('object');
247
+ expect(res.body.success).to.equal(true);
248
+ expect(res.body.user.email).to.equal("test-signupuppercaseemail-" + now + "@email.com");
249
+ expect(res.body.user.password).to.equal(undefined);
264
250
 
265
-
266
- // this.timeout();
267
- var now = Date.now();
268
- var email = "test-signupUpperCaseEmail-" + now + "@email.com";
269
- var pwd = "Pwd1234!";
270
-
271
-
272
- chai.request(server)
273
- .post('/auth/signup' )
274
- .send({email:email, password:pwd, lastname:"lastname", firstname: "firstname", disableEmail: true})
275
- .end((err, res) => {
276
- //console.log("res", res);
277
- console.log("res.body", res.body);
278
- res.should.have.status(200);
279
- res.body.should.be.a('object');
280
- expect(res.body.success).to.equal(true);
281
- expect(res.body.user.email).to.equal("test-signupuppercaseemail-" + now + "@email.com");
282
- expect(res.body.user.password).to.equal(undefined);
283
-
284
- done();
285
- });
286
-
251
+ done();
252
+ });
287
253
  });
288
254
 
289
- // mocha test/authentication.js --grep 'signupkOWrongEmail'
255
+ // mocha test/authentication.js --grep 'signupkOWrongEmail'
256
+ it('signupkOWrongEmail', (done) => {
290
257
 
291
- it('signupkOWrongEmail', (done) => {
258
+ var email = "test-signuoOk-" + Date.now() + "@email";
259
+ var pwd = "Pwd1234!";
292
260
 
293
-
294
- // this.timeout();
295
-
296
- var email = "test-signuoOk-" + Date.now() + "@email";
297
- var pwd = "Pwd1234!";
298
-
299
-
300
- chai.request(server)
301
- .post('/auth/signup' )
302
- .send({email:email, password:pwd, lastname:"lastname", firstname: "firstname", disableEmail: true})
303
- .end((err, res) => {
304
- //console.log("res", res);
305
- console.log("res.body", res.body);
306
- res.should.have.status(422);
307
-
308
- done();
309
- });
310
-
311
-
312
-
261
+ chai.request(server)
262
+ .post('/auth/signup')
263
+ .send({ email: email, password: pwd, lastname: "lastname", firstname: "firstname", disableEmail: true })
264
+ .end((err, res) => {
265
+
266
+ if (err) { console.error("err: ", err); }
267
+ if (log) { console.log("res.body", res.body); }
268
+
269
+ res.should.have.status(422);
270
+
271
+ done();
272
+ });
313
273
  });
314
274
 
315
275
 
316
- // });
276
+ // });
277
+
278
+
279
+
317
280
 
318
281
 
319
282
 
320
283
 
321
- describe('/signInAnonymously', () => {
322
-
323
-
324
284
 
325
- it('signInAnonymouslyOk', (done) => {
326
285
 
327
-
328
- var email = "test-signInAnonymouslyOk-" + Date.now() + "@email.com";
329
- var pwd = "pwd";
330
286
 
331
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
332
- // create(name, createdBy, settings)
333
- projectService.create("test-signInAnonymouslyOk", savedUser._id).then(function(savedProject) {
334
-
287
+
288
+
289
+
290
+ });
291
+
292
+ describe('/signInAnonymously', () => {
293
+
294
+
295
+ it('signInAnonymouslyOk', (done) => {
296
+
297
+ var email = "test-signInAnonymouslyOk-" + Date.now() + "@email.com";
298
+ var pwd = "pwd";
299
+
300
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
301
+ // create(name, createdBy, settings)
302
+ projectService.create("test-signInAnonymouslyOk", savedUser._id).then(function (savedProject) {
303
+
335
304
  chai.request(server)
336
- .post('/auth/signinAnonymously' )
337
- .send({ id_project: savedProject._id, email: "email@email.com"})
305
+ .post('/auth/signinAnonymously')
306
+ .send({ id_project: savedProject._id, email: "email@email.com" })
338
307
  .end((err, res) => {
339
- //console.log("res", res);
340
- console.log("res.body", res.body);
308
+
309
+ if (err) { console.error("err: ", err); }
310
+ if (log) { console.log("res.body", res.body); }
311
+
341
312
  res.should.have.status(200);
342
313
  res.body.should.be.a('object');
343
- expect(res.body.success).to.equal(true);
344
- expect(res.body.user.email).to.equal("email@email.com");
345
- expect(res.body.token).to.not.equal(undefined);
346
-
314
+ expect(res.body.success).to.equal(true);
315
+ expect(res.body.user.email).to.equal("email@email.com");
316
+ expect(res.body.token).to.not.equal(undefined);
317
+
347
318
  done();
348
319
  });
349
- });
350
320
  });
351
-
352
-
353
- });
354
-
355
-
356
-
321
+ });
322
+ });
357
323
 
358
- // it('signInAnonymouslyReLoginSameProject', (done) => {
359
-
360
-
361
- // var email = "test-signInAnonymouslyReLogin-" + Date.now() + "@email.com";
362
- // var pwd = "pwd";
363
-
364
- // userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
365
- // // create(name, createdBy, settings)
366
- // projectService.create("test-signInAnonymouslyReLogin", savedUser._id).then(function(savedProject) {
367
-
368
- // chai.request(server)
369
- // .post('/auth/signinAnonymously' )
370
- // .send({ id_project: savedProject._id, email: "email@email.com"})
371
- // .end((err, res) => {
372
- // //console.log("res", res);
373
- // console.log("res.body", res.body);
374
- // res.should.have.status(200);
375
- // res.body.should.be.a('object');
376
- // expect(res.body.success).to.equal(true);
377
- // expect(res.body.user.email).to.equal("email@email.com");
378
- // expect(res.body.token).to.not.equal(undefined);
379
- // expect(res.body.user._id).to.not.equal(undefined);
380
324
 
381
- // var uuid = res.body.user._id.toString();
382
- // console.log("uuid", uuid);
325
+ // it('signInAnonymouslyReLoginSameProject', (done) => {
383
326
 
384
- // var token = res.body.token;
385
- // console.log("token", token);
386
327
 
387
- // chai.request(server)
388
- // .post('/auth/resigninAnonymously' )
389
- // .set('Authorization', token)
390
- // .send({ id_project: savedProject._id, email: "email@email.com"})
391
- // .end((err, res) => {
392
- // //console.log("res", res);
393
- // console.log("res.body", res.body);
394
- // res.should.have.status(200);
395
- // res.body.should.be.a('object');
396
- // expect(res.body.success).to.equal(true);
397
- // expect(res.body.user.email).to.equal("email@email.com");
398
- // expect(res.body.token).to.not.equal(undefined);
399
- // expect(res.body.user._id.toString()).to.equal(uuid.toString());
328
+ // var email = "test-signInAnonymouslyReLogin-" + Date.now() + "@email.com";
329
+ // var pwd = "pwd";
330
+
331
+ // userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
332
+ // // create(name, createdBy, settings)
333
+ // projectService.create("test-signInAnonymouslyReLogin", savedUser._id).then(function(savedProject) {
400
334
 
401
- // done();
402
- // });
403
- // });
404
- // });
405
- // });
406
-
407
-
408
- // });
335
+ // chai.request(server)
336
+ // .post('/auth/signinAnonymously' )
337
+ // .send({ id_project: savedProject._id, email: "email@email.com"})
338
+ // .end((err, res) => {
339
+ // //console.log("res", res);
340
+ // console.log("res.body", res.body);
341
+ // res.should.have.status(200);
342
+ // res.body.should.be.a('object');
343
+ // expect(res.body.success).to.equal(true);
344
+ // expect(res.body.user.email).to.equal("email@email.com");
345
+ // expect(res.body.token).to.not.equal(undefined);
346
+ // expect(res.body.user._id).to.not.equal(undefined);
409
347
 
348
+ // var uuid = res.body.user._id.toString();
349
+ // console.log("uuid", uuid);
410
350
 
351
+ // var token = res.body.token;
352
+ // console.log("token", token);
411
353
 
354
+ // chai.request(server)
355
+ // .post('/auth/resigninAnonymously' )
356
+ // .set('Authorization', token)
357
+ // .send({ id_project: savedProject._id, email: "email@email.com"})
358
+ // .end((err, res) => {
359
+ // //console.log("res", res);
360
+ // console.log("res.body", res.body);
361
+ // res.should.have.status(200);
362
+ // res.body.should.be.a('object');
363
+ // expect(res.body.success).to.equal(true);
364
+ // expect(res.body.user.email).to.equal("email@email.com");
365
+ // expect(res.body.token).to.not.equal(undefined);
366
+ // expect(res.body.user._id.toString()).to.equal(uuid.toString());
412
367
 
368
+ // done();
369
+ // });
370
+ // });
371
+ // });
372
+ // });
413
373
 
414
- // it('signInAnonymouslyReLoginDifferentProject', (done) => {
415
374
 
416
-
417
- // var email = "test-signInAnonymouslyReLogin-" + Date.now() + "@email.com";
418
- // var pwd = "pwd";
375
+ // });
419
376
 
420
- // userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
421
- // // create(name, createdBy, settings)
422
- // projectService.create("test-signInAnonymouslyReLogin", savedUser._id).then(function(savedProject) {
423
377
 
424
- // projectService.create("test-signInAnonymouslyReLoginDifferent", savedUser._id).then(function(savedProjectDifferent) {
425
-
426
- // chai.request(server)
427
- // .post('/auth/signinAnonymously' )
428
- // .send({ id_project: savedProject._id, email: "email@email.com"})
429
- // .end((err, res) => {
430
- // //console.log("res", res);
431
- // console.log("res.body", res.body);
432
- // res.should.have.status(200);
433
- // res.body.should.be.a('object');
434
- // expect(res.body.success).to.equal(true);
435
- // expect(res.body.user.email).to.equal("email@email.com");
436
- // expect(res.body.token).to.not.equal(undefined);
437
- // expect(res.body.user._id).to.not.equal(undefined);
438
378
 
439
- // var uuid = res.body.user._id.toString();
440
- // console.log("uuid", uuid);
441
379
 
442
- // var token = res.body.token;
443
- // console.log("token", token);
444
380
 
445
- // chai.request(server)
446
- // .post('/auth/resigninAnonymously' )
447
- // .set('Authorization', token)
448
- // .send({ id_project: savedProjectDifferent._id, email: "email@email.com"})
449
- // .end((err, res) => {
450
- // //console.log("res", res);
451
- // console.log("res.body", res.body);
452
- // res.should.have.status(200);
453
- // res.body.should.be.a('object');
454
- // expect(res.body.success).to.equal(true);
455
- // expect(res.body.user.email).to.equal("email@email.com");
456
- // expect(res.body.token).to.not.equal(undefined);
457
- // expect(res.body.user._id.toString()).to.equal(uuid.toString());
458
-
459
- // done();
460
- // });
461
- // });
462
- // });
463
- // });
464
- // });
465
-
466
- // });
467
-
468
-
469
-
470
-
471
- });
381
+ // it('signInAnonymouslyReLoginDifferentProject', (done) => {
472
382
 
473
383
 
384
+ // var email = "test-signInAnonymouslyReLogin-" + Date.now() + "@email.com";
385
+ // var pwd = "pwd";
474
386
 
387
+ // userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
388
+ // // create(name, createdBy, settings)
389
+ // projectService.create("test-signInAnonymouslyReLogin", savedUser._id).then(function(savedProject) {
475
390
 
391
+ // projectService.create("test-signInAnonymouslyReLoginDifferent", savedUser._id).then(function(savedProjectDifferent) {
476
392
 
393
+ // chai.request(server)
394
+ // .post('/auth/signinAnonymously' )
395
+ // .send({ id_project: savedProject._id, email: "email@email.com"})
396
+ // .end((err, res) => {
397
+ // //console.log("res", res);
398
+ // console.log("res.body", res.body);
399
+ // res.should.have.status(200);
400
+ // res.body.should.be.a('object');
401
+ // expect(res.body.success).to.equal(true);
402
+ // expect(res.body.user.email).to.equal("email@email.com");
403
+ // expect(res.body.token).to.not.equal(undefined);
404
+ // expect(res.body.user._id).to.not.equal(undefined);
477
405
 
478
- describe('/signinWithCustomToken', () => {
479
-
406
+ // var uuid = res.body.user._id.toString();
407
+ // console.log("uuid", uuid);
480
408
 
481
- it('signinWithCustomTokenOk', (done) => {
409
+ // var token = res.body.token;
410
+ // console.log("token", token);
482
411
 
483
-
484
- var email = "test-signinwithcustomtoken-" + Date.now() + "@email.com";
485
- var pwd = "pwd";
412
+ // chai.request(server)
413
+ // .post('/auth/resigninAnonymously' )
414
+ // .set('Authorization', token)
415
+ // .send({ id_project: savedProjectDifferent._id, email: "email@email.com"})
416
+ // .end((err, res) => {
417
+ // //console.log("res", res);
418
+ // console.log("res.body", res.body);
419
+ // res.should.have.status(200);
420
+ // res.body.should.be.a('object');
421
+ // expect(res.body.success).to.equal(true);
422
+ // expect(res.body.user.email).to.equal("email@email.com");
423
+ // expect(res.body.token).to.not.equal(undefined);
424
+ // expect(res.body.user._id.toString()).to.equal(uuid.toString());
425
+
426
+ // done();
427
+ // });
428
+ // });
429
+ // });
430
+ // });
431
+ // });
432
+
433
+ // });
486
434
 
487
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
488
- // create(name, createdBy, settings)
489
- projectService.create("test-signinWithCustomToken", savedUser._id).then(function(savedProject) {
490
-
491
- chai.request(server)
492
- .post('/'+ savedProject._id + '/keys/generate')
493
- .auth(email, pwd)
494
- .send()
495
- .end((err, res) => {
496
- //console.log("res", res);
497
- console.log("res.body", res.body);
498
- res.should.have.status(200);
499
- res.body.should.be.a('object');
500
- expect(res.body.jwtSecret).to.not.equal(null);
501
-
502
- // 'E11000 duplicate key error collection: tiledesk-test.users index: email_1 dup key: { email: "email@email.com" }' }
503
- var externalUserObj = {_id: "123", firstname:"andrea", lastname:"leo", email: "email2@email.com", customAttr: "c1"};
504
-
505
- console.log("externalUserObj", externalUserObj);
435
+ });
506
436
 
437
+ describe('/signinWithCustomToken', () => {
507
438
 
508
- var signOptions = {
509
- subject: 'userexternal',
510
- audience: 'https://tiledesk.com/projects/'+savedProject._id ,
511
- };
512
439
 
440
+ it('signinWithCustomTokenOk', (done) => {
513
441
 
514
- var jwtToken = jwt.sign(externalUserObj, res.body.jwtSecret,signOptions);
515
-
516
- console.log("jwtToken", jwtToken);
442
+ var email = "test-signinwithcustomtoken-" + Date.now() + "@email.com";
443
+ var pwd = "pwd";
517
444
 
445
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
446
+ // create(name, createdBy, settings)
447
+ projectService.create("test-signinWithCustomToken", savedUser._id).then(function (savedProject) {
518
448
 
519
449
  chai.request(server)
520
- .post('/auth/signinWithCustomToken' )
521
- .set('Authorization', 'JWT '+jwtToken)
522
- //.send({ id_project: savedProject._id})
450
+ .post('/' + savedProject._id + '/keys/generate')
451
+ .auth(email, pwd)
523
452
  .send()
524
453
  .end((err, res) => {
525
- //console.log("res", res);
526
- console.log("res.body", res.body);
454
+
455
+ if (err) { console.error("err: ", err); }
456
+ if (log) { console.log("res.body", res.body); }
457
+
527
458
  res.should.have.status(200);
528
459
  res.body.should.be.a('object');
529
- expect(res.body.success).to.equal(true);
530
- expect(res.body.user.email).to.equal("email2@email.com");
531
- expect(res.body.user.firstname).to.equal("andrea");
532
- expect(res.body.user.customAttr).to.equal("c1");
533
-
534
-
535
- expect(res.body.token).to.not.equal(undefined);
536
- expect(res.body.token).to.equal('JWT '+jwtToken);
537
-
538
-
539
- done();
460
+ expect(res.body.jwtSecret).to.not.equal(null);
461
+
462
+ // 'E11000 duplicate key error collection: tiledesk-test.users index: email_1 dup key: { email: "email@email.com" }' }
463
+ var externalUserObj = { _id: "123", firstname: "andrea", lastname: "leo", email: "email2@email.com", customAttr: "c1" };
464
+ if (log) { console.log("externalUserObj", externalUserObj); }
465
+
466
+ var signOptions = {
467
+ subject: 'userexternal',
468
+ audience: 'https://tiledesk.com/projects/' + savedProject._id,
469
+ };
470
+
471
+ var jwtToken = jwt.sign(externalUserObj, res.body.jwtSecret, signOptions);
472
+ if (log) { console.log("jwtToken", jwtToken); }
473
+
474
+ chai.request(server)
475
+ .post('/auth/signinWithCustomToken')
476
+ .set('Authorization', 'JWT ' + jwtToken)
477
+ //.send({ id_project: savedProject._id})
478
+ .send()
479
+ .end((err, res) => {
480
+
481
+ if (err) { console.error("err: ", err); }
482
+ if (log) { console.log("res.body", res.body); }
483
+
484
+ res.should.have.status(200);
485
+ res.body.should.be.a('object');
486
+ expect(res.body.success).to.equal(true);
487
+ expect(res.body.user.email).to.equal("email2@email.com");
488
+ expect(res.body.user.firstname).to.equal("andrea");
489
+ expect(res.body.user.customAttr).to.equal("c1");
490
+ expect(res.body.token).to.not.equal(undefined);
491
+ expect(res.body.token).to.equal('JWT ' + jwtToken);
492
+
493
+ done();
494
+ });
540
495
  });
541
- });
542
496
  });
543
497
  });
544
-
545
- });
498
+ });
546
499
 
547
-
548
500
 
501
+ it('signinWithCustomTokenKO', (done) => {
549
502
 
503
+ var email = "test-signinwithcustomtoken-" + Date.now() + "@email.com";
504
+ var pwd = "pwd";
550
505
 
506
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
507
+ // create(name, createdBy, settings)
508
+ projectService.create("test-signinWithCustomTokenKO", savedUser._id).then(function (savedProject) {
551
509
 
552
- it('signinWithCustomTokenKO', (done) => {
510
+ chai.request(server)
511
+ .post('/' + savedProject._id + '/keys/generate')
512
+ .auth(email, pwd)
513
+ .send()
514
+ .end((err, res) => {
553
515
 
554
-
555
- var email = "test-signinwithcustomtoken-" + Date.now() + "@email.com";
556
- var pwd = "pwd";
516
+ if (err) { console.error("err: ", err); }
517
+ if (log) { console.log("res.body", res.body); }
557
518
 
558
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
559
- // create(name, createdBy, settings)
560
- projectService.create("test-signinWithCustomTokenKO", savedUser._id).then(function(savedProject) {
561
-
562
- chai.request(server)
563
- .post('/'+ savedProject._id + '/keys/generate')
564
- .auth(email, pwd)
565
- .send()
566
- .end((err, res) => {
567
- //console.log("res", res);
568
- console.log("res.body", res.body);
569
- res.should.have.status(200);
570
- res.body.should.be.a('object');
571
- expect(res.body.jwtSecret).to.not.equal(null);
572
-
519
+ res.should.have.status(200);
520
+ res.body.should.be.a('object');
521
+ expect(res.body.jwtSecret).to.not.equal(null);
573
522
 
574
- var externalUserObj = {_id: "123", name:"andrea", surname:"leo", customAttr: "c1"};
575
-
576
- console.log("externalUserObj", externalUserObj);
523
+ var externalUserObj = { _id: "123", name: "andrea", surname: "leo", customAttr: "c1" };
524
+ if (log) { console.log("externalUserObj", externalUserObj); }
577
525
 
526
+ var signOptions = {
527
+ subject: 'userexternal',
528
+ audience: 'https://tiledesk.com/projects/' + savedProject._id,
529
+ };
578
530
 
579
- var signOptions = {
580
- subject: 'userexternal',
581
- audience: 'https://tiledesk.com/projects/'+savedProject._id ,
582
- };
583
531
 
532
+ var jwtToken = jwt.sign(externalUserObj, res.body.jwtSecret + "1234567KOOOOOOO", signOptions);
533
+ if (log) { console.log("jwtToken", jwtToken); }
584
534
 
585
- var jwtToken = jwt.sign(externalUserObj, res.body.jwtSecret+"1234567KOOOOOOO",signOptions);
586
-
587
- console.log("jwtToken", jwtToken);
535
+ chai.request(server)
536
+ .post('/auth/signinWithCustomToken')
537
+ .set('Authorization', 'JWT ' + jwtToken)
538
+ .send({ id_project: savedProject._id })
539
+ .end((err, res) => {
588
540
 
541
+ if (err) { console.error("err: ", err); }
542
+ if (log) { console.log("res.body", res.body); }
589
543
 
590
- chai.request(server)
591
- .post('/auth/signinWithCustomToken' )
592
- .set('Authorization', 'JWT '+jwtToken)
593
- .send({ id_project: savedProject._id})
594
- .end((err, res) => {
595
- //console.log("res", res);
596
- // console.log("res.body", res.body);
597
- res.should.have.status(401);
598
-
599
- done();
544
+ res.should.have.status(401);
545
+
546
+ done();
547
+ });
600
548
  });
601
- });
602
549
  });
603
550
  });
604
-
605
- });
551
+ });
606
552
 
607
- });
608
553
 
554
+ it('signinWithCustomTokenKONoID', (done) => {
609
555
 
556
+ var email = "test-signinwithcustomtokenkonoid-" + Date.now() + "@email.com";
557
+ var pwd = "pwd";
610
558
 
559
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
560
+ // create(name, createdBy, settings)
561
+ projectService.create("test-signinWithCustomTokenKONoID", savedUser._id).then(function (savedProject) {
611
562
 
612
- it('signinWithCustomTokenKONoID', (done) => {
563
+ chai.request(server)
564
+ .post('/' + savedProject._id + '/keys/generate')
565
+ .auth(email, pwd)
566
+ .send()
567
+ .end((err, res) => {
613
568
 
614
-
615
- var email = "test-signinwithcustomtokenkonoid-" + Date.now() + "@email.com";
616
- var pwd = "pwd";
569
+ if (err) { console.error("err: ", err); }
570
+ if (log) { console.log("res.body", res.body); }
617
571
 
618
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
619
- // create(name, createdBy, settings)
620
- projectService.create("test-signinWithCustomTokenKONoID", savedUser._id).then(function(savedProject) {
621
-
622
- chai.request(server)
623
- .post('/'+ savedProject._id + '/keys/generate')
624
- .auth(email, pwd)
625
- .send()
626
- .end((err, res) => {
627
- //console.log("res", res);
628
- console.log("res.body", res.body);
629
- res.should.have.status(200);
630
- res.body.should.be.a('object');
631
- expect(res.body.jwtSecret).to.not.equal(null);
632
-
633
- // 'E11000 duplicate key error collection: tiledesk-test.users index: email_1 dup key: { email: "email@email.com" }' }
634
- var externalUserObj = {firstname:"andrea", lastname:"leo", email: "email2@email.com"};
635
-
636
- console.log("externalUserObj", externalUserObj);
572
+ res.should.have.status(200);
573
+ res.body.should.be.a('object');
574
+ expect(res.body.jwtSecret).to.not.equal(null);
637
575
 
576
+ // 'E11000 duplicate key error collection: tiledesk-test.users index: email_1 dup key: { email: "email@email.com" }' }
577
+ var externalUserObj = { firstname: "andrea", lastname: "leo", email: "email2@email.com" };
578
+ if (log) { console.log("externalUserObj", externalUserObj); }
638
579
 
639
- var signOptions = {
640
- subject: 'userexternal',
641
- audience: 'https://tiledesk.com/projects/'+savedProject._id ,
642
- };
580
+ var signOptions = {
581
+ subject: 'userexternal',
582
+ audience: 'https://tiledesk.com/projects/' + savedProject._id,
583
+ };
643
584
 
585
+ var jwtToken = jwt.sign(externalUserObj, res.body.jwtSecret, signOptions);
586
+ if (log) { console.log("jwtToken", jwtToken); }
644
587
 
645
- var jwtToken = jwt.sign(externalUserObj, res.body.jwtSecret,signOptions);
646
-
647
- console.log("jwtToken", jwtToken);
588
+ chai.request(server)
589
+ .post('/auth/signinWithCustomToken')
590
+ .set('Authorization', 'JWT ' + jwtToken)
591
+ //.send({ id_project: savedProject._id})
592
+ .send()
593
+ .end((err, res) => {
648
594
 
595
+ if (err) { console.error("err: ", err); }
596
+ if (log) { console.log("res.body", res.body); }
649
597
 
650
- chai.request(server)
651
- .post('/auth/signinWithCustomToken' )
652
- .set('Authorization', 'JWT '+jwtToken)
653
- //.send({ id_project: savedProject._id})
654
- .send()
655
- .end((err, res) => {
656
- //console.log("res", res);
657
- console.log("res.body", res.body);
658
- res.should.have.status(401);
659
-
660
- done();
661
- });
598
+ res.should.have.status(401);
599
+
600
+ done();
601
+ });
602
+ });
662
603
  });
663
604
  });
664
- });
665
-
666
- }).timeout(20000);
667
605
 
606
+ }).timeout(20000);
668
607
 
669
608
 
609
+ // mocha test/authentication.js --grep 'signinWithCustomTokenKONoAud'
610
+ it('signinWithCustomTokenKONoAud', (done) => {
670
611
 
671
- it('signinWithCustomTokenKONoAud', (done) => {
612
+ var email = "test-signinwithcustomtokenkowrongaud-" + Date.now() + "@email.com";
613
+ var pwd = "pwd";
672
614
 
673
-
674
- var email = "test-signinwithcustomtokenkowrongaud-" + Date.now() + "@email.com";
675
- var pwd = "pwd";
615
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
616
+ // create(name, createdBy, settings)
617
+ projectService.create("test-signinWithCustomTokenKOWrongAud", savedUser._id).then(function (savedProject) {
676
618
 
677
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
678
- // create(name, createdBy, settings)
679
- projectService.create("test-signinWithCustomTokenKOWrongAud", savedUser._id).then(function(savedProject) {
680
-
681
- chai.request(server)
682
- .post('/'+ savedProject._id + '/keys/generate')
683
- .auth(email, pwd)
684
- .send()
685
- .end((err, res) => {
686
- //console.log("res", res);
687
- console.log("res.body", res.body);
688
- res.should.have.status(200);
689
- res.body.should.be.a('object');
690
- expect(res.body.jwtSecret).to.not.equal(null);
691
-
692
- // 'E11000 duplicate key error collection: tiledesk-test.users index: email_1 dup key: { email: "email@email.com" }' }
693
- var externalUserObj = {_id: 1234, firstname:"andrea", lastname:"leo", email: "email2@email.com"};
694
-
695
- console.log("externalUserObj", externalUserObj);
619
+ chai.request(server)
620
+ .post('/' + savedProject._id + '/keys/generate')
621
+ .auth(email, pwd)
622
+ .send()
623
+ .end((err, res) => {
696
624
 
625
+ if (err) { console.error("err: ", err); }
626
+ if (log) { console.log("res.body", res.body); }
697
627
 
698
- var signOptions = {
699
- subject: 'userexternal',
700
- //audience: 'https://tiledesk.com/projects/'+savedProject._id ,
701
- };
628
+ res.should.have.status(200);
629
+ res.body.should.be.a('object');
630
+ expect(res.body.jwtSecret).to.not.equal(null);
702
631
 
632
+ // 'E11000 duplicate key error collection: tiledesk-test.users index: email_1 dup key: { email: "email@email.com" }' }
633
+ var externalUserObj = { _id: 1234, firstname: "andrea", lastname: "leo", email: "email2@email.com" };
634
+ if (log) { console.log("externalUserObj", externalUserObj); }
703
635
 
704
- var jwtToken = jwt.sign(externalUserObj, res.body.jwtSecret,signOptions);
705
-
706
- console.log("jwtToken", jwtToken);
636
+ var signOptions = {
637
+ subject: 'userexternal',
638
+ //audience: 'https://tiledesk.com/projects/'+savedProject._id ,
639
+ };
707
640
 
641
+ var jwtToken = jwt.sign(externalUserObj, res.body.jwtSecret, signOptions);
642
+ if (log) { console.log("jwtToken", jwtToken); }
708
643
 
709
- chai.request(server)
710
- .post('/auth/signinWithCustomToken' )
711
- .set('Authorization', 'JWT '+jwtToken)
712
- //.send({ id_project: savedProject._id})
713
- .send()
714
- .end((err, res) => {
715
- //console.log("res", res);
716
- console.log("res.body", res.body);
717
- res.should.have.status(401);
718
-
719
- done();
720
- });
644
+ chai.request(server)
645
+ .post('/auth/signinWithCustomToken')
646
+ .set('Authorization', 'JWT ' + jwtToken)
647
+ //.send({ id_project: savedProject._id})
648
+ .send()
649
+ .end((err, res) => {
650
+
651
+ if (err) { console.error("err: ", err); }
652
+ if (log) { console.log("res.body", res.body); }
653
+
654
+ res.should.have.status(401);
655
+
656
+ done();
657
+ });
658
+ });
721
659
  });
722
660
  });
723
661
  });
724
-
725
- });
726
-
727
662
 
728
663
 
729
- // mocha test/authentication.js --grep 'signinWithCustomTokenOkTwoSigninWithCT'
664
+ // mocha test/authentication.js --grep 'signinWithCustomTokenOkTwoSigninWithCT'
665
+ it('signinWithCustomTokenOkTwoSigninWithCT', (done) => {
730
666
 
731
- it('signinWithCustomTokenOkTwoSigninWithCT', (done) => {
667
+ var email = "test-signinwithcustomtokenoktwosigninwithct-" + Date.now() + "@email.com";
668
+ var pwd = "pwd";
732
669
 
733
-
734
- var email = "test-signinwithcustomtokenoktwosigninwithct-" + Date.now() + "@email.com";
735
- var pwd = "pwd";
670
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
671
+ // create(name, createdBy, settings)
672
+ projectService.create("test-signinWithCustomTokenOkTwoSigninWithCT", savedUser._id).then(function (savedProject) {
736
673
 
737
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
738
- // create(name, createdBy, settings)
739
- projectService.create("test-signinWithCustomTokenOkTwoSigninWithCT", savedUser._id).then(function(savedProject) {
740
-
741
- chai.request(server)
742
- .post('/'+ savedProject._id + '/keys/generate')
743
- .auth(email, pwd)
744
- .send()
745
- .end((err, res) => {
746
- //console.log("res", res);
747
- console.log("res.body", res.body);
748
- res.should.have.status(200);
749
- res.body.should.be.a('object');
750
- expect(res.body.jwtSecret).to.not.equal(null);
751
-
752
- // 'E11000 duplicate key error collection: tiledesk-test.users index: email_1 dup key: { email: "email@email.com" }' }
753
- var externalUserObj = {_id: "123", firstname:"andrea", lastname:"leo", email: "email2@email.com", customAttr: "c1"};
754
-
755
- console.log("externalUserObj", externalUserObj);
674
+ chai.request(server)
675
+ .post('/' + savedProject._id + '/keys/generate')
676
+ .auth(email, pwd)
677
+ .send()
678
+ .end((err, res) => {
756
679
 
680
+ if (err) { console.error("err: ", err); }
681
+ if (log) { console.log("res.body", res.body); }
757
682
 
758
- var signOptions = {
759
- subject: 'userexternal',
760
- audience: 'https://tiledesk.com/projects/'+savedProject._id ,
761
- };
683
+ res.should.have.status(200);
684
+ res.body.should.be.a('object');
685
+ expect(res.body.jwtSecret).to.not.equal(null);
762
686
 
687
+ // 'E11000 duplicate key error collection: tiledesk-test.users index: email_1 dup key: { email: "email@email.com" }' }
688
+ var externalUserObj = { _id: "123", firstname: "andrea", lastname: "leo", email: "email2@email.com", customAttr: "c1" };
689
+ if (log) { console.log("externalUserObj", externalUserObj); }
763
690
 
764
- var jwtToken = jwt.sign(externalUserObj, res.body.jwtSecret,signOptions);
765
-
766
- console.log("jwtToken", jwtToken);
691
+ var signOptions = {
692
+ subject: 'userexternal',
693
+ audience: 'https://tiledesk.com/projects/' + savedProject._id,
694
+ };
767
695
 
696
+ var jwtToken = jwt.sign(externalUserObj, res.body.jwtSecret, signOptions);
697
+ if (log) { console.log("jwtToken", jwtToken); }
768
698
 
769
- chai.request(server)
770
- .post('/auth/signinWithCustomToken' )
771
- .set('Authorization', 'JWT '+jwtToken)
772
- //.send({ id_project: savedProject._id})
773
- .send()
774
- .end((err, res) => {
775
- //console.log("res", res);
776
- console.log("res.body", res.body);
777
- res.should.have.status(200);
778
- res.body.should.be.a('object');
779
- expect(res.body.success).to.equal(true);
780
- expect(res.body.user.email).to.equal("email2@email.com");
781
- expect(res.body.user.firstname).to.equal("andrea");
782
- expect(res.body.user.customAttr).to.equal("c1");
783
-
784
-
785
- expect(res.body.token).to.not.equal(undefined);
786
- expect(res.body.token).to.equal('JWT '+jwtToken);
787
-
788
-
789
- chai.request(server)
790
- .post('/auth/signinWithCustomToken' )
791
- .set('Authorization', 'JWT '+jwtToken)
699
+ chai.request(server)
700
+ .post('/auth/signinWithCustomToken')
701
+ .set('Authorization', 'JWT ' + jwtToken)
792
702
  //.send({ id_project: savedProject._id})
793
703
  .send()
794
704
  .end((err, res) => {
795
- //console.log("res", res);
796
- console.log("res.body", res.body);
705
+
706
+ if (err) { console.error("err: ", err); }
707
+ if (log) { console.log("res.body", res.body); }
708
+
797
709
  res.should.have.status(200);
798
710
  res.body.should.be.a('object');
799
- expect(res.body.success).to.equal(true);
800
- expect(res.body.user.email).to.equal("email2@email.com");
801
- expect(res.body.user.firstname).to.equal("andrea");
802
- expect(res.body.user.customAttr).to.equal("c1");
803
-
804
-
805
- expect(res.body.token).to.not.equal(undefined);
806
- expect(res.body.token).to.equal('JWT '+jwtToken);
807
-
808
-
809
- done();
711
+ expect(res.body.success).to.equal(true);
712
+ expect(res.body.user.email).to.equal("email2@email.com");
713
+ expect(res.body.user.firstname).to.equal("andrea");
714
+ expect(res.body.user.customAttr).to.equal("c1");
715
+ expect(res.body.token).to.not.equal(undefined);
716
+ expect(res.body.token).to.equal('JWT ' + jwtToken);
717
+
718
+ chai.request(server)
719
+ .post('/auth/signinWithCustomToken')
720
+ .set('Authorization', 'JWT ' + jwtToken)
721
+ //.send({ id_project: savedProject._id})
722
+ .send()
723
+ .end((err, res) => {
724
+
725
+ if (err) { console.error("err: ", err); }
726
+ if (log) { console.log("res.body", res.body); }
727
+
728
+ res.should.have.status(200);
729
+ res.body.should.be.a('object');
730
+ expect(res.body.success).to.equal(true);
731
+ expect(res.body.user.email).to.equal("email2@email.com");
732
+ expect(res.body.user.firstname).to.equal("andrea");
733
+ expect(res.body.user.customAttr).to.equal("c1");
734
+ expect(res.body.token).to.not.equal(undefined);
735
+ expect(res.body.token).to.equal('JWT ' + jwtToken);
736
+
737
+ done();
738
+ });
810
739
  });
811
- });
740
+ });
812
741
  });
813
742
  });
814
- });
815
-
816
- }).timeout(20000);
817
-
818
-
819
-
820
-
821
743
 
822
- // mocha test/authentication.js --grep 'signinWithCustomTokenRoleNew'
744
+ }).timeout(20000);
823
745
 
824
746
 
825
- it('signinWithCustomTokenRoleNew', (done) => {
747
+ // mocha test/authentication.js --grep 'signinWithCustomTokenRoleNew'
748
+ it('signinWithCustomTokenRoleNew', (done) => {
826
749
 
827
-
828
- var email = "test-signinWithCustomTokenRole-" + Date.now() + "@email.com";
829
- var pwd = "pwd";
750
+ var email = "test-signinWithCustomTokenRole-" + Date.now() + "@email.com";
751
+ var pwd = "pwd";
752
+ var emailToCheck = "emailrole" + Date.now() + "@email.com";
830
753
 
754
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
755
+ // create(name, createdBy, settings)
756
+ projectService.create("test-signinWithCustomTokenRole", savedUser._id).then(function (savedProject) {
831
757
 
832
- var emailToCheck = "emailrole"+ Date.now() +"@email.com";
758
+ chai.request(server)
759
+ .post('/' + savedProject._id + '/keys/generate')
760
+ .auth(email, pwd)
761
+ .send()
762
+ .end((err, res) => {
833
763
 
764
+ if (err) { console.error("err: ", err); }
765
+ if (log) { console.log("res.body", res.body); }
834
766
 
835
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
836
- // create(name, createdBy, settings)
837
- projectService.create("test-signinWithCustomTokenRole", savedUser._id).then(function(savedProject) {
838
-
839
- chai.request(server)
840
- .post('/'+ savedProject._id + '/keys/generate')
841
- .auth(email, pwd)
842
- .send()
843
- .end((err, res) => {
844
- //console.log("res", res);
845
- console.log("res.body", res.body);
846
- res.should.have.status(200);
847
- res.body.should.be.a('object');
848
- expect(res.body.jwtSecret).to.not.equal(null);
849
-
850
- // 'E11000 duplicate key error collection: tiledesk-test.users index: email_1 dup key: { email: "email@email.com" }' }
851
- var externalUserObj = {_id: "123", firstname:"andrea", lastname:"leo", email: emailToCheck, role:"admin"};
852
-
853
- console.log("externalUserObj", externalUserObj);
767
+ res.should.have.status(200);
768
+ res.body.should.be.a('object');
769
+ expect(res.body.jwtSecret).to.not.equal(null);
854
770
 
771
+ // 'E11000 duplicate key error collection: tiledesk-test.users index: email_1 dup key: { email: "email@email.com" }' }
772
+ var externalUserObj = { _id: "123", firstname: "andrea", lastname: "leo", email: emailToCheck, role: "admin" };
773
+ if (log) { console.log("externalUserObj", externalUserObj); }
855
774
 
856
- var signOptions = {
857
- subject: 'userexternal',
858
- audience: 'https://tiledesk.com/projects/'+savedProject._id ,
859
- };
775
+ var signOptions = {
776
+ subject: 'userexternal',
777
+ audience: 'https://tiledesk.com/projects/' + savedProject._id,
778
+ };
860
779
 
780
+ var jwtToken = jwt.sign(externalUserObj, res.body.jwtSecret, signOptions);
781
+ if (log) { console.log("jwtToken", jwtToken); }
861
782
 
862
- var jwtToken = jwt.sign(externalUserObj, res.body.jwtSecret,signOptions);
863
-
864
- console.log("jwtToken", jwtToken);
783
+ chai.request(server)
784
+ .post('/auth/signinWithCustomToken')
785
+ .set('Authorization', 'JWT ' + jwtToken)
786
+ //.send({ id_project: savedProject._id})
787
+ .send()
788
+ .end((err, res) => {
865
789
 
790
+ if (err) { console.error("err: ", err); }
791
+ if (log) { console.log("res.body", res.body); }
866
792
 
867
- chai.request(server)
868
- .post('/auth/signinWithCustomToken' )
869
- .set('Authorization', 'JWT '+jwtToken)
870
- //.send({ id_project: savedProject._id})
871
- .send()
872
- .end((err, res) => {
873
- //console.log("res", res);
874
- console.log("res.body", res.body);
875
- res.should.have.status(200);
876
- res.body.should.be.a('object');
877
- expect(res.body.success).to.equal(true);
878
- console.log("1");
879
-
880
- expect(res.body.user.email).to.equal(emailToCheck);
881
- console.log("2");
882
- expect(res.body.user.firstname).to.equal("andrea");
883
- // expect(res.body.user._id).to.not.equal("123");
884
- console.log("3");
885
-
886
-
887
- expect(res.body.token).to.not.equal(undefined);
888
- // expect(res.body.token).to.equal('JWT '+jwtToken);
889
-
890
- console.log("4");
891
- done();
892
- });
793
+ res.should.have.status(200);
794
+ res.body.should.be.a('object');
795
+ expect(res.body.success).to.equal(true);
796
+ expect(res.body.user.email).to.equal(emailToCheck);
797
+ expect(res.body.user.firstname).to.equal("andrea");
798
+ // expect(res.body.user._id).to.not.equal("123");
799
+ expect(res.body.token).to.not.equal(undefined);
800
+ // expect(res.body.token).to.equal('JWT '+jwtToken);
801
+ done();
802
+ });
803
+ });
893
804
  });
894
805
  });
895
806
  });
896
807
 
897
- });
898
-
899
-
900
-
901
-
902
808
 
903
- // mocha test/authentication.js --grep 'signinWithCustomTokenRole'
809
+ // mocha test/authentication.js --grep 'signinWithCustomTokenRole'
810
+ it('signinWithCustomTokenRoleEmailAlreadyUsed', (done) => {
904
811
 
812
+ var email = "test-signinWithCustomTokenRoleEmailAlreadyUsed-" + Date.now() + "@email.com";
813
+ var pwd = "pwd";
814
+ var emailToCheck = "emailrole" + Date.now() + "@email.com";
905
815
 
906
- it('signinWithCustomTokenRoleEmailAlreadyUsed', (done) => {
816
+ userService.signup(emailToCheck, pwd, "andrea", "leo").then(function (savedUserToCheck) {
817
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
818
+ projectService.create("test-signinWithCustomTokenRoleEmailAlreadyUsed", savedUser._id).then(function (savedProject) {
907
819
 
908
-
909
- var email = "test-signinWithCustomTokenRoleEmailAlreadyUsed-" + Date.now() + "@email.com";
910
- var pwd = "pwd";
911
-
912
-
913
- var emailToCheck = "emailrole"+ Date.now() +"@email.com";
820
+ chai.request(server)
821
+ .post('/' + savedProject._id + '/keys/generate')
822
+ .auth(email, pwd)
823
+ .send()
824
+ .end((err, res) => {
914
825
 
915
- userService.signup( emailToCheck ,pwd, "andrea", "leo").then(function(savedUserToCheck) {
826
+ if (err) { console.error("err: ", err); }
827
+ if (log) { console.log("res.body", res.body); }
916
828
 
917
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
918
- // create(name, createdBy, settings)
919
- projectService.create("test-signinWithCustomTokenRoleEmailAlreadyUsed", savedUser._id).then(function(savedProject) {
920
-
921
- chai.request(server)
922
- .post('/'+ savedProject._id + '/keys/generate')
923
- .auth(email, pwd)
924
- .send()
925
- .end((err, res) => {
926
- //console.log("res", res);
927
- console.log("res.body", res.body);
928
- res.should.have.status(200);
929
- res.body.should.be.a('object');
930
- expect(res.body.jwtSecret).to.not.equal(null);
931
-
932
- // 'E11000 duplicate key error collection: tiledesk-test.users index: email_1 dup key: { email: "email@email.com" }' }
933
- var externalUserObj = {_id: "123", firstname:"andrea", lastname:"leo", email: emailToCheck, role:"admin"};
934
-
935
- console.log("externalUserObj", externalUserObj);
829
+ res.should.have.status(200);
830
+ res.body.should.be.a('object');
831
+ expect(res.body.jwtSecret).to.not.equal(null);
936
832
 
833
+ // 'E11000 duplicate key error collection: tiledesk-test.users index: email_1 dup key: { email: "email@email.com" }' }
834
+ var externalUserObj = { _id: "123", firstname: "andrea", lastname: "leo", email: emailToCheck, role: "admin" };
835
+ if (log) { console.log("externalUserObj", externalUserObj); }
937
836
 
938
- var signOptions = {
939
- subject: 'userexternal',
940
- audience: 'https://tiledesk.com/projects/'+savedProject._id ,
941
- };
837
+ var signOptions = {
838
+ subject: 'userexternal',
839
+ audience: 'https://tiledesk.com/projects/' + savedProject._id,
840
+ };
942
841
 
842
+ var jwtToken = jwt.sign(externalUserObj, res.body.jwtSecret, signOptions);
843
+ if (log) { console.log("jwtToken", jwtToken); }
943
844
 
944
- var jwtToken = jwt.sign(externalUserObj, res.body.jwtSecret,signOptions);
945
-
946
- console.log("jwtToken", jwtToken);
845
+ chai.request(server)
846
+ .post('/auth/signinWithCustomToken')
847
+ .set('Authorization', 'JWT ' + jwtToken)
848
+ //.send({ id_project: savedProject._id})
849
+ .send()
850
+ .end((err, res) => {
947
851
 
852
+ if (err) { console.error("err: ", err); }
853
+ if (log) { console.log("res.body", res.body); }
948
854
 
949
- chai.request(server)
950
- .post('/auth/signinWithCustomToken' )
951
- .set('Authorization', 'JWT '+jwtToken)
952
- //.send({ id_project: savedProject._id})
953
- .send()
954
- .end((err, res) => {
955
- //console.log("res", res);
956
- console.log("res.body", res.body);
957
- res.should.have.status(200);
958
- res.body.should.be.a('object');
959
- expect(res.body.success).to.equal(true);
960
- // console.log("1");
961
-
962
- expect(res.body.user.email).to.equal(emailToCheck);
963
- // console.log("2");
964
- expect(res.body.user.firstname).to.equal("andrea");
965
- // expect(res.body.user._id).to.not.equal("123");
966
- // console.log("3");
967
-
968
-
969
- expect(res.body.token).to.not.equal(undefined);
970
- // expect(res.body.token).to.equal('JWT '+jwtToken);
971
-
972
- // console.log("4");
973
- done();
855
+ res.should.have.status(200);
856
+ res.body.should.be.a('object');
857
+ expect(res.body.success).to.equal(true);
858
+ expect(res.body.user.email).to.equal(emailToCheck);
859
+ expect(res.body.user.firstname).to.equal("andrea");
860
+ // expect(res.body.user._id).to.not.equal("123");
861
+ expect(res.body.token).to.not.equal(undefined);
862
+ // expect(res.body.token).to.equal('JWT '+jwtToken);
863
+ done();
864
+ });
865
+ });
974
866
  });
975
867
  });
976
868
  });
977
869
  });
978
- });
979
- });
980
-
981
-
982
-
983
-
984
870
 
985
871
 
872
+ // mocha test/authentication.js --grep 'signinWithCustomTokenRoleSameOwnerEmail'
873
+ it('signinWithCustomTokenRoleSameOwnerEmail', (done) => {
986
874
 
987
- // mocha test/authentication.js --grep 'signinWithCustomTokenRoleSameOwnerEmail'
875
+ var email = "test-sctrolesameowner-" + Date.now() + "@email.com";
876
+ var pwd = "pwd";
877
+ var emailToCheck = email;
988
878
 
879
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
880
+ projectService.create("test-signinWithCustomTokenRoleEmailAlreadyUsed", savedUser._id).then(function (savedProject) {
989
881
 
990
- it('signinWithCustomTokenRoleSameOwnerEmail', (done) => {
991
-
992
-
993
- var email = "test-sctrolesameowner-" + Date.now() + "@email.com";
994
- var pwd = "pwd";
995
-
996
-
997
- var emailToCheck = email;
882
+ chai.request(server)
883
+ .post('/' + savedProject._id + '/keys/generate')
884
+ .auth(email, pwd)
885
+ .send()
886
+ .end((err, res) => {
998
887
 
888
+ if (err) { console.error("err: ", err); }
889
+ if (log) { console.log("res.body", res.body); }
999
890
 
1000
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
1001
- // create(name, createdBy, settings)
1002
- projectService.create("test-signinWithCustomTokenRoleEmailAlreadyUsed", savedUser._id).then(function(savedProject) {
1003
-
1004
- chai.request(server)
1005
- .post('/'+ savedProject._id + '/keys/generate')
1006
- .auth(email, pwd)
1007
- .send()
1008
- .end((err, res) => {
1009
- //console.log("res", res);
1010
- console.log("res.body", res.body);
1011
- res.should.have.status(200);
1012
- res.body.should.be.a('object');
1013
- expect(res.body.jwtSecret).to.not.equal(null);
1014
-
1015
- // 'E11000 duplicate key error collection: tiledesk-test.users index: email_1 dup key: { email: "email@email.com" }' }
1016
- var externalUserObj = {_id: "123", firstname:"andrea", lastname:"leo", email: emailToCheck, role:"admin"};
1017
-
1018
- console.log("externalUserObj", externalUserObj);
891
+ res.should.have.status(200);
892
+ res.body.should.be.a('object');
893
+ expect(res.body.jwtSecret).to.not.equal(null);
1019
894
 
895
+ // 'E11000 duplicate key error collection: tiledesk-test.users index: email_1 dup key: { email: "email@email.com" }' }
896
+ var externalUserObj = { _id: "123", firstname: "andrea", lastname: "leo", email: emailToCheck, role: "admin" };
897
+ if (log) { console.log("externalUserObj", externalUserObj); }
1020
898
 
1021
- var signOptions = {
1022
- subject: 'userexternal',
1023
- audience: 'https://tiledesk.com/projects/'+savedProject._id ,
1024
- };
899
+ var signOptions = {
900
+ subject: 'userexternal',
901
+ audience: 'https://tiledesk.com/projects/' + savedProject._id,
902
+ };
1025
903
 
904
+ var jwtToken = jwt.sign(externalUserObj, res.body.jwtSecret, signOptions);
905
+ if (log) { console.log("jwtToken", jwtToken); }
1026
906
 
1027
- var jwtToken = jwt.sign(externalUserObj, res.body.jwtSecret,signOptions);
1028
-
1029
- console.log("jwtToken", jwtToken);
907
+ chai.request(server)
908
+ .post('/auth/signinWithCustomToken')
909
+ .set('Authorization', 'JWT ' + jwtToken)
910
+ //.send({ id_project: savedProject._id})
911
+ .send()
912
+ .end((err, res) => {
1030
913
 
914
+ if (err) { console.error("err: ", err); }
915
+ if (log) { console.log("res.body", res.body); }
1031
916
 
1032
- chai.request(server)
1033
- .post('/auth/signinWithCustomToken' )
1034
- .set('Authorization', 'JWT '+jwtToken)
1035
- //.send({ id_project: savedProject._id})
1036
- .send()
1037
- .end((err, res) => {
1038
- //console.log("res", res);
1039
- console.log("res.body", res.body);
1040
- res.should.have.status(200);
1041
- res.body.should.be.a('object');
1042
- expect(res.body.success).to.equal(true);
1043
- console.log("1");
1044
-
1045
- expect(res.body.user.email).to.equal(emailToCheck);
1046
- console.log("2");
1047
- expect(res.body.user.firstname).to.equal("Test Firstname");
1048
- // expect(res.body.user._id).to.not.equal("123");
1049
- console.log("3");
1050
-
1051
-
1052
- expect(res.body.token).to.not.equal(undefined);
1053
- // expect(res.body.token).to.equal('JWT '+jwtToken);
1054
-
1055
- console.log("4");
1056
- done();
1057
- });
917
+ res.should.have.status(200);
918
+ res.body.should.be.a('object');
919
+ expect(res.body.success).to.equal(true);
920
+ expect(res.body.user.email).to.equal(emailToCheck);
921
+ expect(res.body.user.firstname).to.equal("Test Firstname");
922
+ // expect(res.body.user._id).to.not.equal("123");
923
+ expect(res.body.token).to.not.equal(undefined);
924
+ // expect(res.body.token).to.equal('JWT '+jwtToken);
925
+ done();
926
+ });
927
+ });
1058
928
  });
1059
929
  });
1060
930
  });
1061
- });
1062
-
1063
-
1064
-
1065
-
1066
931
 
1067
- }).timeout(20000);
1068
932
 
933
+ }).timeout(20000);
1069
934
 
935
+ });