1 | var Tools = require("../../lib/tools");
|
2 |
|
3 | describe ("Tools", function() {
|
4 |
|
5 | it ("should hashify a string with sha1", function() {
|
6 | expect(Tools.hashify("tornado")).to.equal("474446ad24ee5490f8e879012ee2a855a7c7bf56");
|
7 | });
|
8 |
|
9 | it ("should not authorize empty email", function() {
|
10 | expect(Tools.isAuthorized(" ")).to.equal(false);
|
11 | expect(Tools.isAuthorized("")).to.equal(false);
|
12 | expect(Tools.isAuthorized()).to.equal(false);
|
13 | expect(Tools.isAuthorized(null)).to.equal(false);
|
14 | });
|
15 |
|
16 | it ("should authorize with 'jingouser'", function() {
|
17 | expect(Tools.isAuthorized("jingouser")).to.equal(false);
|
18 | expect(Tools.isAuthorized("jingouser",'',true)).to.equal(true);
|
19 | expect(Tools.isAuthorized("jingouser",'',false)).to.equal(false);
|
20 | });
|
21 |
|
22 | it ("should authorize with empty pattern", function() {
|
23 | expect(Tools.isAuthorized("claudio.cicali@gmail.com")).to.equal(true);
|
24 | expect(Tools.isAuthorized("claudio.cicali@gmail.com", null)).to.equal(true);
|
25 | expect(Tools.isAuthorized("claudio.cicali@gmail.com", "")).to.equal(true);
|
26 | });
|
27 |
|
28 | it ("should not authorize if email doesn't seems an email", function() {
|
29 | expect(Tools.isAuthorized("zumpa",".*")).to.equal(false);
|
30 | expect(Tools.isAuthorized("zumpa@",".*")).to.equal(false);
|
31 | expect(Tools.isAuthorized("zumpa@.com",".*")).to.equal(false);
|
32 | expect(Tools.isAuthorized("@zumpa",".*")).to.equal(false);
|
33 | });
|
34 |
|
35 | it ("should not authorize if the pattern is an invalid regexp", function() {
|
36 | expect(Tools.isAuthorized("zumpa@zot.com","*")).to.equal(false);
|
37 | });
|
38 |
|
39 | it ("should not authorize if email doesn't match a pattern", function() {
|
40 | expect(Tools.isAuthorized("zumpa@zot.com","saaa.*")).to.equal(false);
|
41 | expect(Tools.isAuthorized("zumpa@zot.com",".*@google\.com")).to.equal(false);
|
42 | expect(Tools.isAuthorized("zumpa@zot.com",".*@zot\.it")).to.equal(false);
|
43 | });
|
44 |
|
45 | it ("should authorize if email matches a pattern", function() {
|
46 | expect(Tools.isAuthorized("zumpa@zot.com",".*")).to.equal(true);
|
47 | expect(Tools.isAuthorized("zumpa@zot.com","zumpa.*")).to.equal(true);
|
48 | expect(Tools.isAuthorized("zumpa@zot.com",".*@zot.com,.*@zot.it")).to.equal(true);
|
49 | expect(Tools.isAuthorized("zumpa@zot.com","google.com,.*@zot.com,.*@zot.it")).to.equal(true);
|
50 | expect(Tools.isAuthorized("zumpa@zot.com","google.com,.*@zot.org , .*@zot.com")).to.equal(true);
|
51 | });
|
52 |
|
53 | });
|