2016-10-09 19:14:02 +00:00
|
|
|
|
"use strict";
|
|
|
|
|
|
2017-06-26 09:01:55 +00:00
|
|
|
|
const path = require("path");
|
2017-07-06 15:33:09 +00:00
|
|
|
|
const expect = require("chai").expect;
|
|
|
|
|
const util = require("../util");
|
|
|
|
|
const Helper = require("../../src/helper");
|
|
|
|
|
const link = require("../../src/plugins/irc-events/link.js");
|
2015-09-30 22:39:57 +00:00
|
|
|
|
|
|
|
|
|
describe("Link plugin", function() {
|
2017-11-27 23:47:19 +00:00
|
|
|
|
this.slow(200);
|
|
|
|
|
|
2017-12-09 23:56:05 +00:00
|
|
|
|
let app;
|
|
|
|
|
|
|
|
|
|
beforeEach(function(done) {
|
|
|
|
|
app = util.createWebserver();
|
|
|
|
|
app.get("/real-test-image.png", function(req, res) {
|
2018-01-28 07:20:24 +00:00
|
|
|
|
res.sendFile(path.resolve(__dirname, "../../client/img/logo-grey-bg-120x120px.png"));
|
2017-06-26 09:01:55 +00:00
|
|
|
|
});
|
2017-12-09 23:56:05 +00:00
|
|
|
|
this.connection = app.listen(9002, done);
|
2015-09-30 22:39:57 +00:00
|
|
|
|
|
|
|
|
|
this.irc = util.createClient();
|
|
|
|
|
this.network = util.createNetwork();
|
2017-07-06 15:33:09 +00:00
|
|
|
|
|
|
|
|
|
Helper.config.prefetchStorage = false;
|
2015-09-30 22:39:57 +00:00
|
|
|
|
});
|
|
|
|
|
|
2017-12-09 23:56:05 +00:00
|
|
|
|
afterEach(function(done) {
|
|
|
|
|
this.connection.close(done);
|
|
|
|
|
});
|
|
|
|
|
|
2015-09-30 22:39:57 +00:00
|
|
|
|
it("should be able to fetch basic information about URLs", function(done) {
|
2017-07-19 05:26:29 +00:00
|
|
|
|
const url = "http://localhost:9002/basic";
|
2017-04-08 12:34:31 +00:00
|
|
|
|
const message = this.irc.createMessage({
|
2017-11-15 06:35:15 +00:00
|
|
|
|
text: url,
|
2016-12-09 20:46:53 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
link(this.irc, this.network.channels[0], message);
|
2015-09-30 22:39:57 +00:00
|
|
|
|
|
2017-07-21 05:28:51 +00:00
|
|
|
|
expect(message.previews).to.deep.equal([{
|
|
|
|
|
body: "",
|
|
|
|
|
head: "",
|
|
|
|
|
link: url,
|
|
|
|
|
thumb: "",
|
2017-07-24 06:01:25 +00:00
|
|
|
|
type: "loading",
|
|
|
|
|
shown: true,
|
2017-07-21 05:28:51 +00:00
|
|
|
|
}]);
|
|
|
|
|
|
2017-12-09 23:56:05 +00:00
|
|
|
|
app.get("/basic", function(req, res) {
|
2017-06-26 09:01:55 +00:00
|
|
|
|
res.send("<title>test title</title><meta name='description' content='simple description'>");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.irc.once("msg:preview", function(data) {
|
2017-07-06 06:16:01 +00:00
|
|
|
|
expect(data.preview.type).to.equal("link");
|
|
|
|
|
expect(data.preview.head).to.equal("test title");
|
|
|
|
|
expect(data.preview.body).to.equal("simple description");
|
2017-07-19 05:26:29 +00:00
|
|
|
|
expect(data.preview.link).to.equal(url);
|
|
|
|
|
|
|
|
|
|
expect(message.previews).to.deep.equal([data.preview]);
|
2017-06-26 09:01:55 +00:00
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should prefer og:title over title", function(done) {
|
|
|
|
|
const message = this.irc.createMessage({
|
2017-11-15 06:35:15 +00:00
|
|
|
|
text: "http://localhost:9002/basic-og",
|
2017-06-26 09:01:55 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
link(this.irc, this.network.channels[0], message);
|
|
|
|
|
|
2017-12-09 23:56:05 +00:00
|
|
|
|
app.get("/basic-og", function(req, res) {
|
2017-06-26 09:01:55 +00:00
|
|
|
|
res.send("<title>test</title><meta property='og:title' content='opengraph test'>");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.irc.once("msg:preview", function(data) {
|
2018-06-11 08:32:32 +00:00
|
|
|
|
expect(data.preview.head).to.equal("opengraph test");
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should find only the first matching tag", function(done) {
|
|
|
|
|
const message = this.irc.createMessage({
|
|
|
|
|
text: "http://localhost:9002/duplicate-tags",
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
link(this.irc, this.network.channels[0], message);
|
|
|
|
|
|
|
|
|
|
app.get("/duplicate-tags", function(req, res) {
|
|
|
|
|
res.send("<title>test</title><title>magnifying glass icon</title><meta name='description' content='desc1'><meta name='description' content='desc2'>");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.irc.once("msg:preview", function(data) {
|
|
|
|
|
expect(data.preview.head).to.equal("test");
|
|
|
|
|
expect(data.preview.body).to.equal("desc1");
|
2017-06-26 09:01:55 +00:00
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should prefer og:description over description", function(done) {
|
|
|
|
|
const message = this.irc.createMessage({
|
2017-11-15 06:35:15 +00:00
|
|
|
|
text: "http://localhost:9002/description-og",
|
2017-06-26 09:01:55 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
link(this.irc, this.network.channels[0], message);
|
|
|
|
|
|
2017-12-09 23:56:05 +00:00
|
|
|
|
app.get("/description-og", function(req, res) {
|
2017-06-26 09:01:55 +00:00
|
|
|
|
res.send("<meta name='description' content='simple description'><meta property='og:description' content='opengraph description'>");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.irc.once("msg:preview", function(data) {
|
2017-07-06 06:16:01 +00:00
|
|
|
|
expect(data.preview.body).to.equal("opengraph description");
|
2017-06-26 09:01:55 +00:00
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should find og:image with full url", function(done) {
|
|
|
|
|
const message = this.irc.createMessage({
|
2017-11-15 06:35:15 +00:00
|
|
|
|
text: "http://localhost:9002/thumb",
|
2017-06-26 09:01:55 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
link(this.irc, this.network.channels[0], message);
|
|
|
|
|
|
2017-12-09 23:56:05 +00:00
|
|
|
|
app.get("/thumb", function(req, res) {
|
2017-06-26 09:01:55 +00:00
|
|
|
|
res.send("<title>Google</title><meta property='og:image' content='http://localhost:9002/real-test-image.png'>");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.irc.once("msg:preview", function(data) {
|
2017-07-06 06:16:01 +00:00
|
|
|
|
expect(data.preview.head).to.equal("Google");
|
|
|
|
|
expect(data.preview.thumb).to.equal("http://localhost:9002/real-test-image.png");
|
2017-06-26 09:01:55 +00:00
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2017-08-13 09:58:27 +00:00
|
|
|
|
it("should find image_src", function(done) {
|
2017-06-26 09:01:55 +00:00
|
|
|
|
const message = this.irc.createMessage({
|
2017-11-15 06:35:15 +00:00
|
|
|
|
text: "http://localhost:9002/thumb-image-src",
|
2017-06-26 09:01:55 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
link(this.irc, this.network.channels[0], message);
|
|
|
|
|
|
2017-12-09 23:56:05 +00:00
|
|
|
|
app.get("/thumb-image-src", function(req, res) {
|
2017-08-13 09:58:27 +00:00
|
|
|
|
res.send("<link rel='image_src' href='http://localhost:9002/real-test-image.png'>");
|
2017-06-26 09:01:55 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.irc.once("msg:preview", function(data) {
|
2017-08-13 09:58:27 +00:00
|
|
|
|
expect(data.preview.thumb).to.equal("http://localhost:9002/real-test-image.png");
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should correctly resolve relative protocol", function(done) {
|
|
|
|
|
const message = this.irc.createMessage({
|
2017-11-15 06:35:15 +00:00
|
|
|
|
text: "http://localhost:9002/thumb-image-src",
|
2017-08-13 09:58:27 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
link(this.irc, this.network.channels[0], message);
|
|
|
|
|
|
2017-12-09 23:56:05 +00:00
|
|
|
|
app.get("/thumb-image-src", function(req, res) {
|
2017-08-13 09:58:27 +00:00
|
|
|
|
res.send("<link rel='image_src' href='//localhost:9002/real-test-image.png'>");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.irc.once("msg:preview", function(data) {
|
|
|
|
|
expect(data.preview.thumb).to.equal("http://localhost:9002/real-test-image.png");
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should resolve url correctly for relative url", function(done) {
|
|
|
|
|
const message = this.irc.createMessage({
|
2017-11-15 06:35:15 +00:00
|
|
|
|
text: "http://localhost:9002/relative-thumb",
|
2017-08-13 09:58:27 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
link(this.irc, this.network.channels[0], message);
|
|
|
|
|
|
2017-12-09 23:56:05 +00:00
|
|
|
|
app.get("/relative-thumb", function(req, res) {
|
2017-08-13 09:58:27 +00:00
|
|
|
|
res.send("<title>test relative image</title><meta property='og:image' content='/real-test-image.png'>");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.irc.once("msg:preview", function(data) {
|
|
|
|
|
expect(data.preview.thumb).to.equal("http://localhost:9002/real-test-image.png");
|
|
|
|
|
expect(data.preview.head).to.equal("test relative image");
|
|
|
|
|
expect(data.preview.link).to.equal("http://localhost:9002/relative-thumb");
|
2017-06-26 09:01:55 +00:00
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should send untitled page if there is a thumbnail", function(done) {
|
|
|
|
|
const message = this.irc.createMessage({
|
2017-11-15 06:35:15 +00:00
|
|
|
|
text: "http://localhost:9002/thumb-no-title",
|
2017-06-26 09:01:55 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
link(this.irc, this.network.channels[0], message);
|
|
|
|
|
|
2017-12-09 23:56:05 +00:00
|
|
|
|
app.get("/thumb-no-title", function(req, res) {
|
2017-06-26 09:01:55 +00:00
|
|
|
|
res.send("<meta property='og:image' content='http://localhost:9002/real-test-image.png'>");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.irc.once("msg:preview", function(data) {
|
2017-07-06 06:16:01 +00:00
|
|
|
|
expect(data.preview.head).to.equal("Untitled page");
|
|
|
|
|
expect(data.preview.thumb).to.equal("http://localhost:9002/real-test-image.png");
|
2017-07-06 15:33:09 +00:00
|
|
|
|
expect(data.preview.link).to.equal("http://localhost:9002/thumb-no-title");
|
2017-06-26 09:01:55 +00:00
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should not send thumbnail if image is 404", function(done) {
|
|
|
|
|
const message = this.irc.createMessage({
|
2017-11-15 06:35:15 +00:00
|
|
|
|
text: "http://localhost:9002/thumb-404",
|
2017-06-26 09:01:55 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
link(this.irc, this.network.channels[0], message);
|
|
|
|
|
|
2017-12-09 23:56:05 +00:00
|
|
|
|
app.get("/thumb-404", function(req, res) {
|
2017-06-26 09:01:55 +00:00
|
|
|
|
res.send("<title>404 image</title><meta property='og:image' content='http://localhost:9002/this-image-does-not-exist.png'>");
|
2015-09-30 22:39:57 +00:00
|
|
|
|
});
|
|
|
|
|
|
2017-06-26 09:01:55 +00:00
|
|
|
|
this.irc.once("msg:preview", function(data) {
|
2017-07-06 06:16:01 +00:00
|
|
|
|
expect(data.preview.head).to.equal("404 image");
|
2017-07-06 15:33:09 +00:00
|
|
|
|
expect(data.preview.link).to.equal("http://localhost:9002/thumb-404");
|
2017-07-06 06:16:01 +00:00
|
|
|
|
expect(data.preview.thumb).to.be.empty;
|
2017-06-26 09:01:55 +00:00
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should send image preview", function(done) {
|
|
|
|
|
const message = this.irc.createMessage({
|
2017-11-15 06:35:15 +00:00
|
|
|
|
text: "http://localhost:9002/real-test-image.png",
|
2017-06-26 09:01:55 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
link(this.irc, this.network.channels[0], message);
|
|
|
|
|
|
|
|
|
|
this.irc.once("msg:preview", function(data) {
|
2017-07-06 06:16:01 +00:00
|
|
|
|
expect(data.preview.type).to.equal("image");
|
|
|
|
|
expect(data.preview.link).to.equal("http://localhost:9002/real-test-image.png");
|
2017-07-06 15:33:09 +00:00
|
|
|
|
expect(data.preview.thumb).to.equal("http://localhost:9002/real-test-image.png");
|
2015-09-30 22:39:57 +00:00
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
2017-07-06 06:16:01 +00:00
|
|
|
|
|
|
|
|
|
it("should load multiple URLs found in messages", function(done) {
|
|
|
|
|
const message = this.irc.createMessage({
|
2017-11-15 06:35:15 +00:00
|
|
|
|
text: "http://localhost:9002/one http://localhost:9002/two",
|
2017-07-06 06:16:01 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
link(this.irc, this.network.channels[0], message);
|
|
|
|
|
|
2017-07-21 05:28:51 +00:00
|
|
|
|
expect(message.previews).to.eql([{
|
|
|
|
|
body: "",
|
|
|
|
|
head: "",
|
|
|
|
|
link: "http://localhost:9002/one",
|
|
|
|
|
thumb: "",
|
2017-07-24 06:01:25 +00:00
|
|
|
|
type: "loading",
|
|
|
|
|
shown: true,
|
2017-07-21 05:28:51 +00:00
|
|
|
|
}, {
|
|
|
|
|
body: "",
|
|
|
|
|
head: "",
|
|
|
|
|
link: "http://localhost:9002/two",
|
|
|
|
|
thumb: "",
|
2017-07-24 06:01:25 +00:00
|
|
|
|
type: "loading",
|
|
|
|
|
shown: true,
|
2017-07-21 05:28:51 +00:00
|
|
|
|
}]);
|
2017-07-19 05:26:29 +00:00
|
|
|
|
|
2017-12-09 23:56:05 +00:00
|
|
|
|
app.get("/one", function(req, res) {
|
2017-07-06 06:16:01 +00:00
|
|
|
|
res.send("<title>first title</title>");
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-09 23:56:05 +00:00
|
|
|
|
app.get("/two", function(req, res) {
|
2017-07-06 06:16:01 +00:00
|
|
|
|
res.send("<title>second title</title>");
|
|
|
|
|
});
|
|
|
|
|
|
2017-07-19 05:26:29 +00:00
|
|
|
|
const previews = [];
|
2017-07-06 06:16:01 +00:00
|
|
|
|
|
|
|
|
|
this.irc.on("msg:preview", function(data) {
|
|
|
|
|
if (data.preview.link === "http://localhost:9002/one") {
|
|
|
|
|
expect(data.preview.head).to.equal("first title");
|
2017-07-21 05:28:51 +00:00
|
|
|
|
previews[0] = data.preview;
|
2017-07-06 06:16:01 +00:00
|
|
|
|
} else if (data.preview.link === "http://localhost:9002/two") {
|
|
|
|
|
expect(data.preview.head).to.equal("second title");
|
2017-07-21 05:28:51 +00:00
|
|
|
|
previews[1] = data.preview;
|
2017-07-06 06:16:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-21 05:28:51 +00:00
|
|
|
|
if (previews[0] && previews[1]) {
|
|
|
|
|
expect(message.previews).to.eql(previews);
|
2017-07-06 06:16:01 +00:00
|
|
|
|
done();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
2017-12-28 13:34:49 +00:00
|
|
|
|
|
|
|
|
|
it("should use client's preferred language as Accept-Language header", function(done) {
|
|
|
|
|
const language = "sv,en-GB;q=0.9,en;q=0.8";
|
|
|
|
|
this.irc.language = language;
|
|
|
|
|
|
|
|
|
|
app.get("/language-check", function(req, res) {
|
|
|
|
|
expect(req.headers["accept-language"]).to.equal(language);
|
|
|
|
|
res.send();
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const message = this.irc.createMessage({
|
|
|
|
|
text: "http://localhost:9002/language-check",
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
link(this.irc, this.network.channels[0], message);
|
|
|
|
|
});
|
2018-03-08 17:43:39 +00:00
|
|
|
|
|
2018-03-23 14:50:52 +00:00
|
|
|
|
it("should send accept text/html for initial request", function(done) {
|
|
|
|
|
app.get("/accept-header-html", function(req, res) {
|
|
|
|
|
expect(req.headers.accept).to.equal("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
|
|
|
|
|
res.send();
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const message = this.irc.createMessage({
|
|
|
|
|
text: "http://localhost:9002/accept-header-html",
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
link(this.irc, this.network.channels[0], message);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should send accept */* for meta image", function(done) {
|
|
|
|
|
app.get("/accept-header-thumb", function(req, res) {
|
|
|
|
|
res.send("<title>404 image</title><meta property='og:image' content='http://localhost:9002/accept-header-thumb.png'>");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.get("/accept-header-thumb.png", function(req, res) {
|
|
|
|
|
expect(req.headers.accept).to.equal("*/*");
|
|
|
|
|
res.send();
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const message = this.irc.createMessage({
|
|
|
|
|
text: "http://localhost:9002/accept-header-thumb",
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
link(this.irc, this.network.channels[0], message);
|
|
|
|
|
});
|
|
|
|
|
|
2018-03-13 19:19:28 +00:00
|
|
|
|
it("should not add slash to url", function(done) {
|
|
|
|
|
const message = this.irc.createMessage({
|
|
|
|
|
text: "http://localhost:9002",
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
link(this.irc, this.network.channels[0], message);
|
|
|
|
|
|
|
|
|
|
this.irc.once("msg:preview", function(data) {
|
|
|
|
|
expect(data.preview.link).to.equal("http://localhost:9002");
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2018-03-08 17:43:39 +00:00
|
|
|
|
it("should work on non-ASCII urls", function(done) {
|
|
|
|
|
const message = this.irc.createMessage({
|
|
|
|
|
text:
|
|
|
|
|
"http://localhost:9002/unicode/ıoı-test " +
|
|
|
|
|
"http://localhost:9002/unicode/русский-текст-test " +
|
|
|
|
|
"http://localhost:9002/unicode/🙈-emoji-test " +
|
|
|
|
|
"http://localhost:9002/unicodeq/?q=ıoı-test " +
|
|
|
|
|
"http://localhost:9002/unicodeq/?q=русский-текст-test " +
|
|
|
|
|
"http://localhost:9002/unicodeq/?q=🙈-emoji-test",
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
link(this.irc, this.network.channels[0], message);
|
|
|
|
|
|
|
|
|
|
app.get("/unicode/:q", function(req, res) {
|
|
|
|
|
res.send(`<title>${req.params.q}</title>`);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.get("/unicodeq/", function(req, res) {
|
|
|
|
|
res.send(`<title>${req.query.q}</title>`);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const previews = [];
|
|
|
|
|
|
|
|
|
|
this.irc.on("msg:preview", function(data) {
|
|
|
|
|
previews.push(data.preview.link);
|
|
|
|
|
|
2018-03-13 19:19:28 +00:00
|
|
|
|
if (data.preview.link.includes("ıoı-test")) {
|
2018-03-08 17:43:39 +00:00
|
|
|
|
expect(data.preview.head).to.equal("ıoı-test");
|
2018-03-13 19:19:28 +00:00
|
|
|
|
} else if (data.preview.link.includes("русский-текст-test")) {
|
2018-03-08 17:43:39 +00:00
|
|
|
|
expect(data.preview.head).to.equal("русский-текст-test");
|
2018-03-13 19:19:28 +00:00
|
|
|
|
} else if (data.preview.link.includes("🙈-emoji-test")) {
|
2018-03-08 17:43:39 +00:00
|
|
|
|
expect(data.preview.head).to.equal("🙈-emoji-test");
|
|
|
|
|
} else {
|
|
|
|
|
expect("This should never happen").to.equal(data.preview.link);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (previews.length === 5) {
|
2018-03-09 02:00:51 +00:00
|
|
|
|
expect(message.previews.map((preview) => preview.link)).to.have.members(previews);
|
2018-03-08 17:43:39 +00:00
|
|
|
|
done();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
2018-04-27 11:11:54 +00:00
|
|
|
|
|
|
|
|
|
it("should fetch protocol-aware links", function(done) {
|
|
|
|
|
const message = this.irc.createMessage({
|
|
|
|
|
text: "//localhost:9002",
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
link(this.irc, this.network.channels[0], message);
|
|
|
|
|
|
|
|
|
|
this.irc.once("msg:preview", function(data) {
|
2018-06-09 06:07:37 +00:00
|
|
|
|
expect(data.preview.link).to.equal("http://localhost:9002");
|
2018-04-27 11:11:54 +00:00
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2018-04-27 13:27:26 +00:00
|
|
|
|
it("should de-duplicate links", function(done) {
|
|
|
|
|
const message = this.irc.createMessage({
|
2018-06-09 06:07:37 +00:00
|
|
|
|
text: "//localhost:9002 http://localhost:9002 http://localhost:9002",
|
2018-04-27 13:27:26 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
link(this.irc, this.network.channels[0], message);
|
|
|
|
|
|
|
|
|
|
expect(message.previews).to.deep.equal([{
|
|
|
|
|
type: "loading",
|
|
|
|
|
head: "",
|
|
|
|
|
body: "",
|
|
|
|
|
thumb: "",
|
2018-06-09 06:07:37 +00:00
|
|
|
|
link: "http://localhost:9002",
|
2018-04-27 13:27:26 +00:00
|
|
|
|
shown: true,
|
|
|
|
|
}]);
|
|
|
|
|
|
|
|
|
|
this.irc.once("msg:preview", function(data) {
|
2018-06-09 06:07:37 +00:00
|
|
|
|
expect(data.preview.link).to.equal("http://localhost:9002");
|
2018-04-27 13:27:26 +00:00
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2018-04-27 11:11:54 +00:00
|
|
|
|
it("should not try to fetch links with wrong protocol", function() {
|
|
|
|
|
const message = this.irc.createMessage({
|
|
|
|
|
text: "ssh://example.com ftp://example.com irc://example.com http:////////example.com",
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(message.previews).to.be.empty;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should not try to fetch links with username or password", function() {
|
|
|
|
|
const message = this.irc.createMessage({
|
|
|
|
|
text: "http://root:'some%pass'@hostname/database http://a:%p@c http://a:%p@example.com http://test@example.com",
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(message.previews).to.be.empty;
|
|
|
|
|
});
|
2018-06-10 17:32:52 +00:00
|
|
|
|
|
|
|
|
|
it("should fetch same link only once at the same time", function(done) {
|
|
|
|
|
const message = this.irc.createMessage({
|
|
|
|
|
text: "http://localhost:9002/basic-og-once",
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
let requests = 0;
|
|
|
|
|
let responses = 0;
|
|
|
|
|
|
|
|
|
|
this.irc.language = "very nice language";
|
|
|
|
|
|
|
|
|
|
link(this.irc, this.network.channels[0], message);
|
|
|
|
|
link(this.irc, this.network.channels[0], message);
|
|
|
|
|
process.nextTick(() => link(this.irc, this.network.channels[0], message));
|
|
|
|
|
|
|
|
|
|
app.get("/basic-og-once", function(req, res) {
|
|
|
|
|
requests++;
|
|
|
|
|
|
|
|
|
|
expect(req.header("accept-language")).to.equal("very nice language");
|
|
|
|
|
|
|
|
|
|
// delay the request so it doesn't resolve immediately
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
res.send("<title>test prefetch</title>");
|
|
|
|
|
}, 100);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const cb = (data) => {
|
|
|
|
|
responses++;
|
|
|
|
|
|
|
|
|
|
expect(data.preview.head, "test prefetch");
|
|
|
|
|
|
|
|
|
|
if (responses === 3) {
|
|
|
|
|
this.irc.removeListener("msg:preview", cb);
|
|
|
|
|
expect(requests).to.equal(1);
|
|
|
|
|
done();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
this.irc.on("msg:preview", cb);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should fetch same link with different languages multiple times", function(done) {
|
|
|
|
|
const message = this.irc.createMessage({
|
|
|
|
|
text: "http://localhost:9002/basic-og-once-lang",
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const requests = [];
|
|
|
|
|
let responses = 0;
|
|
|
|
|
|
|
|
|
|
this.irc.language = "first language";
|
|
|
|
|
link(this.irc, this.network.channels[0], message);
|
|
|
|
|
|
2018-07-06 09:29:21 +00:00
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.irc.language = "second language";
|
|
|
|
|
link(this.irc, this.network.channels[0], message);
|
|
|
|
|
}, 100);
|
2018-06-10 17:32:52 +00:00
|
|
|
|
|
|
|
|
|
app.get("/basic-og-once-lang", function(req, res) {
|
|
|
|
|
requests.push(req.header("accept-language"));
|
|
|
|
|
|
|
|
|
|
// delay the request so it doesn't resolve immediately
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
res.send("<title>test prefetch</title>");
|
|
|
|
|
}, 100);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const cb = (data) => {
|
|
|
|
|
responses++;
|
|
|
|
|
|
|
|
|
|
expect(data.preview.head, "test prefetch");
|
|
|
|
|
|
|
|
|
|
if (responses === 2) {
|
|
|
|
|
this.irc.removeListener("msg:preview", cb);
|
|
|
|
|
expect(requests).to.deep.equal([
|
|
|
|
|
"first language",
|
|
|
|
|
"second language",
|
|
|
|
|
]);
|
|
|
|
|
done();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
this.irc.on("msg:preview", cb);
|
|
|
|
|
});
|
2014-11-17 20:14:28 +00:00
|
|
|
|
});
|