Improves proxy support (#1129)
Improves proxy support - Automatically detect and dehyphenise https proxies which use EZProxy HttpsHyphens - Web translators now pass around Zotero.Proxy instances which can proxify/deproxify urls passed to `translate.setLocation()` before calling `translate.getTranslators()`/ translate.detect()`. The proxy passing is done within connector background/injected processes and between standalone and connectors. - Proxy protocol unified with connectors. Connectors can now pass proxies to `/connector/save_items`. The proxies will be used to resolve true item and attachment urls when saving. Closes zotero/zotero#578, zotero/zotero#721 Relevant zotero/zotero#34, zotero/zotero#556
This commit is contained in:
parent
c2ebcc9dbc
commit
747c11c917
16 changed files with 392 additions and 124 deletions
|
@ -57,13 +57,41 @@ describe("Connector Server", function () {
|
|||
);
|
||||
|
||||
assert.isTrue(Zotero.Translators.get.calledWith('dummy-translator'));
|
||||
assert.equal(response.response, code);
|
||||
let translatorCode = yield translator.getCode();
|
||||
assert.equal(response.response, translatorCode);
|
||||
|
||||
Zotero.Translators.get.restore();
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
describe("/connector/detect", function() {
|
||||
it("should return relevant translators with proxies", function* () {
|
||||
var code = 'function detectWeb() {return "newspaperArticle";}\nfunction doWeb() {}';
|
||||
var translator = buildDummyTranslator("web", code, {target: "https://www.example.com/.*"});
|
||||
sinon.stub(Zotero.Translators, 'getAllForType').resolves([translator]);
|
||||
|
||||
var response = yield Zotero.HTTP.request(
|
||||
'POST',
|
||||
connectorServerPath + "/connector/detect",
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify({
|
||||
uri: "https://www-example-com.proxy.example.com/article",
|
||||
html: "<head><title>Owl</title></head><body><p>🦉</p></body>"
|
||||
})
|
||||
}
|
||||
);
|
||||
|
||||
assert.equal(JSON.parse(response.response)[0].proxy.scheme, 'https://%h.proxy.example.com/%p');
|
||||
|
||||
Zotero.Translators.getAllForType.restore();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe("/connector/saveItems", function () {
|
||||
// TODO: Test cookies
|
||||
it("should save a translated item to the current selected collection", function* () {
|
||||
|
@ -185,6 +213,49 @@ describe("Connector Server", function () {
|
|||
win.ZoteroPane.collectionsView.getSelectedLibraryID(), Zotero.Libraries.userLibraryID
|
||||
);
|
||||
});
|
||||
|
||||
it("should use the provided proxy to deproxify item url", function* () {
|
||||
yield selectLibrary(win, Zotero.Libraries.userLibraryID);
|
||||
yield waitForItemsLoad(win);
|
||||
|
||||
var body = {
|
||||
items: [
|
||||
{
|
||||
itemType: "newspaperArticle",
|
||||
title: "Title",
|
||||
creators: [
|
||||
{
|
||||
firstName: "First",
|
||||
lastName: "Last",
|
||||
creatorType: "author"
|
||||
}
|
||||
],
|
||||
attachments: [],
|
||||
url: "https://www-example-com.proxy.example.com/path"
|
||||
}
|
||||
],
|
||||
uri: "https://www-example-com.proxy.example.com/path",
|
||||
proxy: {scheme: 'https://%h.proxy.example.com/%p', dotsToHyphens: true}
|
||||
};
|
||||
|
||||
var promise = waitForItemEvent('add');
|
||||
var req = yield Zotero.HTTP.request(
|
||||
'POST',
|
||||
connectorServerPath + "/connector/saveItems",
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify(body)
|
||||
}
|
||||
);
|
||||
|
||||
// Check item
|
||||
var ids = yield promise;
|
||||
assert.lengthOf(ids, 1);
|
||||
var item = Zotero.Items.get(ids[0]);
|
||||
assert.equal(item.getField('url'), 'https://www.example.com/path');
|
||||
});
|
||||
});
|
||||
|
||||
describe("/connector/saveSnapshot", function () {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue