SciCatProject / SciCatProject/backend
Testing access of specific users to the instances by ID
@sofyalaski is already working on this.
Since Mar 20, 2025.
- Dominant language
- TypeScript
- Stars
- 27
- Forks
- 37
- Avg merge
- 17h 32m
- Merged PRs (30d)
- 38
Description
Summary
While testing GET endpoints we have many tests that just compare the number of instances a user should get but not check them by ID. Changing that by also specifying the IDs would make changing tests, avoid mess (especially adding new ones) easier and explicitly check access to correct instances.
Current Behaviour
An example from current master in test/DatasetAuthorization.js:
it("0100: list of datasets for Admin Ingestor", async () => {
return request(appUrl)
.get("/api/v3/Datasets")
.set("Accept", "application/json")
.set({ Authorization: `Bearer ${accessTokenAdminIngestor}` })
.expect(TestData.SuccessfulGetStatusCode)
.expect("Content-Type", /json/)
.then((res) => {
res.body.should.be.an("array").to.have.lengthOf(3);
});
});
This type of test that checks for the length of a response array appears for both v3 and v4 APIs and for datasets, jobs, samples etc.
Expected Behaviour
When these instances get created with post endpoints, assign Ids to them ( done anyway for some of them), reuse them especially in case of complex authorization rules to not only check the array size but also presence of certain Ids:
it("0350: Access jobs as user5", async () => {
return request(appUrl)
.get(`/api/v3/Jobs/`)
.send({})
.set("Accept", "application/json")
.set({ Authorization: `Bearer ${accessTokenUser51}` })
.expect(TestData.SuccessfulGetStatusCode)
.expect("Content-Type", /json/)
.then((res) => {
res.body.should.be.an("array").to.have.lengthOf(2);
res.body.map(job => job.id).should.include.members([jobId4, jobId5]);
});
});
Details
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.