Skip to content

Commit 0f0b4d3

Browse files
committed
Added pleaseNotify tests for xml-rpc aggregators
1 parent 4be2901 commit 0f0b4d3

File tree

4 files changed

+75
-92
lines changed

4 files changed

+75
-92
lines changed

services/notify-one-challenge.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
(function () {
22
"use strict";
33

4-
const getRandomPassword = require('./get-random-password'),
4+
const notifyOne = require('./notify-one'),
5+
getRandomPassword = require('./get-random-password'),
56
querystring = require('querystring'),
67
request = require('request-promise-native');
78

8-
async function notifyOneChallenge(resourceUrl, apiurl) {
9+
async function notifyOneChallengeRest(apiurl, resourceUrl) {
910
const challenge = getRandomPassword(20),
1011
testUrl = apiurl + '?' + querystring.stringify({
1112
'url': resourceUrl,
@@ -21,5 +22,14 @@
2122
}
2223
}
2324

25+
function notifyOneChallenge(notifyProcedure, apiurl, protocol, resourceUrl) {
26+
if ('xml-rpc' === protocol) {
27+
// rssCloud.root originally didn't support this flow
28+
return notifyOne(notifyProcedure, apiurl, protocol, resourceUrl);
29+
}
30+
31+
return notifyOneChallengeRest(apiurl, resourceUrl);
32+
}
33+
2434
module.exports = notifyOneChallenge;
2535
}());

services/parse-notify-params.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
params.notifyProcedure = false;
127127
}
128128

129-
parts.scheme = 'http';
129+
parts.scheme = 'https-post' === params.protocol ? 'https' : 'http';
130130
parts.port = rpcParams[1];
131131
parts.path = rpcParams[2];
132132

services/please-notify.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060

6161
try {
6262
if (diffDomain) {
63-
await notifyOneChallenge(resourceUrl, apiurl);
63+
await notifyOneChallenge(notifyProcedure, apiurl, protocol, resourceUrl);
6464
} else {
6565
await notifyOne(notifyProcedure, apiurl, protocol, resourceUrl);
6666
}

test/please-notify.js

Lines changed: 61 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ const chai = require("chai"),
55
SERVER_URL = process.env.APP_URL || "http://localhost:5337",
66
mock = require("./mock"),
77
mongodb = require("./mongodb"),
8-
xmlrpc = require("davexmlrpc");
8+
xmlrpc = require("davexmlrpc"),
9+
rpcReturnSuccess = require('../services/rpc-return-success');
910

1011
chai.use(chaiHttp);
1112
chai.use(chaiXml);
@@ -33,7 +34,7 @@ function pleaseNotify(pingProtocol, body, returnFormat) {
3334
}
3435
}
3536

36-
for (const protocol of ['http-post', 'https-post']) {
37+
for (const protocol of ['http-post', 'https-post', 'xml-rpc']) {
3738
for (const returnFormat of ['XML', 'JSON']) {
3839
for (const pingProtocol of ['REST']) {
3940

@@ -66,24 +67,28 @@ for (const pingProtocol of ['REST']) {
6667

6768
it('should accept a pleaseNotify for new resource', async () => {
6869
const feedPath = '/rss.xml',
69-
pingPath = '/feedupdated',
7070
resourceUrl = mock.serverUrl + feedPath;
7171

72-
let body = {
72+
let pingPath = '/feedupdated',
73+
notifyProcedure = false;
74+
75+
if ('xml-rpc' === protocol) {
76+
pingPath = '/RPC2';
77+
notifyProcedure = 'river.feedUpdated';
78+
}
79+
80+
const body = {
7381
domain: mock.serverDomain,
74-
port: 'http-post' === protocol ? mock.serverPort : mock.secureServerPort,
82+
port: 'https-post' === protocol ? mock.secureServerPort : mock.serverPort,
7583
path: pingPath,
76-
notifyProcedure: false,
84+
notifyProcedure: notifyProcedure,
7785
protocol,
7886
url1: resourceUrl
7987
};
8088

81-
if ('xml-rpc' === protocol) {
82-
// body = {}
83-
}
84-
8589
mock.route('GET', feedPath, 200, '<RSS Feed />');
8690
mock.route('GET', pingPath, 200, (req) => { return req.query.challenge; });
91+
mock.rpc(notifyProcedure, rpcReturnSuccess(true));
8792

8893
let res = await pleaseNotify(pingProtocol, body, returnFormat);
8994

@@ -96,28 +101,39 @@ for (const pingProtocol of ['REST']) {
96101
}
97102

98103
expect(mock.requests.GET).property(feedPath).lengthOf(1, `Missing GET ${feedPath}`);
99-
expect(mock.requests.GET).property(pingPath).lengthOf(1, `Missing GET ${pingPath}`);
104+
105+
if ('xml-rpc' === protocol) {
106+
expect(mock.requests.RPC2).property(notifyProcedure).lengthOf(1, `Missing XML-RPC call ${notifyProcedure}`);
107+
expect(mock.requests.RPC2[notifyProcedure][0]).property('rpcBody');
108+
expect(mock.requests.RPC2[notifyProcedure][0].rpcBody.params[0]).equal(resourceUrl);
109+
} else {
110+
expect(mock.requests.GET).property(pingPath).lengthOf(1, `Missing GET ${pingPath}`);
111+
}
100112
});
101113

102114
it('should accept a pleaseNotify without domain for new resource', async () => {
103115
const feedPath = '/rss.xml',
104-
pingPath = '/feedupdated',
105116
resourceUrl = mock.serverUrl + feedPath;
106117

107-
let body = {
108-
port: 'http-post' === protocol ? mock.serverPort : mock.secureServerPort,
118+
let pingPath = '/feedupdated',
119+
notifyProcedure = false;
120+
121+
if ('xml-rpc' === protocol) {
122+
pingPath = '/RPC2';
123+
notifyProcedure = 'river.feedUpdated';
124+
}
125+
126+
const body = {
127+
port: 'https-post' === protocol ? mock.secureServerPort : mock.serverPort,
109128
path: pingPath,
110-
notifyProcedure: false,
129+
notifyProcedure: notifyProcedure,
111130
protocol,
112131
url1: resourceUrl
113132
};
114133

115-
if ('xml-rpc' === protocol) {
116-
// body = {}
117-
}
118-
119134
mock.route('GET', feedPath, 200, '<RSS Feed />');
120135
mock.route('POST', pingPath, 200, 'Thanks for the update! :-)');
136+
mock.rpc(notifyProcedure, rpcReturnSuccess(true));
121137

122138
let res = await pleaseNotify(pingProtocol, body, returnFormat);
123139

@@ -130,87 +146,39 @@ for (const pingProtocol of ['REST']) {
130146
}
131147

132148
expect(mock.requests.GET).property(feedPath).lengthOf(1, `Missing GET ${feedPath}`);
133-
expect(mock.requests.POST).property(pingPath).lengthOf(1, `Missing POST ${pingPath}`);
134-
});
135149

136-
// it('should accept a pleaseNotify for new resource and return JSON', async () => {
137-
// const feedPath = '/rss.xml',
138-
// pingPath = '/feedupdated',
139-
// resourceUrl = mock.serverUrl + feedPath,
140-
// notifyProcedure = false,
141-
// apiurl = ('http-post' === protocol ? mock.serverUrl : mock.secureServerUrl) + pingPath;
142-
143-
// mock.route('GET', feedPath, 200, '<RSS Feed />');
144-
// mock.route('GET', pingPath, 200, (req) => { return req.query.challenge; });
145-
146-
// let res = await chai
147-
// .request(SERVER_URL)
148-
// .post("/pleaseNotify")
149-
// .set('accept', 'application/json')
150-
// .set('content-type', 'application/x-www-form-urlencoded')
151-
// .send({
152-
// domain: 'rsscloud-tests',
153-
// port: 8002,
154-
// path: pingPath,
155-
// notifyProcedure: false,
156-
// protocol,
157-
// url1: resourceUrl
158-
// });
159-
160-
// expect(res).status(200);
161-
// expect(res.body).deep.equal({ success: true, msg: `Thanks for the registration. It worked. When the resource updates we\'ll notify you. Don\'t forget to re-register after 24 hours, your subscription will expire in 25. Keep on truckin!` });
162-
// expect(mock.requests.GET).property(feedPath).lengthOf(1, `Missing GET ${feedPath}`);
163-
// expect(mock.requests.GET).property(pingPath).lengthOf(1, `Missing GET ${pingPath}`);
164-
// });
165-
166-
// it('should accept a pleaseNotify without domain for new resource and return JSON', async () => {
167-
// const feedPath = '/rss.xml',
168-
// pingPath = '/feedupdated',
169-
// resourceUrl = mock.serverUrl + feedPath,
170-
// notifyProcedure = false,
171-
// apiurl = ('http-post' === protocol ? mock.serverUrl : mock.secureServerUrl) + pingPath;
172-
173-
// mock.route('GET', feedPath, 200, '<RSS Feed />');
174-
// mock.route('POST', pingPath, 200, '');
175-
176-
// let res = await chai
177-
// .request(SERVER_URL)
178-
// .post("/pleaseNotify")
179-
// .set('accept', 'application/json')
180-
// .set('content-type', 'application/x-www-form-urlencoded')
181-
// .send({
182-
// port: 8002,
183-
// path: pingPath,
184-
// notifyProcedure: false,
185-
// protocol,
186-
// url1: resourceUrl
187-
// });
188-
189-
// expect(res).status(200);
190-
// expect(res.body).deep.equal({ success: true, msg: `Thanks for the registration. It worked. When the resource updates we\'ll notify you. Don\'t forget to re-register after 24 hours, your subscription will expire in 25. Keep on truckin!` });
191-
// expect(mock.requests.GET).property(feedPath).lengthOf(1, `Missing GET ${feedPath}`);
192-
// expect(mock.requests.POST).property(pingPath).lengthOf(1, `Missing POST ${pingPath}`);
193-
// });
150+
if ('xml-rpc' === protocol) {
151+
expect(mock.requests.RPC2).property(notifyProcedure).lengthOf(1, `Missing XML-RPC call ${notifyProcedure}`);
152+
expect(mock.requests.RPC2[notifyProcedure][0]).property('rpcBody');
153+
expect(mock.requests.RPC2[notifyProcedure][0].rpcBody.params[0]).equal(resourceUrl);
154+
} else {
155+
expect(mock.requests.POST).property(pingPath).lengthOf(1, `Missing POST ${pingPath}`);
156+
}
157+
});
194158

195159
it('should reject a pleaseNotify for bad resource', async () => {
196160
const feedPath = '/rss.xml',
197-
pingPath = '/feedupdated',
198161
resourceUrl = mock.serverUrl + feedPath;
199162

200-
let body = {
201-
port: 'http-post' === protocol ? mock.serverPort : mock.secureServerPort,
163+
let pingPath = '/feedupdated',
164+
notifyProcedure = false;
165+
166+
if ('xml-rpc' === protocol) {
167+
pingPath = '/RPC2';
168+
notifyProcedure = 'river.feedUpdated';
169+
}
170+
171+
const body = {
172+
port: 'https-post' === protocol ? mock.secureServerPort : mock.serverPort,
202173
path: pingPath,
203-
notifyProcedure: false,
174+
notifyProcedure: notifyProcedure,
204175
protocol,
205176
url1: resourceUrl
206177
};
207178

208-
if ('xml-rpc' === protocol) {
209-
// body = {}
210-
}
211-
212179
mock.route('GET', feedPath, 404, 'Not Found');
213180
mock.route('POST', pingPath, 200, 'Thanks for the update! :-)');
181+
mock.rpc(notifyProcedure, rpcReturnSuccess(true));
214182

215183
let res = await pleaseNotify(pingProtocol, body, returnFormat);
216184

@@ -223,7 +191,12 @@ for (const pingProtocol of ['REST']) {
223191
}
224192

225193
expect(mock.requests.GET).property(feedPath).lengthOf(1, `Missing GET ${feedPath}`);
226-
expect(mock.requests.POST).property(pingPath).lengthOf(0, `Should not POST ${pingPath}`);
194+
195+
if ('xml-rpc' === protocol) {
196+
expect(mock.requests.RPC2).property(notifyProcedure).lengthOf(0, `Should not XML-RPC call ${notifyProcedure}`);
197+
} else {
198+
expect(mock.requests.POST).property(pingPath).lengthOf(0, `Should not POST ${pingPath}`);
199+
}
227200
});
228201
});
229202

0 commit comments

Comments
 (0)