UNPKG

2.44 kBJavaScriptView Raw
1// Jasmine test checking bad authentications
2
3var CodeGradX = require('../codegradxlib.js');
4
5describe('CodeGradX bad authentication', function () {
6
7 function make_faildone (done) {
8 return function faildone (reason) {
9 var state = CodeGradX.getCurrentState();
10 state.debug('faildone', reason).show();
11 //console.log(reason);
12 fail(reason);
13 done();
14 };
15 }
16
17 it('missing username', function (done) {
18 var state = new CodeGradX.State();
19 var faildone = make_faildone(done);
20 state.getAuthenticatedUser('', 'xxx')
21 .then(function (user) {
22 faildone();
23 })
24 .catch(function (reason) {
25 //console.log(reason);
26 expect(reason.message)
27 .toEqual(jasmine.stringMatching(/e150/));
28 done();
29 });
30 });
31
32 it('missing password', function (done) {
33 var state = new CodeGradX.State();
34 var faildone = make_faildone(done);
35 state.getAuthenticatedUser('schmilblick', '')
36 .then(function (user) {
37 faildone();
38 })
39 .catch(function (reason) {
40 //console.log(reason);
41 expect(reason.message)
42 .toEqual(jasmine.stringMatching(/e151/));
43 done();
44 });
45 });
46
47 it('bad username', function (done) {
48 var state = new CodeGradX.State();
49 var faildone = make_faildone(done);
50 state.getAuthenticatedUser('schmilblick', 'nop')
51 .then(function (user) {
52 faildone();
53 })
54 .catch(function (reason) {
55 //console.log(reason);
56 expect(reason.message)
57 .toEqual(jasmine.stringMatching(/e152-a/));
58 done();
59 });
60 });
61
62 it('bad password', function (done) {
63 var state = new CodeGradX.State();
64 var faildone = make_faildone(done);
65 state.getAuthenticatedUser('nobody:0', 'nop')
66 .then(function (user) {
67 faildone();
68 })
69 .catch(function (reason) {
70 //console.log(reason);
71 //state.log.show();
72 expect(reason.message)
73 .toEqual(jasmine.stringMatching(/e152-b/));
74 done();
75 });
76 });
77
78});