"use strict"; const fs = require("fs"); const path = require("path"); const crypto = require("crypto"); const expect = require("chai").expect; const util = require("../util"); const Helper = require("../../src/helper"); const link = require("../../src/plugins/irc-events/link.js"); describe("Image storage", function() { // Increase timeout due to unpredictable I/O on CI services this.timeout(process.env.CI ? 25000 : 5000); this.slow(200); const testImagePath = path.resolve(__dirname, "../../client/img/logo-grey-bg-120x120px.png"); const correctImageHash = crypto .createHash("sha256") .update(fs.readFileSync(testImagePath)) .digest("hex"); const correctImageURL = `storage/${correctImageHash.substring( 0, 2 )}/${correctImageHash.substring(2, 4)}/${correctImageHash.substring(4)}.png`; const testSvgPath = path.resolve(__dirname, "../../client/img/logo-grey-bg.svg"); const correctSvgHash = crypto .createHash("sha256") .update(fs.readFileSync(testSvgPath)) .digest("hex"); const correctSvgURL = `storage/${correctSvgHash.substring(0, 2)}/${correctSvgHash.substring( 2, 4 )}/${correctSvgHash.substring(4)}.svg`; before(function(done) { this.app = util.createWebserver(); this.app.get("/real-test-image.png", function(req, res) { res.sendFile(testImagePath); }); this.app.get("/logo.svg", function(req, res) { res.sendFile(testSvgPath); }); this.connection = this.app.listen(0, () => { this.port = this.connection.address().port; done(); }); }); after(function(done) { this.connection.close(done); }); beforeEach(function() { this.irc = util.createClient(); this.network = util.createNetwork(); Helper.config.prefetchStorage = true; }); afterEach(function() { Helper.config.prefetchStorage = false; }); it("should store the thumbnail", function(done) { const port = this.port; const message = this.irc.createMessage({ text: "http://localhost:" + port + "/thumb", }); link(this.irc, this.network.channels[0], message); this.app.get("/thumb", function(req, res) { res.send( "