diff --git a/packages/server/test/unit/blacklist_spec.js b/packages/server/test/unit/blacklist_spec.js index f9989705a6..5c40b2dddd 100644 --- a/packages/server/test/unit/blacklist_spec.js +++ b/packages/server/test/unit/blacklist_spec.js @@ -1,54 +1,53 @@ -/* - * decaffeinate suggestions: - * DS102: Remove unnecessary code created because of implicit returns - * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md - */ -require("../spec_helper"); +require('../spec_helper') -const blacklist = require(`${root}lib/util/blacklist`); +const blacklist = require(`${root}lib/util/blacklist`) const hosts = [ - "*.google.com", - "shop.apple.com", - "localhost:6666", - "adwords.com", - "*yahoo.com" -]; + '*.google.com', + 'shop.apple.com', + 'localhost:6666', + 'adwords.com', + '*yahoo.com', +] -const matchesStr = function(url, host, val) { - const m = blacklist.matches(url, host); - return expect(!!m).to.eq(val, `url: '${url}' did not pass`); -}; +const matchesStr = function (url, host, val) { + const m = blacklist.matches(url, host) -const matchesArray = function(url, val) { - const m = blacklist.matches(url, hosts); - return expect(!!m).to.eq(val, `url: '${url}' did not pass`); -}; + expect(!!m).to.eq(val, `url: '${url}' did not pass`) +} -const matchesHost = (url, host) => expect(blacklist.matches(url, hosts)).to.eq(host); +const matchesArray = function (url, val) { + const m = blacklist.matches(url, hosts) -describe("lib/util/blacklist", function() { - it("handles hosts, ports, wildcards", function() { - matchesArray("https://mail.google.com/foo", true); - matchesArray("https://shop.apple.com/bar", true); - matchesArray("http://localhost:6666/", true); - matchesArray("https://localhost:6666/", true); - matchesArray("https://adwords.com:443/", true); - matchesArray("http://adwords.com:80/quux", true); - matchesArray("https://yahoo.com:443/asdf", true); - matchesArray("http://mail.yahoo.com:443/asdf", true); + expect(!!m).to.eq(val, `url: '${url}' did not pass`) +} - matchesArray("https://buy.adwords.com:443/", false); - matchesArray("http://localhost:66667", false); - matchesArray("http://mac.apple.com/", false); +const matchesHost = (url, host) => { + expect(blacklist.matches(url, hosts)).to.eq(host) +} - matchesStr("https://localhost:6666/foo", "localhost:6666", true); - return matchesStr("https://localhost:6666/foo", "localhost:5555", false); - }); +describe('lib/util/blacklist', () => { + it('handles hosts, ports, wildcards', () => { + matchesArray('https://mail.google.com/foo', true) + matchesArray('https://shop.apple.com/bar', true) + matchesArray('http://localhost:6666/', true) + matchesArray('https://localhost:6666/', true) + matchesArray('https://adwords.com:443/', true) + matchesArray('http://adwords.com:80/quux', true) + matchesArray('https://yahoo.com:443/asdf', true) + matchesArray('http://mail.yahoo.com:443/asdf', true) - return it("returns the matched host", function() { - matchesHost("https://shop.apple.com:443/foo", "shop.apple.com"); - matchesHost("http://mail.yahoo.com:80/bar", "*yahoo.com"); - return matchesHost("https://localhost:6666/bar", "localhost:6666"); - }); -}); + matchesArray('https://buy.adwords.com:443/', false) + matchesArray('http://localhost:66667', false) + matchesArray('http://mac.apple.com/', false) + + matchesStr('https://localhost:6666/foo', 'localhost:6666', true) + matchesStr('https://localhost:6666/foo', 'localhost:5555', false) + }) + + it('returns the matched host', () => { + matchesHost('https://shop.apple.com:443/foo', 'shop.apple.com') + matchesHost('http://mail.yahoo.com:80/bar', '*yahoo.com') + matchesHost('https://localhost:6666/bar', 'localhost:6666') + }) +}) diff --git a/packages/server/test/unit/buffers_spec.js b/packages/server/test/unit/buffers_spec.js index 47c284473f..29885f7c15 100644 --- a/packages/server/test/unit/buffers_spec.js +++ b/packages/server/test/unit/buffers_spec.js @@ -1,78 +1,77 @@ -/* - * decaffeinate suggestions: - * DS102: Remove unnecessary code created because of implicit returns - * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md - */ -require("../spec_helper"); +require('../spec_helper') -const buffers = require(`${root}lib/util/buffers`); +const buffers = require(`${root}lib/util/buffers`) -describe("lib/util/buffers", function() { - beforeEach(() => buffers.reset()); +describe('lib/util/buffers', () => { + beforeEach(() => { + buffers.reset() + }) - afterEach(() => buffers.reset()); + afterEach(() => { + buffers.reset() + }) - context("#get", function() { - it("returns buffer by url", function() { - const obj = {url: "foo"}; + context('#get', () => { + it('returns buffer by url', () => { + const obj = { url: 'foo' } - buffers.set(obj); + buffers.set(obj) - const buffer = buffers.get("foo"); + const buffer = buffers.get('foo') - return expect(buffer).to.deep.eq(obj); - }); - - return it("falls back to setting the port when buffer could not be found", function() { - const obj = {url: "https://www.google.com/"}; - - buffers.set(obj); - - const buffer = buffers.get("https://www.google.com:443/"); - - return expect(buffer).to.deep.eq(obj); - }); - }); - - context("#getByOriginalUrl", () => - it("returns buffer by originalUrl", function() { - const obj = {originalUrl: "foo"}; - - buffers.set(obj); - - const buffer = buffers.getByOriginalUrl("foo"); - - return expect(buffer).to.deep.eq(obj); + expect(buffer).to.deep.eq(obj) }) - ); - return context("#take", function() { - it("removes the found buffer", function() { - const obj = {url: "https://www.google.com/"}; + it('falls back to setting the port when buffer could not be found', () => { + const obj = { url: 'https://www.google.com/' } - buffers.set(obj); + buffers.set(obj) - expect(buffers.all()).to.have.length(1); + const buffer = buffers.get('https://www.google.com:443/') - const buffer = buffers.take("https://www.google.com:443/"); + expect(buffer).to.deep.eq(obj) + }) + }) - expect(buffer).to.deep.eq(obj); + context('#getByOriginalUrl', () => { + it('returns buffer by originalUrl', () => { + const obj = { originalUrl: 'foo' } - return expect(buffers.all()).to.have.length(0); - }); + buffers.set(obj) - return it("does not remove anything when not found", function() { - const obj = {url: "https://www.google.com/"}; + const buffer = buffers.getByOriginalUrl('foo') - buffers.set(obj); + expect(buffer).to.deep.eq(obj) + }) + }) - expect(buffers.all()).to.have.length(1); + context('#take', () => { + it('removes the found buffer', () => { + const obj = { url: 'https://www.google.com/' } - const buffer = buffers.take("asdf"); + buffers.set(obj) - expect(buffer).to.be.undefined; + expect(buffers.all()).to.have.length(1) - return expect(buffers.all()).to.have.length(1); - }); - }); -}); + const buffer = buffers.take('https://www.google.com:443/') + + expect(buffer).to.deep.eq(obj) + + expect(buffers.all()).to.have.length(0) + }) + + it('does not remove anything when not found', () => { + const obj = { url: 'https://www.google.com/' } + + buffers.set(obj) + + expect(buffers.all()).to.have.length(1) + + const buffer = buffers.take('asdf') + + expect(buffer).to.be.undefined + + expect(buffers.all()).to.have.length(1) + }) + }) +}) diff --git a/packages/server/test/unit/cors_spec.js b/packages/server/test/unit/cors_spec.js index acbf83b385..56b2192510 100644 --- a/packages/server/test/unit/cors_spec.js +++ b/packages/server/test/unit/cors_spec.js @@ -1,264 +1,265 @@ -/* - * decaffeinate suggestions: - * DS102: Remove unnecessary code created because of implicit returns - * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md - */ -require("../spec_helper"); +require('../spec_helper') -const cors = require(`${root}lib/util/cors`); +const cors = require(`${root}lib/util/cors`) -describe("lib/util/cors", function() { - context(".parseUrlIntoDomainTldPort", function() { - beforeEach(function() { - return this.isEq = (url, obj) => expect(cors.parseUrlIntoDomainTldPort(url)).to.deep.eq(obj); - }); +describe('lib/util/cors', () => { + context('.parseUrlIntoDomainTldPort', () => { + beforeEach(function () { + this.isEq = (url, obj) => { + expect(cors.parseUrlIntoDomainTldPort(url)).to.deep.eq(obj) + } + }) - it("parses https://www.google.com", function() { - return this.isEq("https://www.google.com", { - port: "443", - domain: "google", - tld: "com" - }); - }); + it('parses https://www.google.com', function () { + this.isEq('https://www.google.com', { + port: '443', + domain: 'google', + tld: 'com', + }) + }) - it("parses http://localhost:8080", function() { - return this.isEq("http://localhost:8080", { - port: "8080", - domain: "", - tld: "localhost" - }); - }); + it('parses http://localhost:8080', function () { + this.isEq('http://localhost:8080', { + port: '8080', + domain: '', + tld: 'localhost', + }) + }) - it("parses http://app.localhost:8080", function() { - return this.isEq("http://app.localhost:8080", { - port: "8080", - domain: "app", - tld: "localhost" - }); - }); + it('parses http://app.localhost:8080', function () { + this.isEq('http://app.localhost:8080', { + port: '8080', + domain: 'app', + tld: 'localhost', + }) + }) - it("parses http://app.localhost.dev:8080", function() { - return this.isEq("http://app.localhost.dev:8080", { - port: "8080", - domain: "localhost", - tld: "dev" - }); - }); + it('parses http://app.localhost.dev:8080', function () { + this.isEq('http://app.localhost.dev:8080', { + port: '8080', + domain: 'localhost', + tld: 'dev', + }) + }) - it("parses http://app.local:8080", function() { - return this.isEq("http://app.local:8080", { - port: "8080", - domain: "app", - tld: "local" - }); - }); + it('parses http://app.local:8080', function () { + this.isEq('http://app.local:8080', { + port: '8080', + domain: 'app', + tld: 'local', + }) + }) - //# public suffix example of a private tld - it("parses https://example.herokuapp.com", function() { - return this.isEq("https://example.herokuapp.com", { - port: "443", - domain: "example", - tld: "herokuapp.com" - }); - }); + // public suffix example of a private tld + it('parses https://example.herokuapp.com', function () { + this.isEq('https://example.herokuapp.com', { + port: '443', + domain: 'example', + tld: 'herokuapp.com', + }) + }) - it("parses http://www.local.nl", function() { - return this.isEq("http://www.local.nl", { - port: "80", - domain: "local", - tld: "nl" - }); - }); + it('parses http://www.local.nl', function () { + this.isEq('http://www.local.nl', { + port: '80', + domain: 'local', + tld: 'nl', + }) + }) - //# https://github.com/cypress-io/cypress/issues/3717 - it("parses http://dev.classea12.beta.gouv.fr", function() { - return this.isEq("http://dev.classea12.beta.gouv.fr", { - port: "80", - domain: "beta", - tld: "gouv.fr" - }); - }); + // https://github.com/cypress-io/cypress/issues/3717 + it('parses http://dev.classea12.beta.gouv.fr', function () { + this.isEq('http://dev.classea12.beta.gouv.fr', { + port: '80', + domain: 'beta', + tld: 'gouv.fr', + }) + }) - it("parses http://www.local.nl:8080", function() { - return this.isEq("http://www.local.nl:8080", { - port: "8080", - domain: "local", - tld: "nl" - }); - }); + it('parses http://www.local.nl:8080', function () { + this.isEq('http://www.local.nl:8080', { + port: '8080', + domain: 'local', + tld: 'nl', + }) + }) - return it("parses 192.168.1.1:8080", function() { - return this.isEq("http://192.168.1.1:8080", { - port: "8080", - domain: "", - tld: "192.168.1.1" - }); - }); - }); + it('parses 192.168.1.1:8080', function () { + this.isEq('http://192.168.1.1:8080', { + port: '8080', + domain: '', + tld: '192.168.1.1', + }) + }) + }) - context(".urlMatchesOriginPolicyProps", function() { - beforeEach(function() { + context('.urlMatchesOriginPolicyProps', () => { + beforeEach(function () { this.isFalse = (url, props) => { - return expect(cors.urlMatchesOriginPolicyProps(url, props)).to.be.false; - }; + expect(cors.urlMatchesOriginPolicyProps(url, props)).to.be.false + } - return this.isTrue = (url, props) => { - return expect(cors.urlMatchesOriginPolicyProps(url, props)).to.be.true; - }; - }); + this.isTrue = (url, props) => { + expect(cors.urlMatchesOriginPolicyProps(url, props)).to.be.true + } + }) - describe("domain + subdomain", function() { - beforeEach(function() { - return this.props = cors.parseUrlIntoDomainTldPort("https://staging.google.com"); - }); + describe('domain + subdomain', () => { + beforeEach(function () { + this.props = cors.parseUrlIntoDomainTldPort('https://staging.google.com') + }) - it("does not match", function() { - this.isFalse("https://foo.bar:443", this.props); - this.isFalse("http://foo.bar:80", this.props); - this.isFalse("http://foo.bar", this.props); - this.isFalse("http://staging.google.com", this.props); - this.isFalse("http://staging.google.com:80", this.props); - this.isFalse("https://staging.google2.com:443", this.props); - this.isFalse("https://staging.google.net:443", this.props); - this.isFalse("https://google.net:443", this.props); - return this.isFalse("http://google.com", this.props); - }); + it('does not match', function () { + this.isFalse('https://foo.bar:443', this.props) + this.isFalse('http://foo.bar:80', this.props) + this.isFalse('http://foo.bar', this.props) + this.isFalse('http://staging.google.com', this.props) + this.isFalse('http://staging.google.com:80', this.props) + this.isFalse('https://staging.google2.com:443', this.props) + this.isFalse('https://staging.google.net:443', this.props) + this.isFalse('https://google.net:443', this.props) + this.isFalse('http://google.com', this.props) + }) - return it("matches", function() { - this.isTrue("https://staging.google.com:443", this.props); - this.isTrue("https://google.com:443", this.props); - this.isTrue("https://foo.google.com:443", this.props); - return this.isTrue("https://foo.bar.google.com:443", this.props); - }); - }); + it('matches', function () { + this.isTrue('https://staging.google.com:443', this.props) + this.isTrue('https://google.com:443', this.props) + this.isTrue('https://foo.google.com:443', this.props) + this.isTrue('https://foo.bar.google.com:443', this.props) + }) + }) - describe("public suffix", function() { - beforeEach(function() { - return this.props = cors.parseUrlIntoDomainTldPort("https://example.gitlab.io"); - }); + describe('public suffix', () => { + beforeEach(function () { + this.props = cors.parseUrlIntoDomainTldPort('https://example.gitlab.io') + }) - it("does not match", function() { - this.isFalse("http://example.gitlab.io", this.props); - return this.isFalse("https://foo.gitlab.io:443", this.props); - }); + it('does not match', function () { + this.isFalse('http://example.gitlab.io', this.props) + this.isFalse('https://foo.gitlab.io:443', this.props) + }) - return it("matches", function() { - this.isTrue("https://example.gitlab.io:443", this.props); - return this.isTrue("https://foo.example.gitlab.io:443", this.props); - }); - }); + it('matches', function () { + this.isTrue('https://example.gitlab.io:443', this.props) + this.isTrue('https://foo.example.gitlab.io:443', this.props) + }) + }) - describe("localhost", function() { - beforeEach(function() { - return this.props = cors.parseUrlIntoDomainTldPort("http://localhost:4200"); - }); + describe('localhost', () => { + beforeEach(function () { + this.props = cors.parseUrlIntoDomainTldPort('http://localhost:4200') + }) - it("does not match", function() { - this.isFalse("http://localhost:4201", this.props); - return this.isFalse("http://localhoss:4200", this.props); - }); + it('does not match', function () { + this.isFalse('http://localhost:4201', this.props) + this.isFalse('http://localhoss:4200', this.props) + }) - return it("matches", function() { - return this.isTrue("http://localhost:4200", this.props); - }); - }); + it('matches', function () { + this.isTrue('http://localhost:4200', this.props) + }) + }) - describe("app.localhost", function() { - beforeEach(function() { - return this.props = cors.parseUrlIntoDomainTldPort("http://app.localhost:4200"); - }); + describe('app.localhost', () => { + beforeEach(function () { + this.props = cors.parseUrlIntoDomainTldPort('http://app.localhost:4200') + }) - it("does not match", function() { - this.isFalse("http://app.localhost:4201", this.props); - return this.isFalse("http://app.localhoss:4200", this.props); - }); + it('does not match', function () { + this.isFalse('http://app.localhost:4201', this.props) + this.isFalse('http://app.localhoss:4200', this.props) + }) - return it("matches", function() { - this.isTrue("http://app.localhost:4200", this.props); - return this.isTrue("http://name.app.localhost:4200", this.props); - }); - }); + it('matches', function () { + this.isTrue('http://app.localhost:4200', this.props) + this.isTrue('http://name.app.localhost:4200', this.props) + }) + }) - describe("local", function() { - beforeEach(function() { - return this.props = cors.parseUrlIntoDomainTldPort("http://brian.dev.local"); - }); + describe('local', () => { + beforeEach(function () { + this.props = cors.parseUrlIntoDomainTldPort('http://brian.dev.local') + }) - it("does not match", function() { - this.isFalse("https://brian.dev.local:443", this.props); - this.isFalse("https://brian.dev.local", this.props); - return this.isFalse("http://brian.dev2.local:81", this.props); - }); + it('does not match', function () { + this.isFalse('https://brian.dev.local:443', this.props) + this.isFalse('https://brian.dev.local', this.props) + this.isFalse('http://brian.dev2.local:81', this.props) + }) - return it("matches", function() { - this.isTrue("http://jennifer.dev.local:80", this.props); - return this.isTrue("http://jennifer.dev.local", this.props); - }); - }); + it('matches', function () { + this.isTrue('http://jennifer.dev.local:80', this.props) + this.isTrue('http://jennifer.dev.local', this.props) + }) + }) - return describe("ip address", function() { - beforeEach(function() { - return this.props = cors.parseUrlIntoDomainTldPort("http://192.168.5.10"); - }); + describe('ip address', () => { + beforeEach(function () { + this.props = cors.parseUrlIntoDomainTldPort('http://192.168.5.10') + }) - it("does not match", function() { - this.isFalse("http://192.168.5.10:443", this.props); - this.isFalse("https://192.168.5.10", this.props); - this.isFalse("http://193.168.5.10", this.props); - return this.isFalse("http://193.168.5.10:80", this.props); - }); + it('does not match', function () { + this.isFalse('http://192.168.5.10:443', this.props) + this.isFalse('https://192.168.5.10', this.props) + this.isFalse('http://193.168.5.10', this.props) + this.isFalse('http://193.168.5.10:80', this.props) + }) - return it("matches", function() { - this.isTrue("http://192.168.5.10", this.props); - return this.isTrue("http://192.168.5.10:80", this.props); - }); - }); - }); + it('matches', function () { + this.isTrue('http://192.168.5.10', this.props) + this.isTrue('http://192.168.5.10:80', this.props) + }) + }) + }) - return context(".urlMatchesOriginProtectionSpace", function() { - const isMatch = (urlStr, origin) => - expect(urlStr, `the url: '${urlStr}' did not match origin protection space: '${origin}'`).to.satisfy(() => cors.urlMatchesOriginProtectionSpace(urlStr, origin)) - ; + context('.urlMatchesOriginProtectionSpace', () => { + const isMatch = (urlStr, origin) => { + expect(urlStr, `the url: '${urlStr}' did not match origin protection space: '${origin}'`).to.satisfy(() => { + return cors.urlMatchesOriginProtectionSpace(urlStr, origin) + }) + } - const isNotMatch = (urlStr, origin) => + const isNotMatch = (urlStr, origin) => { expect(urlStr, `the url: '${urlStr}' matched origin protection space: '${origin}'`) - .not.to.satisfy(() => cors.urlMatchesOriginProtectionSpace(urlStr, origin)) - ; + .not.to.satisfy(() => { + return cors.urlMatchesOriginProtectionSpace(urlStr, origin) + }) + } - it("ports", function() { - isMatch("http://example.com/", "http://example.com:80"); - isMatch("http://example.com:80/", "http://example.com"); - isMatch("http://example.com:80/", "http://example.com:80"); - isMatch("https://example.com:443/", "https://example.com:443"); - isMatch("https://example.com:443/", "https://example.com"); - isMatch("https://example.com/", "https://example.com:443"); + it('ports', () => { + isMatch('http://example.com/', 'http://example.com:80') + isMatch('http://example.com:80/', 'http://example.com') + isMatch('http://example.com:80/', 'http://example.com:80') + isMatch('https://example.com:443/', 'https://example.com:443') + isMatch('https://example.com:443/', 'https://example.com') + isMatch('https://example.com/', 'https://example.com:443') - isNotMatch("https://example.com:1234/", "https://example.com"); - return isNotMatch("https://example.com:1234/", "https://example.com:443"); - }); + isNotMatch('https://example.com:1234/', 'https://example.com') + isNotMatch('https://example.com:1234/', 'https://example.com:443') + }) - it("schemes", function() { - isNotMatch("http://example.com/", "https://example.com"); - isNotMatch("https://example.com/", "http://example.com"); - isNotMatch("http://example.com/", "ftp://example.com"); - return isNotMatch("http://example.com/", "file://example.com"); - }); + it('schemes', () => { + isNotMatch('http://example.com/', 'https://example.com') + isNotMatch('https://example.com/', 'http://example.com') + isNotMatch('http://example.com/', 'ftp://example.com') + isNotMatch('http://example.com/', 'file://example.com') + }) - it("does not factor in path or search", function() { - isMatch("http://example.com/foo", "http://example.com"); - isMatch("http://example.com/foo/bar", "http://example.com"); - isMatch("http://example.com/?foo=bar", "http://example.com"); - return isMatch("http://example.com/foo?bar=baz", "http://example.com"); - }); + it('does not factor in path or search', () => { + isMatch('http://example.com/foo', 'http://example.com') + isMatch('http://example.com/foo/bar', 'http://example.com') + isMatch('http://example.com/?foo=bar', 'http://example.com') + isMatch('http://example.com/foo?bar=baz', 'http://example.com') + }) - return it("subdomains", function() { - isMatch("http://example.com/", "http://example.com"); - isMatch("http://www.example.com/", "http://www.example.com"); - isMatch("http://foo.bar.example.com/", "http://foo.bar.example.com"); + it('subdomains', () => { + isMatch('http://example.com/', 'http://example.com') + isMatch('http://www.example.com/', 'http://www.example.com') + isMatch('http://foo.bar.example.com/', 'http://foo.bar.example.com') - isNotMatch("http://www.example.com/", "http://example.com"); - isNotMatch("http://foo.example.com/", "http://bar.example.com"); - return isNotMatch("http://foo.example.com/", "http://foo.bar.example.com"); - }); - }); -}); + isNotMatch('http://www.example.com/', 'http://example.com') + isNotMatch('http://foo.example.com/', 'http://bar.example.com') + isNotMatch('http://foo.example.com/', 'http://foo.bar.example.com') + }) + }) +}) diff --git a/packages/server/test/unit/security_spec.js b/packages/server/test/unit/security_spec.js index 2142d7764b..3f0dfdea37 100644 --- a/packages/server/test/unit/security_spec.js +++ b/packages/server/test/unit/security_spec.js @@ -1,16 +1,11 @@ -/* - * decaffeinate suggestions: - * DS102: Remove unnecessary code created because of implicit returns - * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md - */ -require("../spec_helper"); +require('../spec_helper') -const _ = require("lodash"); -const rp = require("request-promise"); -const concat = require("concat-stream"); -const fs = require(`${root}lib/util/fs`); -const security = require(`${root}lib/util/security`); -const Fixtures = require(`${root}test/support/helpers/fixtures`); +const _ = require('lodash') +const rp = require('request-promise') +const concat = require('concat-stream') +const fs = require(`${root}lib/util/fs`) +const security = require(`${root}lib/util/security`) +const Fixtures = require(`${root}test/support/helpers/fixtures`) const original = `\ @@ -75,7 +70,7 @@ const original = `\ \ -`; +` const expected = `\ @@ -140,42 +135,44 @@ const expected = `\ \ -`; +` -describe("lib/util/security", function() { - context(".strip", function() { - it("replaces obstructive code", () => expect(security.strip(original)).to.eq(expected)); +describe('lib/util/security', () => { + context('.strip', () => { + it('replaces obstructive code', () => { + expect(security.strip(original)).to.eq(expected) + }) - it("replaces jira window getter", function() { + it('replaces jira window getter', () => { const jira = `\ for (; !function (n) { return n === n.parent }(n)\ -`; +` const jira2 = `\ function(n){for(;!function(l){return l===l.parent}(l)&&function(l){try{if(void 0==l.location.href)return!1}catch(l){return!1}return!0}(l.parent);)l=l.parent;return l}\ -`; +` expect(security.strip(jira)).to.eq(`\ for (; !function (n) { return n === n.parent || n.parent.__Cypress__ }(n)\ -`); +`) - return expect(security.strip(jira2)).to.eq(`\ + expect(security.strip(jira2)).to.eq(`\ function(n){for(;!function(l){return l===l.parent || l.parent.__Cypress__}(l)&&function(l){try{if(void 0==l.location.href)return!1}catch(l){return!1}return!0}(l.parent);)l=l.parent;return l}\ -`); - }); +`) + }) - return describe("libs", function() { - //# go out and download all of these libs and ensure - //# that we can run them through the security strip - //# and that they are not modified! + describe('libs', () => { + // go out and download all of these libs and ensure + // that we can run them through the security strip + // and that they are not modified! - const cdnUrl = "https://cdnjs.cloudflare.com/ajax/libs"; + const cdnUrl = 'https://cdnjs.cloudflare.com/ajax/libs' - const needsDash = ["backbone", "underscore"]; + const needsDash = ['backbone', 'underscore'] let libs = { jquery: `${cdnUrl}/jquery/3.3.1/jquery.js`, @@ -194,23 +191,23 @@ function(n){for(;!function(l){return l===l.parent || l.parent.__Cypress__}(l)&&f foundation: `${cdnUrl}/foundation/6.4.3/js/foundation.js`, require: `${cdnUrl}/require.js/2.3.5/require.js`, rxjs: `${cdnUrl}/rxjs/5.5.6/Rx.js`, - bluebird: `${cdnUrl}/bluebird/3.5.1/bluebird.js` - }; + bluebird: `${cdnUrl}/bluebird/3.5.1/bluebird.js`, + } libs = _ .chain(libs) .clone() - .reduce(function(memo, url, lib) { - memo[lib] = url; - memo[lib + "Min"] = url - .replace(/js$/, "min.js") - .replace(/css$/, "min.css"); + .reduce((memo, url, lib) => { + memo[lib] = url + memo[`${lib}Min`] = url + .replace(/js$/, 'min.js') + .replace(/css$/, 'min.css') if (needsDash.includes(lib)) { - memo[lib + "Min"] = url.replace("min", "-min"); + memo[`${lib}Min`] = url.replace('min', '-min') } - return memo; + return memo } , {}) .extend({ @@ -220,79 +217,82 @@ function(n){for(;!function(l){return l===l.parent || l.parent.__Cypress__}(l)&&f emberProd: `${cdnUrl}/ember.js/2.18.2/ember.prod.js`, reactDev: `${cdnUrl}/react/16.2.0/umd/react.development.js`, reactProd: `${cdnUrl}/react/16.2.0/umd/react.production.min.js`, - vendorBundle: "https://s3.amazonaws.com/internal-test-runner-assets.cypress.io/vendor.bundle.js", - hugeApp: "https://s3.amazonaws.com/internal-test-runner-assets.cypress.io/huge_app.js" + vendorBundle: 'https://s3.amazonaws.com/internal-test-runner-assets.cypress.io/vendor.bundle.js', + hugeApp: 'https://s3.amazonaws.com/internal-test-runner-assets.cypress.io/huge_app.js', }) - .value(); + .value() - return _.each(libs, (url, lib) => - it(`does not alter code from: '${lib}'`, function() { - nock.enableNetConnect(); + return _.each(libs, (url, lib) => { + it(`does not alter code from: '${lib}'`, function () { + nock.enableNetConnect() - this.timeout(10000); + this.timeout(10000) - const pathToLib = Fixtures.path(`server/libs/${lib}`); + const pathToLib = Fixtures.path(`server/libs/${lib}`) - const downloadFile = () => - rp(url) - .then(resp => - fs + const downloadFile = () => { + return rp(url) + .then((resp) => { + return fs .outputFileAsync(pathToLib, resp) .return(resp) - ) - ; - return fs - .readFileAsync(pathToLib, "utf8") - .catch(downloadFile) - .then(function(libCode) { - let stripped = security.strip(libCode); - //# nothing should have changed! + }) + } - //# TODO: this is currently failing but we're - //# going to accept this for now and make this - //# test pass, but need to refactor to using - //# inline expressions and change the strategy - //# for removing obstructive code - if (lib === "hugeApp") { + return fs + .readFileAsync(pathToLib, 'utf8') + .catch(downloadFile) + .then((libCode) => { + let stripped = security.strip(libCode) + // nothing should have changed! + + // TODO: this is currently failing but we're + // going to accept this for now and make this + // test pass, but need to refactor to using + // inline expressions and change the strategy + // for removing obstructive code + if (lib === 'hugeApp') { stripped = stripped.replace( - "window.self !== window.self", - "window.self !== window.top" - ); + 'window.self !== window.self', + 'window.self !== window.top' + ) } try { - return expect(stripped).to.eq(libCode); + expect(stripped).to.eq(libCode) } catch (err) { - fs.outputFileSync(pathToLib + "Diff", stripped); - throw new Error(`code from '${lib}' was different`); + fs.outputFileSync(`${pathToLib}Diff`, stripped) + throw new Error(`code from '${lib}' was different`) } - }); + }) }) - ); - }); - }); + }) + }) + }) - return context(".stripStream", () => - it("replaces obstructive code", function(done) { - const haystacks = original.split("\n"); + context('.stripStream', () => { + it('replaces obstructive code', (done) => { + const haystacks = original.split('\n') - const replacer = security.stripStream(); + const replacer = security.stripStream() - replacer.pipe(concat({encoding: "string"}, function(str) { - str = str.trim(); + replacer.pipe(concat({ encoding: 'string' }, (str) => { + str = str.trim() try { - expect(str).to.eq(expected); - return done(); + expect(str).to.eq(expected) + + done() } catch (err) { - return done(err); + done(err) } + })) + + haystacks.forEach((haystack) => { + replacer.write(`${haystack}\n`) }) - ); - haystacks.forEach(haystack => replacer.write(haystack + "\n")); - - return replacer.end(); + replacer.end() }) - ); -}); + }) +})