2022-06-19 00:25:21 +00:00
|
|
|
|
import path from "path";
|
|
|
|
|
import {expect} from "chai";
|
|
|
|
|
import util from "../util";
|
|
|
|
|
import Config from "../../server/config";
|
2024-04-17 18:22:56 +00:00
|
|
|
|
import link from "../../server/plugins/irc-events/link";
|
|
|
|
|
import {LinkPreview} from "../../shared/types/msg";
|
2015-09-30 22:39:57 +00:00
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
describe("Link plugin", function () {
|
2019-11-27 18:25:29 +00:00
|
|
|
|
// Increase timeout due to unpredictable I/O on CI services
|
2020-02-09 12:21:45 +00:00
|
|
|
|
this.timeout(util.isRunningOnCI() ? 25000 : 5000);
|
|
|
|
|
this.slow(300);
|
2017-11-27 23:47:19 +00:00
|
|
|
|
|
2019-12-19 11:40:32 +00:00
|
|
|
|
const loremIpsum = `Lorem ipsum dolor sit amet, consectetur adipiscing elit.\
|
|
|
|
|
Vivamus at pretium mauris. Aenean eu orci id erat pulvinar\
|
|
|
|
|
commodo cursus ac augue. Ut dui quam, tempus ac felis et,\
|
|
|
|
|
efficitur auctor nisl. Sed semper sit amet metus eu fringilla.\
|
|
|
|
|
Vivamus vitae ligula quis eros rutrum tristique. Suspendisse\
|
|
|
|
|
luctus molestie tortor, in finibus nulla rutrum quis. Proin\
|
|
|
|
|
congue ut elit eget congue. Nam pretium blandit nibh nec laoreet.\
|
|
|
|
|
Suspendisse vehicula turpis urna, sit amet molestie diam dapibus in.\
|
|
|
|
|
Vivamus bibendum vulputate tincidunt. Sed vitae ligula felis.`;
|
|
|
|
|
|
2017-12-09 23:56:05 +00:00
|
|
|
|
let app;
|
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
beforeEach(function (done) {
|
2017-12-09 23:56:05 +00:00
|
|
|
|
app = util.createWebserver();
|
2020-03-21 20:55:36 +00:00
|
|
|
|
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
|
|
|
|
});
|
2023-06-25 16:34:23 +00:00
|
|
|
|
this.connection = app.listen(0, "127.0.0.1", () => {
|
2019-10-04 11:19:04 +00:00
|
|
|
|
this.port = this.connection.address().port;
|
2023-06-25 16:34:23 +00:00
|
|
|
|
this.host = this.connection.address().address;
|
2019-10-04 11:19:04 +00:00
|
|
|
|
done();
|
|
|
|
|
});
|
2015-09-30 22:39:57 +00:00
|
|
|
|
|
2023-06-25 16:34:23 +00:00
|
|
|
|
this._makeUrl = (_path: string): string => `http://${this.host}:${this.port}/${_path}`;
|
|
|
|
|
|
2015-09-30 22:39:57 +00:00
|
|
|
|
this.irc = util.createClient();
|
|
|
|
|
this.network = util.createNetwork();
|
2017-07-06 15:33:09 +00:00
|
|
|
|
|
2022-05-01 19:12:39 +00:00
|
|
|
|
Config.values.prefetchStorage = false;
|
2015-09-30 22:39:57 +00:00
|
|
|
|
});
|
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
afterEach(function (done) {
|
2017-12-09 23:56:05 +00:00
|
|
|
|
this.connection.close(done);
|
|
|
|
|
});
|
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
it("should be able to fetch basic information about URLs", function (done) {
|
2023-06-25 16:34:23 +00:00
|
|
|
|
const url = this._makeUrl("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
|
|
|
|
});
|
|
|
|
|
|
2020-07-22 15:28:12 +00:00
|
|
|
|
link(this.irc, this.network.channels[0], message, message.text);
|
2015-09-30 22:39:57 +00:00
|
|
|
|
|
2019-07-17 09:33:59 +00:00
|
|
|
|
expect(message.previews).to.deep.equal([
|
|
|
|
|
{
|
|
|
|
|
body: "",
|
|
|
|
|
head: "",
|
|
|
|
|
link: url,
|
|
|
|
|
thumb: "",
|
2019-08-09 20:20:08 +00:00
|
|
|
|
size: -1,
|
2019-07-17 09:33:59 +00:00
|
|
|
|
type: "loading",
|
2019-12-23 10:26:57 +00:00
|
|
|
|
shown: null,
|
2019-07-17 09:33:59 +00:00
|
|
|
|
},
|
|
|
|
|
]);
|
2017-07-21 05:28:51 +00:00
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
app.get("/basic", function (req, res) {
|
2019-07-17 09:33:59 +00:00
|
|
|
|
res.send(
|
|
|
|
|
"<title>test title</title><meta name='description' content='simple description'>"
|
|
|
|
|
);
|
2017-06-26 09:01:55 +00:00
|
|
|
|
});
|
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
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();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
it("should be able to display body for text/plain", function (done) {
|
2023-06-25 16:34:23 +00:00
|
|
|
|
const url = this._makeUrl("basic-text");
|
2019-12-19 11:40:32 +00:00
|
|
|
|
const message = this.irc.createMessage({
|
|
|
|
|
text: url,
|
|
|
|
|
});
|
|
|
|
|
|
2020-07-22 15:28:12 +00:00
|
|
|
|
link(this.irc, this.network.channels[0], message, message.text);
|
2019-12-19 11:40:32 +00:00
|
|
|
|
|
|
|
|
|
expect(message.previews).to.deep.equal([
|
|
|
|
|
{
|
|
|
|
|
body: "",
|
|
|
|
|
head: "",
|
|
|
|
|
link: url,
|
|
|
|
|
thumb: "",
|
|
|
|
|
size: -1,
|
|
|
|
|
type: "loading",
|
2019-12-23 10:26:57 +00:00
|
|
|
|
shown: null,
|
2019-12-19 11:40:32 +00:00
|
|
|
|
},
|
|
|
|
|
]);
|
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
app.get("/basic-text", function (req, res) {
|
2019-12-19 11:40:32 +00:00
|
|
|
|
res.type("text").send(loremIpsum);
|
|
|
|
|
});
|
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
this.irc.once("msg:preview", function (data) {
|
2019-12-19 11:40:32 +00:00
|
|
|
|
expect(data.preview.type).to.equal("link");
|
|
|
|
|
expect(data.preview.head).to.equal("Untitled page");
|
|
|
|
|
expect(data.preview.body).to.equal(loremIpsum.substring(0, 300));
|
|
|
|
|
expect(data.preview.body).to.have.length(300);
|
|
|
|
|
expect(data.preview.link).to.equal(url);
|
|
|
|
|
|
|
|
|
|
expect(message.previews).to.deep.equal([data.preview]);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
it("should truncate head and body", function (done) {
|
2023-06-25 16:34:23 +00:00
|
|
|
|
const url = this._makeUrl("truncate");
|
2019-12-19 11:40:32 +00:00
|
|
|
|
const message = this.irc.createMessage({
|
|
|
|
|
text: url,
|
|
|
|
|
});
|
|
|
|
|
|
2020-07-22 15:28:12 +00:00
|
|
|
|
link(this.irc, this.network.channels[0], message, message.text);
|
2019-12-19 11:40:32 +00:00
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
app.get("/truncate", function (req, res) {
|
2019-12-19 11:40:32 +00:00
|
|
|
|
res.send(
|
|
|
|
|
`<title>${loremIpsum}</title><meta name='description' content='${loremIpsum}'>`
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
this.irc.once("msg:preview", function (data) {
|
2019-12-19 11:40:32 +00:00
|
|
|
|
expect(data.preview.type).to.equal("link");
|
|
|
|
|
expect(data.preview.head).to.equal(loremIpsum.substring(0, 100));
|
|
|
|
|
expect(data.preview.body).to.equal(loremIpsum.substring(0, 300));
|
|
|
|
|
expect(data.preview.link).to.equal(url);
|
|
|
|
|
|
|
|
|
|
expect(message.previews).to.deep.equal([data.preview]);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
it("should prefer og:title over title", function (done) {
|
2017-06-26 09:01:55 +00:00
|
|
|
|
const message = this.irc.createMessage({
|
2023-06-25 16:34:23 +00:00
|
|
|
|
text: this._makeUrl("basic-og"),
|
2017-06-26 09:01:55 +00:00
|
|
|
|
});
|
|
|
|
|
|
2020-07-22 15:28:12 +00:00
|
|
|
|
link(this.irc, this.network.channels[0], message, message.text);
|
2017-06-26 09:01:55 +00:00
|
|
|
|
|
2020-03-21 20:55:36 +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'>");
|
|
|
|
|
});
|
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
this.irc.once("msg:preview", function (data) {
|
2018-06-11 08:32:32 +00:00
|
|
|
|
expect(data.preview.head).to.equal("opengraph test");
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
it("should find only the first matching tag", function (done) {
|
2018-06-11 08:32:32 +00:00
|
|
|
|
const message = this.irc.createMessage({
|
2023-06-25 16:34:23 +00:00
|
|
|
|
text: this._makeUrl("duplicate-tags"),
|
2018-06-11 08:32:32 +00:00
|
|
|
|
});
|
|
|
|
|
|
2020-07-22 15:28:12 +00:00
|
|
|
|
link(this.irc, this.network.channels[0], message, message.text);
|
2018-06-11 08:32:32 +00:00
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
app.get("/duplicate-tags", function (req, res) {
|
2019-07-17 09:33:59 +00:00
|
|
|
|
res.send(
|
|
|
|
|
"<title>test</title><title>magnifying glass icon</title><meta name='description' content='desc1'><meta name='description' content='desc2'>"
|
|
|
|
|
);
|
2018-06-11 08:32:32 +00:00
|
|
|
|
});
|
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
this.irc.once("msg:preview", function (data) {
|
2018-06-11 08:32:32 +00:00
|
|
|
|
expect(data.preview.head).to.equal("test");
|
|
|
|
|
expect(data.preview.body).to.equal("desc1");
|
2017-06-26 09:01:55 +00:00
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
it("should prefer og:description over description", function (done) {
|
2017-06-26 09:01:55 +00:00
|
|
|
|
const message = this.irc.createMessage({
|
2023-06-25 16:34:23 +00:00
|
|
|
|
text: this._makeUrl("description-og"),
|
2017-06-26 09:01:55 +00:00
|
|
|
|
});
|
|
|
|
|
|
2020-07-22 15:28:12 +00:00
|
|
|
|
link(this.irc, this.network.channels[0], message, message.text);
|
2017-06-26 09:01:55 +00:00
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
app.get("/description-og", function (req, res) {
|
2019-07-17 09:33:59 +00:00
|
|
|
|
res.send(
|
|
|
|
|
"<meta name='description' content='simple description'><meta property='og:description' content='opengraph description'>"
|
|
|
|
|
);
|
2017-06-26 09:01:55 +00:00
|
|
|
|
});
|
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
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();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
it("should find og:image with full url", function (done) {
|
2017-06-26 09:01:55 +00:00
|
|
|
|
const message = this.irc.createMessage({
|
2023-06-25 16:34:23 +00:00
|
|
|
|
text: this._makeUrl("thumb"),
|
2017-06-26 09:01:55 +00:00
|
|
|
|
});
|
|
|
|
|
|
2020-07-22 15:28:12 +00:00
|
|
|
|
link(this.irc, this.network.channels[0], message, message.text);
|
2017-06-26 09:01:55 +00:00
|
|
|
|
|
2023-06-25 16:34:23 +00:00
|
|
|
|
const url = this._makeUrl("real-test-image.png");
|
2020-03-21 20:55:36 +00:00
|
|
|
|
app.get("/thumb", function (req, res) {
|
2023-06-25 16:34:23 +00:00
|
|
|
|
res.send(`<title>Google</title><meta property='og:image' content='${url}'>`);
|
2017-06-26 09:01:55 +00:00
|
|
|
|
});
|
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
this.irc.once("msg:preview", function (data) {
|
2017-07-06 06:16:01 +00:00
|
|
|
|
expect(data.preview.head).to.equal("Google");
|
2023-06-25 16:34:23 +00:00
|
|
|
|
expect(data.preview.thumb).to.equal(url);
|
2017-06-26 09:01:55 +00:00
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2020-07-12 02:04:04 +00:00
|
|
|
|
describe("test disableMediaPreview", function () {
|
|
|
|
|
beforeEach(function (done) {
|
2022-05-01 19:12:39 +00:00
|
|
|
|
Config.values.disableMediaPreview = true;
|
2020-07-12 02:04:04 +00:00
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
afterEach(function (done) {
|
2022-05-01 19:12:39 +00:00
|
|
|
|
Config.values.disableMediaPreview = false;
|
2020-07-12 02:04:04 +00:00
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
it("should ignore og:image if disableMediaPreview", function (done) {
|
|
|
|
|
app.get("/nonexistent-test-image.png", function () {
|
|
|
|
|
throw "Should not fetch image";
|
|
|
|
|
});
|
|
|
|
|
|
2023-06-25 16:34:23 +00:00
|
|
|
|
const invalid_url = this._makeUrl("nonexistent-test-image.png");
|
2020-07-12 02:04:04 +00:00
|
|
|
|
app.get("/thumb", function (req, res) {
|
2023-06-25 16:34:23 +00:00
|
|
|
|
res.send(`<title>Google</title><meta property='og:image' content='${invalid_url}>`);
|
2020-07-12 02:04:04 +00:00
|
|
|
|
});
|
|
|
|
|
const message = this.irc.createMessage({
|
2023-06-25 16:34:23 +00:00
|
|
|
|
text: this._makeUrl("thumb"),
|
2020-07-12 02:04:04 +00:00
|
|
|
|
});
|
|
|
|
|
|
2020-07-22 15:28:12 +00:00
|
|
|
|
link(this.irc, this.network.channels[0], message, message.text);
|
2020-07-12 02:04:04 +00:00
|
|
|
|
|
|
|
|
|
this.irc.once("msg:preview", function (data) {
|
|
|
|
|
expect(data.preview.head).to.equal("Google");
|
|
|
|
|
expect(data.preview.type).to.equal("link");
|
|
|
|
|
expect(data.preview.thumb).to.equal("");
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
it("should ignore og:video if disableMediaPreview", function (done) {
|
2023-06-25 16:34:23 +00:00
|
|
|
|
app.get("/nonexistent-video.mp4", function () {
|
2020-07-12 02:04:04 +00:00
|
|
|
|
throw "Should not fetch video";
|
|
|
|
|
});
|
|
|
|
|
|
2023-06-25 16:34:23 +00:00
|
|
|
|
const invalid_url = this._makeUrl("nonexistent-video.mp4");
|
2020-07-12 02:04:04 +00:00
|
|
|
|
app.get("/thumb", function (req, res) {
|
|
|
|
|
res.send(
|
2023-06-25 16:34:23 +00:00
|
|
|
|
`<title>Google</title><meta property='og:video:type' content='video/mp4'><meta property='og:video' content='${invalid_url}'>`
|
2020-07-12 02:04:04 +00:00
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
const message = this.irc.createMessage({
|
2023-06-25 16:34:23 +00:00
|
|
|
|
text: this._makeUrl("thumb"),
|
2020-07-12 02:04:04 +00:00
|
|
|
|
});
|
|
|
|
|
|
2020-07-22 15:28:12 +00:00
|
|
|
|
link(this.irc, this.network.channels[0], message, message.text);
|
2020-07-12 02:04:04 +00:00
|
|
|
|
|
|
|
|
|
this.irc.once("msg:preview", function (data) {
|
|
|
|
|
expect(data.preview.head).to.equal("Google");
|
|
|
|
|
expect(data.preview.type).to.equal("link");
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
it("should find image_src", function (done) {
|
2017-06-26 09:01:55 +00:00
|
|
|
|
const message = this.irc.createMessage({
|
2023-06-25 16:34:23 +00:00
|
|
|
|
text: this._makeUrl("thumb-image-src"),
|
2017-06-26 09:01:55 +00:00
|
|
|
|
});
|
|
|
|
|
|
2020-07-22 15:28:12 +00:00
|
|
|
|
link(this.irc, this.network.channels[0], message, message.text);
|
2017-06-26 09:01:55 +00:00
|
|
|
|
|
2023-06-25 16:34:23 +00:00
|
|
|
|
const url = this._makeUrl("real-test-image.png");
|
2020-03-21 20:55:36 +00:00
|
|
|
|
app.get("/thumb-image-src", function (req, res) {
|
2023-06-25 16:34:23 +00:00
|
|
|
|
res.send(`<link rel='image_src' href='${url}'>`);
|
2017-06-26 09:01:55 +00:00
|
|
|
|
});
|
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
this.irc.once("msg:preview", function (data) {
|
2023-06-25 16:34:23 +00:00
|
|
|
|
expect(data.preview.thumb).to.equal(url);
|
2017-08-13 09:58:27 +00:00
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
it("should correctly resolve relative protocol", function (done) {
|
2017-08-13 09:58:27 +00:00
|
|
|
|
const message = this.irc.createMessage({
|
2023-06-25 16:34:23 +00:00
|
|
|
|
text: this._makeUrl("thumb-image-src"),
|
2017-08-13 09:58:27 +00:00
|
|
|
|
});
|
|
|
|
|
|
2020-07-22 15:28:12 +00:00
|
|
|
|
link(this.irc, this.network.channels[0], message, message.text);
|
2017-08-13 09:58:27 +00:00
|
|
|
|
|
2023-06-25 16:34:23 +00:00
|
|
|
|
const real_image_url = this._makeUrl("real-test-image.png");
|
2020-03-21 20:55:36 +00:00
|
|
|
|
app.get("/thumb-image-src", function (req, res) {
|
2023-06-25 16:34:23 +00:00
|
|
|
|
res.send(`<link rel='image_src' href='${real_image_url}'>`);
|
2017-08-13 09:58:27 +00:00
|
|
|
|
});
|
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
this.irc.once("msg:preview", function (data) {
|
2023-06-25 16:34:23 +00:00
|
|
|
|
expect(data.preview.thumb).to.equal(real_image_url);
|
2017-08-13 09:58:27 +00:00
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
it("should resolve url correctly for relative url", function (done) {
|
2023-06-25 16:34:23 +00:00
|
|
|
|
const relative_thumb_url = this._makeUrl("relative-thumb");
|
2017-08-13 09:58:27 +00:00
|
|
|
|
const message = this.irc.createMessage({
|
2023-06-25 16:34:23 +00:00
|
|
|
|
text: relative_thumb_url,
|
2017-08-13 09:58:27 +00:00
|
|
|
|
});
|
|
|
|
|
|
2020-07-22 15:28:12 +00:00
|
|
|
|
link(this.irc, this.network.channels[0], message, message.text);
|
2017-08-13 09:58:27 +00:00
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
app.get("/relative-thumb", function (req, res) {
|
2019-07-17 09:33:59 +00:00
|
|
|
|
res.send(
|
|
|
|
|
"<title>test relative image</title><meta property='og:image' content='/real-test-image.png'>"
|
|
|
|
|
);
|
2017-08-13 09:58:27 +00:00
|
|
|
|
});
|
2023-06-25 16:34:23 +00:00
|
|
|
|
const real_image_url = this._makeUrl("real-test-image.png");
|
2017-08-13 09:58:27 +00:00
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
this.irc.once("msg:preview", function (data) {
|
2023-06-25 16:34:23 +00:00
|
|
|
|
expect(data.preview.thumb).to.equal(real_image_url);
|
2017-08-13 09:58:27 +00:00
|
|
|
|
expect(data.preview.head).to.equal("test relative image");
|
2023-06-25 16:34:23 +00:00
|
|
|
|
expect(data.preview.link).to.equal(relative_thumb_url);
|
2017-06-26 09:01:55 +00:00
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
it("should send untitled page if there is a thumbnail", function (done) {
|
2023-06-25 16:34:23 +00:00
|
|
|
|
const real_image_url = this._makeUrl("real-test-image.png");
|
|
|
|
|
const thumb_no_title_url = this._makeUrl("thumb-no-title");
|
2017-06-26 09:01:55 +00:00
|
|
|
|
const message = this.irc.createMessage({
|
2023-06-25 16:34:23 +00:00
|
|
|
|
text: thumb_no_title_url,
|
2017-06-26 09:01:55 +00:00
|
|
|
|
});
|
|
|
|
|
|
2020-07-22 15:28:12 +00:00
|
|
|
|
link(this.irc, this.network.channels[0], message, message.text);
|
2017-06-26 09:01:55 +00:00
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
app.get("/thumb-no-title", function (req, res) {
|
2023-06-25 16:34:23 +00:00
|
|
|
|
res.send(`<meta property='og:image' content='${real_image_url}'>`);
|
2017-06-26 09:01:55 +00:00
|
|
|
|
});
|
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
this.irc.once("msg:preview", function (data) {
|
2017-07-06 06:16:01 +00:00
|
|
|
|
expect(data.preview.head).to.equal("Untitled page");
|
2023-06-25 16:34:23 +00:00
|
|
|
|
expect(data.preview.thumb).to.equal(real_image_url);
|
|
|
|
|
expect(data.preview.link).to.equal(thumb_no_title_url);
|
2017-06-26 09:01:55 +00:00
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
it("should send untitled page if there is body", function (done) {
|
2023-06-25 16:34:23 +00:00
|
|
|
|
const body_no_title_url = this._makeUrl("body-no-title");
|
2019-12-19 11:40:32 +00:00
|
|
|
|
const message = this.irc.createMessage({
|
2023-06-25 16:34:23 +00:00
|
|
|
|
text: body_no_title_url,
|
2019-12-19 11:40:32 +00:00
|
|
|
|
});
|
|
|
|
|
|
2020-07-22 15:28:12 +00:00
|
|
|
|
link(this.irc, this.network.channels[0], message, message.text);
|
2019-12-19 11:40:32 +00:00
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
app.get("/body-no-title", function (req, res) {
|
2019-12-19 11:40:32 +00:00
|
|
|
|
res.send("<meta name='description' content='hello world'>");
|
|
|
|
|
});
|
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
this.irc.once("msg:preview", function (data) {
|
2019-12-19 11:40:32 +00:00
|
|
|
|
expect(data.preview.head).to.equal("Untitled page");
|
|
|
|
|
expect(data.preview.body).to.equal("hello world");
|
|
|
|
|
expect(data.preview.thumb).to.equal("");
|
2023-06-25 16:34:23 +00:00
|
|
|
|
expect(data.preview.link).to.equal(body_no_title_url);
|
2019-12-19 11:40:32 +00:00
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
it("should not send thumbnail if image is 404", function (done) {
|
2023-06-25 16:34:23 +00:00
|
|
|
|
const thumb_404_url = this._makeUrl("thumb-404");
|
2017-06-26 09:01:55 +00:00
|
|
|
|
const message = this.irc.createMessage({
|
2023-06-25 16:34:23 +00:00
|
|
|
|
text: thumb_404_url,
|
2017-06-26 09:01:55 +00:00
|
|
|
|
});
|
|
|
|
|
|
2020-07-22 15:28:12 +00:00
|
|
|
|
link(this.irc, this.network.channels[0], message, message.text);
|
2017-06-26 09:01:55 +00:00
|
|
|
|
|
2023-06-25 16:34:23 +00:00
|
|
|
|
const invalid_url = this._makeUrl("this-image-does-not-exist.png");
|
2020-03-21 20:55:36 +00:00
|
|
|
|
app.get("/thumb-404", function (req, res) {
|
2023-06-25 16:34:23 +00:00
|
|
|
|
res.send(`<title>404 image</title><meta property='og:image' content='${invalid_url}>`);
|
2015-09-30 22:39:57 +00:00
|
|
|
|
});
|
|
|
|
|
|
2020-03-21 20:55:36 +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");
|
2023-06-25 16:34:23 +00:00
|
|
|
|
expect(data.preview.link).to.equal(thumb_404_url);
|
2017-07-06 06:16:01 +00:00
|
|
|
|
expect(data.preview.thumb).to.be.empty;
|
2017-06-26 09:01:55 +00:00
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
it("should send image preview", function (done) {
|
2023-06-25 16:34:23 +00:00
|
|
|
|
const real_image_url = this._makeUrl("real-test-image.png");
|
2017-06-26 09:01:55 +00:00
|
|
|
|
const message = this.irc.createMessage({
|
2023-06-25 16:34:23 +00:00
|
|
|
|
text: real_image_url,
|
2017-06-26 09:01:55 +00:00
|
|
|
|
});
|
|
|
|
|
|
2020-07-22 15:28:12 +00:00
|
|
|
|
link(this.irc, this.network.channels[0], message, message.text);
|
2017-06-26 09:01:55 +00:00
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
this.irc.once("msg:preview", function (data) {
|
2017-07-06 06:16:01 +00:00
|
|
|
|
expect(data.preview.type).to.equal("image");
|
2023-06-25 16:34:23 +00:00
|
|
|
|
expect(data.preview.link).to.equal(real_image_url);
|
|
|
|
|
expect(data.preview.thumb).to.equal(real_image_url);
|
2019-08-09 20:20:08 +00:00
|
|
|
|
expect(data.preview.size).to.equal(960);
|
2015-09-30 22:39:57 +00:00
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
2017-07-06 06:16:01 +00:00
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
it("should load multiple URLs found in messages", function (done) {
|
2023-06-25 16:34:23 +00:00
|
|
|
|
const url_one = this._makeUrl("one");
|
|
|
|
|
const url_two = this._makeUrl("two");
|
2017-07-06 06:16:01 +00:00
|
|
|
|
const message = this.irc.createMessage({
|
2023-06-25 16:34:23 +00:00
|
|
|
|
text: `${url_one} ${url_two}`,
|
2017-07-06 06:16:01 +00:00
|
|
|
|
});
|
|
|
|
|
|
2020-07-22 15:28:12 +00:00
|
|
|
|
link(this.irc, this.network.channels[0], message, message.text);
|
2017-07-06 06:16:01 +00:00
|
|
|
|
|
2019-07-17 09:33:59 +00:00
|
|
|
|
expect(message.previews).to.eql([
|
|
|
|
|
{
|
|
|
|
|
body: "",
|
|
|
|
|
head: "",
|
2023-06-25 16:34:23 +00:00
|
|
|
|
link: url_one,
|
2019-07-17 09:33:59 +00:00
|
|
|
|
thumb: "",
|
2019-08-09 20:20:08 +00:00
|
|
|
|
size: -1,
|
2019-07-17 09:33:59 +00:00
|
|
|
|
type: "loading",
|
2019-12-23 10:26:57 +00:00
|
|
|
|
shown: null,
|
2019-07-17 09:33:59 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
body: "",
|
|
|
|
|
head: "",
|
2023-06-25 16:34:23 +00:00
|
|
|
|
link: url_two,
|
2019-07-17 09:33:59 +00:00
|
|
|
|
thumb: "",
|
2019-08-09 20:20:08 +00:00
|
|
|
|
size: -1,
|
2019-07-17 09:33:59 +00:00
|
|
|
|
type: "loading",
|
2019-12-23 10:26:57 +00:00
|
|
|
|
shown: null,
|
2019-07-17 09:33:59 +00:00
|
|
|
|
},
|
|
|
|
|
]);
|
2017-07-19 05:26:29 +00:00
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
app.get("/one", function (req, res) {
|
2017-07-06 06:16:01 +00:00
|
|
|
|
res.send("<title>first title</title>");
|
|
|
|
|
});
|
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
app.get("/two", function (req, res) {
|
2017-07-06 06:16:01 +00:00
|
|
|
|
res.send("<title>second title</title>");
|
|
|
|
|
});
|
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
|
const previews: LinkPreview[] = [];
|
2017-07-06 06:16:01 +00:00
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
this.irc.on("msg:preview", function (data) {
|
2023-06-25 16:34:23 +00:00
|
|
|
|
if (data.preview.link === url_one) {
|
2017-07-06 06:16:01 +00:00
|
|
|
|
expect(data.preview.head).to.equal("first title");
|
2017-07-21 05:28:51 +00:00
|
|
|
|
previews[0] = data.preview;
|
2023-06-25 16:34:23 +00:00
|
|
|
|
} else if (data.preview.link === url_two) {
|
2017-07-06 06:16:01 +00:00
|
|
|
|
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
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
it("should use client's preferred language as Accept-Language header", function (done) {
|
2017-12-28 13:34:49 +00:00
|
|
|
|
const language = "sv,en-GB;q=0.9,en;q=0.8";
|
2019-07-16 09:51:22 +00:00
|
|
|
|
this.irc.config.browser.language = language;
|
2017-12-28 13:34:49 +00:00
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
app.get("/language-check", function (req, res) {
|
2017-12-28 13:34:49 +00:00
|
|
|
|
expect(req.headers["accept-language"]).to.equal(language);
|
|
|
|
|
res.send();
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const message = this.irc.createMessage({
|
2023-06-25 16:34:23 +00:00
|
|
|
|
text: this._makeUrl("language-check"),
|
2017-12-28 13:34:49 +00:00
|
|
|
|
});
|
|
|
|
|
|
2020-07-22 15:28:12 +00:00
|
|
|
|
link(this.irc, this.network.channels[0], message, message.text);
|
2017-12-28 13:34:49 +00:00
|
|
|
|
});
|
2018-03-08 17:43:39 +00:00
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
it("should send accept text/html for initial request", function (done) {
|
|
|
|
|
app.get("/accept-header-html", function (req, res) {
|
2019-07-17 09:33:59 +00:00
|
|
|
|
expect(req.headers.accept).to.equal(
|
|
|
|
|
"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
|
|
|
|
|
);
|
2018-03-23 14:50:52 +00:00
|
|
|
|
res.send();
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const message = this.irc.createMessage({
|
2023-06-25 16:34:23 +00:00
|
|
|
|
text: this._makeUrl("accept-header-html"),
|
2018-03-23 14:50:52 +00:00
|
|
|
|
});
|
|
|
|
|
|
2020-07-22 15:28:12 +00:00
|
|
|
|
link(this.irc, this.network.channels[0], message, message.text);
|
2018-03-23 14:50:52 +00:00
|
|
|
|
});
|
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
it("should send accept */* for meta image", function (done) {
|
2023-06-25 16:34:23 +00:00
|
|
|
|
const msg_url = this._makeUrl("msg");
|
|
|
|
|
const image_url = this._makeUrl("image-url.png");
|
|
|
|
|
app.get("/msg", function (req, res) {
|
|
|
|
|
res.send(`<title>404 image</title><meta property='og:image' content='${image_url}'>`);
|
2018-03-23 14:50:52 +00:00
|
|
|
|
});
|
|
|
|
|
|
2023-06-25 16:34:23 +00:00
|
|
|
|
app.get("/image-url.png", function (req, res) {
|
2018-03-23 14:50:52 +00:00
|
|
|
|
expect(req.headers.accept).to.equal("*/*");
|
|
|
|
|
res.send();
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const message = this.irc.createMessage({
|
2023-06-25 16:34:23 +00:00
|
|
|
|
text: msg_url,
|
2018-03-23 14:50:52 +00:00
|
|
|
|
});
|
|
|
|
|
|
2020-07-22 15:28:12 +00:00
|
|
|
|
link(this.irc, this.network.channels[0], message, message.text);
|
2018-03-23 14:50:52 +00:00
|
|
|
|
});
|
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
it("should not add slash to url", function (done) {
|
2023-06-25 16:34:23 +00:00
|
|
|
|
const url = this._makeUrl("").slice(0, -1); // trim the trailing slash for testing
|
2018-03-13 19:19:28 +00:00
|
|
|
|
const message = this.irc.createMessage({
|
2023-06-25 16:34:23 +00:00
|
|
|
|
text: url,
|
2018-03-13 19:19:28 +00:00
|
|
|
|
});
|
|
|
|
|
|
2020-07-22 15:28:12 +00:00
|
|
|
|
link(this.irc, this.network.channels[0], message, message.text);
|
2018-03-13 19:19:28 +00:00
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
this.irc.once("msg:preview", function (data) {
|
2023-06-25 16:34:23 +00:00
|
|
|
|
expect(data.preview.link).to.equal(url);
|
2018-03-13 19:19:28 +00:00
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
it("should work on non-ASCII urls", function (done) {
|
2023-06-25 16:34:23 +00:00
|
|
|
|
const links = [
|
|
|
|
|
"unicode/ıoı-test",
|
|
|
|
|
"unicode/русский-текст-test",
|
|
|
|
|
"unicode/🙈-emoji-test",
|
|
|
|
|
"unicodeq/?q=ıoı-test",
|
|
|
|
|
"unicodeq/?q=русский-текст-test",
|
|
|
|
|
"unicodeq/?q=🙈-emoji-test",
|
|
|
|
|
].map((p) => this._makeUrl(p) as string);
|
2018-03-08 17:43:39 +00:00
|
|
|
|
const message = this.irc.createMessage({
|
2023-06-25 16:34:23 +00:00
|
|
|
|
text: links.join(" "),
|
2018-03-08 17:43:39 +00:00
|
|
|
|
});
|
|
|
|
|
|
2020-07-22 15:28:12 +00:00
|
|
|
|
link(this.irc, this.network.channels[0], message, message.text);
|
2018-03-08 17:43:39 +00:00
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
app.get("/unicode/:q", function (req, res) {
|
2018-03-08 17:43:39 +00:00
|
|
|
|
res.send(`<title>${req.params.q}</title>`);
|
|
|
|
|
});
|
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
app.get("/unicodeq/", function (req, res) {
|
2018-03-08 17:43:39 +00:00
|
|
|
|
res.send(`<title>${req.query.q}</title>`);
|
|
|
|
|
});
|
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
|
const previews: LinkPreview[] = [];
|
2018-03-08 17:43:39 +00:00
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
this.irc.on("msg:preview", function (data) {
|
2018-03-08 17:43:39 +00:00
|
|
|
|
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) {
|
2022-06-19 00:25:21 +00:00
|
|
|
|
expect(
|
|
|
|
|
message.previews.map((preview) => preview.link as LinkPreview)
|
|
|
|
|
).to.have.members(previews);
|
2018-03-08 17:43:39 +00:00
|
|
|
|
done();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
2018-04-27 11:11:54 +00:00
|
|
|
|
|
2020-08-04 17:15:50 +00:00
|
|
|
|
it("should not fetch links without a schema", function () {
|
2019-10-04 11:19:04 +00:00
|
|
|
|
const port = this.port;
|
2023-06-25 16:34:23 +00:00
|
|
|
|
const host = this.host;
|
2018-04-27 11:11:54 +00:00
|
|
|
|
const message = this.irc.createMessage({
|
2023-06-25 16:34:23 +00:00
|
|
|
|
text: `//${host}:${port} ${host}:${port} //${host}:${port}/test ${host}:${port}/test`,
|
2018-04-27 11:11:54 +00:00
|
|
|
|
});
|
|
|
|
|
|
2020-07-22 15:28:12 +00:00
|
|
|
|
link(this.irc, this.network.channels[0], message, message.text);
|
2018-04-27 11:11:54 +00:00
|
|
|
|
|
2020-08-04 17:15:50 +00:00
|
|
|
|
expect(message.previews).to.be.empty;
|
2018-04-27 11:11:54 +00:00
|
|
|
|
});
|
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
it("should de-duplicate links", function (done) {
|
2019-10-04 11:19:04 +00:00
|
|
|
|
const port = this.port;
|
2023-06-25 16:34:23 +00:00
|
|
|
|
const host = this.host;
|
2018-04-27 13:27:26 +00:00
|
|
|
|
const message = this.irc.createMessage({
|
2023-06-25 16:34:23 +00:00
|
|
|
|
text: `//${host}:${port}/ http://${host}:${port}/ http://${host}:${port}/`,
|
2018-04-27 13:27:26 +00:00
|
|
|
|
});
|
|
|
|
|
|
2020-07-22 15:28:12 +00:00
|
|
|
|
link(this.irc, this.network.channels[0], message, message.text);
|
2018-04-27 13:27:26 +00:00
|
|
|
|
|
2023-06-25 16:34:23 +00:00
|
|
|
|
const root_url = this._makeUrl("");
|
2019-07-17 09:33:59 +00:00
|
|
|
|
expect(message.previews).to.deep.equal([
|
|
|
|
|
{
|
|
|
|
|
type: "loading",
|
|
|
|
|
head: "",
|
|
|
|
|
body: "",
|
|
|
|
|
thumb: "",
|
2019-08-09 20:20:08 +00:00
|
|
|
|
size: -1,
|
2023-06-25 16:34:23 +00:00
|
|
|
|
link: root_url,
|
2019-12-23 10:26:57 +00:00
|
|
|
|
shown: null,
|
2019-07-17 09:33:59 +00:00
|
|
|
|
},
|
|
|
|
|
]);
|
2018-04-27 13:27:26 +00:00
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
this.irc.once("msg:preview", function (data) {
|
2023-06-25 16:34:23 +00:00
|
|
|
|
expect(data.preview.link).to.equal(root_url);
|
2019-12-23 10:15:23 +00:00
|
|
|
|
expect(data.preview.type).to.equal("error");
|
2018-04-27 13:27:26 +00:00
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
it("should not try to fetch links with wrong protocol", function () {
|
2018-04-27 11:11:54 +00:00
|
|
|
|
const message = this.irc.createMessage({
|
|
|
|
|
text: "ssh://example.com ftp://example.com irc://example.com http:////////example.com",
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(message.previews).to.be.empty;
|
|
|
|
|
});
|
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
it("should not try to fetch links with username or password", function () {
|
2018-04-27 11:11:54 +00:00
|
|
|
|
const message = this.irc.createMessage({
|
2022-02-09 23:27:34 +00:00
|
|
|
|
text: "http://root:'some%pass'@hostname/database http://a:%p@c http://a:%p@example.com http://test@example.com",
|
2018-04-27 11:11:54 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(message.previews).to.be.empty;
|
|
|
|
|
});
|
2018-06-10 17:32:52 +00:00
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
it("should fetch same link only once at the same time", function (done) {
|
2018-06-10 17:32:52 +00:00
|
|
|
|
const message = this.irc.createMessage({
|
2023-06-25 16:34:23 +00:00
|
|
|
|
text: this._makeUrl("basic-og-once"),
|
2018-06-10 17:32:52 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
let requests = 0;
|
|
|
|
|
let responses = 0;
|
|
|
|
|
|
2019-07-16 09:51:22 +00:00
|
|
|
|
this.irc.config.browser.language = "very nice language";
|
2018-06-10 17:32:52 +00:00
|
|
|
|
|
2020-07-22 15:28:12 +00:00
|
|
|
|
link(this.irc, this.network.channels[0], message, message.text);
|
|
|
|
|
link(this.irc, this.network.channels[0], message, message.text);
|
|
|
|
|
process.nextTick(() => link(this.irc, this.network.channels[0], message, message.text));
|
2018-06-10 17:32:52 +00:00
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
app.get("/basic-og-once", function (req, res) {
|
2018-06-10 17:32:52 +00:00
|
|
|
|
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);
|
|
|
|
|
});
|
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
it("should fetch same link with different languages multiple times", function (done) {
|
2018-06-10 17:32:52 +00:00
|
|
|
|
const message = this.irc.createMessage({
|
2023-06-25 16:34:23 +00:00
|
|
|
|
text: this._makeUrl("basic-og-once-lang"),
|
2018-06-10 17:32:52 +00:00
|
|
|
|
});
|
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
|
const requests: string[] = [];
|
2018-06-10 17:32:52 +00:00
|
|
|
|
let responses = 0;
|
|
|
|
|
|
2019-07-16 09:51:22 +00:00
|
|
|
|
this.irc.config.browser.language = "first language";
|
2020-07-22 15:28:12 +00:00
|
|
|
|
link(this.irc, this.network.channels[0], message, message.text);
|
2018-06-10 17:32:52 +00:00
|
|
|
|
|
2018-07-06 09:29:21 +00:00
|
|
|
|
setTimeout(() => {
|
2019-07-16 09:51:22 +00:00
|
|
|
|
this.irc.config.browser.language = "second language";
|
2020-07-22 15:28:12 +00:00
|
|
|
|
link(this.irc, this.network.channels[0], message, message.text);
|
2018-07-06 09:29:21 +00:00
|
|
|
|
}, 100);
|
2018-06-10 17:32:52 +00:00
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
|
app.get("/basic-og-once-lang", function (req, res) {
|
2018-06-10 17:32:52 +00:00
|
|
|
|
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);
|
2019-07-17 09:33:59 +00:00
|
|
|
|
expect(requests).to.deep.equal(["first language", "second language"]);
|
2018-06-10 17:32:52 +00:00
|
|
|
|
done();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
this.irc.on("msg:preview", cb);
|
|
|
|
|
});
|
2014-11-17 20:14:28 +00:00
|
|
|
|
});
|