forked from confirmedcode/Main
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.js
More file actions
137 lines (123 loc) · 3.64 KB
/
Copy pathbasic.js
File metadata and controls
137 lines (123 loc) · 3.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// Chai + Server (Server must be loaded before other utilities)
const chai = require("chai");
chai.use(require("chai-http"));
const server = require("../app");
const Constants = require('./constants.js');
const { reset, changeDate, resetDate } = require("./utilities.js");
const { User } = require("shared/models");
const { Secure } = require("shared/utilities");
// describe.only("Skip All", () => {
// it("should skip all tests", (done) => {
// done();
// return;
// });
// });
// describe.only("Just Reset", () => {
// beforeEach(reset);
// it("should reset", (done) => {
// done();
// return;
// });
// });
describe("Basic", () => {
describe("Get user email", () => {
beforeEach(reset);
it("should respond with correct user email", (done) => {
User.getWithEmail(Constants.EXISTING_USER_EMAIL)
.then(user => {
user.email.should.equal(Constants.EXISTING_USER_EMAIL);
done();
})
.catch(error => {
done(error);
});
});
});
describe("AES Encryption", () => {
it("decrypted text should equal text", (done) => {
const key = Secure.randomString(32);
const encrypted = Secure.aesEncrypt("testDecryption@blah.com", key);
Secure.aesDecrypt(encrypted, key).should.equal("testDecryption@blah.com");
done();
});
});
describe("Health Check", () => {
it("should respond 200 and JSON OK", (done) => {
chai.request(server)
.get("/health")
.end((error, response) => {
response.should.have.status(200);
response.body.message.should.contain("OK from");
done();
});
});
});
describe("Get IP", () => {
it("should get an IP", (done) => {
chai.request(server)
.get("/ip")
.end((error, response) => {
response.should.have.status(200);
response.body.ip.should.exist;
done();
});
});
});
describe("Get IP with Trust Proxy Header", () => {
it("should get the passed in IP", (done) => {
chai.request(server)
.get("/ip")
.set('X-Forwarded-For', '123.45.67.89, 9.9.9.9, 111.111.111.111')
.end((error, response) => {
response.should.have.status(200);
response.body.ip.should.equal("123.45.67.89");
done();
});
});
});
describe("404 Not Found", () => {
it("should respond 404", (done) => {
chai.request(server)
.get("/invalid-url")
.end((error, response) => {
response.should.have.status(404);
response.body.message.should.contain("Not Found");
done();
});
});
});
describe("404 Not Found - Browser", () => {
it("should respond 404", (done) => {
chai.request(server)
.get("/invalid-url")
.set("Accept", "text/html")
.end((error, response) => {
response.should.have.status(404);
response.text.should.contain("does not exist");
done();
});
});
});
describe("Force a 500 Error - Browser", () => {
it("should not expose error details to client", (done) => {
chai.request(server)
.get("/error-test")
.set("Accept", "text/html")
.end((error, response) => {
response.text.should.contain("Unknown");
done();
});
});
});
describe("Force a 500 Error", () => {
it("should not expose error details to client", (done) => {
chai.request(server)
.get("/error-test")
.end((error, response) => {
response.should.have.status(500);
response.body.code.should.equal(-1);
done();
});
});
});
});