2017-12-24 00:32:02 +09:00
|
|
|
/* Copyright 2017 Mozilla Foundation
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import {
|
2018-01-13 17:01:50 +09:00
|
|
|
createResponseStatusError,
|
|
|
|
extractFilenameFromHeader,
|
|
|
|
validateRangeRequestCapabilities,
|
|
|
|
validateResponseStatus,
|
2020-01-02 20:00:16 +09:00
|
|
|
} from "../../src/display/network_utils.js";
|
2017-12-24 00:32:02 +09:00
|
|
|
import {
|
|
|
|
MissingPDFException,
|
|
|
|
UnexpectedResponseException,
|
2020-01-02 20:00:16 +09:00
|
|
|
} from "../../src/shared/util.js";
|
2017-12-24 00:32:02 +09:00
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
describe("network_utils", function () {
|
|
|
|
describe("validateRangeRequestCapabilities", function () {
|
2022-03-21 20:55:54 +09:00
|
|
|
it("rejects invalid rangeChunkSize", function () {
|
|
|
|
expect(function () {
|
|
|
|
validateRangeRequestCapabilities({ rangeChunkSize: "abc" });
|
|
|
|
}).toThrow(
|
|
|
|
new Error("rangeChunkSize must be an integer larger than zero.")
|
|
|
|
);
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
expect(function () {
|
2017-12-24 00:32:02 +09:00
|
|
|
validateRangeRequestCapabilities({ rangeChunkSize: 0 });
|
2022-03-21 20:55:54 +09:00
|
|
|
}).toThrow(
|
|
|
|
new Error("rangeChunkSize must be an integer larger than zero.")
|
|
|
|
);
|
2017-12-24 00:32:02 +09:00
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("rejects disabled or non-HTTP range requests", function () {
|
2017-12-24 00:32:02 +09:00
|
|
|
expect(
|
|
|
|
validateRangeRequestCapabilities({
|
|
|
|
disableRange: true,
|
|
|
|
isHttp: true,
|
2018-10-08 02:26:29 +09:00
|
|
|
getResponseHeader: headerName => {
|
|
|
|
if (headerName === "Content-Length") {
|
|
|
|
return 8;
|
|
|
|
}
|
2019-05-10 19:54:06 +09:00
|
|
|
throw new Error(`Unexpected headerName: ${headerName}`);
|
2018-10-08 02:26:29 +09:00
|
|
|
},
|
2017-12-24 00:32:02 +09:00
|
|
|
rangeChunkSize: 64,
|
2018-10-08 02:26:29 +09:00
|
|
|
})
|
|
|
|
).toEqual({
|
|
|
|
allowRangeRequests: false,
|
|
|
|
suggestedLength: 8,
|
|
|
|
});
|
2017-12-24 00:32:02 +09:00
|
|
|
|
|
|
|
expect(
|
|
|
|
validateRangeRequestCapabilities({
|
|
|
|
disableRange: false,
|
|
|
|
isHttp: false,
|
2018-10-08 02:26:29 +09:00
|
|
|
getResponseHeader: headerName => {
|
|
|
|
if (headerName === "Content-Length") {
|
|
|
|
return 8;
|
|
|
|
}
|
2019-05-10 19:54:06 +09:00
|
|
|
throw new Error(`Unexpected headerName: ${headerName}`);
|
2018-10-08 02:26:29 +09:00
|
|
|
},
|
2017-12-24 00:32:02 +09:00
|
|
|
rangeChunkSize: 64,
|
2018-10-08 02:26:29 +09:00
|
|
|
})
|
|
|
|
).toEqual({
|
|
|
|
allowRangeRequests: false,
|
|
|
|
suggestedLength: 8,
|
|
|
|
});
|
2017-12-24 00:32:02 +09:00
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("rejects invalid Accept-Ranges header values", function () {
|
2017-12-24 00:32:02 +09:00
|
|
|
expect(
|
|
|
|
validateRangeRequestCapabilities({
|
|
|
|
disableRange: false,
|
|
|
|
isHttp: true,
|
|
|
|
getResponseHeader: headerName => {
|
|
|
|
if (headerName === "Accept-Ranges") {
|
|
|
|
return "none";
|
2018-10-08 02:26:29 +09:00
|
|
|
} else if (headerName === "Content-Length") {
|
|
|
|
return 8;
|
2017-12-24 00:32:02 +09:00
|
|
|
}
|
2019-05-10 19:54:06 +09:00
|
|
|
throw new Error(`Unexpected headerName: ${headerName}`);
|
2017-12-24 00:32:02 +09:00
|
|
|
},
|
|
|
|
rangeChunkSize: 64,
|
2018-10-08 02:26:29 +09:00
|
|
|
})
|
|
|
|
).toEqual({
|
|
|
|
allowRangeRequests: false,
|
|
|
|
suggestedLength: 8,
|
|
|
|
});
|
2017-12-24 00:32:02 +09:00
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("rejects invalid Content-Encoding header values", function () {
|
2017-12-24 00:32:02 +09:00
|
|
|
expect(
|
|
|
|
validateRangeRequestCapabilities({
|
|
|
|
disableRange: false,
|
|
|
|
isHttp: true,
|
|
|
|
getResponseHeader: headerName => {
|
|
|
|
if (headerName === "Accept-Ranges") {
|
|
|
|
return "bytes";
|
|
|
|
} else if (headerName === "Content-Encoding") {
|
|
|
|
return "gzip";
|
2018-10-08 02:26:29 +09:00
|
|
|
} else if (headerName === "Content-Length") {
|
|
|
|
return 8;
|
2017-12-24 00:32:02 +09:00
|
|
|
}
|
2019-05-10 19:54:06 +09:00
|
|
|
throw new Error(`Unexpected headerName: ${headerName}`);
|
2017-12-24 00:32:02 +09:00
|
|
|
},
|
|
|
|
rangeChunkSize: 64,
|
2018-10-08 02:26:29 +09:00
|
|
|
})
|
|
|
|
).toEqual({
|
|
|
|
allowRangeRequests: false,
|
|
|
|
suggestedLength: 8,
|
|
|
|
});
|
2017-12-24 00:32:02 +09:00
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("rejects invalid Content-Length header values", function () {
|
2017-12-24 00:32:02 +09:00
|
|
|
expect(
|
|
|
|
validateRangeRequestCapabilities({
|
|
|
|
disableRange: false,
|
|
|
|
isHttp: true,
|
|
|
|
getResponseHeader: headerName => {
|
|
|
|
if (headerName === "Accept-Ranges") {
|
|
|
|
return "bytes";
|
|
|
|
} else if (headerName === "Content-Encoding") {
|
|
|
|
return null;
|
|
|
|
} else if (headerName === "Content-Length") {
|
|
|
|
return "eight";
|
|
|
|
}
|
2019-05-10 19:54:06 +09:00
|
|
|
throw new Error(`Unexpected headerName: ${headerName}`);
|
2017-12-24 00:32:02 +09:00
|
|
|
},
|
|
|
|
rangeChunkSize: 64,
|
2018-10-08 02:26:29 +09:00
|
|
|
})
|
|
|
|
).toEqual({
|
|
|
|
allowRangeRequests: false,
|
|
|
|
suggestedLength: undefined,
|
|
|
|
});
|
2017-12-24 00:32:02 +09:00
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("rejects file sizes that are too small for range requests", function () {
|
2017-12-24 00:32:02 +09:00
|
|
|
expect(
|
|
|
|
validateRangeRequestCapabilities({
|
|
|
|
disableRange: false,
|
|
|
|
isHttp: true,
|
|
|
|
getResponseHeader: headerName => {
|
|
|
|
if (headerName === "Accept-Ranges") {
|
|
|
|
return "bytes";
|
|
|
|
} else if (headerName === "Content-Encoding") {
|
|
|
|
return null;
|
|
|
|
} else if (headerName === "Content-Length") {
|
|
|
|
return 8;
|
|
|
|
}
|
2019-05-10 19:54:06 +09:00
|
|
|
throw new Error(`Unexpected headerName: ${headerName}`);
|
2017-12-24 00:32:02 +09:00
|
|
|
},
|
|
|
|
rangeChunkSize: 64,
|
|
|
|
})
|
|
|
|
).toEqual({
|
|
|
|
allowRangeRequests: false,
|
|
|
|
suggestedLength: 8,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("accepts file sizes large enough for range requests", function () {
|
2017-12-24 00:32:02 +09:00
|
|
|
expect(
|
|
|
|
validateRangeRequestCapabilities({
|
|
|
|
disableRange: false,
|
|
|
|
isHttp: true,
|
|
|
|
getResponseHeader: headerName => {
|
|
|
|
if (headerName === "Accept-Ranges") {
|
|
|
|
return "bytes";
|
|
|
|
} else if (headerName === "Content-Encoding") {
|
|
|
|
return null;
|
|
|
|
} else if (headerName === "Content-Length") {
|
|
|
|
return 8192;
|
|
|
|
}
|
2019-05-10 19:54:06 +09:00
|
|
|
throw new Error(`Unexpected headerName: ${headerName}`);
|
2017-12-24 00:32:02 +09:00
|
|
|
},
|
|
|
|
rangeChunkSize: 64,
|
|
|
|
})
|
|
|
|
).toEqual({
|
|
|
|
allowRangeRequests: true,
|
|
|
|
suggestedLength: 8192,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
describe("extractFilenameFromHeader", function () {
|
|
|
|
it("returns null when content disposition header is blank", function () {
|
2018-01-17 00:24:36 +09:00
|
|
|
expect(
|
|
|
|
extractFilenameFromHeader(headerName => {
|
|
|
|
if (headerName === "Content-Disposition") {
|
|
|
|
return null;
|
|
|
|
}
|
2019-05-10 19:54:06 +09:00
|
|
|
throw new Error(`Unexpected headerName: ${headerName}`);
|
2018-01-17 00:24:36 +09:00
|
|
|
})
|
|
|
|
).toBeNull();
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
2018-01-17 00:24:36 +09:00
|
|
|
expect(
|
|
|
|
extractFilenameFromHeader(headerName => {
|
|
|
|
if (headerName === "Content-Disposition") {
|
|
|
|
return undefined;
|
|
|
|
}
|
2019-05-10 19:54:06 +09:00
|
|
|
throw new Error(`Unexpected headerName: ${headerName}`);
|
2018-01-17 00:24:36 +09:00
|
|
|
})
|
|
|
|
).toBeNull();
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
2018-01-17 00:24:36 +09:00
|
|
|
expect(
|
|
|
|
extractFilenameFromHeader(headerName => {
|
|
|
|
if (headerName === "Content-Disposition") {
|
|
|
|
return "";
|
|
|
|
}
|
2019-05-10 19:54:06 +09:00
|
|
|
throw new Error(`Unexpected headerName: ${headerName}`);
|
2018-01-17 00:24:36 +09:00
|
|
|
})
|
|
|
|
).toBeNull();
|
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("gets the filename from the response header", function () {
|
2018-01-17 00:24:36 +09:00
|
|
|
expect(
|
|
|
|
extractFilenameFromHeader(headerName => {
|
|
|
|
if (headerName === "Content-Disposition") {
|
|
|
|
return "inline";
|
|
|
|
}
|
2019-05-10 19:54:06 +09:00
|
|
|
throw new Error(`Unexpected headerName: ${headerName}`);
|
2018-01-17 00:24:36 +09:00
|
|
|
})
|
|
|
|
).toBeNull();
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
2018-01-17 00:24:36 +09:00
|
|
|
expect(
|
|
|
|
extractFilenameFromHeader(headerName => {
|
|
|
|
if (headerName === "Content-Disposition") {
|
|
|
|
return "attachment";
|
|
|
|
}
|
2019-05-10 19:54:06 +09:00
|
|
|
throw new Error(`Unexpected headerName: ${headerName}`);
|
2018-01-17 00:24:36 +09:00
|
|
|
})
|
|
|
|
).toBeNull();
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
2018-01-17 00:24:36 +09:00
|
|
|
expect(
|
|
|
|
extractFilenameFromHeader(headerName => {
|
|
|
|
if (headerName === "Content-Disposition") {
|
|
|
|
return 'attachment; filename="filename.pdf"';
|
|
|
|
}
|
2019-05-10 19:54:06 +09:00
|
|
|
throw new Error(`Unexpected headerName: ${headerName}`);
|
2018-01-17 00:24:36 +09:00
|
|
|
})
|
|
|
|
).toEqual("filename.pdf");
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
2018-02-05 01:58:10 +09:00
|
|
|
expect(
|
|
|
|
extractFilenameFromHeader(headerName => {
|
|
|
|
if (headerName === "Content-Disposition") {
|
|
|
|
return 'attachment; filename="filename.pdf and spaces.pdf"';
|
|
|
|
}
|
2019-05-10 19:54:06 +09:00
|
|
|
throw new Error(`Unexpected headerName: ${headerName}`);
|
2018-02-05 01:58:10 +09:00
|
|
|
})
|
|
|
|
).toEqual("filename.pdf and spaces.pdf");
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
2018-02-05 01:58:10 +09:00
|
|
|
expect(
|
|
|
|
extractFilenameFromHeader(headerName => {
|
|
|
|
if (headerName === "Content-Disposition") {
|
|
|
|
return 'attachment; filename="tl;dr.pdf"';
|
|
|
|
}
|
2019-05-10 19:54:06 +09:00
|
|
|
throw new Error(`Unexpected headerName: ${headerName}`);
|
2018-02-05 01:58:10 +09:00
|
|
|
})
|
|
|
|
).toEqual("tl;dr.pdf");
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
2018-01-20 01:39:31 +09:00
|
|
|
expect(
|
|
|
|
extractFilenameFromHeader(headerName => {
|
|
|
|
if (headerName === "Content-Disposition") {
|
|
|
|
return "attachment; filename=filename.pdf";
|
|
|
|
}
|
2019-05-10 19:54:06 +09:00
|
|
|
throw new Error(`Unexpected headerName: ${headerName}`);
|
2018-01-20 01:39:31 +09:00
|
|
|
})
|
|
|
|
).toEqual("filename.pdf");
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
2018-02-05 01:58:10 +09:00
|
|
|
expect(
|
|
|
|
extractFilenameFromHeader(headerName => {
|
|
|
|
if (headerName === "Content-Disposition") {
|
|
|
|
return "attachment; filename=filename.pdf someotherparam";
|
|
|
|
}
|
2019-05-10 19:54:06 +09:00
|
|
|
throw new Error(`Unexpected headerName: ${headerName}`);
|
2018-02-05 01:58:10 +09:00
|
|
|
})
|
|
|
|
).toEqual("filename.pdf");
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
2019-07-30 12:37:10 +09:00
|
|
|
expect(
|
|
|
|
extractFilenameFromHeader(headerName => {
|
|
|
|
if (headerName === "Content-Disposition") {
|
|
|
|
return 'attachment; filename="%e4%b8%ad%e6%96%87.pdf"';
|
|
|
|
}
|
|
|
|
throw new Error(`Unexpected headerName: ${headerName}`);
|
|
|
|
})
|
|
|
|
).toEqual("中文.pdf");
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
2019-07-30 12:37:10 +09:00
|
|
|
expect(
|
|
|
|
extractFilenameFromHeader(headerName => {
|
|
|
|
if (headerName === "Content-Disposition") {
|
|
|
|
return 'attachment; filename="100%.pdf"';
|
|
|
|
}
|
|
|
|
throw new Error(`Unexpected headerName: ${headerName}`);
|
|
|
|
})
|
|
|
|
).toEqual("100%.pdf");
|
2018-01-20 01:39:31 +09:00
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("gets the filename from the response header (RFC 6266)", function () {
|
2018-01-20 01:39:31 +09:00
|
|
|
expect(
|
|
|
|
extractFilenameFromHeader(headerName => {
|
|
|
|
if (headerName === "Content-Disposition") {
|
|
|
|
return "attachment; filename*=filename.pdf";
|
|
|
|
}
|
2019-05-10 19:54:06 +09:00
|
|
|
throw new Error(`Unexpected headerName: ${headerName}`);
|
2018-01-20 01:39:31 +09:00
|
|
|
})
|
|
|
|
).toEqual("filename.pdf");
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
2018-01-20 01:39:31 +09:00
|
|
|
expect(
|
|
|
|
extractFilenameFromHeader(headerName => {
|
|
|
|
if (headerName === "Content-Disposition") {
|
|
|
|
return "attachment; filename*=''filename.pdf";
|
|
|
|
}
|
2019-05-10 19:54:06 +09:00
|
|
|
throw new Error(`Unexpected headerName: ${headerName}`);
|
2018-01-20 01:39:31 +09:00
|
|
|
})
|
|
|
|
).toEqual("filename.pdf");
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
2018-01-20 01:39:31 +09:00
|
|
|
expect(
|
|
|
|
extractFilenameFromHeader(headerName => {
|
|
|
|
if (headerName === "Content-Disposition") {
|
|
|
|
return "attachment; filename*=utf-8''filename.pdf";
|
|
|
|
}
|
2019-05-10 19:54:06 +09:00
|
|
|
throw new Error(`Unexpected headerName: ${headerName}`);
|
2018-01-20 01:39:31 +09:00
|
|
|
})
|
|
|
|
).toEqual("filename.pdf");
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
2018-01-20 01:39:31 +09:00
|
|
|
expect(
|
|
|
|
extractFilenameFromHeader(headerName => {
|
|
|
|
if (headerName === "Content-Disposition") {
|
|
|
|
return "attachment; filename=no.pdf; filename*=utf-8''filename.pdf";
|
|
|
|
}
|
2019-05-10 19:54:06 +09:00
|
|
|
throw new Error(`Unexpected headerName: ${headerName}`);
|
2018-01-20 01:39:31 +09:00
|
|
|
})
|
|
|
|
).toEqual("filename.pdf");
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
2018-01-20 01:39:31 +09:00
|
|
|
expect(
|
|
|
|
extractFilenameFromHeader(headerName => {
|
|
|
|
if (headerName === "Content-Disposition") {
|
|
|
|
return "attachment; filename*=utf-8''filename.pdf; filename=no.pdf";
|
|
|
|
}
|
2019-05-10 19:54:06 +09:00
|
|
|
throw new Error(`Unexpected headerName: ${headerName}`);
|
2018-01-20 01:39:31 +09:00
|
|
|
})
|
|
|
|
).toEqual("filename.pdf");
|
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("gets the filename from the response header (RFC 2231)", function () {
|
2018-01-20 01:39:31 +09:00
|
|
|
// Tests continuations (RFC 2231 section 3, via RFC 5987 section 3.1).
|
|
|
|
expect(
|
|
|
|
extractFilenameFromHeader(headerName => {
|
|
|
|
if (headerName === "Content-Disposition") {
|
|
|
|
return "attachment; filename*0=filename; filename*1=.pdf";
|
|
|
|
}
|
2019-05-10 19:54:06 +09:00
|
|
|
throw new Error(`Unexpected headerName: ${headerName}`);
|
2018-01-20 01:39:31 +09:00
|
|
|
})
|
|
|
|
).toEqual("filename.pdf");
|
2018-01-17 00:24:36 +09:00
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("only extracts filename with pdf extension", function () {
|
2018-01-17 00:24:36 +09:00
|
|
|
expect(
|
|
|
|
extractFilenameFromHeader(headerName => {
|
|
|
|
if (headerName === "Content-Disposition") {
|
|
|
|
return 'attachment; filename="filename.png"';
|
|
|
|
}
|
2019-05-10 19:54:06 +09:00
|
|
|
throw new Error(`Unexpected headerName: ${headerName}`);
|
2018-01-17 00:24:36 +09:00
|
|
|
})
|
|
|
|
).toBeNull();
|
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("extension validation is case insensitive", function () {
|
2018-01-17 00:24:36 +09:00
|
|
|
expect(
|
|
|
|
extractFilenameFromHeader(headerName => {
|
|
|
|
if (headerName === "Content-Disposition") {
|
|
|
|
return 'form-data; name="fieldName"; filename="file.PdF"';
|
|
|
|
}
|
2019-05-10 19:54:06 +09:00
|
|
|
throw new Error(`Unexpected headerName: ${headerName}`);
|
2018-01-17 00:24:36 +09:00
|
|
|
})
|
|
|
|
).toEqual("file.PdF");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
describe("createResponseStatusError", function () {
|
|
|
|
it("handles missing PDF file responses", function () {
|
2017-12-24 00:32:02 +09:00
|
|
|
expect(createResponseStatusError(404, "https://foo.com/bar.pdf")).toEqual(
|
|
|
|
new MissingPDFException('Missing PDF "https://foo.com/bar.pdf".')
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(createResponseStatusError(0, "file://foo.pdf")).toEqual(
|
|
|
|
new MissingPDFException('Missing PDF "file://foo.pdf".')
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("handles unexpected responses", function () {
|
2017-12-24 00:32:02 +09:00
|
|
|
expect(createResponseStatusError(302, "https://foo.com/bar.pdf")).toEqual(
|
|
|
|
new UnexpectedResponseException(
|
|
|
|
"Unexpected server response (302) while retrieving PDF " +
|
|
|
|
'"https://foo.com/bar.pdf".'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(createResponseStatusError(0, "https://foo.com/bar.pdf")).toEqual(
|
|
|
|
new UnexpectedResponseException(
|
|
|
|
"Unexpected server response (0) while retrieving PDF " +
|
|
|
|
'"https://foo.com/bar.pdf".'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
describe("validateResponseStatus", function () {
|
|
|
|
it("accepts valid response statuses", function () {
|
2017-12-24 00:32:02 +09:00
|
|
|
expect(validateResponseStatus(200)).toEqual(true);
|
|
|
|
expect(validateResponseStatus(206)).toEqual(true);
|
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("rejects invalid response statuses", function () {
|
2017-12-24 00:32:02 +09:00
|
|
|
expect(validateResponseStatus(302)).toEqual(false);
|
|
|
|
expect(validateResponseStatus(404)).toEqual(false);
|
|
|
|
expect(validateResponseStatus(null)).toEqual(false);
|
|
|
|
expect(validateResponseStatus(undefined)).toEqual(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|