forked from mkschreder/node-php
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
127 lines (113 loc) · 3.25 KB
/
index.js
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
/* eslint-env mocha */
var request = require('supertest');
var assert = require('chai').assert;
var express = require('express');
var php = require('../main');
var path = require("path")
var app = express();
var p = path.join("../www/php");
app.use("/", php.cgi(p, { cgi_path: '/usr/bin/', options: { "-c": "/etc/php.ini" } }))
app.use("*", function (req, res) {
return res.send("Thank you for using node-cgi-php. Please map your urls")
})
app.listen(9090, '127.0.0.1')
describe('GET /', function () {
it('should respond with /index.php and valid document', function (done) {
request(app)
.get('/')
.set('Accept', ['application/json', 'text/html', 'text/plain'])
// .expect('Content-Type', /html/)
// .expect('Content-Type', /json/)
// .expect('Content-Type', ['application/json', 'text/html', 'text/plain'])
.expect(200)
.end(function (err, res) {
if (err) {
done(err);
} else {
done();
}
});
});
});
describe('Get /index.php', function () {
it('should return a valid document', function (done) {
request(app)
.get('/index.php')
.set('Accept', ['application/json', 'text/html', 'text/html'])
// .expect('Content-Type', ['application/json', 'text/html', 'text/html'])
.expect(200)
.end(function (err, res) {
if (err) {
done(err);
} else {
// assert.match(res.body.$_SERVER.REMOTE_ADDR, /127.0.0.1|::1/);
// assert.match(res.body.$_SERVER.SCRIPT_FILENAME, /index.php$/);
done();
}
});
});
});
describe('Get /test/index.php', function () {
it('should return a 404 error for /test/index.php', function (done) {
request(app)
.get('/test/index.php')
.set('Accept', ['application/json', 'text/html'])
// .expect('Content-Type', ['application/json', 'text/html'])
.expect(404)
.end(function (err, res) {
if (err) {
done(err);
} else {
done();
}
});
});
});
describe('Get /test', function () {
it('should return a 404 for /test', function (done) {
request(app)
.get('/test')
.set('Accept', ['application/json', 'text/html'])
// .expect('Content-Type', ['application/json', 'text/html'])
.expect(404)
.end(function (err, res) {
if (err) {
done(err);
} else {
done();
}
});
});
});
describe('Get /test/', function () {
it('should return a 404 for /test/', function (done) {
request(app)
.get('/test/')
.set('Accept', ['application/json', 'text/html'])
// .expect('Content-Type', ['application/json', 'text/html'])
.expect(404)
.end(function (err, res) {
if (err) {
done(err);
} else {
done();
}
});
});
});
describe('Get /test/php/index.php', function () {
it('should return a html or json file', function (done) {
request(app)
.get('/test/php/index.php')
.set('Accept', ['application/json', 'text/html'])
// .expect('Content-Type', ['application/json', 'text/html'])
.expect(404)
.end(function (err, res) {
if (err) {
done(err);
} else {
done();
}
});
});
});