kopia lustrzana https://gitlab.com/rysiekpl/libresilient
basic-integrity: more tests! (ref. #19)
rodzic
c1f8d0970b
commit
f52dcfb02a
|
@ -43,7 +43,7 @@ describe("plugin: basic-integrity", () => {
|
|||
}
|
||||
],
|
||||
integrity: {
|
||||
"https://resilient.is/test.json": "sha384-f0N6RLBmS+iCKtRHtVrzOV/tnE469hDiaBYV8jFF9LZj/VREe00W2ombY9xxUfZy"
|
||||
"https://resilient.is/test.json": "sha384-kn5dhxz4RpBmx7xC7Dmq2N43PclV9U/niyh+4Km7oz5W0FaWdz3Op+3K0Qxz8y3z"
|
||||
},
|
||||
requireIntegrity: true
|
||||
}
|
||||
|
@ -132,8 +132,50 @@ describe("plugin: basic-integrity", () => {
|
|||
expect(resolvingFetch).not.toHaveBeenCalled()
|
||||
});
|
||||
|
||||
// TODO: test no configured integrity with requireIntegrity == false
|
||||
// TODO: test integrity from init, no configured integrity
|
||||
// TODO: test integrity from init, configured integrity
|
||||
test("it should return data from the wrapped plugin with no integrity data if requireIntegrity is false", async () => {
|
||||
require("../../plugins/basic-integrity.js");
|
||||
|
||||
init.integrity = {}
|
||||
init.requireIntegrity = false
|
||||
|
||||
const response = await LibResilientPluginConstructors.get('basic-integrity')(LR, init).fetch('https://resilient.is/test.json');
|
||||
|
||||
expect(resolvingFetch).toHaveBeenCalled();
|
||||
expect(resolvingFetch).toHaveBeenCalledWith('https://resilient.is/test.json', {});
|
||||
expect(await response.json()).toEqual({test: "success"})
|
||||
expect(response.url).toEqual('https://resilient.is/test.json')
|
||||
});
|
||||
|
||||
test("it should return data from the wrapped plugin with no integrity data configured when requireIntegrity is true and integrity data is provided in Request() init data", async () => {
|
||||
require("../../plugins/basic-integrity.js");
|
||||
|
||||
init.integrity = {}
|
||||
|
||||
const response = await LibResilientPluginConstructors
|
||||
.get('basic-integrity')(LR, init)
|
||||
.fetch('https://resilient.is/test.json', {
|
||||
integrity: "sha256-Aj9x0DWq9GUL1L8HibLCMa8YLKnV7IYAfpYurqrFwiQ="
|
||||
});
|
||||
|
||||
expect(resolvingFetch).toHaveBeenCalled();
|
||||
expect(resolvingFetch).toHaveBeenCalledWith('https://resilient.is/test.json', {integrity: "sha256-Aj9x0DWq9GUL1L8HibLCMa8YLKnV7IYAfpYurqrFwiQ="});
|
||||
expect(await response.json()).toEqual({test: "success"})
|
||||
expect(response.url).toEqual('https://resilient.is/test.json')
|
||||
});
|
||||
|
||||
test("it should return data from the wrapped plugin with integrity data both configured and coming from Request() init", async () => {
|
||||
require("../../plugins/basic-integrity.js");
|
||||
|
||||
const response = await LibResilientPluginConstructors
|
||||
.get('basic-integrity')(LR, init)
|
||||
.fetch('https://resilient.is/test.json', {
|
||||
integrity: "sha256-Aj9x0DWq9GUL1L8HibLCMa8YLKnV7IYAfpYurqrFwiQ="
|
||||
});
|
||||
|
||||
expect(resolvingFetch).toHaveBeenCalled();
|
||||
expect(resolvingFetch).toHaveBeenCalledWith('https://resilient.is/test.json', {integrity: "sha256-Aj9x0DWq9GUL1L8HibLCMa8YLKnV7IYAfpYurqrFwiQ= sha384-kn5dhxz4RpBmx7xC7Dmq2N43PclV9U/niyh+4Km7oz5W0FaWdz3Op+3K0Qxz8y3z"});
|
||||
expect(await response.json()).toEqual({test: "success"})
|
||||
expect(response.url).toEqual('https://resilient.is/test.json')
|
||||
});
|
||||
|
||||
});
|
||||
|
|
Ładowanie…
Reference in New Issue