UNPKG

5.97 kBJavaScriptView Raw
1// Jasmine test related to the vmauthor virtual machine. The vmauthor
2// virtual machine hosts a full constellation of CodeGradX servers.
3// The vmauthor virtual machine is available from
4// http://paracamplus.com/CodeGradX/VM/latest/
5
6var CodeGradX = require('codegradxagent');
7var Agent = require('../codegradxvmauthor.js');
8var vmauthData = require('./vmauth-data.json');
9
10describe("CodeGradXVMauthor authentication", function () {
11
12 it("should be loaded", function () {
13 expect(Agent).toBeDefined();
14 var agent = new CodeGradX.VMauthorAgent();
15 expect(agent).toBeDefined();
16 });
17
18 function make_faildone (done) {
19 return function faildone (reason) {
20 //agent.state.debug(reason).show();
21 //console.log(reason);
22 fail(reason);
23 done();
24 };
25 }
26
27 it("cannot read absent credentials", function (done) {
28 agent = new CodeGradX.VMauthorAgent();
29 var faildone = make_faildone(done);
30 agent.process([
31 "--credentials", "spec/absentCredentials.json"
32 ]).then(faildone, function (reason) {
33 expect(agent.credentials).not.toBeDefined();
34 done();
35 });
36 });
37
38 var safecookie1;
39
40 it("with user+password", function (done) {
41 agent = new CodeGradX.VMauthorAgent();
42 var faildone = make_faildone(done);
43 agent.process([
44 "--user", vmauthData.login,
45 "--password", vmauthData.password
46 ]).then(function (user) {
47 expect(user).toBeDefined();
48 expect(user.email).toBe('nobody@example.com');
49 safecookie1 = agent.state.currentCookie;
50 done();
51 }, faildone);
52 }, 10*1000); // 10 seconds
53
54 it("with previous cookie", function (done) {
55 agent = CodeGradX.getCurrentAgent();
56 var faildone = make_faildone(done);
57 agent.process([
58 ]).then(function (user) {
59 expect(user).toBeDefined();
60 expect(user.email).toBe('nobody@example.com');
61 done();
62 }, faildone);
63 }, 10*1000); // 10 seconds
64
65 it("update credentials with user+password", function (done) {
66 agent = new CodeGradX.VMauthorAgent();
67 var faildone = make_faildone(done);
68 agent.process([
69 "--user", vmauthData.login,
70 "--password", vmauthData.password,
71 "--update-credentials"
72 ]).then(function (user) {
73 expect(user).toBeDefined();
74 CodeGradX.readFileContent(agent.credentialsFile).then(
75 function (content) {
76 var json = JSON.parse(content);
77 //console.log(JSON.stringify(json));
78 expect(json.cookie).toMatch(/^u=U.{30}/);
79 done();
80 }, faildone);
81 }, faildone);
82 }, 10*1000); // 10 seconds
83
84 it("with user but wrong password", function (done) {
85 agent = new CodeGradX.VMauthorAgent();
86 var faildone = make_faildone(done);
87 agent.state.log.size = 100;
88 agent.process([
89 "--user", vmauthData.login,
90 "--password", '123456WrongPassword'
91 ]).then(faildone, function (reason) {
92 //agent.state.log.show();
93 expect(reason).toBeDefined();
94 done();
95 });
96 }, 10*1000); // 10 seconds
97
98 it("with credentials with cookie", function (done) {
99 agent = new CodeGradX.VMauthorAgent();
100 var faildone = make_faildone(done);
101 agent.process([
102 "--credentials", agent.credentialsFile
103 ]).then(function (user) {
104 expect(user).toBeDefined();
105 done();
106 }, faildone);
107 }, 10*1000); // 10 seconds
108
109 it("with credentials with wrong cookie", function (done) {
110 agent = new CodeGradX.VMauthorAgent();
111 var faildone = make_faildone(done);
112 CodeGradX.writeFileContent(
113 agent.credentialsFile,
114 '{"cookie": ["u=U1234"]}').then(
115 function () {
116 agent.process([
117 "--credentials", agent.credentialsFile
118 ]).then(function (user) {
119 console.log(user);
120 faildone();
121 }, function (reason) {
122 expect(reason).toBeDefined();
123 done();
124 });
125 }, faildone);
126 }, 10*1000); // 10 seconds
127
128 it("with credentials without cookie", function (done) {
129 agent = new CodeGradX.VMauthorAgent();
130 var faildone = make_faildone(done);
131 CodeGradX.writeFileContent(
132 agent.credentialsFile,
133 JSON.stringify({
134 user: vmauthData.login,
135 password: vmauthData.password
136 })).then(function () {
137 agent.process([
138 "--credentials", agent.credentialsFile
139 ]).then(function (user) {
140 expect(user).toBeDefined();
141 done();
142 }, faildone);
143 }, faildone);
144 }, 10*1000); // 10 seconds
145
146 it("cannot authenticate with wrong credentials", function (done) {
147 agent = new CodeGradX.VMauthorAgent();
148 //console.log(agent);
149 var faildone = make_faildone(done);
150 CodeGradX.writeFileContent(
151 agent.credentialsFile,
152 '{"user": "nobody:0", "password": "totallyWrong"}').then(
153 function () {
154 agent.process([
155 "--credentials", agent.credentialsFile
156 ]).then(function (user) {
157 console.log(user);
158 faildone();
159 }, function (reason) {
160 expect(reason).toBeDefined();
161 done();
162 });
163 }, faildone);
164 }, 10*1000); // 10 seconds
165
166});