-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Delete old integrity urls in PATCH and DELETE endpoints
- Loading branch information
1 parent
2b7e276
commit 31d8cdb
Showing
2 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
const request = require("supertest"); | ||
const { app, setConfig } = require("../src/web-server"); | ||
const { | ||
resetManifest: resetMemoryManifest, | ||
} = require("../src/io-methods/memory"); | ||
|
||
describe(`integrity`, () => { | ||
beforeAll(() => { | ||
setConfig({ | ||
manifestFormat: "importmap", | ||
packagesViaTrailingSlashes: true, | ||
locations: { | ||
prod: "memory://prod", | ||
}, | ||
}); | ||
}); | ||
|
||
beforeEach(() => { | ||
resetMemoryManifest(); | ||
}); | ||
|
||
it(`sets integrity field in import map`, async () => { | ||
const url = "/a.js"; | ||
const integrity = "sha256-example"; | ||
|
||
const response = await request(app) | ||
.patch("/services") | ||
.query({ | ||
skip_url_check: true, | ||
}) | ||
.set("accept", "json") | ||
.send({ | ||
service: "a", | ||
url, | ||
integrity, | ||
}) | ||
.expect(200) | ||
.expect("Content-Type", /json/); | ||
|
||
expect(response.body.integrity).toMatchObject({ | ||
[url]: integrity, | ||
}); | ||
}); | ||
|
||
it(`removes old integrity when patching a service`, async () => { | ||
const url = "/a.js"; | ||
const integrity = "sha256-a"; | ||
|
||
const response = await request(app) | ||
.patch("/services") | ||
.query({ | ||
skip_url_check: true, | ||
}) | ||
.set("accept", "json") | ||
.send({ | ||
service: "a", | ||
url, | ||
integrity, | ||
}) | ||
.expect(200) | ||
.expect("Content-Type", /json/); | ||
|
||
expect(response.body.integrity[url]).not.toBeUndefined(); | ||
|
||
const url2 = "/a2.js"; | ||
const integrity2 = "sha256-a2"; | ||
|
||
const response2 = await request(app) | ||
.patch("/services") | ||
.query({ | ||
skip_url_check: true, | ||
}) | ||
.set("accept", "json") | ||
.send({ | ||
service: "a", | ||
url: url2, | ||
integrity: integrity2, | ||
}) | ||
.expect(200) | ||
.expect("Content-Type", /json/); | ||
|
||
expect(response2.body.integrity[url]).toBeUndefined(); | ||
expect(response2.body.integrity[url2]).not.toBeUndefined(); | ||
}); | ||
|
||
it(`deletes old integrity when deleting a service`, async () => { | ||
const url = "/a.js"; | ||
const integrity = "sha256-example"; | ||
|
||
const response = await request(app) | ||
.patch("/services") | ||
.query({ | ||
skip_url_check: true, | ||
}) | ||
.set("accept", "json") | ||
.send({ | ||
service: "a", | ||
url, | ||
integrity, | ||
}) | ||
.expect(200) | ||
.expect("Content-Type", /json/); | ||
|
||
expect(response.body.integrity).toMatchObject({ | ||
[url]: integrity, | ||
}); | ||
|
||
const response2 = await request(app) | ||
.delete("/services/a") | ||
.set("accept", "json") | ||
.send() | ||
.expect(200) | ||
.expect("Content-Type", /json/); | ||
expect(response2.body.integrity[url]).toBeUndefined(); | ||
}); | ||
}); |