Skip to content

Commit 4be2901

Browse files
committed
Consolidated ping tests, started pleaseNotify tests, fixed bugs in services
1 parent e18bc96 commit 4be2901

File tree

13 files changed

+494
-701
lines changed

13 files changed

+494
-701
lines changed

DEVNOTES.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
# Developer Notes
22

3-
## Can I test pleaseNotify without domain? Docker might not allow.
4-
5-
Please notify verifies a reader differently whether or not there is a domain specified. I need to make sure I test both cases.
6-
73
## Make sure I test pleaseNotify with multiple urls including where one url fails.
84

95
Just because one fails doesn't mean the others aren't good. The response from Dave's server is a pass or fail so I'll stick with that and show a failure even if only one fails. This is probably an edge case.
106

11-
## If I ping Dave's server with a bad domain I get the following error:
7+
## OPML Editor fails ping with a bad domain
128

139
```xml
1410
<?xml version="1.0"?>
@@ -17,6 +13,10 @@ Just because one fails doesn't mean the others aren't good. The response from Da
1713

1814
I should make sure I return the same response if possible.
1915

20-
## Is there a way to create mock a server with https in docker?
16+
## OPML Editor fails pleaseNotify if missing parameters
17+
18+
```xml
19+
<?xml version="1.0"?>
20+
<notifyResult success="false" msg="The following parameters were missing from the request body: notifyProcedure, port, path, protocol." />
21+
```
2122

22-
I'm adding https-post as an option and would like to make sure to test it.

docker-compose.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ services:
3131
environment:
3232
APP_URL: http://rsscloud:5337
3333
MONGODB_URI: mongodb://mongodb:27017/rsscloud
34-
MOCK_SERVER_URL: http://rsscloud-tests:8002
34+
MOCK_SERVER_DOMAIN: rsscloud-tests
3535
MOCK_SERVER_PORT: 8002
36-
SECURE_MOCK_SERVER_URL: https://rsscloud-tests:8003
3736
SECURE_MOCK_SERVER_PORT: 8003
3837
volumes:
3938
- ./xunit:/app/xunit

services/notify-one.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,25 @@
2323

2424
async function notifyOneRpc(notifyProcedure, apiurl, resourceUrl) {
2525
const xmldoc = builder.create({
26-
methodCall: {
27-
methodName: notifyProcedure,
28-
params: {
29-
param: [
30-
{ value: resourceUrl }
31-
]
32-
}
26+
methodCall: {
27+
methodName: notifyProcedure,
28+
params: {
29+
param: [
30+
{ value: resourceUrl }
31+
]
3332
}
34-
}).end({ pretty: true }),
35-
36-
res = await request({
37-
method: 'POST',
38-
uri: apiurl,
39-
body: xmldoc,
40-
resolveWithFullResponse: true,
41-
headers: {
42-
'content-type': 'text/xml'
43-
}
44-
});
33+
}
34+
}).end({ pretty: true });
35+
36+
let res = await request({
37+
method: 'POST',
38+
uri: apiurl,
39+
body: xmldoc,
40+
resolveWithFullResponse: true,
41+
headers: {
42+
'content-type': 'text/xml'
43+
}
44+
});
4545

4646
if (res.statusCode < 200 || res.statusCode > 299) {
4747
throw new Error('Notification Failed');

services/parse-notify-params.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
}
8585

8686
if (0 === s.length) {
87-
parts.scheme = 'https-post' === parts.protocol ? 'https' : 'http';
87+
parts.scheme = 'https-post' === params.protocol ? 'https' : 'http';
8888
parts.port = req.body.port;
8989
parts.path = req.body.path;
9090

services/ping.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@
3131

3232
try {
3333
res = await request({
34+
method: 'GET',
3435
uri: resourceUrl,
36+
followRedirect: true,
37+
maxRedirects: 3,
3538
resolveWithFullResponse: true
3639
});
3740
} catch (err) {

services/please-notify.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515

1616
async function checkresourceUrlStatusCode(resourceUrl) {
1717
return request({
18-
method: 'HEAD',
18+
method: 'GET',
1919
uri: resourceUrl,
20-
followRedirect: false,
20+
followRedirect: true,
21+
maxRedirects: 3,
2122
resolveWithFullResponse: true
2223
})
2324
.then(res => {

test/mock.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
1-
const https = require('https');
2-
const fs = require('fs');
3-
const express = require("express");
4-
const bodyParser = require("body-parser"),
1+
const https = require('https'),
2+
fs = require('fs'),
3+
express = require('express'),
4+
bodyParser = require('body-parser'),
55
textParser = bodyParser.text({ type: '*/xml'}),
6-
urlencodedParser = bodyParser.urlencoded({ extended: false });
7-
const parseRpcRequest = require('../services/parse-rpc-request'),
6+
urlencodedParser = bodyParser.urlencoded({ extended: false }),
7+
parseRpcRequest = require('../services/parse-rpc-request'),
8+
MOCK_SERVER_DOMAIN = process.env.MOCK_SERVER_DOMAIN,
89
MOCK_SERVER_PORT = process.env.MOCK_SERVER_PORT || 8002,
9-
MOCK_SERVER_URL = process.env.MOCK_SERVER_URL || `http://localhost:${MOCK_SERVER_PORT}`,
10+
MOCK_SERVER_URL = process.env.MOCK_SERVER_URL || `http://${MOCK_SERVER_DOMAIN}:${MOCK_SERVER_PORT}`,
1011
SECURE_MOCK_SERVER_PORT = process.env.SECURE_MOCK_SERVER_PORT || 8003,
11-
SECURE_MOCK_SERVER_URL = process.env.SECURE_MOCK_SERVER_URL || `http://localhost:${SECURE_MOCK_SERVER_PORT}`;
12-
const rpcReturnFault = require('../services/rpc-return-fault');
12+
SECURE_MOCK_SERVER_URL = process.env.SECURE_MOCK_SERVER_URL || `https://${MOCK_SERVER_DOMAIN}:${SECURE_MOCK_SERVER_PORT}`,
13+
rpcReturnFault = require('../services/rpc-return-fault');
1314

1415
function restController(req, res) {
1516
const method = req.method,
1617
path = req.path;
1718

18-
if (this.routes[method][path]) {
19+
if (this.routes[method] && this.routes[method][path]) {
1920
this.requests[method][path].push(req);
21+
let responseBody = this.routes[method][path].responseBody;
2022
res
2123
.status(this.routes[method][path].status)
22-
.send(this.routes[method][path].responseBody);
24+
.send(typeof responseBody === 'function' ? responseBody(req) : responseBody);
2325
} else {
2426
res
2527
.status(501)
@@ -52,8 +54,11 @@ function rpcController(req, res) {
5254
module.exports = {
5355
app: express(),
5456
server: null,
57+
serverDomain: MOCK_SERVER_DOMAIN,
58+
serverPort: MOCK_SERVER_PORT,
5559
serverUrl: MOCK_SERVER_URL,
5660
secureServer: null,
61+
secureServerPort: SECURE_MOCK_SERVER_PORT,
5762
secureServerUrl: SECURE_MOCK_SERVER_URL,
5863
requests: {
5964
'GET': {},

test/ping-r2r.js

Lines changed: 0 additions & 205 deletions
This file was deleted.

0 commit comments

Comments
 (0)